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_testcache.c
37 * Contains utility functions to test cache.
40 * MODIFICATION HISTORY:
42 * Ver Who Date Changes
43 * ----- ---- -------- -------------------------------------------------------
44 * 1.00a hbm 07/28/09 Initial release
45 * 4.1 asa 05/09/14 Ensured that the address uses for cache test is aligned
51 * This file contain functions that all operate on HAL.
53 ******************************************************************************/
54 #include "xil_cache.h"
55 #include "xil_testcache.h"
57 extern void xil_printf(const char *ctrl1, ...);
59 #define DATA_LENGTH 128
62 static u32 Data[DATA_LENGTH] __attribute__ ((aligned(32)));
63 #elif defined (__ICCARM__)
64 static u32 Data[DATA_LENGTH];
66 static u32 Data[DATA_LENGTH] __attribute__ ((aligned(32)));
70 * Perform DCache range related API test such as Xil_DCacheFlushRange and
71 * Xil_DCacheInvalidateRange. This test function writes a constant value
72 * to the Data array, flushes the range, writes a new value, then invalidates
73 * the corresponding range.
77 * - 0 is returned for a pass
78 * - -1 is returned for a failure
80 int Xil_TestDCacheRange(void)
87 xil_printf("-- Cache Range Test --\n\r");
90 for (Index = 0; Index < DATA_LENGTH; Index++)
91 Data[Index] = 0xA0A00505;
93 xil_printf(" initialize Data done:\r\n");
95 Xil_DCacheFlushRange((u32)Data, DATA_LENGTH * sizeof(u32));
97 xil_printf(" flush range done\r\n");
98 for (Index = 0; Index < DATA_LENGTH; Index++)
99 Data[Index] = Index + 3;
101 Xil_DCacheInvalidateRange((u32)Data, DATA_LENGTH * sizeof(u32));
103 xil_printf(" invalidate dcache range done\r\n");
107 for (Index = 0; Index < DATA_LENGTH; Index++) {
109 if (Value != 0xA0A00505) {
111 xil_printf("Data[%d] = %x\r\n", Index, Value);
117 xil_printf(" Invalidate worked\r\n");
120 xil_printf("Error: Invalidate dcache range not working\r\n");
123 xil_printf("-- Cache Range Test Complete --\r\n");
130 * Perform DCache all related API test such as Xil_DCacheFlush and
131 * Xil_DCacheInvalidate. This test function writes a constant value
132 * to the Data array, flushes the DCache, writes a new value, then invalidates
136 * - 0 is returned for a pass
137 * - -1 is returned for a failure
139 int Xil_TestDCacheAll(void)
145 xil_printf("-- Cache All Test --\n\r");
148 for (Index = 0; Index < DATA_LENGTH; Index++)
149 Data[Index] = 0x50500A0A;
151 xil_printf(" initialize Data done:\r\n");
155 xil_printf(" flush all done\r\n");
157 for (Index = 0; Index < DATA_LENGTH; Index++)
158 Data[Index] = Index + 3;
160 Xil_DCacheInvalidate();
162 xil_printf(" invalidate all done\r\n");
166 for (Index = 0; Index < DATA_LENGTH; Index++) {
168 if (Value != 0x50500A0A) {
170 xil_printf("Data[%d] = %x\r\n", Index, Value);
176 xil_printf(" Invalidate all worked\r\n");
179 xil_printf("Error: Invalidate dcache all not working\r\n");
182 xil_printf("-- DCache all Test Complete --\n\r");
190 * Perform Xil_ICacheInvalidateRange() on a few function pointers.
194 * - 0 is returned for a pass
195 * The function will hang if it fails.
197 int Xil_TestICacheRange(void)
200 Xil_ICacheInvalidateRange((u32)Xil_TestICacheRange, 1024);
201 Xil_ICacheInvalidateRange((u32)Xil_TestDCacheRange, 1024);
202 Xil_ICacheInvalidateRange((u32)Xil_TestDCacheAll, 1024);
204 xil_printf("-- Invalidate icache range done --\r\n");
210 * Perform Xil_ICacheInvalidate().
214 * - 0 is returned for a pass
215 * The function will hang if it fails.
217 int Xil_TestICacheAll(void)
219 Xil_ICacheInvalidate();
220 xil_printf("-- Invalidate icache all done --\r\n");