Re-Refactor code under new specs. BattFs. Nightlytest passed.
[bertos.git] / bertos / cpu / avr / drv / flash_avr.h
index 7b4317d97106029c5bbab80e341f88a153ef6060..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 FlashAvrKFile
+{
+       /**
+        * 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;
+
+
+
+/**
+ * ID for FlashAvr
+ */
+#define KFT_FLASHAVR MAKE_ID('F', 'L', 'A', 'V')
+
+/**
+ * Convert + ASSERT from generic KFile to FlashAvrKFile.
+ */
+INLINE FlashAvrKFile * FLASHAVRKFILE(KFile *fd)
+{
+       ASSERT(fd->_type == KFT_FLASHAVR);
+       return (FlashAvrKFile *)fd;
+}
+
+
+void flash_avr_init(struct FlashAvrKFile *fd);
 
-bool flash_avr_test(void);
-void flash_avr_init(struct KFile *fd);
 
 
 #endif /* DRV_FLASH_AVR_H */