From 053912d477cd8312f69a8b24052d3727da55e0b5 Mon Sep 17 00:00:00 2001 From: NĂ©lio Laranjeiro Date: Tue, 12 Jan 2010 23:51:31 +0100 Subject: digital/avr/modules/trace: fix trace module to use the new flash driver --- digital/avr/modules/trace/test/flood.c | 2 +- digital/avr/modules/trace/trace.c | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'digital/avr/modules/trace') diff --git a/digital/avr/modules/trace/test/flood.c b/digital/avr/modules/trace/test/flood.c index b919d0a6..6cc88a32 100644 --- a/digital/avr/modules/trace/test/flood.c +++ b/digital/avr/modules/trace/test/flood.c @@ -94,7 +94,7 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) case c ('e', 3): /* Erase 4k: * - 3b: address. */ - flash_erase (FLASH_ERASE_4K, addr); + flash_erase (FLASH_ERASE_SECTOR, addr); break; case c ('r', 3): /* Read one byte: diff --git a/digital/avr/modules/trace/trace.c b/digital/avr/modules/trace/trace.c index e4fa6c46..5504fa88 100644 --- a/digital/avr/modules/trace/trace.c +++ b/digital/avr/modules/trace/trace.c @@ -31,11 +31,9 @@ #define TRACE_ARGS_MAX 6 #define TRACE_MAX_ARGS (TRACE_ARGS_MAX * TRACE_ARGS_MAX) - -#define TRACE_BLOCK_SIZE_BYTES 65536 #define TRACE_PAGE 0x80000 -#define TRACE_PAGE_BLOCKS (TRACE_PAGE / TRACE_BLOCK_SIZE_BYTES) -#define TRACE_PAGE_PAGE_NB (FLASH_SIZE / TRACE_PAGE) + +#define FLASH_ADDRESS_HIGH (flash_size () - 1) struct trace_t { @@ -45,6 +43,10 @@ struct trace_t uint32_t addr_start; /** Flash address. */ uint32_t addr; + /** Number of pages. */ + uint8_t nb_pages; + /** Number of block in one trace page. */ + uint8_t page_block_size; }; typedef struct trace_t trace_t; @@ -77,10 +79,10 @@ trace_erase_page (uint32_t addr) { uint8_t i; while (flash_is_busy ()); - for (i = 0; i < TRACE_PAGE_BLOCKS; i++) + for (i = 0; i < trace_global.page_block_size; i++) { - flash_erase (FLASH_ERASE_64K, addr); - addr += TRACE_BLOCK_SIZE_BYTES; + flash_erase (FLASH_ERASE_BLOCK, addr); + addr += flash_block_size (); } } @@ -92,13 +94,14 @@ trace_init (void) uint32_t new_trace_addr = 0; trace_global.status = flash_init (); - + trace_global.nb_pages = flash_size () / TRACE_PAGE; + trace_global.page_block_size = TRACE_PAGE / flash_block_size (); /* Get the first sector to write. */ if (trace_global.status) { uint8_t val = 0; /* Find the possible traces. */ - for (i = 0; i < TRACE_PAGE_PAGE_NB; i++) + for (i = 0; i < trace_global.nb_pages; i++) { val = flash_read (i * TRACE_PAGE); if (i == 0 || lesseq_mod8(new_trace_val, val)) -- cgit v1.2.3