1 /******************************************************************************
3 * Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
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
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.
31 ******************************************************************************/
32 /*****************************************************************************/
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.
42 * MODIFICATION HISTORY:
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
55 * This file may contain architecture-dependent items.
57 ******************************************************************************/
59 #ifndef XIL_IO_H /* prevent circular inclusions */
60 #define XIL_IO_H /* by using protection macros */
66 /***************************** Include Files *********************************/
68 #include "xil_types.h"
69 #include "mb_interface.h"
70 #include "xil_printf.h"
72 /************************** Constant Definitions *****************************/
74 /**************************** Type Definitions *******************************/
76 /***************** Macros (Inline Functions) Definitions *********************/
79 # define INST_SYNC mbar(0)
80 # define DATA_SYNC mbar(1)
87 * The following macros allow optimized I/O operations for memory mapped I/O.
88 * It should be noted that macros cannot be used if synchronization of the I/O
89 * operation is needed as it will likely break some code.
92 /*****************************************************************************/
95 * Perform an input operation for an 8-bit memory location by reading from the
96 * specified address and returning the value read from that address.
98 * @param Addr contains the address to perform the input operation at.
100 * @return The value read from the specified input address.
104 ******************************************************************************/
105 #define Xil_In8(Addr) (*(volatile u8 *)(Addr))
107 /*****************************************************************************/
110 * Perform an input operation for a 16-bit memory location by reading from the
111 * specified address and returning the value read from that address.
113 * @param Addr contains the address to perform the input operation at.
115 * @return The value read from the specified input address.
119 ******************************************************************************/
120 #define Xil_In16(Addr) (*(volatile u16 *)(Addr))
122 /*****************************************************************************/
125 * Perform an input operation for a 32-bit memory location by reading from the
126 * specified address and returning the value read from that address.
128 * @param Addr contains the address to perform the input operation at.
130 * @return The value read from the specified input address.
134 ******************************************************************************/
135 #define Xil_In32(Addr) (*(volatile u32 *)(Addr))
138 /*****************************************************************************/
141 * Perform an output operation for an 8-bit memory location by writing the
142 * specified value to the specified address.
144 * @param Addr contains the address to perform the output operation at.
145 * @param value contains the value to be output at the specified address.
151 ******************************************************************************/
152 #define Xil_Out8(Addr, Value) \
153 (*(volatile u8 *)((Addr)) = (Value))
155 /*****************************************************************************/
158 * Perform an output operation for a 16-bit memory location by writing the
159 * specified value to the specified address.
161 * @param Addr contains the address to perform the output operation at.
162 * @param value contains the value to be output at the specified address.
168 ******************************************************************************/
169 #define Xil_Out16(Addr, Value) \
170 (*(volatile u16 *)((Addr)) = (Value))
172 /*****************************************************************************/
175 * Perform an output operation for a 32-bit memory location by writing the
176 * specified value to the specified address.
178 * @param addr contains the address to perform the output operation at.
179 * @param value contains the value to be output at the specified address.
185 ******************************************************************************/
186 #define Xil_Out32(Addr, Value) \
187 (*(volatile u32 *)((Addr)) = (Value))
190 extern u16 Xil_EndianSwap16(u16 Data);
191 extern u32 Xil_EndianSwap32(u32 Data);
193 #ifndef __LITTLE_ENDIAN__
194 extern u16 Xil_In16LE(u32 Addr);
195 extern u32 Xil_In32LE(u32 Addr);
196 extern void Xil_Out16LE(u32 Addr, u16 Value);
197 extern void Xil_Out32LE(u32 Addr, u32 Value);
201 * Perform an big-endian input operation for a 16-bit memory location
202 * by reading from the specified address and returning the value read from
205 * @param addr contains the address to perform the input operation at.
207 * @return The value read from the specified input address with the
208 * proper endianness. The return value has the same endianness
209 * as that of the processor, i.e. if the processor is
210 * little-engian, the return value is the byte-swapped value read
215 ******************************************************************************/
216 #define Xil_In16BE(Addr) Xil_In16(Addr)
220 * Perform a big-endian input operation for a 32-bit memory location
221 * by reading from the specified address and returning the value read from
224 * @param Addr contains the address to perform the input operation at.
226 * @return The value read from the specified input address with the
227 * proper endianness. The return value has the same endianness
228 * as that of the processor, i.e. if the processor is
229 * little-engian, the return value is the byte-swapped value read
235 ******************************************************************************/
236 #define Xil_In32BE(Addr) Xil_In32(Addr)
238 /*****************************************************************************/
241 * Perform a big-endian output operation for a 16-bit memory location
242 * by writing the specified value to the specified address.
244 * @param Addr contains the address to perform the output operation at.
245 * @param Value contains the value to be output at the specified address.
246 * The value has the same endianness as that of the processor.
247 * If the processor is little-endian, the byte-swapped value is
248 * written to the address.
255 ******************************************************************************/
256 #define Xil_Out16BE(Addr, Value) Xil_Out16(Addr, Value)
258 /*****************************************************************************/
261 * Perform a big-endian output operation for a 32-bit memory location
262 * by writing the specified value to the specified address.
264 * @param Addr contains the address to perform the output operation at.
265 * @param Value contains the value to be output at the specified address.
266 * The value has the same endianness as that of the processor.
267 * If the processor is little-endian, the byte-swapped value is
268 * written to the address.
274 ******************************************************************************/
275 #define Xil_Out32BE(Addr, Value) Xil_Out32(Addr, Value)
277 #define Xil_Htonl(Data) (Data)
278 #define Xil_Htons(Data) (Data)
279 #define Xil_Ntohl(Data) (Data)
280 #define Xil_Ntohs(Data) (Data)
284 extern u16 Xil_In16BE(u32 Addr);
285 extern u32 Xil_In32BE(u32 Addr);
286 extern void Xil_Out16BE(u32 Addr, u16 Value);
287 extern void Xil_Out32BE(u32 Addr, u32 Value);
289 #define Xil_In16LE(Addr) Xil_In16(Addr)
290 #define Xil_In32LE(Addr) Xil_In32(Addr)
291 #define Xil_Out16LE(Addr, Value) Xil_Out16(Addr, Value)
292 #define Xil_Out32LE(Addr, Value) Xil_Out32(Addr, Value)
295 /*****************************************************************************/
298 * Convert a 32-bit number from host byte order to network byte order.
300 * @param Data the 32-bit number to be converted.
302 * @return The converted 32-bit number in network byte order.
306 ******************************************************************************/
307 #define Xil_Htonl(Data) Xil_EndianSwap32(Data)
309 /*****************************************************************************/
312 * Convert a 16-bit number from host byte order to network byte order.
314 * @param Data the 16-bit number to be converted.
316 * @return The converted 16-bit number in network byte order.
320 ******************************************************************************/
321 #define Xil_Htons(Data) Xil_EndianSwap16(Data)
323 /*****************************************************************************/
326 * Convert a 32-bit number from network byte order to host byte order.
328 * @param Value the 32-bit number to be converted.
330 * @return The converted 32-bit number in host byte order.
334 ******************************************************************************/
335 #define Xil_Ntohl(Data) Xil_EndianSwap32(Data)
337 /*****************************************************************************/
340 * Convert a 16-bit number from network byte order to host byte order.
342 * @param Value the 16-bit number to be converted.
344 * @return The converted 16-bit number in host byte order.
348 ******************************************************************************/
349 #define Xil_Ntohs(Data) Xil_EndianSwap16(Data)
357 #endif /* end of protection macro */