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 /*****************************************************************************/
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 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 * 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 Length 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 s32 Xil_TestIO8(u8 *Addr, s32 Length, u8 Value)
119 for (Index = 0; Index < Length; Index++) {
120 Xil_Out8((INTPTR)Addr, Value);
122 ValueIn = Xil_In8((INTPTR)Addr);
124 if ((Value != ValueIn) && (Status == 0)) {
133 /*****************************************************************************/
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.
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.
154 * - -1 is returned for a failure
155 * - 0 is returned for a pass
157 *****************************************************************************/
159 s32 Xil_TestIO16(u16 *Addr, s32 Length, u16 Value, s32 Kind, s32 Swap)
165 Xil_AssertNonvoid(TempAddr16 != NULL);
167 for (Index = 0; Index < Length; Index++) {
170 Xil_Out16LE((INTPTR)TempAddr16, Value);
173 Xil_Out16BE((INTPTR)TempAddr16, Value);
176 Xil_Out16((INTPTR)TempAddr16, Value);
180 ValueIn = Xil_In16((INTPTR)TempAddr16);
182 if ((Kind != 0) && (Swap != 0)) {
183 ValueIn = Swap16(ValueIn);
186 if (Value != ValueIn) {
191 Xil_Out16((INTPTR)TempAddr16, Value);
195 ValueIn = Xil_In16LE((INTPTR)TempAddr16);
198 ValueIn = Xil_In16BE((INTPTR)TempAddr16);
201 ValueIn = Xil_In16((INTPTR)TempAddr16);
206 if ((Kind != 0) && (Swap != 0)) {
207 ValueIn = Swap16(ValueIn);
210 if (Value != ValueIn) {
213 TempAddr16 += sizeof(u16);
219 /*****************************************************************************/
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.
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.
240 * - -1 is returned for a failure
241 * - 0 is returned for a pass
243 *****************************************************************************/
244 s32 Xil_TestIO32(u32 *Addr, s32 Length, u32 Value, s32 Kind, s32 Swap)
250 Xil_AssertNonvoid(TempAddr != NULL);
252 for (Index = 0; Index < Length; Index++) {
255 Xil_Out32LE((INTPTR)TempAddr, Value);
258 Xil_Out32BE((INTPTR)TempAddr, Value);
261 Xil_Out32((INTPTR)TempAddr, Value);
265 ValueIn = Xil_In32((INTPTR)TempAddr);
267 if ((Kind != 0) && (Swap != 0)) {
268 ValueIn = Swap32(ValueIn);
271 if (Value != ValueIn) {
276 Xil_Out32((INTPTR)TempAddr, Value);
281 ValueIn = Xil_In32LE((INTPTR)TempAddr);
284 ValueIn = Xil_In32BE((INTPTR)TempAddr);
287 ValueIn = Xil_In32((INTPTR)TempAddr);
291 if ((Kind != 0) && (Swap != 0)) {
292 ValueIn = Swap32(ValueIn);
295 if (Value != ValueIn) {
298 TempAddr += sizeof(u32);