1 /******************************************************************************
3 * Copyright (C) 2009 - 2015 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 /*****************************************************************************/
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 value.
66 static u16 Swap16(u16 Data)
68 return ((Data >> 8U) & 0x00FFU) | ((Data << 8U) & 0xFF00U);
73 * Endian swap a 32-bit word.
74 * @param Data is the 32-bit word to be swapped.
75 * @return The endian swapped value.
78 static u32 Swap32(u32 Data)
86 Hi16 = (u16)((Data >> 16U) & 0x0000FFFFU);
87 Lo16 = (u16)(Data & 0x0000FFFFU);
89 Swap16Lo = Swap16(Lo16);
90 Swap16Hi = Swap16(Hi16);
92 return (((u32)(Swap16Lo)) << 16U) | ((u32)Swap16Hi);
95 /*****************************************************************************/
98 * @brief Perform a destructive 8-bit wide register IO test where the
99 * register is accessed using Xil_Out8 and Xil_In8, and comparing
100 * the written values by reading them back.
102 * @param Addr: a pointer to the region of memory to be tested.
103 * @param Length: Length of the block.
104 * @param Value: constant used for writting the memory.
107 * - -1 is returned for a failure
108 * - 0 is returned for a pass
110 *****************************************************************************/
112 s32 Xil_TestIO8(u8 *Addr, s32 Length, u8 Value)
118 for (Index = 0; Index < Length; Index++) {
119 Xil_Out8((INTPTR)Addr, Value);
121 ValueIn = Xil_In8((INTPTR)Addr);
123 if ((Value != ValueIn) && (Status == 0)) {
132 /*****************************************************************************/
135 * @brief Perform a destructive 16-bit wide register IO test. Each location
136 * is tested by sequentially writing a 16-bit wide register, reading
137 * the register, and comparing value. This function tests three kinds
138 * of register IO functions, normal register IO, little-endian register
139 * IO, and big-endian register IO. When testing little/big-endian IO,
140 * the function performs the following sequence, Xil_Out16LE/Xil_Out16BE,
141 * Xil_In16, Compare In-Out values, Xil_Out16, Xil_In16LE/Xil_In16BE,
142 * Compare In-Out values. Whether to swap the read-in value before
143 * comparing is controlled by the 5th argument.
145 * @param Addr: a pointer to the region of memory to be tested.
146 * @param Length: Length of the block.
147 * @param Value: constant used for writting the memory.
148 * @param Kind: Type of test. 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.
153 * - -1 is returned for a failure
154 * - 0 is returned for a pass
156 *****************************************************************************/
158 s32 Xil_TestIO16(u16 *Addr, s32 Length, u16 Value, s32 Kind, s32 Swap)
164 Xil_AssertNonvoid(TempAddr16 != NULL);
166 for (Index = 0; Index < Length; Index++) {
169 Xil_Out16LE((INTPTR)TempAddr16, Value);
172 Xil_Out16BE((INTPTR)TempAddr16, Value);
175 Xil_Out16((INTPTR)TempAddr16, Value);
179 ValueIn = Xil_In16((INTPTR)TempAddr16);
181 if ((Kind != 0) && (Swap != 0)) {
182 ValueIn = Swap16(ValueIn);
185 if (Value != ValueIn) {
190 Xil_Out16((INTPTR)TempAddr16, Value);
194 ValueIn = Xil_In16LE((INTPTR)TempAddr16);
197 ValueIn = Xil_In16BE((INTPTR)TempAddr16);
200 ValueIn = Xil_In16((INTPTR)TempAddr16);
205 if ((Kind != 0) && (Swap != 0)) {
206 ValueIn = Swap16(ValueIn);
209 if (Value != ValueIn) {
212 TempAddr16 += sizeof(u16);
218 /*****************************************************************************/
221 * @brief Perform a destructive 32-bit wide register IO test. Each location
222 * is tested by sequentially writing a 32-bit wide regsiter, reading
223 * the register, and comparing value. This function tests three kinds
224 * of register IO functions, normal register IO, little-endian register IO,
225 * and big-endian register IO. When testing little/big-endian IO,
226 * the function perform the following sequence, Xil_Out32LE/
227 * Xil_Out32BE, Xil_In32, Compare, Xil_Out32, Xil_In32LE/Xil_In32BE, Compare.
228 * Whether to swap the read-in value *before comparing is controlled
229 * by the 5th argument.
230 * @param Addr: a pointer to the region of memory to be tested.
231 * @param Length: Length of the block.
232 * @param Value: constant used for writting the memory.
233 * @param Kind: type of test. Acceptable values are:
234 * XIL_TESTIO_DEFAULT, XIL_TESTIO_LE, XIL_TESTIO_BE.
235 * @param Swap: indicates whether to byte swap the read-in value.
238 * - -1 is returned for a failure
239 * - 0 is returned for a pass
241 *****************************************************************************/
242 s32 Xil_TestIO32(u32 *Addr, s32 Length, u32 Value, s32 Kind, s32 Swap)
248 Xil_AssertNonvoid(TempAddr != NULL);
250 for (Index = 0; Index < Length; Index++) {
253 Xil_Out32LE((INTPTR)TempAddr, Value);
256 Xil_Out32BE((INTPTR)TempAddr, Value);
259 Xil_Out32((INTPTR)TempAddr, Value);
263 ValueIn = Xil_In32((INTPTR)TempAddr);
265 if ((Kind != 0) && (Swap != 0)) {
266 ValueIn = Swap32(ValueIn);
269 if (Value != ValueIn) {
274 Xil_Out32((INTPTR)TempAddr, Value);
279 ValueIn = Xil_In32LE((INTPTR)TempAddr);
282 ValueIn = Xil_In32BE((INTPTR)TempAddr);
285 ValueIn = Xil_In32((INTPTR)TempAddr);
289 if ((Kind != 0) && (Swap != 0)) {
290 ValueIn = Swap32(ValueIn);
293 if (Value != ValueIn) {
296 TempAddr += sizeof(u32);