]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A53_64-bit_UltraScale_MPSoC/RTOSDemo_A53_bsp/psu_cortexa53_0/libsrc/standalone_v5_4/src/xil_io.c
Update the Xilinx UltraScale+ 64-bit demo to use the hardware definition and BSP...
[freertos] / FreeRTOS / Demo / CORTEX_A53_64-bit_UltraScale_MPSoC / RTOSDemo_A53_bsp / psu_cortexa53_0 / libsrc / standalone_v5_4 / src / xil_io.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2014 - 2015 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 or non-memory-mapped I/O
38 * architectures.  These functions encapsulate Cortex A53 architecture-specific
39 * I/O requirements.
40 *
41 * @note
42 *
43 * This file contains architecture-dependent code.
44 *
45 * <pre>
46 * MODIFICATION HISTORY:
47 *
48 * Ver   Who      Date     Changes
49 * ----- -------- -------- -----------------------------------------------
50 * 5.00  pkp      05/29/14 First release
51 * </pre>
52 ******************************************************************************/
53
54
55 /***************************** Include Files *********************************/
56 #include "xil_io.h"
57 #include "xil_types.h"
58 #include "xil_assert.h"
59 #include "xpseudo_asm.h"
60 #include "xreg_cortexa53.h"
61
62 /************************** Constant Definitions *****************************/
63
64 /**************************** Type Definitions *******************************/
65
66 /***************** Macros (Inline Functions) Definitions *********************/
67
68 /************************** Function Prototypes ******************************/
69
70 /*****************************************************************************/
71 /**
72 *
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.
75 *
76 * @param        Addr contains the address to perform the input operation
77 *               at.
78 *
79 * @return       The Value read from the specified input address.
80 *
81 * @note         None.
82 *
83 ******************************************************************************/
84 u8 Xil_In8(INTPTR Addr)
85 {
86         return *(volatile u8 *) Addr;
87 }
88
89 /*****************************************************************************/
90 /**
91 *
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.
94 *
95 * @param        Addr contains the address to perform the input operation
96 *               at.
97 *
98 * @return       The Value read from the specified input address.
99 *
100 * @note         None.
101 *
102 ******************************************************************************/
103 u16 Xil_In16(INTPTR Addr)
104 {
105         return *(volatile u16 *) Addr;
106 }
107
108 /*****************************************************************************/
109 /**
110 *
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.
113 *
114 * @param        Addr contains the address to perform the input operation
115 *               at.
116 *
117 * @return       The Value read from the specified input address.
118 *
119 * @note         None.
120 *
121 ******************************************************************************/
122 u32 Xil_In32(INTPTR Addr)
123 {
124         return *(volatile u32 *) Addr;
125 }
126
127 /*****************************************************************************/
128 /**
129 *
130 * Performs an output operation for an 8-bit memory location by writing the
131 * specified Value to the the specified address.
132 *
133 * @param        Addr contains the address to perform the output operation
134 *               at.
135 * @param        Value contains the Value to be output at the specified address.
136 *
137 * @return       None.
138 *
139 * @note         None.
140 *
141 ******************************************************************************/
142 void Xil_Out8(INTPTR Addr, u8 Value)
143 {
144         volatile u8 *LocalAddr = (u8 *)Addr;
145         *LocalAddr = Value;
146 }
147
148 /*****************************************************************************/
149 /**
150 *
151 * Performs an output operation for a 16-bit memory location by writing the
152 * specified Value to the the specified address.
153 *
154 * @param        Addr contains the address to perform the output operation
155 *               at.
156 * @param        Value contains the Value to be output at the specified address.
157 *
158 * @return       None.
159 *
160 * @note         None.
161 *
162 ******************************************************************************/
163 void Xil_Out16(INTPTR Addr, u16 Value)
164 {
165         volatile u16 *LocalAddr = (u16 *)Addr;
166         *LocalAddr = Value;
167 }
168
169 /*****************************************************************************/
170 /**
171 *
172 * Performs an output operation for a 32-bit memory location by writing the
173 * specified Value to the the specified address.
174 *
175 * @param        Addr contains the address to perform the output operation
176 *               at.
177 * @param        Value contains the Value to be output at the specified address.
178 *
179 * @return       None.
180 *
181 * @note         None.
182 *
183 ******************************************************************************/
184 void Xil_Out32(INTPTR Addr, u32 Value)
185 {
186         volatile u32 *LocalAddr = (u32 *)Addr;
187         *LocalAddr = Value;
188 }
189
190 /*****************************************************************************/
191 /**
192 *
193 * Performs an output operation for a 64-bit memory location by writing the
194 * specified Value to the the specified address.
195 *
196 * @param        Addr contains the address to perform the output operation
197 *               at.
198 * @param        Value contains the Value to be output at the specified address.
199 *
200 * @return       None.
201 *
202 * @note         None.
203 *
204 ******************************************************************************/
205 void Xil_Out64(INTPTR Addr, u64 Value)
206 {
207         volatile u64 *LocalAddr = (u64 *)Addr;
208         *LocalAddr = Value;
209 }
210
211 /*****************************************************************************/
212 /**
213 *
214 * Performs an input operation for a 64-bit memory location by reading the
215 * specified Value to the the specified address.
216 *
217 * @param        OutAddress contains the address to perform the output operation
218 *               at.
219 * @param        Value contains the Value to be output at the specified address.
220 *
221 * @return       None.
222 *
223 * @note         None.
224 *
225 ******************************************************************************/
226 u64 Xil_In64(INTPTR Addr)
227 {
228         return *(volatile u64 *) Addr;
229 }
230 /*****************************************************************************/
231 /**
232 *
233 * Performs an input operation for a 16-bit memory location by reading from the
234 * specified address and returning the byte-swapped Value read from that
235 * address.
236 *
237 * @param        Addr contains the address to perform the input operation
238 *               at.
239 *
240 * @return       The byte-swapped Value read from the specified input address.
241 *
242 * @note         None.
243 *
244 ******************************************************************************/
245 u16 Xil_In16BE(INTPTR Addr)
246 {
247         u16 temp;
248         u16 result;
249
250         temp = Xil_In16(Addr);
251
252         result = Xil_EndianSwap16(temp);
253
254         return result;
255 }
256
257 /*****************************************************************************/
258 /**
259 *
260 * Performs an input operation for a 32-bit memory location by reading from the
261 * specified address and returning the byte-swapped Value read from that
262 * address.
263 *
264 * @param        Addr contains the address to perform the input operation
265 *               at.
266 *
267 * @return       The byte-swapped Value read from the specified input address.
268 *
269 * @note         None.
270 *
271 ******************************************************************************/
272 u32 Xil_In32BE(INTPTR Addr)
273 {
274         u32 temp;
275         u32 result;
276
277         temp = Xil_In32(Addr);
278
279         result = Xil_EndianSwap32(temp);
280
281         return result;
282 }
283
284 /*****************************************************************************/
285 /**
286 *
287 * Performs an output operation for a 16-bit memory location by writing the
288 * specified Value to the the specified address. The Value is byte-swapped
289 * before being written.
290 *
291 * @param        Addr contains the address to perform the output operation
292 *               at.
293 * @param        Value contains the Value to be output at the specified address.
294 *
295 * @return       None.
296 *
297 * @note         None.
298 *
299 ******************************************************************************/
300 void Xil_Out16BE(INTPTR Addr, u16 Value)
301 {
302         u16 temp;
303
304         temp = Xil_EndianSwap16(Value);
305
306     Xil_Out16(Addr, temp);
307 }
308
309 /*****************************************************************************/
310 /**
311 *
312 * Performs an output operation for a 32-bit memory location by writing the
313 * specified Value to the the specified address. The Value is byte-swapped
314 * before being written.
315 *
316 * @param        Addr contains the address to perform the output operation
317 *               at.
318 * @param        Value contains the Value to be output at the specified address.
319 *
320 * @return       None.
321 *
322 * @note         None.
323 *
324 ******************************************************************************/
325 void Xil_Out32BE(INTPTR Addr, u32 Value)
326 {
327         u32 temp;
328
329         temp = Xil_EndianSwap32(Value);
330
331     Xil_Out32(Addr, temp);
332 }
333
334 /*****************************************************************************/
335 /**
336 *
337 * Perform a 16-bit endian converion.
338 *
339 * @param        Data contains the value to be converted.
340 *
341 * @return       converted value.
342 *
343 * @note         None.
344 *
345 ******************************************************************************/
346 u16 Xil_EndianSwap16(u16 Data)
347 {
348         return (u16) (((Data & 0xFF00U) >> 8U) | ((Data & 0x00FFU) << 8U));
349 }
350
351 /*****************************************************************************/
352 /**
353 *
354 * Perform a 32-bit endian converion.
355 *
356 * @param        Data contains the value to be converted.
357 *
358 * @return       converted value.
359 *
360 * @note         None.
361 *
362 ******************************************************************************/
363 u32 Xil_EndianSwap32(u32 Data)
364 {
365         u16 LoWord;
366         u16 HiWord;
367
368         /* get each of the half words from the 32 bit word */
369
370         LoWord = (u16) (Data & 0x0000FFFFU);
371         HiWord = (u16) ((Data & 0xFFFF0000U) >> 16U);
372
373         /* byte swap each of the 16 bit half words */
374
375         LoWord = (((LoWord & 0xFF00U) >> 8U) | ((LoWord & 0x00FFU) << 8U));
376         HiWord = (((HiWord & 0xFF00U) >> 8U) | ((HiWord & 0x00FFU) << 8U));
377
378         /* swap the half words before returning the value */
379
380         return ((((u32)LoWord) << (u32)16U) | (u32)HiWord);
381 }