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