]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/standalone_v4_2/src/xil_testcache.c
Common scheduler code:
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / BSP / microblaze_0 / libsrc / standalone_v4_2 / src / xil_testcache.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2009 - 2014 Xilinx, Inc.  All rights reserved.
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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.
18 *
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
25 * SOFTWARE.
26 *
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.
30 *
31 ******************************************************************************/
32 /*****************************************************************************/
33 /**
34 *
35 * @file xil_testcache.c
36 *
37 * Contains utility functions to test cache.
38 *
39 * <pre>
40 * MODIFICATION HISTORY:
41 *
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
46 *                                     cache line.
47 * </pre>
48 *
49 * @note
50 *
51 * This file contain functions that all operate on HAL.
52 *
53 ******************************************************************************/
54 #include "xil_cache.h"
55 #include "xil_testcache.h"
56
57 extern void xil_printf(const char *ctrl1, ...);
58
59 #define DATA_LENGTH 128
60
61 #ifdef __GNUC__
62 static u32 Data[DATA_LENGTH] __attribute__ ((aligned(32)));
63 #elif defined (__ICCARM__)
64 static u32 Data[DATA_LENGTH];
65 #else
66 static u32 Data[DATA_LENGTH] __attribute__ ((aligned(32)));
67 #endif
68
69 /**
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.
74 *
75 * @return
76 *
77 *     - 0 is returned for a pass
78 *     - -1 is returned for a failure
79 */
80 int Xil_TestDCacheRange(void)
81 {
82         int Index;
83         int Status;
84
85         u32 Value;
86
87         xil_printf("-- Cache Range Test --\n\r");
88
89
90         for (Index = 0; Index < DATA_LENGTH; Index++)
91                 Data[Index] = 0xA0A00505;
92
93         xil_printf("    initialize Data done:\r\n");
94
95         Xil_DCacheFlushRange((u32)Data, DATA_LENGTH * sizeof(u32));
96
97         xil_printf("    flush range done\r\n");
98         for (Index = 0; Index < DATA_LENGTH; Index++)
99                 Data[Index] = Index + 3;
100
101         Xil_DCacheInvalidateRange((u32)Data, DATA_LENGTH * sizeof(u32));
102
103         xil_printf("    invalidate dcache range done\r\n");
104
105         Status = 0;
106
107         for (Index = 0; Index < DATA_LENGTH; Index++) {
108                 Value = Data[Index];
109                 if (Value != 0xA0A00505) {
110                         Status = -1;
111                         xil_printf("Data[%d] = %x\r\n", Index, Value);
112                         break;
113                 }
114         }
115
116         if (!Status) {
117                 xil_printf("    Invalidate worked\r\n");
118         }
119         else {
120                 xil_printf("Error: Invalidate dcache range not working\r\n");
121         }
122
123         xil_printf("-- Cache Range Test Complete --\r\n");
124
125         return Status;
126
127 }
128
129 /**
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
133 * the DCache.
134 *
135 * @return
136 *     - 0 is returned for a pass
137 *     - -1 is returned for a failure
138 */
139 int Xil_TestDCacheAll(void)
140 {
141         int Index;
142         int Status;
143         u32 Value;
144
145         xil_printf("-- Cache All Test --\n\r");
146
147
148         for (Index = 0; Index < DATA_LENGTH; Index++)
149                 Data[Index] = 0x50500A0A;
150
151         xil_printf("    initialize Data done:\r\n");
152
153         Xil_DCacheFlush();
154
155         xil_printf("    flush all done\r\n");
156
157         for (Index = 0; Index < DATA_LENGTH; Index++)
158                 Data[Index] = Index + 3;
159
160         Xil_DCacheInvalidate();
161
162         xil_printf("    invalidate all done\r\n");
163
164         Status = 0;
165
166         for (Index = 0; Index < DATA_LENGTH; Index++) {
167                 Value = Data[Index];
168                 if (Value != 0x50500A0A) {
169                         Status = -1;
170                         xil_printf("Data[%d] = %x\r\n", Index, Value);
171                         break;
172                 }
173         }
174
175         if (!Status) {
176                 xil_printf("    Invalidate all worked\r\n");
177         }
178         else {
179                 xil_printf("Error: Invalidate dcache all not working\r\n");
180         }
181
182         xil_printf("-- DCache all Test Complete --\n\r");
183
184         return Status;
185
186 }
187
188
189 /**
190 * Perform Xil_ICacheInvalidateRange() on a few function pointers.
191 *
192 * @return
193 *
194 *     - 0 is returned for a pass
195 *     The function will hang if it fails.
196 */
197 int Xil_TestICacheRange(void)
198 {
199
200         Xil_ICacheInvalidateRange((u32)Xil_TestICacheRange, 1024);
201         Xil_ICacheInvalidateRange((u32)Xil_TestDCacheRange, 1024);
202         Xil_ICacheInvalidateRange((u32)Xil_TestDCacheAll, 1024);
203
204         xil_printf("-- Invalidate icache range done --\r\n");
205
206         return 0;
207 }
208
209 /**
210 * Perform Xil_ICacheInvalidate().
211 *
212 * @return
213 *
214 *     - 0 is returned for a pass
215 *     The function will hang if it fails.
216 */
217 int Xil_TestICacheAll(void)
218 {
219         Xil_ICacheInvalidate();
220         xil_printf("-- Invalidate icache all done --\r\n");
221         return 0;
222 }