comparison packages/devs/flash/synthv2/current/src/synth.c @ 1724:a24dbf2587a3

* src/flash_synth.c: Allow the use of arbitary sized block. * test/flash3.c: Allow the use of small blocks
author asl
date Thu, 09 Sep 2004 13:13:22 +0000
parents 0673c75f3a08
children b16e2895566e
comparison
equal deleted inserted replaced
1723:0cc13d07a67e 1724:a24dbf2587a3
57 #include <string.h> 57 #include <string.h>
58 58
59 #define _FLASH_PRIVATE_ 59 #define _FLASH_PRIVATE_
60 #include <cyg/io/flash.h> 60 #include <cyg/io/flash.h>
61 #include <cyg/flash/synth.h> 61 #include <cyg/flash/synth.h>
62
63 #ifndef MIN
64 #define MIN(x,y) ((x)<(y) ? (x) : (y))
65 #endif
62 66
63 /* Helper function. The Linux system call cannot pass 6 parameters. Instead 67 /* Helper function. The Linux system call cannot pass 6 parameters. Instead
64 a structure is filled in and passed as one parameter */ 68 a structure is filled in and passed as one parameter */
65 static int 69 static int
66 cyg_hal_sys_do_mmap(void *addr, unsigned long length, unsigned long prot, 70 cyg_hal_sys_do_mmap(void *addr, unsigned long length, unsigned long prot,
206 #ifdef CYGDBG_USE_ASSERTS 210 #ifdef CYGDBG_USE_ASSERTS
207 struct cyg_flash_synth_config *config = dev->config; 211 struct cyg_flash_synth_config *config = dev->config;
208 #endif 212 #endif
209 struct cyg_flash_synth_priv *priv = dev->priv; 213 struct cyg_flash_synth_priv *priv = dev->priv;
210 int offset = (int)block_base; 214 int offset = (int)block_base;
211 size_t block_size; 215 size_t remaining;
212 int i; 216 int write_size;
213 217
214 offset -= dev->start; 218 offset -= dev->start;
215 219
216 cyg_hal_sys_lseek(priv->flashfd, offset, 220 cyg_hal_sys_lseek(priv->flashfd, offset,
217 CYG_HAL_SYS_SEEK_SET); 221 CYG_HAL_SYS_SEEK_SET);
221 empty_inited = true; 225 empty_inited = true;
222 } 226 }
223 227
224 CYG_ASSERT(sizeof(empty) < config->block_size, 228 CYG_ASSERT(sizeof(empty) < config->block_size,
225 "Eckk! Can't work with such small blocks"); 229 "Eckk! Can't work with such small blocks");
226 CYG_ASSERT((config->block_size % sizeof(empty)) == 0,
227 "Eckk! Can't work with that odd size block");
228 CYG_ASSERT(config->boot_blocks && sizeof(empty) < config->boot_block_size, 230 CYG_ASSERT(config->boot_blocks && sizeof(empty) < config->boot_block_size,
229 "Eckk! Can't work with such small blocks"); 231 "Eckk! Can't work with such small blocks");
230 CYG_ASSERT((config->boot_blocks && config->block_size % sizeof(empty)) == 0, 232
231 "Eckk! Can't work with that odd size block"); 233 remaining = flash_block_size(dev, block_base);
232 234
233 block_size = flash_block_size(dev, block_base); 235 while (remaining) {
234 236 write_size = MIN(remaining, sizeof(empty));
235 for (i=0; (i * sizeof(empty)) < block_size; i++) { 237 cyg_hal_sys_write(priv->flashfd, empty, write_size);
236 cyg_hal_sys_write(priv->flashfd, empty, sizeof(empty)); 238 remaining -= write_size;
237 } 239 }
238 return CYG_FLASH_ERR_OK; 240 return CYG_FLASH_ERR_OK;
239 } 241 }
240 242
241 static int 243 static int