]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/standalone_v5_4/src/xil_io.h
Update the Microblaze hardware design and BSP to the latest IP and tool versions.
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / BSP / microblaze_0 / libsrc / standalone_v5_4 / src / xil_io.h
1 /******************************************************************************
2 *
3 * Copyright (C) 2009 - 2014 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 * This file contains the interface for the general IO component, which
38 * encapsulates the Input/Output functions for processors that do not
39 * require any special I/O handling.
40 *
41 * <pre>
42 * MODIFICATION HISTORY:
43 *
44 * Ver   Who  Date     Changes
45 * ----- ---- -------- -------------------------------------------------------
46 * 3.00a hbm  07/28/09 Initial release
47 * 3.00a hbm  07/21/10 Added Xil_EndianSwap32/16, Xil_Htonl/s, Xil_Ntohl/s
48 * 3.03a sdm  08/18/11 Added INST_SYNC and DATA_SYNC macros.
49 * 3.07a asa  08/31/12 Added xil_printf.h include
50 * 5.4   sk   01/14/16 Changed xil_io() and xil_out() functions to static inline
51 *                     functions.
52 *
53 * </pre>
54 *
55 * @note
56 *
57 * This file may contain architecture-dependent items.
58 *
59 ******************************************************************************/
60
61 #ifndef XIL_IO_H                        /* prevent circular inclusions */
62 #define XIL_IO_H                        /* by using protection macros */
63
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67
68 /***************************** Include Files *********************************/
69
70 #include "xil_types.h"
71 #include "mb_interface.h"
72 #include "xil_printf.h"
73
74 /************************** Constant Definitions *****************************/
75
76 /**************************** Function Prototypes ****************************/
77
78 static inline u8 Xil_In8(UINTPTR Addr);
79 static inline u16 Xil_In16(UINTPTR Addr);
80 static inline u32 Xil_In32(UINTPTR Addr);
81
82 static inline void Xil_Out8(UINTPTR Addr, u8 Value);
83 static inline void Xil_Out16(UINTPTR Addr, u16 Value);
84 static inline void Xil_Out32(UINTPTR Addr, u32 Value);
85
86 /***************** Macros (Inline Functions) Definitions *********************/
87
88 /*****************************************************************************/
89 /**
90 *
91 * Perform an input operation for an 8-bit memory location by reading from the
92 * specified address and returning the value read from that address.
93 *
94 * @param        Addr contains the address to perform the input operation at.
95 *
96 * @return       The value read from the specified input address.
97 *
98 * @note         None.
99 *
100 ******************************************************************************/
101 static inline u8 Xil_In8(UINTPTR Addr) {
102         return *(volatile u8 *)Addr;
103 }
104
105 /*****************************************************************************/
106 /**
107 *
108 * Perform an input operation for a 16-bit memory location by reading from the
109 * specified address and returning the value read from that address.
110 *
111 * @param        Addr contains the address to perform the input operation at.
112 *
113 * @return       The value read from the specified input address.
114 *
115 * @note         None.
116 *
117 ******************************************************************************/
118 static inline u16 Xil_In16(UINTPTR Addr) {
119         return *(volatile u16 *)Addr;
120 }
121
122 /*****************************************************************************/
123 /**
124 *
125 * Performs an input operation for a 32-bit memory location by reading from the
126 * specified address and returning the Value read from that address.
127 *
128 * @param        Addr contains the address to perform the input operation at.
129 *
130 * @return       The value read from the specified input address.
131 *
132 * @note         None.
133 *
134 ******************************************************************************/
135 static inline u32 Xil_In32(UINTPTR Addr) {
136         return *(volatile u32 *)Addr;
137 }
138
139
140 /*****************************************************************************/
141 /**
142 *
143 * Perform an output operation for an 8-bit memory location by writing the
144 * specified value to the specified address.
145 *
146 * @param        Addr contains the address to perform the output operation at.
147 * @param        value contains the value to be output at the specified address.
148 *
149 * @return       None
150 *
151 * @note         None.
152 *
153 ******************************************************************************/
154 static inline void Xil_Out8(UINTPTR Addr, u8 Value) {
155         volatile u8 *LocalAddr = (u8 *)Addr;
156         *LocalAddr = Value;
157 }
158
159 /*****************************************************************************/
160 /**
161 *
162 * Perform an output operation for a 16-bit memory location by writing the
163 * specified value to the specified address.
164 *
165 * @param        Addr contains the address to perform the output operation at.
166 * @param        value contains the value to be output at the specified address.
167 *
168 * @return       None
169 *
170 * @note         None.
171 *
172 ******************************************************************************/
173 static inline void Xil_Out16(UINTPTR Addr, u16 Value) {
174         volatile u16 *LocalAddr = (u16 *)Addr;
175         *LocalAddr = Value;
176 }
177
178 /*****************************************************************************/
179 /**
180 *
181 * Perform an output operation for a 32-bit memory location by writing the
182 * specified value to the specified address.
183 *
184 * @param        addr contains the address to perform the output operation at.
185 * @param        value contains the value to be output at the specified address.
186 *
187 * @return       None
188 *
189 * @note         None.
190 *
191 ******************************************************************************/
192 static inline void Xil_Out32(UINTPTR Addr, u32 Value) {
193         volatile u32 *LocalAddr = (u32 *)Addr;
194         *LocalAddr = Value;
195 }
196
197 #if defined __GNUC__
198 #  define INST_SYNC             mbar(0)
199 #  define DATA_SYNC             mbar(1)
200 #else
201 #  define INST_SYNC
202 #  define DATA_SYNC
203 #endif /* __GNUC__ */
204
205 /*
206  * The following macros allow optimized I/O operations for memory mapped I/O.
207  * It should be noted that macros cannot be used if synchronization of the I/O
208  * operation is needed as it will likely break some code.
209  */
210
211
212
213 extern u16 Xil_EndianSwap16(u16 Data);
214 extern u32 Xil_EndianSwap32(u32 Data);
215
216 #ifndef __LITTLE_ENDIAN__
217 extern u16 Xil_In16LE(UINTPTR Addr);
218 extern u32 Xil_In32LE(UINTPTR Addr);
219 extern void Xil_Out16LE(UINTPTR Addr, u16 Value);
220 extern void Xil_Out32LE(UINTPTR Addr, u32 Value);
221
222 /**
223 *
224 * Perform an big-endian input operation for a 16-bit memory location
225 * by reading from the specified address and returning the value read from
226 * that address.
227 *
228 * @param        addr contains the address to perform the input operation at.
229 *
230 * @return       The value read from the specified input address with the
231 *               proper endianness. The return value has the same endianness
232 *               as that of the processor, i.e. if the processor is
233 *               little-engian, the return value is the byte-swapped value read
234 *               from the address.
235 *
236 * @note         None.
237 *
238 ******************************************************************************/
239 #define Xil_In16BE(Addr) Xil_In16((Addr))
240
241 /**
242 *
243 * Perform a big-endian input operation for a 32-bit memory location
244 * by reading from the specified address and returning the value read from
245 * that address.
246 *
247 * @param        Addr contains the address to perform the input operation at.
248 *
249 * @return       The value read from the specified input address with the
250 *               proper endianness. The return value has the same endianness
251 *               as that of the processor, i.e. if the processor is
252 *               little-engian, the return value is the byte-swapped value read
253 *               from the address.
254 *
255 *
256 * @note         None.
257 *
258 ******************************************************************************/
259 #define Xil_In32BE(Addr) Xil_In32((Addr))
260
261 /*****************************************************************************/
262 /**
263 *
264 * Perform a big-endian output operation for a 16-bit memory location
265 * by writing the specified value to the specified address.
266 *
267 * @param        Addr contains the address to perform the output operation at.
268 * @param        Value contains the value to be output at the specified address.
269 *               The value has the same endianness as that of the processor.
270 *               If the processor is little-endian, the byte-swapped value is
271 *               written to the address.
272 *
273 *
274 * @return       None
275 *
276 * @note         None.
277 *
278 ******************************************************************************/
279 #define Xil_Out16BE(Addr, Value) Xil_Out16((Addr), (Value))
280
281 /*****************************************************************************/
282 /**
283 *
284 * Perform a big-endian output operation for a 32-bit memory location
285 * by writing the specified value to the specified address.
286 *
287 * @param        Addr contains the address to perform the output operation at.
288 * @param        Value contains the value to be output at the specified address.
289 *               The value has the same endianness as that of the processor.
290 *               If the processor is little-endian, the byte-swapped value is
291 *               written to the address.
292 *
293 * @return       None
294 *
295 * @note         None.
296 *
297 ******************************************************************************/
298 #define Xil_Out32BE(Addr, Value) Xil_Out32((Addr), (Value))
299
300 #define Xil_Htonl(Data) (Data)
301 #define Xil_Htons(Data) (Data)
302 #define Xil_Ntohl(Data) (Data)
303 #define Xil_Ntohs(Data) (Data)
304
305 #else
306
307 extern u16 Xil_In16BE(UINTPTR Addr);
308 extern u32 Xil_In32BE(UINTPTR Addr);
309 extern void Xil_Out16BE(UINTPTR Addr, u16 Value);
310 extern void Xil_Out32BE(UINTPTR Addr, u32 Value);
311
312 #define Xil_In16LE(Addr) Xil_In16((Addr))
313 #define Xil_In32LE(Addr) Xil_In32((Addr))
314 #define Xil_Out16LE(Addr, Value) Xil_Out16((Addr), (Value))
315 #define Xil_Out32LE(Addr, Value) Xil_Out32((Addr), (Value))
316
317
318 /*****************************************************************************/
319 /**
320 *
321 * Convert a 32-bit number from host byte order to network byte order.
322 *
323 * @param        Data the 32-bit number to be converted.
324 *
325 * @return       The converted 32-bit number in network byte order.
326 *
327 * @note         None.
328 *
329 ******************************************************************************/
330 #define Xil_Htonl(Data) Xil_EndianSwap32((Data))
331
332 /*****************************************************************************/
333 /**
334 *
335 * Convert a 16-bit number from host byte order to network byte order.
336 *
337 * @param        Data the 16-bit number to be converted.
338 *
339 * @return       The converted 16-bit number in network byte order.
340 *
341 * @note         None.
342 *
343 ******************************************************************************/
344 #define Xil_Htons(Data) Xil_EndianSwap16((Data))
345
346 /*****************************************************************************/
347 /**
348 *
349 * Convert a 32-bit number from network byte order to host byte order.
350 *
351 * @param        Value the 32-bit number to be converted.
352 *
353 * @return       The converted 32-bit number in host byte order.
354 *
355 * @note         None.
356 *
357 ******************************************************************************/
358 #define Xil_Ntohl(Data) Xil_EndianSwap32((Data))
359
360 /*****************************************************************************/
361 /**
362 *
363 * Convert a 16-bit number from network byte order to host byte order.
364 *
365 * @param        Value the 16-bit number to be converted.
366 *
367 * @return       The converted 16-bit number in host byte order.
368 *
369 * @note         None.
370 *
371 ******************************************************************************/
372 #define Xil_Ntohs(Data) Xil_EndianSwap16((Data))
373
374 #endif
375
376 #ifdef __cplusplus
377 }
378 #endif
379
380 #endif /* end of protection macro */