]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/standalone_v4_2/src/xil_io.c
e7951019dc963e0b5cfeaf91b58728d30fd8834b
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / BSP / microblaze_0 / libsrc / standalone_v4_2 / src / xil_io.c
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.c
36 *
37 * Contains I/O functions for memory-mapped architectures.  These functions
38 * encapsulate generic CPU I/O requirements.
39 *
40 * <pre>
41 * MODIFICATION HISTORY:
42 *
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
47 *
48 * </pre>
49 *
50 * @note
51 *
52 * This file may contain architecture-dependent code.
53 *
54 ******************************************************************************/
55
56 /***************************** Include Files *********************************/
57
58 #include "xil_io.h"
59 #include "xil_types.h"
60
61 /************************** Constant Definitions *****************************/
62
63
64 /**************************** Type Definitions *******************************/
65
66
67 /***************** Macros (Inline Functions) Definitions *********************/
68
69
70 /************************** Function Prototypes ******************************/
71
72
73
74 /*****************************************************************************/
75 /**
76 *
77 * Perform a 16-bit endian converion.
78 *
79 * @param        Data contains the value to be converted.
80 *
81 * @return       converted value.
82 *
83 * @note         None.
84 *
85 ******************************************************************************/
86 u16 Xil_EndianSwap16(u16 Data)
87 {
88         return (u16) (((Data & 0xFF00) >> 8) | ((Data & 0x00FF) << 8));
89 }
90
91 /*****************************************************************************/
92 /**
93 *
94 * Perform a 32-bit endian converion.
95 *
96 * @param        Data contains the value to be converted.
97 *
98 * @return       converted value.
99 *
100 * @note         None.
101 *
102 ******************************************************************************/
103 u32 Xil_EndianSwap32(u32 Data)
104 {
105         u16 LoWord;
106         u16 HiWord;
107
108         /* get each of the half words from the 32 bit word */
109
110         LoWord = (u16) (Data & 0x0000FFFF);
111         HiWord = (u16) ((Data & 0xFFFF0000) >> 16);
112
113         /* byte swap each of the 16 bit half words */
114
115         LoWord = (((LoWord & 0xFF00) >> 8) | ((LoWord & 0x00FF) << 8));
116         HiWord = (((HiWord & 0xFF00) >> 8) | ((HiWord & 0x00FF) << 8));
117
118         /* swap the half words before returning the value */
119
120         return (u32) ((LoWord << 16) | HiWord);
121 }
122
123 /*****************************************************************************/
124 /**
125 *
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.
129 *
130 * @param        Addr contains the address to perform the input operation at.
131 *
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
136 *               address.
137 *
138 *
139 * @note         None.
140 *
141 ******************************************************************************/
142 #ifndef __LITTLE_ENDIAN__
143 u16 Xil_In16LE(u32 Addr)
144 #else
145 u16 Xil_In16BE(u32 Addr)
146 #endif
147 {
148         u16 Value;
149
150         /* get the data then swap it */
151         Value = Xil_In16(Addr);
152
153         return Xil_EndianSwap16(Value);
154 }
155
156 /*****************************************************************************/
157 /**
158 *
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.
162 *
163 * @param        Addr contains the address to perform the input operation at.
164 *
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
169 *               address.
170 *
171 * @note         None.
172 *
173 ******************************************************************************/
174 #ifndef __LITTLE_ENDIAN__
175 u32 Xil_In32LE(u32 Addr)
176 #else
177 u32 Xil_In32BE(u32 Addr)
178 #endif
179 {
180         u32 InValue;
181
182         /* get the data then swap it */
183         InValue = Xil_In32(Addr);
184         return Xil_EndianSwap32(InValue);
185 }
186
187 /*****************************************************************************/
188 /**
189 *
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.
193 *
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.
199 *
200 * @return       None.
201 *
202 * @note         None.
203 *
204 ******************************************************************************/
205 #ifndef __LITTLE_ENDIAN__
206 void Xil_Out16LE(u32 Addr, u16 Value)
207 #else
208 void Xil_Out16BE(u32 Addr, u16 Value)
209 #endif
210 {
211         u16 OutValue;
212
213         /* swap the data then output it */
214         OutValue = Xil_EndianSwap16(Value);
215
216         Xil_Out16(Addr, OutValue);
217 }
218
219 /*****************************************************************************/
220 /**
221 *
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.
225 *
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.
231 *
232 * @return       None.
233 *
234 * @note         None.
235 *
236 ******************************************************************************/
237 #ifndef __LITTLE_ENDIAN__
238 void Xil_Out32LE(u32 Addr, u32 Value)
239 #else
240 void Xil_Out32BE(u32 Addr, u32 Value)
241 #endif
242 {
243         u32 OutValue;
244
245         /* swap the data then output it */
246         OutValue = Xil_EndianSwap32(Value);
247         Xil_Out32(Addr, OutValue);
248 }