1 //==========================================================================
5 // eCos generic DRAM test code
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
41 //#####DESCRIPTIONBEGIN####
44 // Contributors: gthomas
46 // Description: Tool used to test DRAM on eval boards
47 //####DESCRIPTIONEND####
49 #include <pkgconf/system.h>
50 #include <cyg/infra/testcase.h>
54 #include <pkgconf/kernel.h> // Configuration header
56 #ifdef CYGFUN_KERNEL_API_C
58 #include <cyg/kernel/kapi.h>
59 #include <cyg/infra/diag.h>
61 #include <cyg/hal/hal_arch.h>
62 #include CYGHWR_MEMORY_LAYOUT_H // Memory layout
69 #define STACK_SIZE CYGNUM_HAL_STACK_SIZE_MINIMUM
70 static char stack[STACK_SIZE];
71 static cyg_thread thread_data;
72 static cyg_handle_t thread_handle;
74 extern char __bss_end;
81 #define REFRESH_TIME 5
83 int decay_time[] = { 50, 100, 200, 500, 1000 };
84 #define NUM_DECAY sizeof(decay_time)/sizeof(decay_time[0])
95 report_error(void *addr, cyg_uint32 actual, cyg_uint32 expected)
99 if (++error_count > MAX_ERRORS) return;
100 diag_printf(" 0x%08x: expected - 0x%08x, actual - 0x%08x\n",
101 addr, expected, actual);
104 // Fill longwords with their own address and verify
107 addr_test(cyg_uint32 start, cyg_uint32 end)
112 diag_printf("-- Address test\n");
113 for (mp = (cyg_uint32 *)start; mp < (cyg_uint32 *)end; mp++) {
114 *mp = (cyg_uint32)mp;
116 for (mp = (cyg_uint32 *)start; mp < (cyg_uint32 *)end; mp++) {
117 if (*mp != (cyg_uint32)mp) {
118 report_error(mp, *mp, (cyg_uint32)mp);
123 // Fill longwords with zeros
126 zeros_test(cyg_uint32 start, cyg_uint32 end)
131 diag_printf("-- Zeros test\n");
132 for (mp = (cyg_uint32 *)start; mp < (cyg_uint32 *)end; mp++) {
135 for (mp = (cyg_uint32 *)start; mp < (cyg_uint32 *)end; mp++) {
136 if (*mp != (cyg_uint32)0) {
137 report_error(mp, *mp, (cyg_uint32)0);
142 // Fill longwords with all ones
145 ones_test(cyg_uint32 start, cyg_uint32 end)
150 diag_printf("-- Ones test\n");
151 for (mp = (cyg_uint32 *)start; mp < (cyg_uint32 *)end; mp++) {
152 *mp = (cyg_uint32)0xFFFFFFFF;
154 for (mp = (cyg_uint32 *)start; mp < (cyg_uint32 *)end; mp++) {
155 if (*mp != (cyg_uint32)0xFFFFFFFF) {
156 report_error(mp, *mp, (cyg_uint32)0xFFFFFFFF);
161 // Fill longwords with a "walking" bit
164 walking_bit_test(cyg_uint32 start, cyg_uint32 end)
170 diag_printf("-- Walking test\n");
172 for (mp = (cyg_uint32 *)start; mp < (cyg_uint32 *)end; mp++) {
173 *mp = (cyg_uint32)bit;
175 if (bit == 0) bit = 1;
178 for (mp = (cyg_uint32 *)start; mp < (cyg_uint32 *)end; mp++) {
179 if (*mp != (cyg_uint32)bit) {
180 report_error(mp, *mp, (cyg_uint32)bit);
183 if (bit == 0) bit = 1;
187 // Fill longwords with an alternating pattern
190 pattern_test(cyg_uint32 start, cyg_uint32 end)
196 diag_printf("-- Pattern test\n");
198 for (mp = (cyg_uint32 *)start; mp < (cyg_uint32 *)end; mp++) {
199 *mp = (cyg_uint32)pat;
201 for (mp = (cyg_uint32 *)start; mp < (cyg_uint32 *)end; mp++) {
202 if (*mp != (cyg_uint32)pat) {
203 report_error(mp, *mp, (cyg_uint32)pat);
207 for (mp = (cyg_uint32 *)start; mp < (cyg_uint32 *)end; mp++) {
208 *mp = (cyg_uint32)pat;
210 for (mp = (cyg_uint32 *)start; mp < (cyg_uint32 *)end; mp++) {
211 if (*mp != (cyg_uint32)pat) {
212 report_error(mp, *mp, (cyg_uint32)pat);
217 // Verify if refresh works
220 refresh_test(cyg_uint32 start, cyg_uint32 end)
226 diag_printf("-- Refresh test\n");
228 for (mp = (cyg_uint32 *)start; mp < (cyg_uint32 *)end; mp++) {
229 *mp = (cyg_uint32)pat;
231 cyg_thread_delay(REFRESH_TIME*100);
232 for (mp = (cyg_uint32 *)start; mp < (cyg_uint32 *)end; mp++) {
233 if (*mp != (cyg_uint32)pat) {
234 report_error(mp, *mp, (cyg_uint32)pat);
238 for (mp = (cyg_uint32 *)start; mp < (cyg_uint32 *)end; mp++) {
239 *mp = (cyg_uint32)pat;
241 cyg_thread_delay(REFRESH_TIME*100);
242 for (mp = (cyg_uint32 *)start; mp < (cyg_uint32 *)end; mp++) {
243 if (*mp != (cyg_uint32)pat) {
244 report_error(mp, *mp, (cyg_uint32)pat);
249 // See how long we can "sleep" before refresh fails
252 decay_test(cyg_uint32 start, cyg_uint32 end)
258 diag_printf("-- Decay test\n");
259 for (i = 0; i < NUM_DECAY; i++) {
260 diag_printf(" ... %d.%02d sec delay\n", decay_time[i]/100, decay_time[i]%100);
263 for (mp = (cyg_uint32 *)start; mp < (cyg_uint32 *)end; mp++) {
264 *mp = (cyg_uint32)pat;
266 cyg_thread_delay(decay_time[i]);
267 for (mp = (cyg_uint32 *)start; mp < (cyg_uint32 *)end; mp++) {
268 if (*mp != (cyg_uint32)pat) {
269 report_error(mp, *mp, (cyg_uint32)pat);
273 for (mp = (cyg_uint32 *)start; mp < (cyg_uint32 *)end; mp++) {
274 *mp = (cyg_uint32)pat;
276 cyg_thread_delay(decay_time[i]);
277 for (mp = (cyg_uint32 *)start; mp < (cyg_uint32 *)end; mp++) {
278 if (*mp != (cyg_uint32)pat) {
279 report_error(mp, *mp, (cyg_uint32)pat);
282 diag_printf(" ... %d errors\n", error_count);
288 dram_exercise(cyg_addrword_t p)
290 cyg_uint32 start_DRAM, end_DRAM;
295 end_DRAM = CYGMEM_REGION_ram+CYGMEM_REGION_ram_SIZE;
296 start_DRAM = ((cyg_uint32)&__bss_end + 0x00000FFF) & 0xFFFFF000;
297 diag_printf("DRAM test - start: 0x%08x, end: 0x%08x\n", start_DRAM, end_DRAM);
299 for (i = 0; i < NUM_RUNS; i++) {
300 diag_printf("\n*** Start run #%d of %d\n", i+1, NUM_RUNS);
302 addr_test(start_DRAM, end_DRAM);
303 ones_test(start_DRAM, end_DRAM);
304 zeros_test(start_DRAM, end_DRAM);
305 walking_bit_test(start_DRAM, end_DRAM);
306 pattern_test(start_DRAM, end_DRAM);
307 refresh_test(start_DRAM, end_DRAM);
308 decay_test(start_DRAM, end_DRAM);
309 diag_printf("\n*** End run, %d errors, %d total errors\n", run_errors, total_errors);
312 CYG_TEST_PASS_FINISH("DRAM testing complete");
318 // Create a main thread, so we can run the scheduler and have time 'pass'
319 cyg_thread_create(10, // Priority - just a number
320 dram_exercise, // entry
321 0, // entry parameter
325 &thread_handle, // Handle
326 &thread_data // Thread data structure
328 cyg_thread_resume(thread_handle); // Start it
329 cyg_scheduler_start();
330 } // cyg_package_start()
332 #else /* def CYGFUN_KERNEL_API_C */
333 # define NA_MSG "Kernel C API layer disabled"
336 #else /* def CYGPKG_KERNEL */
337 # define NA_MSG "No kernel"