1 /******************************************************************************
3 * Copyright (C) 2014 - 2016 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 * @addtogroup common_io_interfacing_apis Register IO interfacing APIs
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.
45 * MODIFICATION HISTORY:
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
53 ******************************************************************************/
55 #ifndef XIL_IO_H /* prevent circular inclusions */
56 #define XIL_IO_H /* by using protection macros */
62 /***************************** Include Files *********************************/
64 #include "xil_types.h"
65 #include "xil_printf.h"
67 #if defined (__MICROBLAZE__)
68 #include "mb_interface.h"
70 #include "xpseudo_asm.h"
73 /************************** Function Prototypes ******************************/
74 u16 Xil_EndianSwap16(u16 Data);
75 u32 Xil_EndianSwap32(u32 Data);
77 extern u32 XStl_RegUpdate(u32 RegAddr, u32 RegVal);
80 /***************** Macros (Inline Functions) Definitions *********************/
82 #if defined (__MICROBLAZE__)
83 # define INST_SYNC mbar(0)
84 # define DATA_SYNC mbar(1)
86 # define SYNCHRONIZE_IO dmb()
87 # define INST_SYNC isb()
88 # define DATA_SYNC dsb()
91 # define SYNCHRONIZE_IO
98 #if defined (__GNUC__) || defined (__ICCARM__) || defined (__MICROBLAZE__)
101 #define INLINE __inline
104 /*****************************************************************************/
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
111 * @param Addr: contains the address to perform the input operation
113 * @return The 8 bit Value read from the specified input address.
116 ******************************************************************************/
117 static INLINE u8 Xil_In8(UINTPTR Addr)
119 return *(volatile u8 *) Addr;
122 /*****************************************************************************/
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
129 * @param Addr: contains the address to perform the input operation
131 * @return The 16 bit Value read from the specified input address.
133 ******************************************************************************/
134 static INLINE u16 Xil_In16(UINTPTR Addr)
136 return *(volatile u16 *) Addr;
139 /*****************************************************************************/
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.
146 * @param Addr: contains the address to perform the input operation
148 * @return The 32 bit Value read from the specified input address.
150 ******************************************************************************/
151 static INLINE u32 Xil_In32(UINTPTR Addr)
153 return *(volatile u32 *) Addr;
156 /*****************************************************************************/
159 * @brief Performs an input operation for a memory location by reading the
160 * 64 bit Value read from that address.
163 * @param Addr: contains the address to perform the input operation
165 * @return The 64 bit Value read from the specified input address.
167 ******************************************************************************/
168 static INLINE u64 Xil_In64(UINTPTR Addr)
170 return *(volatile u64 *) Addr;
173 /*****************************************************************************/
176 * @brief Performs an output operation for an memory location by
177 * writing the 8 bit Value to the the specified address.
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
185 ******************************************************************************/
186 static INLINE void Xil_Out8(UINTPTR Addr, u8 Value)
188 volatile u8 *LocalAddr = (volatile u8 *)Addr;
192 /*****************************************************************************/
195 * @brief Performs an output operation for a memory location by writing the
196 * 16 bit Value to the the specified address.
198 * @param Addr contains the address to perform the output operation
199 * @param Value contains the Value to be written at the specified address.
203 ******************************************************************************/
204 static INLINE void Xil_Out16(UINTPTR Addr, u16 Value)
206 volatile u16 *LocalAddr = (volatile u16 *)Addr;
210 /*****************************************************************************/
213 * @brief Performs an output operation for a memory location by writing the
214 * 32 bit Value to the the specified address.
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
222 ******************************************************************************/
223 static INLINE void Xil_Out32(UINTPTR Addr, u32 Value)
225 #ifndef ENABLE_SAFETY
226 volatile u32 *LocalAddr = (volatile u32 *)Addr;
229 XStl_RegUpdate(Addr, Value);
233 /*****************************************************************************/
236 * @brief Performs an output operation for a memory location by writing the
237 * 64 bit Value to the the specified address.
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.
244 ******************************************************************************/
245 static INLINE void Xil_Out64(UINTPTR Addr, u64 Value)
247 volatile u64 *LocalAddr = (volatile u64 *)Addr;
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
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)
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
282 #if defined (__MICROBLAZE__)
283 #ifdef __LITTLE_ENDIAN__
284 static INLINE u16 Xil_In16BE(UINTPTR Addr)
286 static INLINE u16 Xil_In16LE(UINTPTR Addr)
289 static INLINE u16 Xil_In16BE(UINTPTR Addr)
292 u16 value = Xil_In16(Addr);
293 return Xil_EndianSwap16(value);
296 #if defined (__MICROBLAZE__)
297 #ifdef __LITTLE_ENDIAN__
298 static INLINE u32 Xil_In32BE(UINTPTR Addr)
300 static INLINE u32 Xil_In32LE(UINTPTR Addr)
303 static INLINE u32 Xil_In32BE(UINTPTR Addr)
306 u32 value = Xil_In32(Addr);
307 return Xil_EndianSwap32(value);
310 #if defined (__MICROBLAZE__)
311 #ifdef __LITTLE_ENDIAN__
312 static INLINE void Xil_Out16BE(UINTPTR Addr, u16 Value)
314 static INLINE void Xil_Out16LE(UINTPTR Addr, u16 Value)
317 static INLINE void Xil_Out16BE(UINTPTR Addr, u16 Value)
320 Value = Xil_EndianSwap16(Value);
321 Xil_Out16(Addr, Value);
324 #if defined (__MICROBLAZE__)
325 #ifdef __LITTLE_ENDIAN__
326 static INLINE void Xil_Out32BE(UINTPTR Addr, u32 Value)
328 static INLINE void Xil_Out32LE(UINTPTR Addr, u32 Value)
331 static INLINE void Xil_Out32BE(UINTPTR Addr, u32 Value)
334 Value = Xil_EndianSwap32(Value);
335 Xil_Out32(Addr, Value);
342 #endif /* end of protection macro */
344 * @} End of "addtogroup common_io_interfacing_apis".