From: qwert Date: Fri, 18 Jul 2008 13:20:38 +0000 (+0000) Subject: Refactor code, "page_buf" moved into KFileFlashAvr struct X-Git-Tag: 2.0.0~437 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=e863779405806aeea209a213eeb82caa8f029acc;p=bertos.git Refactor code, "page_buf" moved into KFileFlashAvr struct git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1497 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cpu/avr/drv/flash_avr.c b/bertos/cpu/avr/drv/flash_avr.c index de1aab39..76023a29 100644 --- a/bertos/cpu/avr/drv/flash_avr.c +++ b/bertos/cpu/avr/drv/flash_avr.c @@ -68,14 +68,6 @@ typedef uint16_t avr_page_addr_t; -/** - * Temporary buffer cointaing data block to - * write on flash. - */ -static uint8_t page_buf[SPM_PAGESIZE]; - - - /* @@ -100,7 +92,7 @@ static void flash_avr_flush(KFileFlashAvr *fd) // Fill the temporary buffer of the AVR for (avr_page_addr_t page_addr = 0; page_addr < SPM_PAGESIZE; page_addr += 2) { - uint16_t word = ((uint16_t)page_buf[page_addr + 1] << 8) | page_buf[page_addr]; + uint16_t word = ((uint16_t)fd->page_buf[page_addr + 1] << 8) | fd->page_buf[page_addr]; ATOMIC(boot_page_fill(page_addr, word)); } @@ -159,7 +151,7 @@ static void flash_avr_loadPage(KFileFlashAvr *fd, avr_page_t page) { flash_avr_flush(fd); // Load page - memcpy_P(page_buf, (const char *)(page * SPM_PAGESIZE), SPM_PAGESIZE); + memcpy_P(fd->page_buf, (const char *)(page * SPM_PAGESIZE), SPM_PAGESIZE); fd->curr_page = page; kprintf("Loaded page %d\n", fd->curr_page); } @@ -192,7 +184,7 @@ static size_t flash_avr_write(struct KFile *_fd, const void *_buf, size_t size) flash_avr_loadPage(fd, page); size_t wr_len = MIN(size, SPM_PAGESIZE - page_addr); - memcpy(page_buf + page_addr, buf, wr_len); + memcpy(fd->page_buf + page_addr, buf, wr_len); fd->page_dirty = true; buf += wr_len; @@ -212,7 +204,7 @@ static size_t flash_avr_write(struct KFile *_fd, const void *_buf, size_t size) static void flash_avr_open(struct KFileFlashAvr *fd) { fd->curr_page = 0; - memcpy_P(page_buf, (const char *)(fd->curr_page * SPM_PAGESIZE), SPM_PAGESIZE); + memcpy_P(fd->page_buf, (const char *)(fd->curr_page * SPM_PAGESIZE), SPM_PAGESIZE); fd->fd.seek_pos = 0; fd->fd.size = (uint16_t)(FLASHEND - CONFIG_FLASH_AVR_BOOTSIZE + 1); diff --git a/bertos/cpu/avr/drv/flash_avr.h b/bertos/cpu/avr/drv/flash_avr.h index db6152a9..99abf9a1 100644 --- a/bertos/cpu/avr/drv/flash_avr.h +++ b/bertos/cpu/avr/drv/flash_avr.h @@ -42,6 +42,7 @@ #include #include +#include /** @@ -70,6 +71,13 @@ typedef struct KFileFlashAvr */ bool page_dirty; + /** + * Temporary buffer cointaing data block to + * write on flash. + */ + uint8_t page_buf[SPM_PAGESIZE]; + + } KFileFlashAvr;