]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/libsrc/standalone_v6_6/src/xil_io.h
Update Zynq, MPSoc Cortex-A53 and MPSoc Cortex-R5 demo projects to build with the...
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / libsrc / standalone_v6_6 / src / xil_io.h
1 /******************************************************************************
2 *
3 * Copyright (C) 2014 - 2016 Xilinx, Inc. All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 *
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
30 *
31 ******************************************************************************/
32 /*****************************************************************************/
33 /**
34 *
35 * @file xil_io.h
36 *
37 * @addtogroup common_io_interfacing_apis Register IO interfacing APIs
38 *
39 * The xil_io.h file contains the interface for the general I/O component, which
40 * encapsulates the Input/Output functions for the processors that do not
41 * require any special I/O handling.
42 *
43 * @{
44 * <pre>
45 * MODIFICATION HISTORY:
46 *
47 * Ver   Who      Date     Changes
48 * ----- -------- -------- -----------------------------------------------
49 * 5.00  pkp      05/29/14 First release
50 * 6.00  mus      08/19/16 Remove checking of __LITTLE_ENDIAN__ flag for
51 *                         ARM processors
52 * </pre>
53 ******************************************************************************/
54
55 #ifndef XIL_IO_H           /* prevent circular inclusions */
56 #define XIL_IO_H           /* by using protection macros */
57
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61
62 /***************************** Include Files *********************************/
63
64 #include "xil_types.h"
65 #include "xil_printf.h"
66
67 #if defined (__MICROBLAZE__)
68 #include "mb_interface.h"
69 #else
70 #include "xpseudo_asm.h"
71 #endif
72
73 /************************** Function Prototypes ******************************/
74 u16 Xil_EndianSwap16(u16 Data);
75 u32 Xil_EndianSwap32(u32 Data);
76 #ifdef ENABLE_SAFETY
77 extern u32 XStl_RegUpdate(u32 RegAddr, u32 RegVal);
78 #endif
79
80 /***************** Macros (Inline Functions) Definitions *********************/
81 #if defined __GNUC__
82 #if defined (__MICROBLAZE__)
83 #  define INST_SYNC             mbar(0)
84 #  define DATA_SYNC             mbar(1)
85 # else
86 #  define SYNCHRONIZE_IO        dmb()
87 #  define INST_SYNC             isb()
88 #  define DATA_SYNC             dsb()
89 # endif
90 #else
91 # define SYNCHRONIZE_IO
92 # define INST_SYNC
93 # define DATA_SYNC
94 # define INST_SYNC
95 # define DATA_SYNC
96 #endif
97
98 #if defined (__GNUC__) || defined (__ICCARM__) || defined (__MICROBLAZE__)
99 #define INLINE inline
100 #else
101 #define INLINE __inline
102 #endif
103
104 /*****************************************************************************/
105 /**
106 *
107 * @brief    Performs an input operation for a memory location by reading
108 *           from the specified address and returning the 8 bit Value read from
109 *            that address.
110 *
111 * @param        Addr: contains the address to perform the input operation
112 *
113 * @return       The 8 bit Value read from the specified input address.
114
115 *
116 ******************************************************************************/
117 static INLINE u8 Xil_In8(UINTPTR Addr)
118 {
119         return *(volatile u8 *) Addr;
120 }
121
122 /*****************************************************************************/
123 /**
124 *
125 * @brief    Performs an input operation for a memory location by reading from
126 *           the specified address and returning the 16 bit Value read from that
127 *           address.
128 *
129 * @param        Addr: contains the address to perform the input operation
130 *
131 * @return       The 16 bit Value read from the specified input address.
132 *
133 ******************************************************************************/
134 static INLINE u16 Xil_In16(UINTPTR Addr)
135 {
136         return *(volatile u16 *) Addr;
137 }
138
139 /*****************************************************************************/
140 /**
141 *
142 * @brief    Performs an input operation for a memory location by
143 *           reading from the specified address and returning the 32 bit Value
144 *           read  from that address.
145 *
146 * @param        Addr: contains the address to perform the input operation
147 *
148 * @return       The 32 bit Value read from the specified input address.
149 *
150 ******************************************************************************/
151 static INLINE u32 Xil_In32(UINTPTR Addr)
152 {
153         return *(volatile u32 *) Addr;
154 }
155
156 /*****************************************************************************/
157 /**
158 *
159 * @brief     Performs an input operation for a memory location by reading the
160 *            64 bit Value read  from that address.
161 *
162 *
163 * @param        Addr: contains the address to perform the input operation
164 *
165 * @return       The 64 bit Value read from the specified input address.
166 *
167 ******************************************************************************/
168 static INLINE u64 Xil_In64(UINTPTR Addr)
169 {
170         return *(volatile u64 *) Addr;
171 }
172
173 /*****************************************************************************/
174 /**
175 *
176 * @brief    Performs an output operation for an memory location by
177 *           writing the 8 bit Value to the the specified address.
178 *
179 * @param        Addr: contains the address to perform the output operation
180 * @param        Value: contains the 8 bit Value to be written at the specified
181 *           address.
182 *
183 * @return       None.
184 *
185 ******************************************************************************/
186 static INLINE void Xil_Out8(UINTPTR Addr, u8 Value)
187 {
188         volatile u8 *LocalAddr = (volatile u8 *)Addr;
189         *LocalAddr = Value;
190 }
191
192 /*****************************************************************************/
193 /**
194 *
195 * @brief    Performs an output operation for a memory location by writing the
196 *            16 bit Value to the the specified address.
197 *
198 * @param        Addr contains the address to perform the output operation
199 * @param        Value contains the Value to be written at the specified address.
200 *
201 * @return       None.
202 *
203 ******************************************************************************/
204 static INLINE void Xil_Out16(UINTPTR Addr, u16 Value)
205 {
206         volatile u16 *LocalAddr = (volatile u16 *)Addr;
207         *LocalAddr = Value;
208 }
209
210 /*****************************************************************************/
211 /**
212 *
213 * @brief    Performs an output operation for a memory location by writing the
214 *           32 bit Value to the the specified address.
215 *
216 * @param        Addr contains the address to perform the output operation
217 * @param        Value contains the 32 bit Value to be written at the specified
218 *           address.
219 *
220 * @return       None.
221 *
222 ******************************************************************************/
223 static INLINE void Xil_Out32(UINTPTR Addr, u32 Value)
224 {
225 #ifndef ENABLE_SAFETY
226         volatile u32 *LocalAddr = (volatile u32 *)Addr;
227         *LocalAddr = Value;
228 #else
229         XStl_RegUpdate(Addr, Value);
230 #endif
231 }
232
233 /*****************************************************************************/
234 /**
235 *
236 * @brief    Performs an output operation for a memory location by writing the
237 *           64 bit Value to the the specified address.
238 *
239 * @param        Addr contains the address to perform the output operation
240 * @param        Value contains 64 bit Value to be written at the specified address.
241 *
242 * @return       None.
243 *
244 ******************************************************************************/
245 static INLINE void Xil_Out64(UINTPTR Addr, u64 Value)
246 {
247         volatile u64 *LocalAddr = (volatile u64 *)Addr;
248         *LocalAddr = Value;
249 }
250
251 #if defined (__MICROBLAZE__)
252 #ifdef __LITTLE_ENDIAN__
253 # define Xil_In16LE     Xil_In16
254 # define Xil_In32LE     Xil_In32
255 # define Xil_Out16LE    Xil_Out16
256 # define Xil_Out32LE    Xil_Out32
257 # define Xil_Htons      Xil_EndianSwap16
258 # define Xil_Htonl      Xil_EndianSwap32
259 # define Xil_Ntohs      Xil_EndianSwap16
260 # define Xil_Ntohl      Xil_EndianSwap32
261 # else
262 # define Xil_In16BE     Xil_In16
263 # define Xil_In32BE     Xil_In32
264 # define Xil_Out16BE    Xil_Out16
265 # define Xil_Out32BE    Xil_Out32
266 # define Xil_Htons(Data) (Data)
267 # define Xil_Htonl(Data) (Data)
268 # define Xil_Ntohs(Data) (Data)
269 # define Xil_Ntohl(Data) (Data)
270 #endif
271 #else
272 # define Xil_In16LE     Xil_In16
273 # define Xil_In32LE     Xil_In32
274 # define Xil_Out16LE    Xil_Out16
275 # define Xil_Out32LE    Xil_Out32
276 # define Xil_Htons      Xil_EndianSwap16
277 # define Xil_Htonl      Xil_EndianSwap32
278 # define Xil_Ntohs      Xil_EndianSwap16
279 # define Xil_Ntohl      Xil_EndianSwap32
280 #endif
281
282 #if defined (__MICROBLAZE__)
283 #ifdef __LITTLE_ENDIAN__
284 static INLINE u16 Xil_In16BE(UINTPTR Addr)
285 #else
286 static INLINE u16 Xil_In16LE(UINTPTR Addr)
287 #endif
288 #else
289 static INLINE u16 Xil_In16BE(UINTPTR Addr)
290 #endif
291 {
292         u16 value = Xil_In16(Addr);
293         return Xil_EndianSwap16(value);
294 }
295
296 #if defined (__MICROBLAZE__)
297 #ifdef __LITTLE_ENDIAN__
298 static INLINE u32 Xil_In32BE(UINTPTR Addr)
299 #else
300 static INLINE u32 Xil_In32LE(UINTPTR Addr)
301 #endif
302 #else
303 static INLINE u32 Xil_In32BE(UINTPTR Addr)
304 #endif
305 {
306         u32 value = Xil_In32(Addr);
307         return Xil_EndianSwap32(value);
308 }
309
310 #if defined (__MICROBLAZE__)
311 #ifdef __LITTLE_ENDIAN__
312 static INLINE void Xil_Out16BE(UINTPTR Addr, u16 Value)
313 #else
314 static INLINE void Xil_Out16LE(UINTPTR Addr, u16 Value)
315 #endif
316 #else
317 static INLINE void Xil_Out16BE(UINTPTR Addr, u16 Value)
318 #endif
319 {
320         Value = Xil_EndianSwap16(Value);
321         Xil_Out16(Addr, Value);
322 }
323
324 #if defined (__MICROBLAZE__)
325 #ifdef __LITTLE_ENDIAN__
326 static INLINE void Xil_Out32BE(UINTPTR Addr, u32 Value)
327 #else
328 static INLINE void Xil_Out32LE(UINTPTR Addr, u32 Value)
329 #endif
330 #else
331 static INLINE void Xil_Out32BE(UINTPTR Addr, u32 Value)
332 #endif
333 {
334         Value = Xil_EndianSwap32(Value);
335         Xil_Out32(Addr, Value);
336 }
337
338 #ifdef __cplusplus
339 }
340 #endif
341
342 #endif /* end of protection macro */
343 /**
344 * @} End of "addtogroup common_io_interfacing_apis".
345 */