Mercurial > flash_v2
annotate packages/devs/flash/sst/39vfxxx/current/include/flash_sst_39vfxxx.inl @ 1755:21fc12d67292
Update following changes to the flash device driver interface
| author | bartv |
|---|---|
| date | Mon, 22 Nov 2004 20:40:54 +0000 |
| parents | 80232dbac7fb |
| children | 9c1d9e5039c2 |
| rev | line source |
|---|---|
| 1346 | 1 #ifndef CYGONCE_DEVS_FLASH_SST_39VFXXX_INL |
| 2 #define CYGONCE_DEVS_FLASH_SST_39VFXXX_INL | |
| 3 //========================================================================== | |
| 4 // | |
| 5 // flash_sst_39vfxxx.inl | |
| 6 // | |
| 7 // SST 39VFxxx series flash driver | |
| 8 // | |
| 9 //========================================================================== | |
| 10 //####ECOSGPLCOPYRIGHTBEGIN#### | |
| 11 // ------------------------------------------- | |
| 12 // This file is part of eCos, the Embedded Configurable Operating System. | |
| 13 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
14 // Copyright (C) 2004 Andrew Lunn |
| 1346 | 15 // |
| 16 // eCos is free software; you can redistribute it and/or modify it under | |
| 17 // the terms of the GNU General Public License as published by the Free | |
| 18 // Software Foundation; either version 2 or (at your option) any later version. | |
| 19 // | |
| 20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY | |
| 21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 22 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 23 // for more details. | |
| 24 // | |
| 25 // You should have received a copy of the GNU General Public License along | |
| 26 // with eCos; if not, write to the Free Software Foundation, Inc., | |
| 27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
| 28 // | |
| 29 // As a special exception, if other files instantiate templates or use macros | |
| 30 // or inline functions from this file, or you compile this file and link it | |
| 31 // with other works to produce a work based on this file, this file does not | |
| 32 // by itself cause the resulting work to be covered by the GNU General Public | |
| 33 // License. However the source code for this file must still be made available | |
| 34 // in accordance with section (3) of the GNU General Public License. | |
| 35 // | |
| 36 // This exception does not invalidate any other reasons why a work based on | |
| 37 // this file might be covered by the GNU General Public License. | |
| 38 // | |
| 39 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. | |
| 40 // at http://sources.redhat.com/ecos/ecos-license/ | |
| 41 // ------------------------------------------- | |
| 42 //####ECOSGPLCOPYRIGHTEND#### | |
| 43 //========================================================================== | |
| 44 //#####DESCRIPTIONBEGIN#### | |
| 45 // | |
| 46 // Author(s): gthomas | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
47 // Contributors: gthomas, jskov, rcassebohm, Andrew Lunn |
| 1346 | 48 // Date: 2001-02-21 |
| 49 // Purpose: | |
| 50 // Description: | |
| 51 // | |
| 52 // Notes: FLASH_P2V is not properly used. | |
| 53 // Needs locking. | |
| 54 //####DESCRIPTIONEND#### | |
| 55 // | |
| 56 //========================================================================== | |
| 57 | |
| 58 #include <pkgconf/hal.h> | |
| 59 #include <cyg/hal/hal_arch.h> | |
| 60 #include <cyg/hal/hal_cache.h> | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
61 #include <cyg/infra/cyg_ass.h> |
| 1346 | 62 #include CYGHWR_MEMORY_LAYOUT_H |
| 63 | |
| 64 #define _FLASH_PRIVATE_ | |
| 65 #include <cyg/io/flash.h> | |
| 66 | |
| 67 //---------------------------------------------------------------------------- | |
| 68 // Common device details. | |
| 69 #define FLASH_Read_ID FLASHWORD( 0x90 ) | |
| 70 #define FLASH_Read_ID_Exit FLASHWORD( 0xF0 ) | |
| 71 #define FLASH_Reset FLASHWORD( 0xFF ) | |
| 72 #define FLASH_Program FLASHWORD( 0xA0 ) | |
| 73 #define FLASH_Block_Erase FLASHWORD( 0x30 ) | |
| 74 | |
| 75 #define FLASH_Data FLASHWORD( 0x80 ) // Data complement | |
| 76 #define FLASH_Busy FLASHWORD( 0x40 ) // "Toggle" bit | |
| 77 #define FLASH_Err FLASHWORD( 0x20 ) | |
| 78 #define FLASH_Sector_Erase_Timer FLASHWORD( 0x08 ) | |
| 79 | |
| 80 #define FLASH_Setup_Addr1 (0x5555) | |
| 81 #define FLASH_Setup_Addr2 (0x2AAA) | |
| 82 #define FLASH_Setup_Code1 FLASHWORD( 0xAA ) | |
| 83 #define FLASH_Setup_Code2 FLASHWORD( 0x55 ) | |
| 84 #define FLASH_Setup_Erase FLASHWORD( 0x80 ) | |
| 85 | |
| 86 // Platform code must define the below | |
| 87 // #define CYGNUM_FLASH_INTERLEAVE : Number of interleaved devices (in parallel) | |
| 88 // #define CYGNUM_FLASH_SERIES : Number of devices in series | |
| 89 // And select one of the below device variants | |
| 90 | |
| 91 #ifdef CYGPKG_DEVS_FLASH_SST_39VF080 | |
| 92 # define FLASH_BLOCK_SIZE (0x1000*CYGNUM_FLASH_INTERLEAVE) | |
| 93 # define FLASH_NUM_REGIONS (256) | |
| 94 # define CYGNUM_FLASH_BASE_MASK (0xFFF00000u) // 1024kB devices | |
| 95 # define CYGNUM_FLASH_WIDTH (8) | |
| 96 # define CYGNUM_FLASH_BLANK (1) | |
| 97 # define CYGNUM_FLASH_ID_MANUFACTURER FLASHWORD(0xBF) | |
| 98 # define CYGNUM_FLASH_ID_DEVICE FLASHWORD(0xD8) | |
| 99 #endif | |
| 100 #ifdef CYGPKG_DEVS_FLASH_SST_39VF016 | |
| 101 # define FLASH_BLOCK_SIZE (0x1000*CYGNUM_FLASH_INTERLEAVE) | |
| 102 # define FLASH_NUM_REGIONS (512) | |
| 103 # define CYGNUM_FLASH_BASE_MASK (0xFFE00000u) // 2048kB devices | |
| 104 # define CYGNUM_FLASH_WIDTH (8) | |
| 105 # define CYGNUM_FLASH_BLANK (1) | |
| 106 # define CYGNUM_FLASH_ID_MANUFACTURER FLASHWORD(0xBF) | |
| 107 # define CYGNUM_FLASH_ID_DEVICE FLASHWORD(0xD9) | |
| 108 #endif | |
| 109 #ifdef CYGPKG_DEVS_FLASH_SST_39VF400 | |
| 110 # define FLASH_BLOCK_SIZE (0x1000*CYGNUM_FLASH_INTERLEAVE) | |
| 111 # define FLASH_NUM_REGIONS (0x80000/FLASH_BLOCK_SIZE) | |
| 112 # define CYGNUM_FLASH_BASE_MASK (0xFFF80000u) // 512kB devices | |
| 113 # define CYGNUM_FLASH_WIDTH (16) | |
| 114 # define CYGNUM_FLASH_BLANK (1) | |
| 115 # define CYGNUM_FLASH_ID_MANUFACTURER FLASHWORD(0x00BF) | |
| 116 # define CYGNUM_FLASH_ID_DEVICE FLASHWORD(0x2780) | |
| 117 #endif | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
118 #ifdef CYGPKG_DEVS_FLASH_SST_39VF160 |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
119 # define FLASH_BLOCK_SIZE (0x1000*CYGNUM_FLASH_INTERLEAVE) |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
120 # define FLASH_NUM_REGIONS (0x200000/FLASH_BLOCK_SIZE) |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
121 # define CYGNUM_FLASH_BASE_MASK (0xFFE00000u) // 512kB devices |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
122 # define CYGNUM_FLASH_WIDTH (16) |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
123 # define CYGNUM_FLASH_BLANK (1) |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
124 # define CYGNUM_FLASH_ID_MANUFACTURER FLASHWORD(0x00BF) |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
125 # define CYGNUM_FLASH_ID_DEVICE FLASHWORD(0x2782) |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
126 #endif |
| 1346 | 127 |
| 128 #define FLASH_DEVICE_SIZE (FLASH_BLOCK_SIZE*FLASH_NUM_REGIONS) | |
| 129 #define CYGNUM_FLASH_DEVICES (CYGNUM_FLASH_INTERLEAVE*CYGNUM_FLASH_SERIES) | |
| 130 | |
| 131 //---------------------------------------------------------------------------- | |
| 132 // Now that device properties are defined, include magic for defining | |
| 133 // accessor type and constants. | |
| 134 #include <cyg/io/flash_dev.h> | |
| 135 | |
| 136 //---------------------------------------------------------------------------- | |
| 137 // Functions that put the flash device into non-read mode must reside | |
| 138 // in RAM. | |
|
1755
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
139 static size_t sst_query(struct cyg_flash_dev *dev, void* data, size_t len) |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
140 __attribute__ ((section (".2ram.flash_query"))); |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
141 static int sst_erase_block(struct cyg_flash_dev *dev, cyg_flashaddr_t block_base) |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
142 __attribute__ ((section (".2ram.flash_erase_block"))); |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
143 static int sst_program(struct cyg_flash_dev *dev, cyg_flashaddr_t base, |
|
1755
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
144 const void* data, size_t length) |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
145 __attribute__ ((section (".2ram.flash_program_buf"))); |
| 1346 | 146 |
| 147 | |
| 148 //---------------------------------------------------------------------------- | |
| 149 // Initialize driver details | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
150 static int |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
151 sst_init(struct cyg_flash_dev *dev) |
| 1346 | 152 { |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
153 flash_data_t id[2]; |
| 1346 | 154 |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
155 dev->funs->flash_query(dev,id,sizeof(id)); |
| 1346 | 156 |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
157 // Check that flash_id data is matching the one the driver was |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
158 // configured for. |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
159 if (id[0] != CYGNUM_FLASH_ID_MANUFACTURER |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
160 || id[1] != CYGNUM_FLASH_ID_DEVICE) |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
161 return CYG_FLASH_ERR_DRV_WRONG_PART; |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
162 return CYG_FLASH_ERR_OK; |
| 1346 | 163 } |
| 164 | |
| 165 //---------------------------------------------------------------------------- | |
| 166 // Map a hardware status to a package error | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
167 static int |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
168 sst_hwr_map_error(struct cyg_flash_dev *dev, int err) |
| 1346 | 169 { |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
170 return err; |
| 1346 | 171 } |
| 172 | |
| 173 | |
| 174 //---------------------------------------------------------------------------- | |
| 175 // Flash Query | |
| 176 // | |
| 177 // Only reads the manufacturer and part number codes for the first | |
| 178 // device(s) in series. It is assumed that any devices in series | |
| 179 // will be of the same type. | |
| 180 | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
181 static size_t |
|
1755
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
182 sst_query(struct cyg_flash_dev *dev, void* data, size_t len) |
| 1346 | 183 { |
| 184 volatile flash_data_t *ROM; | |
| 185 flash_data_t* id = (flash_data_t*) data; | |
| 186 int i; | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
187 |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
188 CYG_ASSERT(len == 2, "Invalid length"); |
| 1346 | 189 |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
190 ROM = (volatile flash_data_t*) dev->start; |
| 1346 | 191 |
| 192 ROM[FLASH_Setup_Addr1] = FLASH_Setup_Code1; | |
| 193 ROM[FLASH_Setup_Addr2] = FLASH_Setup_Code2; | |
| 194 ROM[FLASH_Setup_Addr1] = FLASH_Read_ID; | |
| 195 | |
| 196 // FIXME: 10ms delay | |
| 197 for (i = 10000; i > 0; i--); | |
| 198 | |
| 199 // Manufacturers' code | |
| 200 id[0] = ROM[0]; | |
| 201 // Part number | |
| 202 id[1] = ROM[1]; | |
| 203 | |
| 204 ROM[FLASH_Setup_Addr1] = FLASH_Setup_Code1; | |
| 205 ROM[FLASH_Setup_Addr2] = FLASH_Setup_Code2; | |
| 206 ROM[FLASH_Setup_Addr1] = FLASH_Read_ID_Exit; | |
| 207 | |
| 208 // FIXME: 10ms delay | |
| 209 for (i = 10000; i > 0; i--); | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
210 |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
211 return len; |
| 1346 | 212 } |
| 213 | |
| 214 //---------------------------------------------------------------------------- | |
| 215 // Erase Block | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
216 static int |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
217 sst_erase_block(struct cyg_flash_dev *dev, cyg_flashaddr_t block_base) |
| 1346 | 218 { |
| 219 volatile flash_data_t* ROM; | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
220 volatile flash_data_t* addr_ptr = (volatile flash_data_t*) block_base; |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
221 int len = dev->block_info[0].block_size; |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
222 int res = CYG_FLASH_ERR_OK; |
| 1346 | 223 |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
224 while ((CYG_FLASH_ERR_OK == res) && (len > 0)) { |
| 1346 | 225 int timeout; |
| 226 flash_data_t state, prev_state; | |
| 227 | |
| 228 // Base address of device(s) being programmed. | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
229 ROM = (volatile flash_data_t*)((unsigned long)block_base & ~(FLASH_DEVICE_SIZE-1)); |
| 1346 | 230 |
| 231 // Program data [byte] - 6 step sequence | |
| 232 ROM[FLASH_Setup_Addr1] = FLASH_Setup_Code1; | |
| 233 ROM[FLASH_Setup_Addr2] = FLASH_Setup_Code2; | |
| 234 ROM[FLASH_Setup_Addr1] = FLASH_Setup_Erase; | |
| 235 ROM[FLASH_Setup_Addr1] = FLASH_Setup_Code1; | |
| 236 ROM[FLASH_Setup_Addr2] = FLASH_Setup_Code2; | |
| 237 *addr_ptr = FLASH_Block_Erase; | |
| 238 | |
| 239 // Wait for completion (bit 6 stops toggling) | |
| 240 timeout = 5000000; | |
| 241 prev_state = *addr_ptr & FLASH_Busy; | |
| 242 while (true) { | |
| 243 state = *addr_ptr & FLASH_Busy; | |
| 244 if (prev_state == state) { | |
| 245 break; | |
| 246 } | |
| 247 if (--timeout == 0) { | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
248 res = CYG_FLASH_ERR_DRV_TIMEOUT; |
| 1346 | 249 break; |
| 250 } | |
| 251 prev_state = state; | |
| 252 } | |
| 253 // Verify loaded data bytes | |
| 254 while (len > 0) { | |
| 255 if (*addr_ptr != FLASH_BlankValue) { | |
| 256 // Only update return value if erase operation was OK | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
257 if (CYG_FLASH_ERR_OK == res) res = CYG_FLASH_ERR_DRV_VERIFY; |
| 1346 | 258 break; |
| 259 } | |
| 260 addr_ptr++; | |
| 261 len -= sizeof(*addr_ptr); | |
| 262 } | |
| 263 } | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
264 return CYG_FLASH_ERR_OK; |
| 1346 | 265 } |
| 266 | |
| 267 //---------------------------------------------------------------------------- | |
| 268 // Program Buffer | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
269 static int |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
270 sst_program(struct cyg_flash_dev *dev, cyg_flashaddr_t base, |
|
1755
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
271 const void* data, size_t length) |
| 1346 | 272 { |
| 273 volatile flash_data_t* ROM; | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
274 volatile flash_data_t* addr_ptr = (volatile flash_data_t*) base; |
| 1346 | 275 volatile flash_data_t* data_ptr = (volatile flash_data_t*) data; |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
276 size_t len = length; |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
277 int res = CYG_FLASH_ERR_OK; |
| 1346 | 278 |
| 279 #if 0 | |
| 280 CYG_ASSERT((unsigned long)data_ptr & (sizeof(flash_data_t)-1) == 0, | |
| 281 "Data not properly aligned"); | |
| 282 CYG_ASSERT((unsigned long)addr_ptr & (CYGNUM_FLASH_INTERLEAVE*sizeof(flash_data_t)-1) == 0, | |
| 283 "Addr not properly aligned (to first interleaved device)"); | |
| 284 #endif | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
285 while ((CYG_FLASH_ERR_OK == res) && (len > 0)) { |
| 1346 | 286 int timeout; |
| 287 flash_data_t state, prev_state; | |
| 288 | |
| 289 // Base address of device(s) being programmed. | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
290 ROM = (volatile flash_data_t*)((unsigned long)base & ~(FLASH_DEVICE_SIZE-1)); |
| 1346 | 291 |
| 292 // Program data [byte] - 4 step sequence | |
| 293 ROM[FLASH_Setup_Addr1] = FLASH_Setup_Code1; | |
| 294 ROM[FLASH_Setup_Addr2] = FLASH_Setup_Code2; | |
| 295 ROM[FLASH_Setup_Addr1] = FLASH_Program; | |
| 296 *addr_ptr = *data_ptr; | |
| 297 | |
| 298 // Wait for completion (bit 6 stops toggling) | |
| 299 timeout = 5000000; | |
| 300 prev_state = *addr_ptr & FLASH_Busy; | |
| 301 while (true) { | |
| 302 state = *addr_ptr & FLASH_Busy; | |
| 303 if (prev_state == state) { | |
| 304 break; | |
| 305 } | |
| 306 if (--timeout == 0) { | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
307 res = CYG_FLASH_ERR_DRV_TIMEOUT; |
| 1346 | 308 break; |
| 309 } | |
| 310 prev_state = state; | |
| 311 } | |
| 312 | |
| 313 // Verify loaded data bytes | |
| 314 if (*addr_ptr != *data_ptr) { | |
| 315 // Only update return value if program operation was OK | |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
316 if (CYG_FLASH_ERR_OK == res) res = CYG_FLASH_ERR_DRV_VERIFY; |
|
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
317 break; |
| 1346 | 318 } |
| 319 addr_ptr++; | |
| 320 data_ptr++; | |
| 321 len -= sizeof(*data_ptr); | |
| 322 } | |
| 323 | |
| 324 // Ideally, we'd want to return not only the failure code, but also | |
| 325 // the address/device that reported the error. | |
| 326 return res; | |
| 327 } | |
| 328 | |
|
1755
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
329 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
330 static int |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
331 sst_block_lock(struct cyg_flash_dev *dev, const cyg_flashaddr_t block_base) |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
332 { |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
333 return CYG_DATAFLASH_ERR_INVALID; |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
334 } |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
335 |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
336 static int |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
337 sst_block_unlock(struct cyg_flash_dev *dev, const cyg_flashaddr_t block_base) |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
338 { |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
339 return CYG_DATAFLASH_ERR_INVALID; |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
340 } |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
341 #endif |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
342 |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
343 static const CYG_FLASH_FUNS(cyg_sst_funs, |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
344 sst_init, |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
345 sst_query, |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
346 sst_erase_block, |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
347 sst_program, |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
348 NULL, // read |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
349 sst_hwr_map_error, |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
350 sst_block_lock, |
|
21fc12d67292
Update following changes to the flash device driver interface
bartv
parents:
1749
diff
changeset
|
351 sst_block_unlock); |
|
1701
773d77981a7d
* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
asl
parents:
1346
diff
changeset
|
352 |
| 1346 | 353 #endif // CYGONCE_DEVS_FLASH_SST_39VFXXX_INL |
