From 62dea0dc173ece90867f2aabd0af63c353517bfd Mon Sep 17 00:00:00 2001 From: NĂ©lio Laranjeiro Date: Tue, 21 Oct 2008 13:38:44 +0200 Subject: avr/modules/flash: (see ticket #36) * Update the defines. * Modified the define for the flash page mask. * Update the sector_next function (Not tested yet). --- digital/avr/modules/flash/flash.c | 10 +++++----- digital/avr/modules/flash/flash.h | 13 +++++++------ digital/avr/modules/flash/test/test-flash.c | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/digital/avr/modules/flash/flash.c b/digital/avr/modules/flash/flash.c index edca7273..db5645aa 100644 --- a/digital/avr/modules/flash/flash.c +++ b/digital/avr/modules/flash/flash.c @@ -141,16 +141,16 @@ flash_init (void) } /** Find the next sector to write. - * \return the address of the next sector. - */ + * \param addr the address to start the research. + * \return the address of the next sector. + */ uint32_t -flash_sector_next (void) +flash_sector_next (uint32_t addr) { - uint32_t addr; uint8_t rsp = 0; /* Search for the next address to start writing. */ - for (addr = 0; + for (addr = FLASH_PAGE (addr); (rsp != 0xFF) && (addr < FLASH_ADDRESS_HIGH); addr += FLASH_PAGE_SIZE - 1) { diff --git a/digital/avr/modules/flash/flash.h b/digital/avr/modules/flash/flash.h index 80bff9ec..205eedf1 100644 --- a/digital/avr/modules/flash/flash.h +++ b/digital/avr/modules/flash/flash.h @@ -29,11 +29,11 @@ #define FLASH_ADDRESS_HIGH 0x1FFFFF #define FLASH_ADDRESS_ERROR 0xFFFFFF -#define FLASH_ADDRESS_INC_MASK(val) (val = (val+1) & FLASH_HIGH_ADDRESS) +#define FLASH_ADDRESS_INC_MASK(val) ((val) = (val+1) & FLASH_HIGH_ADDRESS) #define FLASH_PAGE_SIZE 0x1000 -#define FLASH_PAGE_MASK (0xFFF) -#define FLASH_PAGE(val) (val & FLASH_PAGE_MASK) +#define FLASH_PAGE_MASK (FLASH_ADDRESS_HIGH & FLASH_PAGE_SIZE) +#define FLASH_PAGE(val) ((val) & FLASH_PAGE_MASK) #define FLASH_ERASE_FULL 0x60 #define FLASH_ERASE_4K 0x20 @@ -104,10 +104,11 @@ uint8_t flash_init (void); /** Find the next sector to write. - * \return the address of the next sector. - */ + * \param addr the address to start the research. + * \return the address of the next sector. + */ uint32_t -flash_sector_next (void); +flash_sector_next (uint32_t addr); /** Write in the flash byte provided in parameter. * \param data the buffer to store the data. diff --git a/digital/avr/modules/flash/test/test-flash.c b/digital/avr/modules/flash/test/test-flash.c index aea03e44..5d1ba0f6 100644 --- a/digital/avr/modules/flash/test/test-flash.c +++ b/digital/avr/modules/flash/test/test-flash.c @@ -88,7 +88,7 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) break; case c ('p', 0): /* Find the next page to write. */ - addr = flash_sector_next (); + addr = flash_sector_next (0); proto_send3b ('p', addr >> 16, addr >> 8, addr); break; default: -- cgit v1.2.3