Mercurial > flash_v2
comparison packages/io/flash/current/src/legacy_dev.c @ 1752:61fbcc1cb232
Clean up device driver interface
| author | bartv |
|---|---|
| date | Mon, 22 Nov 2004 20:06:35 +0000 |
| parents | fac0499dabd6 |
| children | 400806bc9c4f |
comparison
equal
deleted
inserted
replaced
| 1751:ae5a02813cce | 1752:61fbcc1cb232 |
|---|---|
| 131 return len; | 131 return len; |
| 132 } | 132 } |
| 133 | 133 |
| 134 static int | 134 static int |
| 135 legacy_flash_erase_block (struct cyg_flash_dev *dev, | 135 legacy_flash_erase_block (struct cyg_flash_dev *dev, |
| 136 const cyg_flashaddr_t block_base) | 136 cyg_flashaddr_t block_base) |
| 137 __attribute__ ((section (".2ram.flash_program_buf"))); | 137 __attribute__ ((section (".2ram.flash_program_buf"))); |
| 138 | 138 |
| 139 static int | 139 static int |
| 140 legacy_flash_erase_block (struct cyg_flash_dev *dev, | 140 legacy_flash_erase_block (struct cyg_flash_dev *dev, |
| 141 const cyg_flashaddr_t block_base) | 141 cyg_flashaddr_t block_base) |
| 142 { | 142 { |
| 143 typedef int code_fun(cyg_flashaddr_t, unsigned int); | 143 typedef int code_fun(cyg_flashaddr_t, unsigned int); |
| 144 code_fun *_flash_erase_block; | 144 code_fun *_flash_erase_block; |
| 145 size_t block_size = dev->block_info[0].block_size; | 145 size_t block_size = dev->block_info[0].block_size; |
| 146 | 146 |
| 156 __attribute__ ((section (".2ram.flash_program_buf"))); | 156 __attribute__ ((section (".2ram.flash_program_buf"))); |
| 157 | 157 |
| 158 static int | 158 static int |
| 159 legacy_flash_program(struct cyg_flash_dev *dev, | 159 legacy_flash_program(struct cyg_flash_dev *dev, |
| 160 cyg_flashaddr_t base, | 160 cyg_flashaddr_t base, |
| 161 const void* data, const size_t len) | 161 const void* data, size_t len) |
| 162 { | 162 { |
| 163 typedef int code_fun(cyg_flashaddr_t, const void *, int, unsigned long, int); | 163 typedef int code_fun(cyg_flashaddr_t, const void *, int, unsigned long, int); |
| 164 code_fun *_flash_program_buf; | 164 code_fun *_flash_program_buf; |
| 165 size_t block_size = dev->block_info[0].block_size; | 165 size_t block_size = dev->block_info[0].block_size; |
| 166 size_t block_mask = ~(block_mask -1); | 166 size_t block_mask = ~(block_mask -1); |
| 172 | 172 |
| 173 #ifdef CYGSEM_IO_FLASH_READ_INDIRECT | 173 #ifdef CYGSEM_IO_FLASH_READ_INDIRECT |
| 174 static int | 174 static int |
| 175 legacy_flash_read (struct cyg_flash_dev *dev, | 175 legacy_flash_read (struct cyg_flash_dev *dev, |
| 176 const cyg_flashaddr_t base, | 176 const cyg_flashaddr_t base, |
| 177 void* data, const size_t len) | 177 void* data, size_t len) |
| 178 __attribute__ ((section (".2ram.flash_program_buf"))); | 178 __attribute__ ((section (".2ram.flash_program_buf"))); |
| 179 | 179 |
| 180 static int | 180 static int |
| 181 legacy_flash_read (struct cyg_flash_dev *dev, | 181 legacy_flash_read (struct cyg_flash_dev *dev, |
| 182 const cyg_flashaddr_t base, | 182 const cyg_flashaddr_t base, |
| 183 void* data, const size_t len) | 183 void* data, size_t len) |
| 184 { | 184 { |
| 185 typedef int code_fun(const cyg_flashaddr_t, void *, int, unsigned long, int); | 185 typedef int code_fun(const cyg_flashaddr_t, void *, int, unsigned long, int); |
| 186 code_fun *_flash_read_buf; | 186 code_fun *_flash_read_buf; |
| 187 size_t block_size = dev->block_info[0].block_size; | 187 size_t block_size = dev->block_info[0].block_size; |
| 188 size_t block_mask = ~(block_mask -1); | 188 size_t block_mask = ~(block_mask -1); |
| 196 #else | 196 #else |
| 197 # define LEGACY_FLASH_READ ((int (*)(struct cyg_flash_dev*, const cyg_flashaddr_t, void*, const size_t))0) | 197 # define LEGACY_FLASH_READ ((int (*)(struct cyg_flash_dev*, const cyg_flashaddr_t, void*, const size_t))0) |
| 198 #endif | 198 #endif |
| 199 | 199 |
| 200 | 200 |
| 201 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING | |
| 201 static int | 202 static int |
| 202 legacy_flash_block_lock (struct cyg_flash_dev *dev, | 203 legacy_flash_block_lock (struct cyg_flash_dev *dev, |
| 203 const cyg_flashaddr_t block_base) | 204 const cyg_flashaddr_t block_base) |
| 204 __attribute__ ((section (".2ram.flash_program_buf"))); | 205 __attribute__ ((section (".2ram.flash_program_buf"))); |
| 205 | 206 |
| 206 static int | 207 static int |
| 207 legacy_flash_block_lock (struct cyg_flash_dev *dev, | 208 legacy_flash_block_lock (struct cyg_flash_dev *dev, |
| 208 const cyg_flashaddr_t block_base) | 209 const cyg_flashaddr_t block_base) |
| 209 { | 210 { |
| 210 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING | |
| 211 typedef int code_fun(cyg_flashaddr_t); | 211 typedef int code_fun(cyg_flashaddr_t); |
| 212 code_fun *_flash_lock_block; | 212 code_fun *_flash_lock_block; |
| 213 | 213 |
| 214 _flash_lock_block = (code_fun*) __anonymizer(&flash_lock_block); | 214 _flash_lock_block = (code_fun*) __anonymizer(&flash_lock_block); |
| 215 | 215 |
| 216 return (*_flash_lock_block)(block_base); | 216 return (*_flash_lock_block)(block_base); |
| 217 #else | |
| 218 return CYG_FLASH_ERR_INVALID; | |
| 219 #endif | |
| 220 } | 217 } |
| 221 | 218 |
| 222 static int | 219 static int |
| 223 legacy_flash_block_unlock (struct cyg_flash_dev *dev, | 220 legacy_flash_block_unlock (struct cyg_flash_dev *dev, |
| 224 const cyg_flashaddr_t block_base) | 221 const cyg_flashaddr_t block_base) |
| 226 | 223 |
| 227 static int | 224 static int |
| 228 legacy_flash_block_unlock (struct cyg_flash_dev *dev, | 225 legacy_flash_block_unlock (struct cyg_flash_dev *dev, |
| 229 const cyg_flashaddr_t block_base) | 226 const cyg_flashaddr_t block_base) |
| 230 { | 227 { |
| 231 #ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING | |
| 232 typedef int code_fun(cyg_flashaddr_t, int, int); | 228 typedef int code_fun(cyg_flashaddr_t, int, int); |
| 233 code_fun *_flash_unlock_block; | 229 code_fun *_flash_unlock_block; |
| 234 size_t block_size = dev->block_info[0].block_size; | 230 size_t block_size = dev->block_info[0].block_size; |
| 235 cyg_uint32 blocks = dev->block_info[0].blocks; | 231 cyg_uint32 blocks = dev->block_info[0].blocks; |
| 236 | 232 |
| 237 _flash_unlock_block = (code_fun*) __anonymizer(&flash_unlock_block); | 233 _flash_unlock_block = (code_fun*) __anonymizer(&flash_unlock_block); |
| 238 | 234 |
| 239 return (*_flash_unlock_block)(block_base, block_size, blocks); | 235 return (*_flash_unlock_block)(block_base, block_size, blocks); |
| 240 #else | 236 } |
| 241 return CYG_FLASH_ERR_INVALID; | |
| 242 #endif | 237 #endif |
| 243 } | |
| 244 | 238 |
| 245 // Map a hardware status to a package error | 239 // Map a hardware status to a package error |
| 246 static int | 240 static int |
| 247 legacy_flash_hwr_map_error (struct cyg_flash_dev *dev, int err) | 241 legacy_flash_hwr_map_error (struct cyg_flash_dev *dev, int err) |
| 248 __attribute__ ((section (".2ram.flash_program_buf"))); | 242 __attribute__ ((section (".2ram.flash_program_buf"))); |
| 265 HAL_FLASH_CACHES_OFF(d_cache, i_cache); | 259 HAL_FLASH_CACHES_OFF(d_cache, i_cache); |
| 266 (*_flash_query)(data); | 260 (*_flash_query)(data); |
| 267 HAL_FLASH_CACHES_ON(d_cache, i_cache); | 261 HAL_FLASH_CACHES_ON(d_cache, i_cache); |
| 268 } | 262 } |
| 269 | 263 |
| 270 CYG_FLASH_FUNS(cyg_legacy_funs, | 264 static const CYG_FLASH_FUNS(cyg_legacy_funs, |
| 271 legacy_flash_init, | 265 legacy_flash_init, |
| 272 legacy_flash_query, | 266 legacy_flash_query, |
| 273 legacy_flash_erase_block, | 267 legacy_flash_erase_block, |
| 274 legacy_flash_program, | 268 legacy_flash_program, |
| 275 LEGACY_FLASH_READ, | 269 LEGACY_FLASH_READ, |
| 276 legacy_flash_hwr_map_error, | 270 legacy_flash_hwr_map_error, |
| 277 legacy_flash_block_lock, | 271 legacy_flash_block_lock, |
| 278 legacy_flash_block_unlock | 272 legacy_flash_block_unlock |
| 279 ); | 273 ); |
| 280 | 274 |
| 281 CYG_FLASH_DRIVER(cyg_zzlegacy_flashdev, // zz so that it probably comes last. | 275 CYG_FLASH_DRIVER(cyg_zzlegacy_flashdev, |
| 282 &cyg_legacy_funs, | 276 &cyg_legacy_funs, |
| 283 NULL, // Pointer to config structure | 277 0, // Flags |
| 284 0, // Start address of flash | 278 0, // Start address, filled in by init |
| 285 0); // Size of private structure | 279 0, // End address, filled in by init |
| 286 | 280 0, // Number of block infos, filled in by init |
| 281 NULL, // Block infos, again filled in by init | |
| 282 NULL // Driver private data, none needed | |
| 283 ); |
