annotate packages/devs/flash/synthv2/current/tests/flash3.c @ 1756:2f4e31c45a45

Update following changes to the flash device driver interface
author bartv
date Mon, 22 Nov 2004 20:54:04 +0000
parents a24dbf2587a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
1 /* Hay, the copyright is usefull for something! */
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
2
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
3 static char copyright[] =
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
4 "//=========================================================================="
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
5 "//"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
6 "// flash1.c"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
7 "//"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
8 "// Test flash operations for the synth target synth flash driver"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
9 "//"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
10 "//=========================================================================="
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
11 "//####ECOSGPLCOPYRIGHTBEGIN####"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
12 "// -------------------------------------------"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
13 "// This file is part of eCos, the Embedded Configurable Operating System."
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
14 "// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc."
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
15 "//"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
16 "// eCos is free software; you can redistribute it and/or modify it under"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
17 "// the terms of the GNU General Public License as published by the Free"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
18 "// Software Foundation; either version 2 or (at your option) any later version."
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
19 "//"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
20 "// eCos is distributed in the hope that it will be useful, but WITHOUT ANY"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
21 "// WARRANTY; without even the implied warranty of MERCHANTABILITY or"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
22 "// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
23 "// for more details."
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
24 "//"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
25 "// You should have received a copy of the GNU General Public License along"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
26 "// with eCos; if not, write to the Free Software Foundation, Inc.,"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
27 "// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA."
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
28 "//"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
29 "// As a special exception, if other files instantiate templates or use macros"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
30 "// or inline functions from this file, or you compile this file and link it"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
31 "// with other works to produce a work based on this file, this file does not"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
32 "// by itself cause the resulting work to be covered by the GNU General Public"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
33 "// License. However the source code for this file must still be made available"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
34 "// in accordance with section (3) of the GNU General Public License."
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
35 "//"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
36 "// This exception does not invalidate any other reasons why a work based on"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
37 "// this file might be covered by the GNU General Public License."
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
38 "//"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
39 "// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc."
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
40 "// at http://sources.redhat.com/ecos/ecos-license/"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
41 "// -------------------------------------------"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
42 "//####ECOSGPLCOPYRIGHTEND####"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
43 "//=========================================================================="
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
44 "//#####DESCRIPTIONBEGIN####"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
45 "//"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
46 "// Author(s): andrew.lunn@ascom.ch"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
47 "// Contributors: andrew.lunn"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
48 "// Date: 2000-10-31"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
49 "// Purpose: Test a flash driver"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
50 "// Description: Try out a number of flash operations and make sure"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
51 "// what is in the flash is what we expeect."
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
52 "// "
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
53 "//####DESCRIPTIONEND####"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
54 "//"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
55 "//==========================================================================&"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
56 ;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
57
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
58 #include <pkgconf/system.h>
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1724
diff changeset
59 #ifdef CYGPKG_DEVS_FLASH_SYNTH_V2
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
60 #include <pkgconf/devs_flash_synth_v2.h>
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1724
diff changeset
61 #endif
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1724
diff changeset
62 #ifdef CYGPKG_DEVS_FLASH_SYNTH
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
63 #include <pkgconf/devs_flash_synth.h>
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1724
diff changeset
64 #endif
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
65 #include <cyg/io/flash.h>
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
66 #include <cyg/infra/testcase.h>
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
67 #include <cyg/infra/diag.h>
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
68 #include <cyg/flash/synth.h>
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
69
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
70 #include <string.h>
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
71
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
72 #ifndef CYGINT_ISO_STRING_STRFUNCS
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
73 # define NA_MSG "Need string functions for test"
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
74 #endif
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
75
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
76 #ifdef NA_MSG
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
77 void cyg_user_start(void)
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
78 {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
79 CYG_TEST_INIT();
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
80 CYG_TEST_NA( NA_MSG );
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
81 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
82 #else
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
83
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1724
diff changeset
84 static struct cyg_flash_synth_priv synth_flash_priv3 = {
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1724
diff changeset
85 .block_size = CYGNUM_FLASH_SYNTH_V2_BLOCKSIZE,
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1724
diff changeset
86 .blocks = CYGNUM_FLASH_SYNTH_V2_NUMBLOCKS,
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1724
diff changeset
87 .boot_block_size = CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCKSIZE,
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1724
diff changeset
88 .boot_blocks = CYGNUM_FLASH_SYNTH_V2_NUMBOOT_BLOCKS,
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1724
diff changeset
89 .boot_block_bottom = CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCK_BOTTOM,
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1724
diff changeset
90 .filename = "synth.flash3",
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1724
diff changeset
91 .flashfd = -1
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
92 };
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
93
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
94 CYG_FLASH_DRIVER(cyg_flash_synth_flashdev_flash3,
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
95 &cyg_flash_synth_funs,
1756
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1724
diff changeset
96 0, // flags
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1724
diff changeset
97 0x40020000, // start
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1724
diff changeset
98 0, // end, filled in by init
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1724
diff changeset
99 0, // number of block_info's, filled in by init
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1724
diff changeset
100 synth_flash_priv3.block_info,
2f4e31c45a45 Update following changes to the flash device driver interface
bartv
parents: 1724
diff changeset
101 &synth_flash_priv3);
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
102
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
103 //==========================================================================
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
104 // main
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
105
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
106 void cyg_user_start(void)
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
107 {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
108 int ret;
1720
fcf5b538459b * tests/flash[23].c: Removed calls to cyg_flash_get_block_info()
asl
parents: 1702
diff changeset
109 cyg_flashaddr_t flash_start=0, flash_end=0;
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
110 cyg_flash_info_t info;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
111 cyg_uint32 i=0;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
112 cyg_uint32 j;
1720
fcf5b538459b * tests/flash[23].c: Removed calls to cyg_flash_get_block_info()
asl
parents: 1702
diff changeset
113 int block_size=0, blocks=0;
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
114 cyg_flashaddr_t prog_start;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
115 unsigned char * ptr;
1724
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1720
diff changeset
116 size_t copyright_len;
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1720
diff changeset
117
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
118 CYG_TEST_INIT();
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
119
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
120 // Reference the flash dev so the linker does not throw it away
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
121 CYG_REFERENCE_OBJECT(cyg_flash_synth_flashdev_flash3);
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
122
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
123 ret=cyg_flash_init((cyg_flash_printf *)diag_printf);
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
124
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
125 CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_init");
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
126
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
127 do {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
128 ret = cyg_flash_get_info(i, &info);
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
129 if (ret == CYG_FLASH_ERR_OK) {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
130 diag_printf("INFO: Nth=%d, start=%p, end=%p\n",
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
131 i, info.start, info.end);
1720
fcf5b538459b * tests/flash[23].c: Removed calls to cyg_flash_get_block_info()
asl
parents: 1702
diff changeset
132 if (i == 0) {
fcf5b538459b * tests/flash[23].c: Removed calls to cyg_flash_get_block_info()
asl
parents: 1702
diff changeset
133 flash_start = info.start;
fcf5b538459b * tests/flash[23].c: Removed calls to cyg_flash_get_block_info()
asl
parents: 1702
diff changeset
134 flash_end = info.end;
fcf5b538459b * tests/flash[23].c: Removed calls to cyg_flash_get_block_info()
asl
parents: 1702
diff changeset
135 block_size = info.block_info[0].block_size;
fcf5b538459b * tests/flash[23].c: Removed calls to cyg_flash_get_block_info()
asl
parents: 1702
diff changeset
136 blocks = info.block_info[0].blocks;
fcf5b538459b * tests/flash[23].c: Removed calls to cyg_flash_get_block_info()
asl
parents: 1702
diff changeset
137 }
fcf5b538459b * tests/flash[23].c: Removed calls to cyg_flash_get_block_info()
asl
parents: 1702
diff changeset
138
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
139 for (j=0;j < info.num_block_infos; j++) {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
140 diag_printf("INFO:\t block_size %d, blocks %d\n",
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
141 info.block_info[j].block_size,
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
142 info.block_info[j].blocks);
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
143 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
144 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
145 i++;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
146 } while (ret != CYG_FLASH_ERR_INVALID);
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
147
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
148 /* Erase the whole flash. Not recommended on real hardware since this
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
149 will probably erase the bootloader etc!!! */
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
150 ret=cyg_flash_erase(flash_start,block_size * blocks,NULL);
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
151 CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_erase1");
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
152
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
153 /* check that its actually been erased, and test the mmap area */
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
154 for (ptr=(unsigned char *)flash_start,ret=0;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
155 ptr <= (unsigned char *)flash_end; ptr++) {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
156 if (*ptr != 0xff) {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
157 ret++;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
158 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
159 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
160
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
161 CYG_TEST_PASS_FAIL((ret == 0),"flash empty check");
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
162
1724
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1720
diff changeset
163 // With small blocks we have to use less of the copyright messages
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1720
diff changeset
164 // Since we make assumptions about fitting the message into a
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1720
diff changeset
165 // block.
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1720
diff changeset
166 if (block_size < sizeof(copyright)*2/3) {
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1720
diff changeset
167 copyright_len = block_size / 3;
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1720
diff changeset
168 } else {
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1720
diff changeset
169 copyright_len = sizeof(copyright);
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1720
diff changeset
170 }
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1720
diff changeset
171
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1720
diff changeset
172 ret = cyg_flash_program(flash_start,&copyright,copyright_len,NULL);
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
173 CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_program1");
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
174
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
175 /* Check the contents made it into the flash */
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
176 CYG_TEST_PASS_FAIL(!strncmp((void *)flash_start,
1724
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1720
diff changeset
177 copyright,copyright_len),
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
178 "flash program contents");
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
179
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
180 /* .. and check nothing else changed */
1724
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1720
diff changeset
181 for (ptr=(unsigned char *)flash_start+copyright_len,ret=0;
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
182 ptr < (unsigned char *)flash_end; ptr++) {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
183 if (*ptr != 0xff) {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
184 ret++;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
185 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
186 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
187
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
188 CYG_TEST_PASS_FAIL((ret == 0),"flash program overrun check");
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
189
1724
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1720
diff changeset
190 prog_start = flash_start + block_size - copyright_len/2;
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1720
diff changeset
191 ret = cyg_flash_program(prog_start,&copyright,copyright_len,NULL);
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
192 CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_program2");
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
193
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
194 /* Check the first version is still OK */
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
195 CYG_TEST_PASS_FAIL(!strncmp((void *)flash_start,
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
196 copyright,
1724
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1720
diff changeset
197 copyright_len),
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
198 "Original contents");
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
199
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
200 CYG_TEST_PASS_FAIL(!strncmp((void *)prog_start,
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
201 copyright,
1724
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1720
diff changeset
202 copyright_len),
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
203 "New program contents");
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
204
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
205 /* Check the bit in between is still erased */
1724
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1720
diff changeset
206 for (ptr=(unsigned char *)flash_start+copyright_len,ret=0;
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
207 ptr < (unsigned char *)prog_start; ptr++) {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
208 if (*ptr != 0xff) {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
209 ret++;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
210 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
211 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
212 CYG_TEST_PASS_FAIL((ret == 0),"flash erase check1");
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
213
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
214 /* Erase the second block and make sure the first is not erased */
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
215 ret=cyg_flash_erase(flash_start+block_size,block_size,NULL);
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
216 CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_erase2");
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
217
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
218 /* Check the erase worked */
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
219 for (ptr=(unsigned char *)flash_start+block_size,ret=0;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
220 ptr < (unsigned char *)flash_start+block_size*2;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
221 ptr++) {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
222 if (*ptr != 0xff) {
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
223 ret++;
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
224 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
225 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
226
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
227 CYG_TEST_PASS_FAIL((ret == 0), "flash erase check2");
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
228
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
229 /* Lastly check the first half of the copyright message is still there */
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
230 CYG_TEST_PASS_FAIL(!strncmp((void *)prog_start,
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
231 copyright,
1724
a24dbf2587a3 * src/flash_synth.c: Allow the use of arbitary sized block.
asl
parents: 1720
diff changeset
232 copyright_len/2),
1702
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
233 "Block 1 OK");
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
234
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
235 #if 0
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
236 /* This test is be fatal! Its not run by default!
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
237 Check the flash is read only, by trying to write to it. We expect
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
238 to get an exception */
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
239
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
240 *(char *)flash_start = 'a';
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
241 #endif
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
242
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
243 CYG_TEST_PASS_FINISH("flash3");
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
244 }
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
245
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
246 #endif /* ifndef NA_MSG */
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
247
0673c75f3a08 Import the first version of the synth flash driver which uses the V2 API.
asl
parents:
diff changeset
248 /* EOF flash1.c */