annotate packages/devs/flash/synth/current/tests/flash2.c @ 2863:7d8c61e6225c default tip

* Added execute permissions to files missed in conversion from CVS
author alexs
date Thu, 26 Mar 2009 20:39:18 +0000
parents 72041d295c0b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2630
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
1 /* Hey, the copyright is useful for something! */
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
2
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
3 static char copyright[] =
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
4 "//=========================================================================="
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
5 "//"
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
6 "// flash1.c"
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
7 "//"
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
8 "// Test flash operations for the synth target synth flash driver"
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
9 "//"
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
10 "//=========================================================================="
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
11 "// ####ECOSGPLCOPYRIGHTBEGIN#### "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
12 "// ------------------------------------------- "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
13 "// This file is part of eCos, the Embedded Configurable Operating System. "
2814
465fd3fc7787 * tests/flash2.c (cyg_user_start): Update for minor flash API
jlarmour
parents: 2729
diff changeset
14 "// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2009 Free Software Foundation, Inc. "
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
15 "// "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
16 "// eCos is free software; you can redistribute it and/or modify it under "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
17 "// the terms of the GNU General Public License as published by the Free "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
18 "// Software Foundation; either version 2 or (at your option) any later "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
19 "// version. "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
20 "// "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
21 "// eCos is distributed in the hope that it will be useful, but WITHOUT "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
22 "// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
23 "// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
24 "// for more details. "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
25 "// "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
26 "// You should have received a copy of the GNU General Public License "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
27 "// along with eCos; if not, write to the Free Software Foundation, Inc., "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
28 "// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
29 "// "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
30 "// As a special exception, if other files instantiate templates or use "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
31 "// macros or inline functions from this file, or you compile this file "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
32 "// and link it with other works to produce a work based on this file, "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
33 "// this file does not by itself cause the resulting work to be covered by "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
34 "// the GNU General Public License. However the source code for this file "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
35 "// must still be made available in accordance with section (3) of the GNU "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
36 "// General Public License v2. "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
37 "// "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
38 "// This exception does not invalidate any other reasons why a work based "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
39 "// on this file might be covered by the GNU General Public License. "
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2659
diff changeset
40 "// ------------------------------------------- "
2831
72041d295c0b Fix breakage caused by banner change
bartv
parents: 2824
diff changeset
41 "// ####ECOSGPLCOPYRIGHTEND####"
2630
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
42 "//=========================================================================="
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
43 "//#####DESCRIPTIONBEGIN####"
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
44 "//"
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
45 "// Author(s): andrew.lunn@ascom.ch"
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
46 "// Contributors: andrew.lunn"
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
47 "// Date: 2000-10-31"
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
48 "// Purpose: Test a flash driver"
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
49 "// Description: Try out a number of flash operations and make sure"
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
50 "// what is in the flash is what we expeect."
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
51 "// "
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
52 "//####DESCRIPTIONEND####"
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
53 "//"
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
54 "//==========================================================================&"
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
55 ;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
56
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
57 #include <pkgconf/devs_flash_synth.h>
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
58 #include <cyg/io/flash.h>
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
59 #include <cyg/infra/testcase.h>
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
60 #include <cyg/infra/diag.h>
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
61
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
62 #include <string.h>
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
63
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
64 #ifndef CYGINT_ISO_STRING_STRFUNCS
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
65 # define NA_MSG "Need string functions for test"
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
66 #endif
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
67
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
68 #ifdef NA_MSG
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
69 void cyg_user_start(void)
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
70 {
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
71 CYG_TEST_INIT();
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
72 CYG_TEST_NA( NA_MSG );
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
73 }
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
74 #else
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
75
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
76 //==========================================================================
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
77 // main
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
78
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
79 void cyg_user_start(void)
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
80 {
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
81 int ret;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
82 cyg_flashaddr_t flash_start=0, flash_end=0;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
83 cyg_flash_info_t info;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
84 int block_size=0, blocks=0;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
85 cyg_flashaddr_t prog_start;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
86 unsigned char * ptr;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
87 cyg_uint32 i=0;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
88 cyg_uint32 j;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
89
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
90 CYG_TEST_INIT();
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
91
2814
465fd3fc7787 * tests/flash2.c (cyg_user_start): Update for minor flash API
jlarmour
parents: 2729
diff changeset
92 cyg_flash_set_global_printf((cyg_flash_printf *)&diag_printf);
2824
7b953c0c429e * tests/flash2.c (cyg_user_start): Call cyg_flash_init with
jlarmour
parents: 2814
diff changeset
93 ret=cyg_flash_init(NULL);
2630
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
94
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
95 CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_init");
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
96
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
97 do {
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
98 ret = cyg_flash_get_info(i, &info);
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
99 if (ret == CYG_FLASH_ERR_OK) {
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
100 diag_printf("INFO: Nth=%d, start=%p, end=%p\n",
2659
a8a5496dc26a * tests/flash2.c: Fixed a few warnings.
asl
parents: 2630
diff changeset
101 i, (void *) info.start, (void *) info.end);
2630
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
102 if (i == 0) {
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
103 flash_start = info.start;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
104 flash_end = info.end;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
105 block_size = info.block_info[0].block_size;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
106 blocks = info.block_info[0].blocks;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
107 }
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
108 for (j=0;j < info.num_block_infos; j++) {
2659
a8a5496dc26a * tests/flash2.c: Fixed a few warnings.
asl
parents: 2630
diff changeset
109 diag_printf("INFO:\t block_size %zd, blocks %u\n",
2630
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
110 info.block_info[j].block_size,
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
111 info.block_info[j].blocks);
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
112 }
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
113 }
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
114 i++;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
115 } while (ret != CYG_FLASH_ERR_INVALID);
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
116
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
117 /* Erase the whole flash. Not recommended on real hardware since this
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
118 will probably erase the bootloader etc!!! */
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
119 ret=cyg_flash_erase(flash_start,block_size * blocks,NULL);
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
120 CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_erase1");
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
121
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
122 /* check that its actually been erased, and test the mmap area */
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
123 for (ptr=(unsigned char *)flash_start,ret=0;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
124 ptr <= (unsigned char *)flash_end; ptr++) {
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
125 if (*ptr != 0xff) {
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
126 ret++;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
127 }
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
128 }
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
129
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
130 CYG_TEST_PASS_FAIL((ret == 0),"flash empty check");
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
131
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
132 ret = cyg_flash_program(flash_start,&copyright,sizeof(copyright),NULL);
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
133 CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_program1");
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
134
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
135 /* Check the contents made it into the flash */
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
136 CYG_TEST_PASS_FAIL(!strncmp((void *)flash_start,
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
137 copyright,sizeof(copyright)),
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
138 "flash program contents");
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
139
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
140 /* .. and check nothing else changed */
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
141 for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
142 ptr < (unsigned char *)flash_end; ptr++) {
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
143 if (*ptr != 0xff) {
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
144 ret++;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
145 }
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
146 }
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
147
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
148 CYG_TEST_PASS_FAIL((ret == 0),"flash program overrun check");
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
149
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
150 /* Program over a block boundary */
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
151 prog_start = flash_start + block_size - sizeof(copyright)/2;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
152 ret = cyg_flash_program(prog_start,&copyright,sizeof(copyright),NULL);
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
153 CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_program2");
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
154
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
155 /* Check the first version is still OK */
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
156 CYG_TEST_PASS_FAIL(!strncmp((void *)flash_start,
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
157 copyright,
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
158 sizeof(copyright)),
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
159 "Original contents");
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
160
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
161 CYG_TEST_PASS_FAIL(!strncmp((void *)prog_start,
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
162 copyright,
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
163 sizeof(copyright)),
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
164 "New program contents");
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
165
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
166 /* Check the bit in between is still erased */
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
167 for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
168 ptr < (unsigned char *)prog_start; ptr++) {
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
169 if (*ptr != 0xff) {
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
170 ret++;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
171 }
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
172 }
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
173 CYG_TEST_PASS_FAIL((ret == 0),"flash erase check1");
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
174
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
175 /* Erase the second block and make sure the first is not erased */
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
176 ret=cyg_flash_erase(flash_start+block_size,block_size,NULL);
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
177 CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_erase2");
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
178
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
179 /* Check the erase worked */
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
180 for (ptr=(unsigned char *)flash_start+block_size,ret=0;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
181 ptr < (unsigned char *)flash_start+block_size*2;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
182 ptr++) {
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
183 if (*ptr != 0xff) {
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
184 ret++;
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
185 }
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
186 }
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
187
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
188 CYG_TEST_PASS_FAIL((ret == 0), "flash erase check2");
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
189
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
190 /* Lastly check the first half of the copyright message is still there */
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
191 CYG_TEST_PASS_FAIL(!strncmp((void *)prog_start,
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
192 copyright,
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
193 sizeof(copyright)/2),
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
194 "Block 1 OK");
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
195
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
196 #if 0
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
197 /* This test is be fatal! Its not run by default!
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
198 Check the flash is read only, by trying to write to it. We expect
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
199 to get an exception */
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
200
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
201 *(char *)flash_start = 'a';
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
202 #endif
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
203
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
204 CYG_TEST_PASS_FINISH("flash1");
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
205 }
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
206
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
207 #endif /* ifndef NA_MSG */
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
208
3e8e26d3183a Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents:
diff changeset
209 /* EOF flash2.c */