From ee5a468417fb6810a5bbe4d46617618a9ddb588a Mon Sep 17 00:00:00 2001 From: NĂ©lio Laranjeiro Date: Thu, 7 May 2009 10:07:49 +0200 Subject: * digital/avr/modules/trace: (See #67) * Adapted the trace module to: * Find the last trace in order to start the new one, trace_i = trace_i-1 + 1 * A quarter of the flash is completely erased on the trace init to be used in the future. * Removed the start code useless from now. * tools/trace: * Update the python scripts to use the new trace implementation. --- digital/avr/modules/flash/flash.c | 74 ++++++++------------------------------- digital/avr/modules/flash/flash.h | 24 ++++--------- 2 files changed, 21 insertions(+), 77 deletions(-) (limited to 'digital/avr/modules/flash') diff --git a/digital/avr/modules/flash/flash.c b/digital/avr/modules/flash/flash.c index dffc6d82..7b563bc6 100644 --- a/digital/avr/modules/flash/flash.c +++ b/digital/avr/modules/flash/flash.c @@ -27,6 +27,9 @@ #include "modules/spi/spi.h" #include "modules/utils/utils.h" +#define FLASH_LOG_PAGE_SIZE 0x80000 +#define FLASH_LOG_BUFFER_SIZE 128 + /** Flash access. * The flash contains an address of 21 bits in a range from 0x0-0x1fffff. * This function shall access the memory directly by the SPI. @@ -139,28 +142,6 @@ flash_init (void) return 1; } -/** Find the first writable sector. - * \param addr the address to start the research. - * \return the address of the next sector. - */ -uint32_t -flash_first_sector (void) -{ - uint8_t rsp = 0; - uint32_t addr; - - /* Search for the next address to start writing. */ - for (addr = 0; - (rsp != 0xFF) && (addr < FLASH_ADDRESS_HIGH); - addr += FLASH_PAGE_SIZE) - { - rsp = flash_read (addr); - } - - return addr < (FLASH_ADDRESS_HIGH + 1) ? - addr - FLASH_PAGE_SIZE : FLASH_ADDRESS_ERROR; -} - /** Write in the flash byte provided in parameter. * \param data the buffer to store the data. */ @@ -240,11 +221,11 @@ flash_write_array (uint32_t addr, uint8_t *data, uint32_t length) } } -uint8_t +int8_t flash_log (uint8_t size, uint8_t *args) { - uint8_t buf[128+1]; - uint8_t status = 0x0; + uint8_t buf[FLASH_LOG_BUFFER_SIZE+1]; + int8_t error = 0x0; uint32_t addr = 0; if (size >= 4) @@ -254,37 +235,8 @@ flash_log (uint8_t size, uint8_t *args) switch (args[0]) { case FLASH_CMD_INIT: - status = flash_init (); - if (status) - { - uint32_t res; - uint32_t ended = 0; - for (addr = 0; addr < FLASH_ADDRESS_HIGH; addr += FLASH_PAGE_SIZE) - { - flash_read_array (addr, (uint8_t *) &res, 4); - if (res == 0xFFFFFFFF) - { - ended = addr; - proto_send3b ('e', addr >> 16, addr >> 8, addr); - /* The sector is empty. */ - break; - } - } - - for (addr = FLASH_PAGE (ended - FLASH_PAGE_SIZE); - addr != ended; - addr = FLASH_PAGE (addr - FLASH_PAGE_SIZE)) - { - uint32_t res; - flash_read_array (addr, (uint8_t *) &res, 4); - if (res == FLASH_LOG_CODE_READ) - { - proto_send3b ('i', addr >> 16, addr >> 8, addr); - break; - } - } - } - proto_send1b ('s', status); + error = !flash_init (); + proto_send1b ('s', error ? 0 : 1); break; case FLASH_CMD_READ: if ((size == 5) @@ -292,17 +244,19 @@ flash_log (uint8_t size, uint8_t *args) { flash_read_array (addr, buf, args[4]); proto_send ('r', args[4], buf); - status = 0x1; + error = 0; } else if (size == 4) { proto_send1b ('r', flash_read (addr)); - status = 0x1; + error = 0; } + else + error = 2; break; default: - status = 0x0; + return 3; } - return status; + return error; } diff --git a/digital/avr/modules/flash/flash.h b/digital/avr/modules/flash/flash.h index 9f92259a..d1fec1f0 100644 --- a/digital/avr/modules/flash/flash.h +++ b/digital/avr/modules/flash/flash.h @@ -27,15 +27,12 @@ #include "common.h" #include "io.h" -#define FLASH_ADDRESS_HIGH 0x1FFFFF +#define FLASH_SIZE 0x200000 +#define FLASH_ADDRESS_HIGH (FLASH_SIZE - 1) #define FLASH_ADDRESS_ERROR 0xFFFFFF #define FLASH_ADDRESS_INC(val) \ ((val) + 1) & FLASH_ADDRESS_HIGH -#define FLASH_PAGE_SIZE 0x1000 -#define FLASH_PAGE_MASK (FLASH_ADDRESS_HIGH & ~(FLASH_PAGE_SIZE-1)) -#define FLASH_PAGE(val) ((val) & FLASH_PAGE_MASK) - #define FLASH_ERASE_FULL 0x60 #define FLASH_ERASE_4K 0x20 #define FLASH_ERASE_32K 0x52 @@ -53,9 +50,6 @@ #define FLASH_TBP_US 10 -#define FLASH_LOG_CODE 0xF33FF22F -#define FLASH_LOG_CODE_READ 0x2FF23FF3 - enum { FLASH_CMD_INIT, @@ -114,13 +108,6 @@ flash_status_aai (void) uint8_t flash_init (void); -/** Find the first writable sector. - * \param addr the address to start the research. - * \return the address of the next sector. - */ -uint32_t -flash_first_sector (void); - /** Write in the flash byte provided in parameter. * \param data the buffer to store the data. */ @@ -154,9 +141,12 @@ flash_write_array (uint32_t addr, uint8_t *data, uint32_t length); /** Process the logs * \param size the number of arguments. * \param an array of arguments. - * \return true on success. + * \return - 0 on success, + * - 1 flash not initialised + * - 2 flash read error. + * - 3 command not found. */ -uint8_t +int8_t flash_log (uint8_t size, uint8_t *args); #endif /* flash_h */ -- cgit v1.2.3