From: asterix Date: Mon, 11 Jun 2007 15:26:36 +0000 (+0000) Subject: Add comments. Set static prog_flush function. X-Git-Tag: 1.0.0~439 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=522981c00bd0a016c15beb1ba1f8de27428ebaf8;p=bertos.git Add comments. Set static prog_flush function. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@802 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/mware/prog_avr.c b/mware/prog_avr.c index 3222818e..f2eac38f 100755 --- a/mware/prog_avr.c +++ b/mware/prog_avr.c @@ -31,6 +31,9 @@ typedef uint16_t page_t; */ static uint8_t page_buf[PAGEBUF]; +/** + * Store current flash page memory in use. + */ static page_t curr_pag_num = 0; @@ -51,7 +54,7 @@ static void prog_erase_flash(void) */ RAMPZ = 0x00; - for (flash_addr = 0; (flash_addr < (uint16_t)(APP_END & 0xFFFF)) | (RAMPZ == 0x00); + for (flash_addr = 0; (flash_addr < (uint16_t)(APP_END & 0xFFFF)) | (RAMPZ == 0x00)); { wdt_reset(); @@ -95,8 +98,30 @@ static void prog_pagewrite(uint16_t addr) } +/** + * Flush temporary buffer into flash memory. + */ +static void prog_flush(void) +{ + + /* Fill the temporary buffer of the AVR */ + for (page_addr_t page_addr = 0; page_addr < PAGEBUF; page_addr += 2) + fill_temp_buffer(page_buf[page_addr + 1] | (uint16_t)page_buf[page_addr] << 8, page_addr); + + + wdt_reset(); + + /* Page write */ + prog_pagewrite(curr_page_num * PAGEBUF); +} + /** * Write program memory. + * This function to write on flash memory load a selected page from + * flash memory and save it in temporary buffer. Them update temporary buffer + * with \param buf data. We write in flash memory everery time we + * change current page memory. + * */ size_t prog_write(struct _KFile *fd, const char *buf, size_t size) { @@ -104,15 +129,19 @@ size_t prog_write(struct _KFile *fd, const char *buf, size_t size) page_t page; page_addr_t page_addr; size_t total_write = 0; - + size_t wr_len; + while (size) { + /* Current page memory */ page = fd->SeekPos / PAGEBUF; + + /* Address in page memory */ page_addr = fd->SeekPos % PAGEBUF; - + prog_loadPage(page); - - size_t wr_len = MIN(size, PAGEBUF - page_addr); + + wr_len = MIN(size, PAGEBUF - page_addr); memcpy(page_buf + page_addr, buf, wr_len); buf += wr_len; @@ -120,30 +149,25 @@ size_t prog_write(struct _KFile *fd, const char *buf, size_t size) size -= wr_len; total_write += wr_len; } + /* Return total byte write on flash memory */ return total_write; } -void prog_flush(void) -{ - - /* Fill the temporary buffer of the AVR */ - for (page_addr_t page_addr = 0; page_addr < PAGEBUF; page_addr += 2) - fill_temp_buffer(page_buf[page_addr + 1] | (uint16_t)page_buf[page_addr] << 8, page_addr); - - - wdt_reset(); - /* Page write */ - prog_pagewrite(curr_page_num * PAGEBUF); -} +/** + * Load select \param page memory buffer from AVR flash memory. + * If select page is not current page, we flush it, and then we load + * select page memory flash. + */ void prog_loadPage(page_t page) { if (page != curr_page_num) { prog_flush(); - // Load page + /* Load selet page in temporary buffer store into RAM */ memcpy_P(page_buf, (const char *)(page * PAGEBUF), PAGEBUF); + /* Update current page */ curr_page_num = page; } -} \ No newline at end of file +}