]> 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_testio.c
Update BSP source files for UltraScale Cortex-A53 and Cortex-R5 and Microblaze to...
[freertos] / FreeRTOS / Demo / CORTEX_A53_64-bit_UltraScale_MPSoC / RTOSDemo_A53_bsp / psu_cortexa53_0 / libsrc / standalone_v5_4 / src / xil_testio.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_testmemend.c
36 *
37 * Contains the memory test utility functions.
38 *
39 * <pre>
40 * MODIFICATION HISTORY:
41 *
42 * Ver    Who    Date    Changes
43 * ----- ---- -------- -----------------------------------------------
44 * 1.00a hbm  08/25/09 First release
45 * </pre>
46 *
47 *****************************************************************************/
48
49 /***************************** Include Files ********************************/
50 #include "xil_testio.h"
51 #include "xil_assert.h"
52 #include "xil_io.h"
53
54 /************************** Constant Definitions ****************************/
55 /************************** Function Prototypes *****************************/
56
57
58
59 /**
60  *
61  * Endian swap a 16-bit word.
62  * @param       Data is the 16-bit word to be swapped.
63  * @return      The endian swapped value.
64  *
65  */
66 static u16 Swap16(u16 Data)
67 {
68         return ((Data >> 8U) & 0x00FFU) | ((Data << 8U) & 0xFF00U);
69 }
70
71 /**
72  *
73  * Endian swap a 32-bit word.
74  * @param       Data is the 32-bit word to be swapped.
75  * @return      The endian swapped value.
76  *
77  */
78 static u32 Swap32(u32 Data)
79 {
80         u16 Lo16;
81         u16 Hi16;
82
83         u16 Swap16Lo;
84         u16 Swap16Hi;
85
86         Hi16 = (u16)((Data >> 16U) & 0x0000FFFFU);
87         Lo16 = (u16)(Data & 0x0000FFFFU);
88
89         Swap16Lo = Swap16(Lo16);
90         Swap16Hi = Swap16(Hi16);
91
92         return (((u32)(Swap16Lo)) << 16U) | ((u32)Swap16Hi);
93 }
94
95 /*****************************************************************************/
96 /**
97 *
98 * Perform a destructive 8-bit wide register IO test where the register is
99 * accessed using Xil_Out8 and Xil_In8, and comparing the reading and writing
100 * values.
101 *
102 * @param        Addr is a pointer to the region of memory to be tested.
103 * @param        Length is the Length of the block.
104 * @param        Value is the constant used for writting the memory.
105 *
106 * @return
107 *
108 * - -1 is returned for a failure
109 * - 0 is returned for a pass
110 *
111 *****************************************************************************/
112
113 s32 Xil_TestIO8(u8 *Addr, s32 Length, u8 Value)
114 {
115         u8 ValueIn;
116         s32 Index;
117         s32 Status = 0;
118
119         for (Index = 0; Index < Length; Index++) {
120                 Xil_Out8((INTPTR)Addr, Value);
121
122                 ValueIn = Xil_In8((INTPTR)Addr);
123
124                 if ((Value != ValueIn) && (Status == 0)) {
125                         Status = -1;
126                         break;
127                 }
128         }
129         return Status;
130
131 }
132
133 /*****************************************************************************/
134 /**
135 *
136 * Perform a destructive 16-bit wide register IO test. Each location is tested
137 * by sequentially writing a 16-bit wide register, reading the register, and
138 * comparing value. This function tests three kinds of register IO functions,
139 * normal register IO, little-endian register IO, and big-endian register IO.
140 * When testing little/big-endian IO, the function performs the following
141 * sequence, Xil_Out16LE/Xil_Out16BE, Xil_In16, Compare In-Out values,
142 * Xil_Out16, Xil_In16LE/Xil_In16BE, Compare In-Out values. Whether to swap the
143 * read-in value before comparing is controlled by the 5th argument.
144 *
145 * @param        Addr is a pointer to the region of memory to be tested.
146 * @param        Length is the Length of the block.
147 * @param        Value is the constant used for writting the memory.
148 * @param        Kind is the test kind. Acceptable values are:
149 *               XIL_TESTIO_DEFAULT, XIL_TESTIO_LE, XIL_TESTIO_BE.
150 * @param        Swap indicates whether to byte swap the read-in value.
151 *
152 * @return
153 *
154 * - -1 is returned for a failure
155 * - 0 is returned for a pass
156 *
157 *****************************************************************************/
158
159 s32 Xil_TestIO16(u16 *Addr, s32 Length, u16 Value, s32 Kind, s32 Swap)
160 {
161         u16 *TempAddr16;
162         u16 ValueIn = 0U;
163         s32 Index;
164         TempAddr16 = Addr;
165         Xil_AssertNonvoid(TempAddr16 != NULL);
166
167         for (Index = 0; Index < Length; Index++) {
168                 switch (Kind) {
169                 case XIL_TESTIO_LE:
170                         Xil_Out16LE((INTPTR)TempAddr16, Value);
171                         break;
172                 case XIL_TESTIO_BE:
173                         Xil_Out16BE((INTPTR)TempAddr16, Value);
174                         break;
175                 default:
176                         Xil_Out16((INTPTR)TempAddr16, Value);
177                         break;
178                 }
179
180                 ValueIn = Xil_In16((INTPTR)TempAddr16);
181
182                 if ((Kind != 0) && (Swap != 0)) {
183                         ValueIn = Swap16(ValueIn);
184                 }
185
186                 if (Value != ValueIn) {
187                         return -1;
188                 }
189
190                 /* second round */
191                 Xil_Out16((INTPTR)TempAddr16, Value);
192
193                 switch (Kind) {
194                 case XIL_TESTIO_LE:
195                         ValueIn = Xil_In16LE((INTPTR)TempAddr16);
196                         break;
197                 case XIL_TESTIO_BE:
198                         ValueIn = Xil_In16BE((INTPTR)TempAddr16);
199                         break;
200                 default:
201                         ValueIn = Xil_In16((INTPTR)TempAddr16);
202                         break;
203                 }
204
205
206                 if ((Kind != 0) && (Swap != 0)) {
207                         ValueIn = Swap16(ValueIn);
208                 }
209
210                 if (Value != ValueIn) {
211                         return -1;
212                 }
213                 TempAddr16 += sizeof(u16);
214         }
215         return 0;
216 }
217
218
219 /*****************************************************************************/
220 /**
221 *
222 * Perform a destructive 32-bit wide register IO test. Each location is tested
223 * by sequentially writing a 32-bit wide regsiter, reading the register, and
224 * comparing value. This function tests three kinds of register IO functions,
225 * normal register IO, little-endian register IO, and big-endian register IO.
226 * When testing little/big-endian IO, the function perform the following
227 * sequence, Xil_Out32LE/Xil_Out32BE, Xil_In32, Compare,
228 * Xil_Out32, Xil_In32LE/Xil_In32BE, Compare. Whether to swap the read-in value
229 * before comparing is controlled by the 5th argument.
230 *
231 * @param        Addr is a pointer to the region of memory to be tested.
232 * @param        Length is the Length of the block.
233 * @param        Value is the constant used for writting the memory.
234 * @param        Kind is the test kind. Acceptable values are:
235 *               XIL_TESTIO_DEFAULT, XIL_TESTIO_LE, XIL_TESTIO_BE.
236 * @param        Swap indicates whether to byte swap the read-in value.
237 *
238 * @return
239 *
240 * - -1 is returned for a failure
241 * - 0 is returned for a pass
242 *
243 *****************************************************************************/
244 s32 Xil_TestIO32(u32 *Addr, s32 Length, u32 Value, s32 Kind, s32 Swap)
245 {
246         u32 *TempAddr;
247         u32 ValueIn = 0U;
248         s32 Index;
249         TempAddr = Addr;
250         Xil_AssertNonvoid(TempAddr != NULL);
251
252         for (Index = 0; Index < Length; Index++) {
253                 switch (Kind) {
254                 case XIL_TESTIO_LE:
255                         Xil_Out32LE((INTPTR)TempAddr, Value);
256                         break;
257                 case XIL_TESTIO_BE:
258                         Xil_Out32BE((INTPTR)TempAddr, Value);
259                         break;
260                 default:
261                         Xil_Out32((INTPTR)TempAddr, Value);
262                         break;
263                 }
264
265                 ValueIn = Xil_In32((INTPTR)TempAddr);
266
267                 if ((Kind != 0) && (Swap != 0)) {
268                         ValueIn = Swap32(ValueIn);
269                 }
270
271                 if (Value != ValueIn) {
272                         return -1;
273                 }
274
275                 /* second round */
276                 Xil_Out32((INTPTR)TempAddr, Value);
277
278
279                 switch (Kind) {
280                 case XIL_TESTIO_LE:
281                         ValueIn = Xil_In32LE((INTPTR)TempAddr);
282                         break;
283                 case XIL_TESTIO_BE:
284                         ValueIn = Xil_In32BE((INTPTR)TempAddr);
285                         break;
286                 default:
287                         ValueIn = Xil_In32((INTPTR)TempAddr);
288                         break;
289                 }
290
291                 if ((Kind != 0) && (Swap != 0)) {
292                         ValueIn = Swap32(ValueIn);
293                 }
294
295                 if (Value != ValueIn) {
296                         return -1;
297                 }
298                 TempAddr += sizeof(u32);
299         }
300         return 0;
301 }