1 /******************************************************************************
4 * (c) Copyright 2009 Xilinx, Inc. All rights reserved.
6 * This file contains confidential and proprietary information of Xilinx, Inc.
7 * and is protected under U.S. and international copyright and other
8 * intellectual property laws.
11 * This disclaimer is not a license and does not grant any rights to the
12 * materials distributed herewith. Except as otherwise provided in a valid
13 * license issued to you by Xilinx, and to the maximum extent permitted by
14 * applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL
15 * FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS,
16 * IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
17 * MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE;
18 * and (2) Xilinx shall not be liable (whether in contract or tort, including
19 * negligence, or under any other theory of liability) for any loss or damage
20 * of any kind or nature related to, arising under or in connection with these
21 * materials, including for any direct, or any indirect, special, incidental,
22 * or consequential loss or damage (including loss of data, profits, goodwill,
23 * or any type of loss or damage suffered as a result of any action brought by
24 * a third party) even if such damage or loss was reasonably foreseeable or
25 * Xilinx had been advised of the possibility of the same.
27 * CRITICAL APPLICATIONS
28 * Xilinx products are not designed or intended to be fail-safe, or for use in
29 * any application requiring fail-safe performance, such as life-support or
30 * safety devices or systems, Class III medical devices, nuclear facilities,
31 * applications related to the deployment of airbags, or any other applications
32 * that could lead to death, personal injury, or severe property or
33 * environmental damage (individually and collectively, "Critical
34 * Applications"). Customer assumes the sole risk and liability of any use of
35 * Xilinx products in Critical Applications, subject only to applicable laws
36 * and regulations governing limitations on product liability.
38 * THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE
42 ******************************************************************************/
43 /*****************************************************************************/
46 * @file xil_testmemend.c
48 * Contains the memory test utility functions.
51 * MODIFICATION HISTORY:
53 * Ver Who Date Changes
54 * ----- ---- -------- -----------------------------------------------
55 * 1.00a hbm 08/25/09 First release
58 *****************************************************************************/
60 /***************************** Include Files ********************************/
61 #include "xil_testio.h"
62 #include "xil_assert.h"
65 /************************** Constant Definitions ****************************/
66 /************************** Function Prototypes *****************************/
72 * Endian swap a 16-bit word.
73 * @param Data is the 16-bit word to be swapped.
74 * @return The endian swapped valud.
77 static u16 Swap16(u16 Data)
79 return ((Data >> 8) & 0x00FF) | ((Data << 8) & 0xFF00);
84 * Endian swap a 32-bit word.
85 * @param Data is the 32-bit word to be swapped.
86 * @return The endian swapped valud.
89 static u32 Swap32(u32 Data)
97 Hi16 = (u16)((Data >> 16) & 0x0000FFFF);
98 Lo16 = (u16)(Data & 0x0000FFFF);
100 Swap16Lo = Swap16(Lo16);
101 Swap16Hi = Swap16(Hi16);
103 return (((u32)(Swap16Lo)) << 16) | ((u32)Swap16Hi);
106 /*****************************************************************************/
109 * Perform a destructive 8-bit wide register IO test where the register is
110 * accessed using Xil_Out8 and Xil_In8, and comparing the reading and writing
113 * @param Addr is a pointer to the region of memory to be tested.
114 * @param Len is the length of the block.
115 * @param Value is the constant used for writting the memory.
119 * - -1 is returned for a failure
120 * - 0 is returned for a pass
122 *****************************************************************************/
124 int Xil_TestIO8(u8 *Addr, int Len, u8 Value)
129 for (Index = 0; Index < Len; Index++) {
130 Xil_Out8((u32)Addr, Value);
132 ValueIn = Xil_In8((u32)Addr);
134 if (Value != ValueIn) {
143 /*****************************************************************************/
146 * Perform a destructive 16-bit wide register IO test. Each location is tested
147 * by sequentially writing a 16-bit wide register, reading the register, and
148 * comparing value. This function tests three kinds of register IO functions,
149 * normal register IO, little-endian register IO, and big-endian register IO.
150 * When testing little/big-endian IO, the function performs the following
151 * sequence, Xil_Out16LE/Xil_Out16BE, Xil_In16, Compare In-Out values,
152 * Xil_Out16, Xil_In16LE/Xil_In16BE, Compare In-Out values. Whether to swap the
153 * read-in value before comparing is controlled by the 5th argument.
155 * @param Addr is a pointer to the region of memory to be tested.
156 * @param Len is the length of the block.
157 * @param Value is the constant used for writting the memory.
158 * @param Kind is the test kind. Acceptable values are:
159 * XIL_TESTIO_DEFAULT, XIL_TESTIO_LE, XIL_TESTIO_BE.
160 * @param Swap indicates whether to byte swap the read-in value.
164 * - -1 is returned for a failure
165 * - 0 is returned for a pass
167 *****************************************************************************/
169 int Xil_TestIO16(u16 *Addr, int Len, u16 Value, int Kind, int Swap)
174 for (Index = 0; Index < Len; Index++) {
177 Xil_Out16LE((u32)Addr, Value);
180 Xil_Out16BE((u32)Addr, Value);
183 Xil_Out16((u32)Addr, Value);
187 ValueIn = Xil_In16((u32)Addr);
190 ValueIn = Swap16(ValueIn);
192 if (Value != ValueIn) {
197 Xil_Out16((u32)Addr, Value);
201 ValueIn = Xil_In16LE((u32)Addr);
204 ValueIn = Xil_In16BE((u32)Addr);
207 ValueIn = Xil_In16((u32)Addr);
213 ValueIn = Swap16(ValueIn);
215 if (Value != ValueIn) {
226 /*****************************************************************************/
229 * Perform a destructive 32-bit wide register IO test. Each location is tested
230 * by sequentially writing a 32-bit wide regsiter, reading the register, and
231 * comparing value. This function tests three kinds of register IO functions,
232 * normal register IO, little-endian register IO, and big-endian register IO.
233 * When testing little/big-endian IO, the function perform the following
234 * sequence, Xil_Out32LE/Xil_Out32BE, Xil_In32, Compare,
235 * Xil_Out32, Xil_In32LE/Xil_In32BE, Compare. Whether to swap the read-in value
236 * before comparing is controlled by the 5th argument.
238 * @param Addr is a pointer to the region of memory to be tested.
239 * @param Len is the length of the block.
240 * @param Value is the constant used for writting the memory.
241 * @param Kind is the test kind. Acceptable values are:
242 * XIL_TESTIO_DEFAULT, XIL_TESTIO_LE, XIL_TESTIO_BE.
243 * @param Swap indicates whether to byte swap the read-in value.
247 * - -1 is returned for a failure
248 * - 0 is returned for a pass
250 *****************************************************************************/
251 int Xil_TestIO32(u32 *Addr, int Len, u32 Value, int Kind, int Swap)
256 for (Index = 0; Index < Len; Index++) {
259 Xil_Out32LE((u32)Addr, Value);
262 Xil_Out32BE((u32)Addr, Value);
265 Xil_Out32((u32)Addr, Value);
269 ValueIn = Xil_In32((u32)Addr);
272 ValueIn = Swap32(ValueIn);
274 if (Value != ValueIn) {
279 Xil_Out32((u32)Addr, Value);
284 ValueIn = Xil_In32LE((u32)Addr);
287 ValueIn = Xil_In32BE((u32)Addr);
290 ValueIn = Xil_In32((u32)Addr);
295 ValueIn = Swap32(ValueIn);
297 if (Value != ValueIn) {