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 * Contains I/O functions for memory-mapped architectures. These functions
38 * encapsulate generic CPU I/O requirements.
41 * MODIFICATION HISTORY:
43 * Ver Who Date Changes
44 * ----- ---- -------- -------------------------------------------------------
45 * 3.00a hbm 07/28/09 Initial release
46 * 3.00a hbm 07/21/10 Added Xil_EndianSwap32/16, Xil_Htonl/s, Xil_Ntohl/s
52 * This file may contain architecture-dependent code.
54 ******************************************************************************/
56 /***************************** Include Files *********************************/
59 #include "xil_types.h"
61 /************************** Constant Definitions *****************************/
64 /**************************** Type Definitions *******************************/
67 /***************** Macros (Inline Functions) Definitions *********************/
70 /************************** Function Prototypes ******************************/
74 /*****************************************************************************/
77 * Perform a 16-bit endian converion.
79 * @param Data contains the value to be converted.
81 * @return converted value.
85 ******************************************************************************/
86 u16 Xil_EndianSwap16(u16 Data)
88 return (u16) (((Data & 0xFF00) >> 8) | ((Data & 0x00FF) << 8));
91 /*****************************************************************************/
94 * Perform a 32-bit endian converion.
96 * @param Data contains the value to be converted.
98 * @return converted value.
102 ******************************************************************************/
103 u32 Xil_EndianSwap32(u32 Data)
108 /* get each of the half words from the 32 bit word */
110 LoWord = (u16) (Data & 0x0000FFFF);
111 HiWord = (u16) ((Data & 0xFFFF0000) >> 16);
113 /* byte swap each of the 16 bit half words */
115 LoWord = (((LoWord & 0xFF00) >> 8) | ((LoWord & 0x00FF) << 8));
116 HiWord = (((HiWord & 0xFF00) >> 8) | ((HiWord & 0x00FF) << 8));
118 /* swap the half words before returning the value */
120 return (u32) ((LoWord << 16) | HiWord);
123 /*****************************************************************************/
126 * Perform a little-endian input operation for a 16-bit memory location
127 * by reading from the specified address and returning the byte-swapped value
128 * read from that address.
130 * @param Addr contains the address to perform the input operation at.
132 * @return The value read from the specified input address with the
133 * proper endianness. The return value has the same endianness
134 * as that of the processor, i.e. if the processor is big-engian,
135 * the return value is the byte-swapped value read from the
141 ******************************************************************************/
142 #ifndef __LITTLE_ENDIAN__
143 u16 Xil_In16LE(u32 Addr)
145 u16 Xil_In16BE(u32 Addr)
150 /* get the data then swap it */
151 Value = Xil_In16(Addr);
153 return Xil_EndianSwap16(Value);
156 /*****************************************************************************/
159 * Perform a little-endian input operation for a 32-bit memory location
160 * by reading from the specified address and returning the byte-swapped value
161 * read from that address.
163 * @param Addr contains the address to perform the input operation at.
165 * @return The value read from the specified input address with the
166 * proper endianness. The return value has the same endianness
167 * as that of the processor, i.e. if the processor is big-engian,
168 * the return value is the byte-swapped value read from the
173 ******************************************************************************/
174 #ifndef __LITTLE_ENDIAN__
175 u32 Xil_In32LE(u32 Addr)
177 u32 Xil_In32BE(u32 Addr)
182 /* get the data then swap it */
183 InValue = Xil_In32(Addr);
184 return Xil_EndianSwap32(InValue);
187 /*****************************************************************************/
190 * Perform a little-endian output operation for a 16-bit memory location by
191 * writing the specified value to the the specified address. The value is
192 * byte-swapped before being written.
194 * @param Addr contains the address to perform the output operation at.
195 * @param Value contains the value to be output at the specified address.
196 * The value has the same endianness as that of the processor.
197 * If the processor is big-endian, the byte-swapped value is
198 * written to the address.
204 ******************************************************************************/
205 #ifndef __LITTLE_ENDIAN__
206 void Xil_Out16LE(u32 Addr, u16 Value)
208 void Xil_Out16BE(u32 Addr, u16 Value)
213 /* swap the data then output it */
214 OutValue = Xil_EndianSwap16(Value);
216 Xil_Out16(Addr, OutValue);
219 /*****************************************************************************/
222 * Perform a little-endian output operation for a 32-bit memory location
223 * by writing the specified value to the the specified address. The value is
224 * byte-swapped before being written.
226 * @param Addr contains the address at which the output operation at.
227 * @param Value contains the value to be output at the specified address.
228 * The value has the same endianness as that of the processor.
229 * If the processor is big-endian, the byte-swapped value is
230 * written to the address.
236 ******************************************************************************/
237 #ifndef __LITTLE_ENDIAN__
238 void Xil_Out32LE(u32 Addr, u32 Value)
240 void Xil_Out32BE(u32 Addr, u32 Value)
245 /* swap the data then output it */
246 OutValue = Xil_EndianSwap32(Value);
247 Xil_Out32(Addr, OutValue);