#include <string.h>
-#warning FIXME:This module need to be refactor to kfile interface!
+
#if 1
+
/**
* Definition of type for avr flash module.
*/
*/
static int flash_avr_kfileFlush(struct KFile * fd)
{
- KFILE_ASSERT_GENERIC(fd);
+
+ KFILEFLASHAVR(fd);
(void)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);
size = MIN((uint32_t)size, fd->size - fd->seek_pos);
*/
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);
*/
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);
flash_avr_close(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);
+ KFILEFLASHAVR(fd);
ASSERT(fd->seek_pos + size <= fd->size);
size = MIN((uint32_t)size, fd->size - fd->seek_pos);
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;
#include <cfg/compiler.h>
#include <kern/kfile.h>
+
+/**
+ * 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 */