#include <string.h>
-#warning FIXME:This module need to be refactor to kfile interface!
-#if 1
+
/**
* Definition of type for avr flash module.
* Write current buffered page in flash memory (if modified).
* This function erase flash memory page before writing.
*/
-static int flash_avr_kfileFlush(struct KFile * fd)
+static int flash_avr_kfileFlush(UNUSED_ARG(struct KFile *,fd))
{
- KFILE_ASSERT_GENERIC(fd);
- (void)fd;
+
+ KFILEFLASHAVR(fd);
flash_avr_flush();
return 0;
}
*/
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);
+
+ ASSERT(fd->seek_pos + (kfile_off_t)size <= (kfile_off_t)fd->size);
size = MIN((uint32_t)size, fd->size - fd->seek_pos);
kprintf("Writing at pos[%u]\n", fd->seek_pos);
* \a name and \a mode are unused, cause flash memory is
* threated like one file.
*/
-static void flash_avr_open(struct KFile *fd)
+static void flash_avr_open(struct KFileFlashAvr *fd)
{
- KFILE_ASSERT_GENERIC(fd);
curr_page = 0;
memcpy_P(page_buf, (const char *)(curr_page * SPM_PAGESIZE), SPM_PAGESIZE);
- fd->seek_pos = 0;
- fd->size = (uint16_t)(FLASHEND - CONFIG_FLASH_AVR_BOOTSIZE + 1);
+ fd->fd.seek_pos = 0;
+ fd->fd.size = (uint16_t)(FLASHEND - CONFIG_FLASH_AVR_BOOTSIZE + 1);
page_modified = false;
kprintf("Flash file opened\n");
*/
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;
*/
static struct KFile *flash_avr_reopen(struct KFile *fd)
{
- KFILE_ASSERT_GENERIC(fd);
+ KFileFlashAvr *_fd = KFILEFLASHAVR(fd);
flash_avr_close(fd);
- flash_avr_open(fd);
+ flash_avr_open(_fd);
return fd;
}
*/
static size_t flash_avr_read(struct KFile *fd, void *buf, size_t size)
{
- KFILE_ASSERT_GENERIC(fd);
- ASSERT(fd->seek_pos + size <= fd->size);
+ KFILEFLASHAVR(fd);
+ ASSERT(fd->seek_pos + (kfile_off_t)size <= (kfile_off_t)fd->size);
size = MIN((uint32_t)size, fd->size - fd->seek_pos);
kprintf("Reading at pos[%u]\n", fd->seek_pos);
/**
* Init AVR flash read/write file.
*/
-void flash_avr_init(struct KFile *fd)
+void flash_avr_init(struct KFileFlashAvr *fd)
{
memset(fd, 0, sizeof(*fd));
- DB(fd->_type = KFT_GENERIC);
+ DB(fd->fd._type = KFT_FLASHAVR);
// Set up flash programming functions.
- fd->reopen = flash_avr_reopen;
- fd->close = flash_avr_close;
- fd->read = flash_avr_read;
- fd->write = flash_avr_write;
- fd->seek = kfile_genericSeek;
- fd->flush = flash_avr_kfileFlush;
+ fd->fd.reopen = flash_avr_reopen;
+ fd->fd.close = flash_avr_close;
+ fd->fd.read = flash_avr_read;
+ fd->fd.write = flash_avr_write;
+ fd->fd.seek = kfile_genericSeek;
+ fd->fd.flush = flash_avr_kfileFlush;
flash_avr_open(fd);
}
-#endif
+