1 /******************************************************************************
3 * Copyright (C) 2014 - 2015 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 * Contains I/O functions for memory-mapped or non-memory-mapped I/O
38 * architectures. These functions encapsulate Cortex R5 architecture-specific
43 * This file contains architecture-dependent code.
46 * MODIFICATION HISTORY:
48 * Ver Who Date Changes
49 * ----- -------- -------- -----------------------------------------------
50 * 5.00 pkp 02/20/14 First release
52 ******************************************************************************/
55 /***************************** Include Files *********************************/
57 #include "xil_types.h"
58 #include "xil_assert.h"
59 #include "xpseudo_asm.h"
60 #include "xreg_cortexr5.h"
62 /************************** Constant Definitions *****************************/
64 /**************************** Type Definitions *******************************/
66 /***************** Macros (Inline Functions) Definitions *********************/
68 /************************** Function Prototypes ******************************/
70 /*****************************************************************************/
73 * Performs an input operation for an 8-bit memory location by reading from the
74 * specified address and returning the Value read from that address.
76 * @param Addr contains the address to perform the input operation
79 * @return The Value read from the specified input address.
83 ******************************************************************************/
84 u8 Xil_In8(INTPTR Addr)
86 return *(volatile u8 *) Addr;
89 /*****************************************************************************/
92 * Performs an input operation for a 16-bit memory location by reading from the
93 * specified address and returning the Value read from that address.
95 * @param Addr contains the address to perform the input operation
98 * @return The Value read from the specified input address.
102 ******************************************************************************/
103 u16 Xil_In16(INTPTR Addr)
105 return *(volatile u16 *) Addr;
108 /*****************************************************************************/
111 * Performs an input operation for a 32-bit memory location by reading from the
112 * specified address and returning the Value read from that address.
114 * @param Addr contains the address to perform the input operation
117 * @return The Value read from the specified input address.
121 ******************************************************************************/
122 u32 Xil_In32(INTPTR Addr)
124 return *(volatile u32 *) Addr;
127 /*****************************************************************************/
130 * Performs an output operation for an 8-bit memory location by writing the
131 * specified Value to the the specified address.
133 * @param Addr contains the address to perform the output operation
135 * @param Value contains the Value to be output at the specified address.
141 ******************************************************************************/
142 void Xil_Out8(INTPTR Addr, u8 Value)
144 volatile u8 *LocalAddr = (u8 *)Addr;
148 /*****************************************************************************/
151 * Performs an output operation for a 16-bit memory location by writing the
152 * specified Value to the the specified address.
154 * @param Addr contains the address to perform the output operation
156 * @param Value contains the Value to be output at the specified address.
162 ******************************************************************************/
163 void Xil_Out16(INTPTR Addr, u16 Value)
165 volatile u16 *LocalAddr = (u16 *)Addr;
169 /*****************************************************************************/
172 * Performs an output operation for a 32-bit memory location by writing the
173 * specified Value to the the specified address.
175 * @param Addr contains the address to perform the output operation
177 * @param Value contains the Value to be output at the specified address.
183 ******************************************************************************/
184 void Xil_Out32(INTPTR Addr, u32 Value)
186 volatile u32 *LocalAddr = (u32 *)Addr;
189 /*****************************************************************************/
192 * Performs an output operation for a 64-bit memory location by writing the
193 * specified Value to the the specified address.
195 * @param Addr contains the address to perform the output operation
197 * @param Value contains the Value to be output at the specified address.
203 ******************************************************************************/
204 void Xil_Out64(INTPTR Addr, u64 Value)
206 volatile u64 *LocalAddr = (u64 *)Addr;
210 /*****************************************************************************/
213 * Performs an input operation for a 64-bit memory location by reading the
214 * specified Value to the the specified address.
216 * @param Addr contains the address to perform the output operation
218 * @param Value contains the Value to be output at the specified address.
224 ******************************************************************************/
225 u64 Xil_In64(INTPTR Addr)
227 return *(volatile u64 *) Addr;
229 /*****************************************************************************/
232 * Performs an input operation for a 16-bit memory location by reading from the
233 * specified address and returning the byte-swapped Value read from that
236 * @param Addr contains the address to perform the input operation
239 * @return The byte-swapped Value read from the specified input address.
243 ******************************************************************************/
244 u16 Xil_In16BE(INTPTR Addr)
249 temp = Xil_In16(Addr);
251 result = Xil_EndianSwap16(temp);
256 /*****************************************************************************/
259 * Performs an input operation for a 32-bit memory location by reading from the
260 * specified address and returning the byte-swapped Value read from that
263 * @param Addr contains the address to perform the input operation
266 * @return The byte-swapped Value read from the specified input address.
270 ******************************************************************************/
271 u32 Xil_In32BE(INTPTR Addr)
276 temp = Xil_In32(Addr);
278 result = Xil_EndianSwap32(temp);
283 /*****************************************************************************/
286 * Performs an output operation for a 16-bit memory location by writing the
287 * specified Value to the the specified address. The Value is byte-swapped
288 * before being written.
290 * @param OutAddress contains the address to perform the output operation
292 * @param Value contains the Value to be output at the specified address.
298 ******************************************************************************/
299 void Xil_Out16BE(INTPTR Addr, u16 Value)
303 temp = Xil_EndianSwap16(Value);
305 Xil_Out16(Addr, temp);
308 /*****************************************************************************/
311 * Performs an output operation for a 32-bit memory location by writing the
312 * specified Value to the the specified address. The Value is byte-swapped
313 * before being written.
315 * @param OutAddress contains the address to perform the output operation
317 * @param Value contains the Value to be output at the specified address.
323 ******************************************************************************/
324 void Xil_Out32BE(INTPTR Addr, u32 Value)
328 temp = Xil_EndianSwap32(Value);
330 Xil_Out32(Addr, temp);
333 /*****************************************************************************/
336 * Perform a 16-bit endian converion.
338 * @param Data contains the value to be converted.
340 * @return converted value.
344 ******************************************************************************/
345 u16 Xil_EndianSwap16(u16 Data)
347 return (u16) (((Data & 0xFF00U) >> 8U) | ((Data & 0x00FFU) << 8U));
350 /*****************************************************************************/
353 * Perform a 32-bit endian converion.
355 * @param Data contains the value to be converted.
357 * @return converted value.
361 ******************************************************************************/
362 u32 Xil_EndianSwap32(u32 Data)
367 /* get each of the half words from the 32 bit word */
369 LoWord = (u16) (Data & 0x0000FFFFU);
370 HiWord = (u16) ((Data & 0xFFFF0000U) >> 16U);
372 /* byte swap each of the 16 bit half words */
374 LoWord = (((LoWord & 0xFF00U) >> 8U) | ((LoWord & 0x00FFU) << 8U));
375 HiWord = (((HiWord & 0xFF00U) >> 8U) | ((HiWord & 0x00FFU) << 8U));
377 /* swap the half words before returning the value */
379 return ((((u32)LoWord) << 16U) | (u32)HiWord);