comparison packages/io/flash/current/tests/flash1.c @ 2626:a2f5434df2cb

Merge flashv2 branch to trunk, with eCosCentric additions
author jlarmour
date Tue, 18 Nov 2008 00:56:04 +0000
parents fc88957d075c
children 74dbf4c3f2e1
comparison
equal deleted inserted replaced
2625:e38c98808295 2626:a2f5434df2cb
8 //####ECOSGPLCOPYRIGHTBEGIN#### 8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // ------------------------------------------- 9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System. 10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. 11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 // Copyright (C) 2004 Gary Thomas 12 // Copyright (C) 2004 Gary Thomas
13 // Copyright (C) 2004, 2005 eCosCentric Limited
13 // 14 //
14 // eCos is free software; you can redistribute it and/or modify it under 15 // eCos is free software; you can redistribute it and/or modify it under
15 // the terms of the GNU General Public License as published by the Free 16 // the terms of the GNU General Public License as published by the Free
16 // Software Foundation; either version 2 or (at your option) any later version. 17 // Software Foundation; either version 2 or (at your option) any later version.
17 // 18 //
59 #include <cyg/infra/testcase.h> 60 #include <cyg/infra/testcase.h>
60 61
61 #include <cyg/io/flash.h> 62 #include <cyg/io/flash.h>
62 #include <cyg/hal/hal_if.h> 63 #include <cyg/hal/hal_if.h>
63 64
65 #ifndef CYGSEM_IO_FLASH_LEGACY_API
66 externC void
67 cyg_start( void )
68 {
69 CYG_TEST_INIT();
70 CYG_TEST_NA("Only usable with legacy API");
71 }
72 #else
64 externC void 73 externC void
65 cyg_start( void ) 74 cyg_start( void )
66 { 75 {
67 int stat; 76 int stat;
68 void *err_addr; 77 void *err_addr;
74 CYG_ADDRWORD test_buf1, test_buf2; 83 CYG_ADDRWORD test_buf1, test_buf2;
75 cyg_uint32 *lp1, *lp2; 84 cyg_uint32 *lp1, *lp2;
76 int i, len; 85 int i, len;
77 cyg_bool passed, ok; 86 cyg_bool passed, ok;
78 87
88 CYG_TEST_INIT();
89
79 #if 0 90 #if 0
80 int j; 91 int j;
81 92
82 diag_printf("Testing udelay: "); 93 diag_printf("Testing udelay: ");
83 for (i = 0; i < 30; i++) { 94 for (i = 0; i < 30; i++) {
122 CYG_TEST_FAIL_FINISH("FLASH not enough heap space - reduce size of test region"); 133 CYG_TEST_FAIL_FINISH("FLASH not enough heap space - reduce size of test region");
123 } 134 }
124 diag_printf("... Using test buffers at %p and %p\n", (void *)test_buf1, (void *)test_buf2); 135 diag_printf("... Using test buffers at %p and %p\n", (void *)test_buf1, (void *)test_buf2);
125 flash_test_start = (void *)(flash_start + CYGNUM_IO_FLASH_TEST_OFFSET); 136 flash_test_start = (void *)(flash_start + CYGNUM_IO_FLASH_TEST_OFFSET);
126 137
138 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
139 // Unlock test
140 diag_printf("... Unlock test\n");
141 ok = true;
142 if ((stat = flash_unlock(flash_test_start,
143 CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) {
144 diag_printf("FLASH: unlock failed: %s\n", flash_errmsg(stat));
145 ok = false;
146 }
147 #endif
148
127 // Erase test 149 // Erase test
128 diag_printf("... Erase test\n"); 150 diag_printf("... Erase test\n");
129 ok = true; 151 ok = true;
130 if ((stat = flash_erase(flash_test_start, 152 if ((stat = flash_erase(flash_test_start,
131 CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != FLASH_ERR_OK) { 153 CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) {
132 diag_printf("FLASH: erase failed: %s\n", flash_errmsg(stat)); 154 diag_printf("FLASH: erase failed: %s\n", flash_errmsg(stat));
133 ok = false; 155 ok = false;
134 } 156 }
135 if (ok && (stat = flash_read(flash_test_start, (void *)test_buf1, 157 if (ok && (stat = flash_read(flash_test_start, (void *)test_buf1,
136 CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != FLASH_ERR_OK) { 158 CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) {
137 diag_printf("FLASH: read/verify after erase failed: %s\n", flash_errmsg(stat)); 159 diag_printf("FLASH: read/verify after erase failed: %s\n", flash_errmsg(stat));
138 ok = false; 160 ok = false;
139 } 161 }
140 lp1 = (cyg_uint32 *)test_buf1; 162 lp1 = (cyg_uint32 *)test_buf1;
141 for (i = 0; i < CYGNUM_IO_FLASH_TEST_LENGTH; i += sizeof(cyg_uint32)) { 163 for (i = 0; i < CYGNUM_IO_FLASH_TEST_LENGTH; i += sizeof(cyg_uint32)) {
148 } 170 }
149 // Try reading in little pieces 171 // Try reading in little pieces
150 len = CYGNUM_IO_FLASH_TEST_LENGTH; 172 len = CYGNUM_IO_FLASH_TEST_LENGTH;
151 flash_addr = flash_test_start; 173 flash_addr = flash_test_start;
152 while (len > 0) { 174 while (len > 0) {
153 if ((stat = flash_read(flash_addr, (void *)test_buf1, 0x200, &err_addr)) != FLASH_ERR_OK) { 175 if ((stat = flash_read(flash_addr, (void *)test_buf1, 0x200, &err_addr)) != CYG_FLASH_ERR_OK) {
154 diag_printf("FLASH: read[short]/verify after erase failed: %s\n", flash_errmsg(stat)); 176 diag_printf("FLASH: read[short]/verify after erase failed: %s\n", flash_errmsg(stat));
155 ok = false; 177 ok = false;
156 break; 178 break;
157 } 179 }
158 flash_addr = (cyg_uint8 *)flash_addr + 0x200; 180 flash_addr = (cyg_uint8 *)flash_addr + 0x200;
182 *lp1 = (cyg_uint32)lp1; 204 *lp1 = (cyg_uint32)lp1;
183 lp1++; 205 lp1++;
184 } 206 }
185 ok = true; 207 ok = true;
186 if (ok && (stat = flash_program(flash_test_start, (void *)test_buf1, 208 if (ok && (stat = flash_program(flash_test_start, (void *)test_buf1,
187 CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != FLASH_ERR_OK) { 209 CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) {
188 diag_printf("FLASH: write failed: %s\n", flash_errmsg(stat)); 210 diag_printf("FLASH: write failed: %s\n", flash_errmsg(stat));
189 ok = false; 211 ok = false;
190 } 212 }
191 if (ok && (stat = flash_read(flash_test_start, (void *)test_buf2, 213 if (ok && (stat = flash_read(flash_test_start, (void *)test_buf2,
192 CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != FLASH_ERR_OK) { 214 CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) {
193 diag_printf("FLASH: read/verify after write failed: %s\n", flash_errmsg(stat)); 215 diag_printf("FLASH: read/verify after write failed: %s\n", flash_errmsg(stat));
194 ok = false; 216 ok = false;
195 } 217 }
196 lp1 = (cyg_uint32 *)test_buf1; 218 lp1 = (cyg_uint32 *)test_buf1;
197 lp2 = (cyg_uint32 *)test_buf2; 219 lp2 = (cyg_uint32 *)test_buf2;
207 len = CYGNUM_IO_FLASH_TEST_LENGTH; 229 len = CYGNUM_IO_FLASH_TEST_LENGTH;
208 flash_addr = flash_test_start; 230 flash_addr = flash_test_start;
209 lp1 = (cyg_uint32 *)test_buf1; 231 lp1 = (cyg_uint32 *)test_buf1;
210 lp2 = (cyg_uint32 *)test_buf2; 232 lp2 = (cyg_uint32 *)test_buf2;
211 while (len > 0) { 233 while (len > 0) {
212 if ((stat = flash_read(flash_addr, lp2, 0x200, &err_addr)) != FLASH_ERR_OK) { 234 if ((stat = flash_read(flash_addr, lp2, 0x200, &err_addr)) != CYG_FLASH_ERR_OK) {
213 diag_printf("FLASH: read[short]/verify after erase failed: %s\n", flash_errmsg(stat)); 235 diag_printf("FLASH: read[short]/verify after erase failed: %s\n", flash_errmsg(stat));
214 ok = false; 236 ok = false;
215 break; 237 break;
216 } 238 }
217 flash_addr = (cyg_uint8 *)flash_addr + 0x200; 239 flash_addr = (cyg_uint8 *)flash_addr + 0x200;
225 len = 0; 247 len = 0;
226 break; 248 break;
227 } 249 }
228 } 250 }
229 } 251 }
230 252
231 if (!ok) { 253 if (!ok) {
232 CYG_TEST_INFO("FLASH write/verify failed"); 254 CYG_TEST_INFO("FLASH write/verify failed");
233 } 255 }
234 256
257 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
258 // Lock test
259 diag_printf("... Lock test\n");
260 ok = true;
261 if ((stat = flash_lock(flash_test_start,
262 CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) {
263 diag_printf("FLASH: unlock failed: %s\n", flash_errmsg(stat));
264 ok = false;
265 }
266 #endif
267
235 if (passed) { 268 if (passed) {
236 CYG_TEST_PASS_FINISH("FLASH test1"); 269 CYG_TEST_PASS_FINISH("FLASH test1");
237 } else { 270 } else {
238 CYG_TEST_FAIL_FINISH("FLASH test1"); 271 CYG_TEST_FAIL_FINISH("FLASH test1");
239 } 272 }
240 } 273 }
274 #endif
241 275
242 // EOF flash1.c 276 // EOF flash1.c