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 /*****************************************************************************/
35 * @file xil_testmemend.c
37 * Contains the memory test utility functions.
40 * MODIFICATION HISTORY:
42 * Ver Who Date Changes
43 * ----- ---- -------- -----------------------------------------------
44 * 1.00a hbm 08/25/09 First release
47 *****************************************************************************/
49 /***************************** Include Files ********************************/
50 #include "xil_testio.h"
51 #include "xil_assert.h"
54 /************************** Constant Definitions ****************************/
55 /************************** Function Prototypes *****************************/
61 * Endian swap a 16-bit word.
62 * @param Data is the 16-bit word to be swapped.
63 * @return The endian swapped valud.
66 static u16 Swap16(u16 Data)
68 return ((Data >> 8) & 0x00FF) | ((Data << 8) & 0xFF00);
73 * Endian swap a 32-bit word.
74 * @param Data is the 32-bit word to be swapped.
75 * @return The endian swapped valud.
78 static u32 Swap32(u32 Data)
86 Hi16 = (u16)((Data >> 16) & 0x0000FFFF);
87 Lo16 = (u16)(Data & 0x0000FFFF);
89 Swap16Lo = Swap16(Lo16);
90 Swap16Hi = Swap16(Hi16);
92 return (((u32)(Swap16Lo)) << 16) | ((u32)Swap16Hi);
95 /*****************************************************************************/
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
102 * @param Addr is a pointer to the region of memory to be tested.
103 * @param Len is the length of the block.
104 * @param Value is the constant used for writting the memory.
108 * - -1 is returned for a failure
109 * - 0 is returned for a pass
111 *****************************************************************************/
113 int Xil_TestIO8(u8 *Addr, int Len, u8 Value)
118 for (Index = 0; Index < Len; Index++) {
119 Xil_Out8((u32)Addr, Value);
121 ValueIn = Xil_In8((u32)Addr);
123 if (Value != ValueIn) {
132 /*****************************************************************************/
135 * Perform a destructive 16-bit wide register IO test. Each location is tested
136 * by sequentially writing a 16-bit wide register, reading the register, and
137 * comparing value. This function tests three kinds of register IO functions,
138 * normal register IO, little-endian register IO, and big-endian register IO.
139 * When testing little/big-endian IO, the function performs the following
140 * sequence, Xil_Out16LE/Xil_Out16BE, Xil_In16, Compare In-Out values,
141 * Xil_Out16, Xil_In16LE/Xil_In16BE, Compare In-Out values. Whether to swap the
142 * read-in value before comparing is controlled by the 5th argument.
144 * @param Addr is a pointer to the region of memory to be tested.
145 * @param Len is the length of the block.
146 * @param Value is the constant used for writting the memory.
147 * @param Kind is the test kind. Acceptable values are:
148 * XIL_TESTIO_DEFAULT, XIL_TESTIO_LE, XIL_TESTIO_BE.
149 * @param Swap indicates whether to byte swap the read-in value.
153 * - -1 is returned for a failure
154 * - 0 is returned for a pass
156 *****************************************************************************/
158 int Xil_TestIO16(u16 *Addr, int Len, u16 Value, int Kind, int Swap)
163 for (Index = 0; Index < Len; Index++) {
166 Xil_Out16LE((u32)Addr, Value);
169 Xil_Out16BE((u32)Addr, Value);
172 Xil_Out16((u32)Addr, Value);
176 ValueIn = Xil_In16((u32)Addr);
179 ValueIn = Swap16(ValueIn);
181 if (Value != ValueIn) {
186 Xil_Out16((u32)Addr, Value);
190 ValueIn = Xil_In16LE((u32)Addr);
193 ValueIn = Xil_In16BE((u32)Addr);
196 ValueIn = Xil_In16((u32)Addr);
202 ValueIn = Swap16(ValueIn);
204 if (Value != ValueIn) {
215 /*****************************************************************************/
218 * Perform a destructive 32-bit wide register IO test. Each location is tested
219 * by sequentially writing a 32-bit wide regsiter, reading the register, and
220 * comparing value. This function tests three kinds of register IO functions,
221 * normal register IO, little-endian register IO, and big-endian register IO.
222 * When testing little/big-endian IO, the function perform the following
223 * sequence, Xil_Out32LE/Xil_Out32BE, Xil_In32, Compare,
224 * Xil_Out32, Xil_In32LE/Xil_In32BE, Compare. Whether to swap the read-in value
225 * before comparing is controlled by the 5th argument.
227 * @param Addr is a pointer to the region of memory to be tested.
228 * @param Len is the length of the block.
229 * @param Value is the constant used for writting the memory.
230 * @param Kind is the test kind. Acceptable values are:
231 * XIL_TESTIO_DEFAULT, XIL_TESTIO_LE, XIL_TESTIO_BE.
232 * @param Swap indicates whether to byte swap the read-in value.
236 * - -1 is returned for a failure
237 * - 0 is returned for a pass
239 *****************************************************************************/
240 int Xil_TestIO32(u32 *Addr, int Len, u32 Value, int Kind, int Swap)
245 for (Index = 0; Index < Len; Index++) {
248 Xil_Out32LE((u32)Addr, Value);
251 Xil_Out32BE((u32)Addr, Value);
254 Xil_Out32((u32)Addr, Value);
258 ValueIn = Xil_In32((u32)Addr);
261 ValueIn = Swap32(ValueIn);
263 if (Value != ValueIn) {
268 Xil_Out32((u32)Addr, Value);
273 ValueIn = Xil_In32LE((u32)Addr);
276 ValueIn = Xil_In32BE((u32)Addr);
279 ValueIn = Xil_In32((u32)Addr);
284 ValueIn = Swap32(ValueIn);
286 if (Value != ValueIn) {