Refactor KFileFlashAvr in FlashAvrKFile. Tested. It work.
[bertos.git] / bertos / cpu / avr / drv / flash_avr.h
index f078c38e6be99359a50aaee49ba51bf9655b291d..4a0aea73f88eaacb05f61198121333d0c0ee1f8f 100644 (file)
 
 #include <cfg/compiler.h>
 #include <kern/kfile.h>
+#include <avr/io.h>
+
+
+/**
+ * Definition of type for avr flash module.
+ */
+typedef uint16_t avr_page_t;
 
 
 /**
  * FlashAvr KFile context structure.
  */
-typedef struct KFileFlashAvr
+typedef struct FlashAvrKFile
 {
-       KFile fd;               ///< File descriptor.
-} KFileFlashAvr;
+       /**
+        * File descriptor.
+        */
+       KFile fd;
+
+       /**
+        * Current buffered page.
+        */
+       avr_page_t curr_page;
+
+       /**
+        * Flag for checking if current page is modified.
+        */
+       bool page_dirty;
+
+       /**
+        * Temporary buffer cointaing data block to
+        * write on flash.
+        */
+       uint8_t page_buf[SPM_PAGESIZE];
+
+
+} FlashAvrKFile;
 
 
 
@@ -60,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);