X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fcpu%2Farm%2Fdrv%2Fflash_at91.c;h=514d54e4326811042b4ea7dcafcf0e1f5e815857;hb=55574912ce4d7364597388a112805147a9618351;hp=50b8ccb4041c2cd1f409a58757f6a500bd71361d;hpb=f5836fc506729b54921d5514f74a99706fda0f7f;p=bertos.git diff --git a/bertos/cpu/arm/drv/flash_at91.c b/bertos/cpu/arm/drv/flash_at91.c index 50b8ccb4..514d54e4 100644 --- a/bertos/cpu/arm/drv/flash_at91.c +++ b/bertos/cpu/arm/drv/flash_at91.c @@ -139,10 +139,7 @@ static bool flash_getStatus(struct KBlock *blk) static size_t at91_flash_readDirect(struct KBlock *blk, block_idx_t idx, void *buf, size_t offset, size_t size) { - ASSERT(offset == 0); - ASSERT(size == blk->blk_size); - - memcpy(buf, (void *)(idx * blk->blk_size), size); + memcpy(buf, (void *)(idx * blk->blk_size + FLASH_BASE + offset), size); return size; } @@ -151,7 +148,7 @@ static size_t at91_flash_writeDirect(struct KBlock *blk, block_idx_t idx, const ASSERT(offset == 0); ASSERT(size == blk->blk_size); - uint32_t *addr = (uint32_t *)(idx * blk->blk_size); + uint32_t *addr = (uint32_t *)(idx * blk->blk_size + FLASH_BASE); const uint8_t *buf = (const uint8_t *)_buf; while (size) @@ -164,7 +161,7 @@ static size_t at91_flash_writeDirect(struct KBlock *blk, block_idx_t idx, const size -= 4; buf += 4; - addr += 4; + addr++; } flash_sendWRcmd(idx); @@ -223,18 +220,20 @@ static void common_init(Flash *fls) fls->blk.blk_size = FLASH_PAGE_SIZE_BYTES; fls->blk.blk_cnt = FLASH_MEM_SIZE / FLASH_PAGE_SIZE_BYTES; - } -void flash_hw_init(Flash *fls) +void flash_hw_init(Flash *fls, UNUSED_ARG(int, flags)) { common_init(fls); fls->blk.priv.vt = &flash_at91_buffered_vt; fls->blk.priv.flags |= KB_BUFFERED | KB_PARTIAL_WRITE; fls->blk.priv.buf = flash_buf; + + /* Load the first block in the cache */ + memcpy(fls->blk.priv.buf, (void *)(FLASH_BASE), fls->blk.blk_size); } -void flash_hw_initUnbuffered(Flash *fls) +void flash_hw_initUnbuffered(Flash *fls, UNUSED_ARG(int, flags)) { common_init(fls); fls->blk.priv.vt = &flash_at91_unbuffered_vt;