]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/libsrc/standalone_v5_4/src/xil_io.c
xTaskGenericNotify() now sets xYieldPending to pdTRUE even when the 'higher priority...
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / libsrc / standalone_v5_4 / src / xil_io.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2009 - 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 A9 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 * 1.00a ecm/sdm  10/24/09 First release
51 * 3.06a sgd      05/15/12 Pointer volatile used for the all read functions
52 * 3.07a sgd      08/17/12 Removed barriers (SYNCHRONIZE_IO) calls.
53 * 3.09a sgd      02/05/13 Comments cleanup
54 * </pre>
55 ******************************************************************************/
56
57
58 /***************************** Include Files *********************************/
59 #include "xil_io.h"
60 #include "xil_types.h"
61 #include "xil_assert.h"
62 #include "xpseudo_asm.h"
63 #include "xreg_cortexa9.h"
64
65 /************************** Constant Definitions *****************************/
66
67 /**************************** Type Definitions *******************************/
68
69 /***************** Macros (Inline Functions) Definitions *********************/
70
71 /************************** Function Prototypes ******************************/
72
73 /*****************************************************************************/
74 /**
75 *
76 * Performs an input operation for an 8-bit memory location by reading from the
77 * specified address and returning the Value read from that address.
78 *
79 * @param        Addr contains the address to perform the input operation
80 *               at.
81 *
82 * @return       The Value read from the specified input address.
83 *
84 * @note         None.
85 *
86 ******************************************************************************/
87 u8 Xil_In8(INTPTR Addr)
88 {
89         return *(volatile u8 *) Addr;
90 }
91
92 /*****************************************************************************/
93 /**
94 *
95 * Performs an input operation for a 16-bit memory location by reading from the
96 * specified address and returning the Value read from that address.
97 *
98 * @param        Addr contains the address to perform the input operation
99 *               at.
100 *
101 * @return       The Value read from the specified input address.
102 *
103 * @note         None.
104 *
105 ******************************************************************************/
106 u16 Xil_In16(INTPTR Addr)
107 {
108         return *(volatile u16 *) Addr;
109 }
110
111 /*****************************************************************************/
112 /**
113 *
114 * Performs an input operation for a 32-bit memory location by reading from the
115 * specified address and returning the Value read from that address.
116 *
117 * @param        Addr contains the address to perform the input operation
118 *               at.
119 *
120 * @return       The Value read from the specified input address.
121 *
122 * @note         None.
123 *
124 ******************************************************************************/
125 u32 Xil_In32(UINTPTR Addr)
126 {
127         return *(volatile u32 *) Addr;
128 }
129
130 /*****************************************************************************/
131 /**
132 *
133 * Performs an output operation for an 8-bit memory location by writing the
134 * specified Value to the the specified address.
135 *
136 * @param        Addr contains the address to perform the output operation
137 *               at.
138 * @param        Value contains the Value to be output at the specified address.
139 *
140 * @return       None.
141 *
142 * @note         None.
143 *
144 ******************************************************************************/
145 void Xil_Out8(INTPTR Addr, u8 Value)
146 {
147         volatile u8 *LocalAddr = (u8 *)Addr;
148         *LocalAddr = Value;
149 }
150
151 /*****************************************************************************/
152 /**
153 *
154 * Performs an output operation for a 16-bit memory location by writing the
155 * specified Value to the the specified address.
156 *
157 * @param        Addr contains the address to perform the output operation
158 *               at.
159 * @param        Value contains the Value to be output at the specified address.
160 *
161 * @return       None.
162 *
163 * @note         None.
164 *
165 ******************************************************************************/
166 void Xil_Out16(INTPTR Addr, u16 Value)
167 {
168         volatile u16 *LocalAddr = (u16 *)Addr;
169         *LocalAddr = Value;
170 }
171
172 /*****************************************************************************/
173 /**
174 *
175 * Performs an output operation for a 32-bit memory location by writing the
176 * specified Value to the the specified address.
177 *
178 * @param        Addr contains the address to perform the output operation
179 *               at.
180 * @param        Value contains the Value to be output at the specified address.
181 *
182 * @return       None.
183 *
184 * @note         None.
185 *
186 ******************************************************************************/
187 void Xil_Out32(UINTPTR Addr, u32 Value)
188 {
189         volatile u32 *LocalAddr = (u32 *)Addr;
190         *LocalAddr = Value;
191 }
192
193 /*****************************************************************************/
194 /**
195 *
196 * Performs an input operation for a 16-bit memory location by reading from the
197 * specified address and returning the byte-swapped Value read from that
198 * address.
199 *
200 * @param        Addr contains the address to perform the input operation
201 *               at.
202 *
203 * @return       The byte-swapped Value read from the specified input address.
204 *
205 * @note         None.
206 *
207 ******************************************************************************/
208 u16 Xil_In16BE(INTPTR Addr)
209 {
210         u16 temp;
211         u16 result;
212
213         temp = Xil_In16(Addr);
214
215         result = Xil_EndianSwap16(temp);
216
217         return result;
218 }
219
220 /*****************************************************************************/
221 /**
222 *
223 * Performs an input operation for a 32-bit memory location by reading from the
224 * specified address and returning the byte-swapped Value read from that
225 * address.
226 *
227 * @param        Addr contains the address to perform the input operation
228 *               at.
229 *
230 * @return       The byte-swapped Value read from the specified input address.
231 *
232 * @note         None.
233 *
234 ******************************************************************************/
235 u32 Xil_In32BE(INTPTR Addr)
236 {
237         u32 temp;
238         u32 result;
239
240         temp = Xil_In32(Addr);
241
242         result = Xil_EndianSwap32(temp);
243
244         return result;
245 }
246
247 /*****************************************************************************/
248 /**
249 *
250 * Performs an output operation for a 16-bit memory location by writing the
251 * specified Value to the the specified address. The Value is byte-swapped
252 * before being written.
253 *
254 * @param        Addr contains the address to perform the output operation
255 *               at.
256 * @param        Value contains the Value to be output at the specified address.
257 *
258 * @return       None.
259 *
260 * @note         None.
261 *
262 ******************************************************************************/
263 void Xil_Out16BE(INTPTR Addr, u16 Value)
264 {
265         u16 temp;
266
267         temp = Xil_EndianSwap16(Value);
268
269     Xil_Out16(Addr, temp);
270 }
271
272 /*****************************************************************************/
273 /**
274 *
275 * Performs an output operation for a 32-bit memory location by writing the
276 * specified Value to the the specified address. The Value is byte-swapped
277 * before being written.
278 *
279 * @param        Addr contains the address to perform the output operation
280 *               at.
281 * @param        Value contains the Value to be output at the specified address.
282 *
283 * @return       None.
284 *
285 * @note         None.
286 *
287 ******************************************************************************/
288 void Xil_Out32BE(INTPTR Addr, u32 Value)
289 {
290         u32 temp;
291
292         temp = Xil_EndianSwap32(Value);
293
294     Xil_Out32(Addr, temp);
295 }
296
297 /*****************************************************************************/
298 /**
299 *
300 * Perform a 16-bit endian converion.
301 *
302 * @param        Data contains the value to be converted.
303 *
304 * @return       converted value.
305 *
306 * @note         None.
307 *
308 ******************************************************************************/
309 u16 Xil_EndianSwap16(u16 Data)
310 {
311         return (u16) (((Data & 0xFF00U) >> 8U) | ((Data & 0x00FFU) << 8U));
312 }
313
314 /*****************************************************************************/
315 /**
316 *
317 * Perform a 32-bit endian converion.
318 *
319 * @param        Data contains the value to be converted.
320 *
321 * @return       converted value.
322 *
323 * @note         None.
324 *
325 ******************************************************************************/
326 u32 Xil_EndianSwap32(u32 Data)
327 {
328         u16 LoWord;
329         u16 HiWord;
330
331         /* get each of the half words from the 32 bit word */
332
333         LoWord = (u16) (Data & 0x0000FFFFU);
334         HiWord = (u16) ((Data & 0xFFFF0000U) >> 16U);
335
336         /* byte swap each of the 16 bit half words */
337
338         LoWord = (((LoWord & 0xFF00U) >> 8U) | ((LoWord & 0x00FFU) << 8U));
339         HiWord = (((HiWord & 0xFF00U) >> 8U) | ((HiWord & 0x00FFU) << 8U));
340
341         /* swap the half words before returning the value */
342
343         return ((((u32)LoWord) << (u32)16U) | (u32)HiWord);
344 }