From b59de1faa4a3d4656d9ffe3e2cc513abc55fb6b3 Mon Sep 17 00:00:00 2001 From: qwert Date: Mon, 4 Aug 2008 15:28:27 +0000 Subject: [PATCH] Refactor KFileFlashAvr in FlashAvrKFile. Tested. It work. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1538 38d2e660-2303-0410-9eaa-f027e97ec537 --- app/triface/boot/main.c | 2 +- bertos/cpu/avr/drv/flash_avr.c | 18 +++++++++--------- bertos/cpu/avr/drv/flash_avr.h | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/triface/boot/main.c b/app/triface/boot/main.c index 97b1cefc..478ebcd8 100644 --- a/app/triface/boot/main.c +++ b/app/triface/boot/main.c @@ -63,7 +63,7 @@ int main(void) { - KFileFlashAvr flash; + FlashAvrKFile flash; KFileSerial ser; diff --git a/bertos/cpu/avr/drv/flash_avr.c b/bertos/cpu/avr/drv/flash_avr.c index cc5780a6..c64f935b 100644 --- a/bertos/cpu/avr/drv/flash_avr.c +++ b/bertos/cpu/avr/drv/flash_avr.c @@ -83,7 +83,7 @@ typedef uint16_t avr_page_addr_t; * * This function is only use internally in this module. */ -static void flash_avr_flush(KFileFlashAvr *fd) +static void flash_avr_flush(FlashAvrKFile *fd) { if (fd->page_dirty) { @@ -141,7 +141,7 @@ static void flash_avr_flush(KFileFlashAvr *fd) */ static int flash_avr_kfileFlush(struct KFile *_fd) { - KFileFlashAvr *fd = KFILEFLASHAVR(_fd); + FlashAvrKFile *fd = FLASHAVRKFILE(_fd); flash_avr_flush(fd); return 0; } @@ -151,7 +151,7 @@ static int flash_avr_kfileFlush(struct KFile *_fd) * Check current page and if \a page is different, load it in * temporary buffer. */ -static void flash_avr_loadPage(KFileFlashAvr *fd, avr_page_t page) +static void flash_avr_loadPage(FlashAvrKFile *fd, avr_page_t page) { if (page != fd->curr_page) { @@ -170,7 +170,7 @@ static void flash_avr_loadPage(KFileFlashAvr *fd, avr_page_t page) */ static size_t flash_avr_write(struct KFile *_fd, const void *_buf, size_t size) { - KFileFlashAvr *fd = KFILEFLASHAVR(_fd); + FlashAvrKFile *fd = FLASHAVRKFILE(_fd); const uint8_t *buf =(const uint8_t *)_buf; avr_page_t page; @@ -207,7 +207,7 @@ static size_t flash_avr_write(struct KFile *_fd, const void *_buf, size_t size) * \a name and \a mode are unused, cause flash memory is * threated like one file. */ -static void flash_avr_open(struct KFileFlashAvr *fd) +static void flash_avr_open(struct FlashAvrKFile *fd) { fd->curr_page = 0; memcpy_P(fd->page_buf, (const char *)(fd->curr_page * SPM_PAGESIZE), SPM_PAGESIZE); @@ -224,7 +224,7 @@ static void flash_avr_open(struct KFileFlashAvr *fd) */ static int flash_avr_close(struct KFile *_fd) { - KFileFlashAvr *fd = KFILEFLASHAVR(_fd); + FlashAvrKFile *fd = FLASHAVRKFILE(_fd); flash_avr_flush(fd); LOG_INFO("Flash file closed\n"); return 0; @@ -235,7 +235,7 @@ static int flash_avr_close(struct KFile *_fd) */ static struct KFile *flash_avr_reopen(struct KFile *fd) { - KFileFlashAvr *_fd = KFILEFLASHAVR(fd); + FlashAvrKFile *_fd = FLASHAVRKFILE(fd); flash_avr_close(fd); flash_avr_open(_fd); return fd; @@ -248,7 +248,7 @@ static struct KFile *flash_avr_reopen(struct KFile *fd) */ static size_t flash_avr_read(struct KFile *_fd, void *buf, size_t size) { - KFileFlashAvr *fd = KFILEFLASHAVR(_fd); + FlashAvrKFile *fd = FLASHAVRKFILE(_fd); ASSERT(fd->fd.seek_pos + (kfile_off_t)size <= (kfile_off_t)fd->fd.size); size = MIN((uint32_t)size, fd->fd.size - fd->fd.seek_pos); @@ -272,7 +272,7 @@ static size_t flash_avr_read(struct KFile *_fd, void *buf, size_t size) /** * Init AVR flash read/write file. */ -void flash_avr_init(struct KFileFlashAvr *fd) +void flash_avr_init(struct FlashAvrKFile *fd) { memset(fd, 0, sizeof(*fd)); DB(fd->fd._type = KFT_FLASHAVR); diff --git a/bertos/cpu/avr/drv/flash_avr.h b/bertos/cpu/avr/drv/flash_avr.h index 11838eba..4a0aea73 100644 --- a/bertos/cpu/avr/drv/flash_avr.h +++ b/bertos/cpu/avr/drv/flash_avr.h @@ -54,7 +54,7 @@ typedef uint16_t avr_page_t; /** * FlashAvr KFile context structure. */ -typedef struct KFileFlashAvr +typedef struct FlashAvrKFile { /** * File descriptor. @@ -78,7 +78,7 @@ typedef struct KFileFlashAvr uint8_t page_buf[SPM_PAGESIZE]; -} KFileFlashAvr; +} FlashAvrKFile; @@ -88,16 +88,16 @@ typedef struct KFileFlashAvr #define KFT_FLASHAVR MAKE_ID('F', 'L', 'A', 'V') /** - * Convert + ASSERT from generic KFile to KFileFlashAvr. + * Convert + ASSERT from generic KFile to FlashAvrKFile. */ -INLINE KFileFlashAvr * KFILEFLASHAVR(KFile *fd) +INLINE FlashAvrKFile * FLASHAVRKFILE(KFile *fd) { ASSERT(fd->_type == KFT_FLASHAVR); - return (KFileFlashAvr *)fd; + return (FlashAvrKFile *)fd; } -void flash_avr_init(struct KFileFlashAvr *fd); +void flash_avr_init(struct FlashAvrKFile *fd); -- 2.25.1