From: qwert Date: Thu, 17 Jul 2008 14:59:51 +0000 (+0000) Subject: Modified flash_avr module to work with new kfile interface. Addedd a new tipe of... X-Git-Tag: 2.0.0~446 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=2b1ef1c4e079e86db8512cec4dac031a0d19cb2f;p=bertos.git Modified flash_avr module to work with new kfile interface. Addedd a new tipe of custom KFile: KFileFlashAvr. Add new macro KFILEFLASHAVR for automatic conversion from a KFile to a KFIleFlashAvr struct. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1488 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cpu/avr/drv/flash_avr.c b/bertos/cpu/avr/drv/flash_avr.c index 01a515f6..ad350b29 100644 --- a/bertos/cpu/avr/drv/flash_avr.c +++ b/bertos/cpu/avr/drv/flash_avr.c @@ -60,9 +60,10 @@ #include -#warning FIXME:This module need to be refactor to kfile interface! + #if 1 + /** * Definition of type for avr flash module. */ @@ -150,7 +151,8 @@ static void flash_avr_flush(void) */ static int flash_avr_kfileFlush(struct KFile * fd) { - KFILE_ASSERT_GENERIC(fd); + + KFILEFLASHAVR(fd); (void)fd; flash_avr_flush(); return 0; @@ -180,13 +182,14 @@ static void flash_avr_loadPage(avr_page_t page) */ static size_t flash_avr_write(struct KFile *fd, const void *_buf, size_t size) { - KFILE_ASSERT_GENERIC(fd); + KFILEFLASHAVR(fd); const uint8_t *buf =(const uint8_t *)_buf; avr_page_t page; avr_page_addr_t page_addr; size_t total_write = 0; + ASSERT(fd->seek_pos + size <= fd->size); size = MIN((uint32_t)size, fd->size - fd->seek_pos); @@ -218,7 +221,7 @@ static size_t flash_avr_write(struct KFile *fd, const void *_buf, size_t size) */ static void flash_avr_open(struct KFile *fd) { - KFILE_ASSERT_GENERIC(fd); + KFILEFLASHAVR(fd); curr_page = 0; memcpy_P(page_buf, (const char *)(curr_page * SPM_PAGESIZE), SPM_PAGESIZE); @@ -234,7 +237,7 @@ static void flash_avr_open(struct KFile *fd) */ static int flash_avr_close(UNUSED_ARG(struct KFile *,fd)) { - KFILE_ASSERT_GENERIC(fd); + KFILEFLASHAVR(fd); flash_avr_flush(); kprintf("Flash file closed\n"); return 0; @@ -245,7 +248,7 @@ static int flash_avr_close(UNUSED_ARG(struct KFile *,fd)) */ static struct KFile *flash_avr_reopen(struct KFile *fd) { - KFILE_ASSERT_GENERIC(fd); + KFILEFLASHAVR(fd); flash_avr_close(fd); flash_avr_open(fd); return fd; @@ -258,7 +261,7 @@ static struct KFile *flash_avr_reopen(struct KFile *fd) */ static size_t flash_avr_read(struct KFile *fd, void *buf, size_t size) { - KFILE_ASSERT_GENERIC(fd); + KFILEFLASHAVR(fd); ASSERT(fd->seek_pos + size <= fd->size); size = MIN((uint32_t)size, fd->size - fd->seek_pos); @@ -285,7 +288,7 @@ static size_t flash_avr_read(struct KFile *fd, void *buf, size_t size) void flash_avr_init(struct KFile *fd) { memset(fd, 0, sizeof(*fd)); - DB(fd->_type = KFT_GENERIC); + DB(fd->_type = KFT_FLASHAVR); // Set up flash programming functions. fd->reopen = flash_avr_reopen; diff --git a/bertos/cpu/avr/drv/flash_avr.h b/bertos/cpu/avr/drv/flash_avr.h index 7b4317d9..390f648d 100644 --- a/bertos/cpu/avr/drv/flash_avr.h +++ b/bertos/cpu/avr/drv/flash_avr.h @@ -43,8 +43,36 @@ #include #include + +/** + * FlashAvr KFile context structure. + */ +typedef struct KFileFlashAvr +{ + KFile fd; ///< File descriptor. +} KFileFlashAvr; + + + +/** + * ID for FlashAvr + */ +#define KFT_FLASHAVR MAKE_ID('F', 'L', 'A', 'V') + +/** + * Convert + ASSERT from generic KFile to KFileFlashAvr. + */ +INLINE KFileFlashAvr * KFILEFLASHAVR(KFile *fd) +{ + ASSERT(fd->_type == KFT_FLASHAVR); + return (KFileFlashAvr *)fd; +} + + + bool flash_avr_test(void); void flash_avr_init(struct KFile *fd); + #endif /* DRV_FLASH_AVR_H */