Mercurial > ecos
annotate 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 |
| rev | line source |
|---|---|
| 1732 | 1 //================================================================= |
| 2 // | |
| 3 // flash1.c | |
| 4 // | |
| 5 // Simple tests for FLASH drivers | |
| 6 // | |
| 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. | |
| 12 // Copyright (C) 2004 Gary Thomas | |
|
2626
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
13 // Copyright (C) 2004, 2005 eCosCentric Limited |
| 1732 | 14 // |
| 15 // eCos is free software; you can redistribute it and/or modify it under | |
| 16 // the terms of the GNU General Public License as published by the Free | |
| 17 // Software Foundation; either version 2 or (at your option) any later version. | |
| 18 // | |
| 19 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY | |
| 20 // WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 21 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 22 // for more details. | |
| 23 // | |
| 24 // You should have received a copy of the GNU General Public License along | |
| 25 // with eCos; if not, write to the Free Software Foundation, Inc., | |
| 26 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
| 27 // | |
| 28 // As a special exception, if other files instantiate templates or use macros | |
| 29 // or inline functions from this file, or you compile this file and link it | |
| 30 // with other works to produce a work based on this file, this file does not | |
| 31 // by itself cause the resulting work to be covered by the GNU General Public | |
| 32 // License. However the source code for this file must still be made available | |
| 33 // in accordance with section (3) of the GNU General Public License. | |
| 34 // | |
| 35 // This exception does not invalidate any other reasons why a work based on | |
| 36 // this file might be covered by the GNU General Public License. | |
| 37 // | |
| 38 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. | |
| 39 // at http://sources.redhat.com/ecos/ecos-license/ | |
| 40 // ------------------------------------------- | |
| 41 //####ECOSGPLCOPYRIGHTEND#### | |
| 42 //================================================================= | |
| 43 //#####DESCRIPTIONBEGIN#### | |
| 44 // | |
| 45 // Author(s): gthomas | |
| 46 // Contributors: | |
| 47 // Date: 2004-04-24 | |
| 48 // Description: Simple test of FLASH I/O. | |
| 49 // | |
| 50 // Options: | |
| 51 //####DESCRIPTIONEND#### | |
| 52 | |
| 53 // #define DEBUG_PRINTFS | |
| 54 | |
| 55 #include <pkgconf/hal.h> | |
| 56 #include <pkgconf/io_flash.h> | |
| 57 #include CYGHWR_MEMORY_LAYOUT_H | |
| 58 | |
| 59 #include <cyg/infra/diag.h> | |
| 60 #include <cyg/infra/testcase.h> | |
| 61 | |
| 62 #include <cyg/io/flash.h> | |
| 63 #include <cyg/hal/hal_if.h> | |
| 64 | |
|
2626
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
65 #ifndef CYGSEM_IO_FLASH_LEGACY_API |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
66 externC void |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
67 cyg_start( void ) |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
68 { |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
69 CYG_TEST_INIT(); |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
70 CYG_TEST_NA("Only usable with legacy API"); |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
71 } |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
72 #else |
| 1732 | 73 externC void |
| 74 cyg_start( void ) | |
| 75 { | |
| 76 int stat; | |
| 77 void *err_addr; | |
| 78 CYG_ADDRWORD flash_start, flash_end; | |
| 2055 | 79 void **flash_start_addr = (void *)&flash_start; |
| 80 void **flash_end_addr = (void *)&flash_end; | |
| 1732 | 81 void *flash_test_start, *flash_addr; |
| 2055 | 82 cyg_int32 flash_block_size, flash_num_blocks; |
| 1732 | 83 CYG_ADDRWORD test_buf1, test_buf2; |
| 84 cyg_uint32 *lp1, *lp2; | |
|
1928
5445c3413b0f
* tests/flash1.c: Fixed compiler warning with diag_printf.
asl
parents:
1732
diff
changeset
|
85 int i, len; |
| 1732 | 86 cyg_bool passed, ok; |
| 87 | |
|
2626
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
88 CYG_TEST_INIT(); |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
89 |
| 1732 | 90 #if 0 |
|
1928
5445c3413b0f
* tests/flash1.c: Fixed compiler warning with diag_printf.
asl
parents:
1732
diff
changeset
|
91 int j; |
|
5445c3413b0f
* tests/flash1.c: Fixed compiler warning with diag_printf.
asl
parents:
1732
diff
changeset
|
92 |
| 1732 | 93 diag_printf("Testing udelay: "); |
| 94 for (i = 0; i < 30; i++) { | |
| 95 for (j = 0; j < 1000; j++) { | |
| 96 CYGACC_CALL_IF_DELAY_US(1000); // Should be 1 second | |
| 97 } | |
| 98 diag_printf("."); | |
| 99 } | |
| 100 diag_printf("\n"); | |
| 101 #endif | |
| 102 | |
| 103 passed = true; | |
| 104 | |
| 105 if ((stat = flash_init(diag_printf)) != 0) { | |
| 106 diag_printf("FLASH: driver init failed: %s\n", flash_errmsg(stat)); | |
| 107 CYG_TEST_FAIL_FINISH("FLASH driver init failed"); | |
| 108 } | |
| 2055 | 109 flash_get_limits((void *)0, flash_start_addr, flash_end_addr); |
| 1732 | 110 // Keep 'end' address as last valid location, to avoid wrap around problems |
| 111 flash_end = flash_end - 1; | |
| 112 flash_get_block_info(&flash_block_size, &flash_num_blocks); | |
| 113 | |
| 2055 | 114 diag_printf("FLASH: 0x%x - 0x%x, %d blocks of 0x%x bytes each.\n", |
| 115 flash_start, flash_end + 1, flash_num_blocks, | |
| 116 flash_block_size); | |
| 1732 | 117 |
| 118 // Verify that the testing limits are within the bounds of the | |
| 119 // physical device. Also verify that the size matches with | |
| 120 // the erase block size on the device | |
| 121 if ((CYGNUM_IO_FLASH_TEST_OFFSET > (flash_end - flash_start)) || | |
| 122 ((CYGNUM_IO_FLASH_TEST_OFFSET + CYGNUM_IO_FLASH_TEST_LENGTH) > (flash_end - flash_start))) { | |
| 123 CYG_TEST_FAIL_FINISH("FLASH test region outside physical limits"); | |
| 124 } | |
| 125 if ((CYGNUM_IO_FLASH_TEST_LENGTH % flash_block_size) != 0) { | |
| 126 CYG_TEST_FAIL_FINISH("FLASH test region must be integral multiple of erase block size"); | |
| 127 } | |
| 128 | |
| 129 // Allocate two buffers large enough for the test | |
| 130 test_buf1 = (CYG_ADDRWORD)CYGMEM_SECTION_heap1; | |
| 131 test_buf2 = test_buf1 + CYGNUM_IO_FLASH_TEST_LENGTH; | |
| 132 if (CYGMEM_SECTION_heap1_SIZE < (CYGNUM_IO_FLASH_TEST_LENGTH * 2)) { | |
| 133 CYG_TEST_FAIL_FINISH("FLASH not enough heap space - reduce size of test region"); | |
| 134 } | |
| 135 diag_printf("... Using test buffers at %p and %p\n", (void *)test_buf1, (void *)test_buf2); | |
| 136 flash_test_start = (void *)(flash_start + CYGNUM_IO_FLASH_TEST_OFFSET); | |
| 137 | |
|
2626
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
138 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
139 // Unlock test |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
140 diag_printf("... Unlock test\n"); |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
141 ok = true; |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
142 if ((stat = flash_unlock(flash_test_start, |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
143 CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) { |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
144 diag_printf("FLASH: unlock failed: %s\n", flash_errmsg(stat)); |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
145 ok = false; |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
146 } |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
147 #endif |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
148 |
| 1732 | 149 // Erase test |
| 150 diag_printf("... Erase test\n"); | |
| 151 ok = true; | |
| 152 if ((stat = flash_erase(flash_test_start, | |
|
2626
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
153 CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) { |
| 1732 | 154 diag_printf("FLASH: erase failed: %s\n", flash_errmsg(stat)); |
| 155 ok = false; | |
| 156 } | |
| 157 if (ok && (stat = flash_read(flash_test_start, (void *)test_buf1, | |
|
2626
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
158 CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) { |
| 1732 | 159 diag_printf("FLASH: read/verify after erase failed: %s\n", flash_errmsg(stat)); |
| 160 ok = false; | |
| 161 } | |
| 162 lp1 = (cyg_uint32 *)test_buf1; | |
| 163 for (i = 0; i < CYGNUM_IO_FLASH_TEST_LENGTH; i += sizeof(cyg_uint32)) { | |
| 164 if (*lp1++ != 0xFFFFFFFF) { | |
|
1928
5445c3413b0f
* tests/flash1.c: Fixed compiler warning with diag_printf.
asl
parents:
1732
diff
changeset
|
165 diag_printf("FLASH: non-erased data found at offset %x\n", (CYG_ADDRWORD)(lp1-1) - test_buf1); |
| 1732 | 166 diag_dump_buf((void *)(lp1-1), 32); |
| 167 ok = false; | |
| 168 break; | |
| 169 } | |
| 170 } | |
| 171 // Try reading in little pieces | |
| 172 len = CYGNUM_IO_FLASH_TEST_LENGTH; | |
| 173 flash_addr = flash_test_start; | |
| 174 while (len > 0) { | |
|
2626
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
175 if ((stat = flash_read(flash_addr, (void *)test_buf1, 0x200, &err_addr)) != CYG_FLASH_ERR_OK) { |
| 1732 | 176 diag_printf("FLASH: read[short]/verify after erase failed: %s\n", flash_errmsg(stat)); |
| 177 ok = false; | |
| 178 break; | |
| 179 } | |
| 180 flash_addr = (cyg_uint8 *)flash_addr + 0x200; | |
| 181 len -= 0x200; | |
| 182 lp1 = (cyg_uint32 *)test_buf1; | |
| 183 for (i = 0; i < 0x200; i += sizeof(cyg_uint32)) { | |
| 184 if (*lp1++ != 0xFFFFFFFF) { | |
| 185 diag_printf("FLASH: non-erased data found at offset %p\n", | |
| 186 (cyg_uint8 *)flash_addr + (CYG_ADDRWORD)((lp1-1) - test_buf1)); | |
| 187 diag_dump_buf((void *)(lp1-1), 32); | |
| 188 ok = false; | |
| 189 len = 0; | |
| 190 break; | |
| 191 } | |
| 192 } | |
| 193 } | |
| 194 | |
| 195 if (!ok) { | |
| 196 CYG_TEST_INFO("FLASH erase failed"); | |
| 197 passed = false; | |
| 198 } | |
| 199 | |
| 200 // Simple write/verify test | |
| 201 diag_printf("... Write/verify test\n"); | |
| 202 lp1 = (cyg_uint32 *)test_buf1; | |
| 203 for (i = 0; i < CYGNUM_IO_FLASH_TEST_LENGTH; i += sizeof(cyg_uint32)) { | |
| 204 *lp1 = (cyg_uint32)lp1; | |
| 205 lp1++; | |
| 206 } | |
| 207 ok = true; | |
| 208 if (ok && (stat = flash_program(flash_test_start, (void *)test_buf1, | |
|
2626
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
209 CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) { |
| 1732 | 210 diag_printf("FLASH: write failed: %s\n", flash_errmsg(stat)); |
| 211 ok = false; | |
| 212 } | |
| 213 if (ok && (stat = flash_read(flash_test_start, (void *)test_buf2, | |
|
2626
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
214 CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) { |
| 1732 | 215 diag_printf("FLASH: read/verify after write failed: %s\n", flash_errmsg(stat)); |
| 216 ok = false; | |
| 217 } | |
| 218 lp1 = (cyg_uint32 *)test_buf1; | |
| 219 lp2 = (cyg_uint32 *)test_buf2; | |
| 220 for (i = 0; i < CYGNUM_IO_FLASH_TEST_LENGTH; i += sizeof(cyg_uint32)) { | |
| 221 if (*lp2++ != *lp1++) { | |
|
1928
5445c3413b0f
* tests/flash1.c: Fixed compiler warning with diag_printf.
asl
parents:
1732
diff
changeset
|
222 diag_printf("FLASH: incorrect data found at offset %x\n", (CYG_ADDRWORD)(lp2-1) - test_buf2); |
| 1732 | 223 diag_dump_buf((void *)(lp2-1), 32); |
| 224 ok = false; | |
| 225 break; | |
| 226 } | |
| 227 } | |
| 228 // Try reading in little pieces | |
| 229 len = CYGNUM_IO_FLASH_TEST_LENGTH; | |
| 230 flash_addr = flash_test_start; | |
| 231 lp1 = (cyg_uint32 *)test_buf1; | |
| 232 lp2 = (cyg_uint32 *)test_buf2; | |
| 233 while (len > 0) { | |
|
2626
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
234 if ((stat = flash_read(flash_addr, lp2, 0x200, &err_addr)) != CYG_FLASH_ERR_OK) { |
| 1732 | 235 diag_printf("FLASH: read[short]/verify after erase failed: %s\n", flash_errmsg(stat)); |
| 236 ok = false; | |
| 237 break; | |
| 238 } | |
| 239 flash_addr = (cyg_uint8 *)flash_addr + 0x200; | |
| 240 len -= 0x200; | |
| 241 for (i = 0; i < 0x200; i += sizeof(cyg_uint32)) { | |
| 242 if (*lp2++ != *lp1++) { | |
| 243 diag_printf("FLASH: incorrect data found at offset %p\n", | |
| 244 (cyg_uint8 *)flash_addr + (CYG_ADDRWORD)((lp2-1) - test_buf2)); | |
| 245 diag_dump_buf((void *)(lp2-1), 32); | |
| 246 ok = false; | |
| 247 len = 0; | |
| 248 break; | |
| 249 } | |
| 250 } | |
| 251 } | |
|
2626
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
252 |
| 1732 | 253 if (!ok) { |
| 254 CYG_TEST_INFO("FLASH write/verify failed"); | |
| 255 } | |
| 256 | |
|
2626
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
257 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
258 // Lock test |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
259 diag_printf("... Lock test\n"); |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
260 ok = true; |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
261 if ((stat = flash_lock(flash_test_start, |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
262 CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) { |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
263 diag_printf("FLASH: unlock failed: %s\n", flash_errmsg(stat)); |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
264 ok = false; |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
265 } |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
266 #endif |
|
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
267 |
| 1732 | 268 if (passed) { |
| 269 CYG_TEST_PASS_FINISH("FLASH test1"); | |
| 270 } else { | |
| 271 CYG_TEST_FAIL_FINISH("FLASH test1"); | |
| 272 } | |
| 273 } | |
|
2626
a2f5434df2cb
Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
2055
diff
changeset
|
274 #endif |
| 1732 | 275 |
| 276 // EOF flash1.c |
