Merge some fix from trunk.
[bertos.git] / bertos / drv / flash.h
index c1844e314b62439b5bf0084d811234d4c8ba88b2..9ea5665075e815793a0e9daf8ccaa2a2d903e8a0 100644 (file)
@@ -36,7 +36,8 @@
 * \author Daniele Basile <asterix@develer.com>
 *
 * $WIZ$ module_name = "flash"
-* $WIZ$ module_depends = "kfile"
+* $WIZ$ module_depends = "kfile", "kfile_block", "kblock"
+* $WIZ$ module_configuration = "bertos/cfg/cfg_emb_flash.h"
 */
 
 #ifndef DRV_FLASH_H
 #include <io/kfile.h>
 #include <io/kfile_block.h>
 
+#include <cpu/attr.h>
+
+#if COMPILER_C99
+       #define flash_init(...)           PP_CAT(flash_init_, COUNT_PARMS(__VA_ARGS__)) (__VA_ARGS__)
+#else
+       #define flash_init(args...)       PP_CAT(flash_init_, COUNT_PARMS(args)) (args)
+#endif
+
 /*
  * Embedded flash error flags
  */
@@ -83,7 +92,7 @@ typedef struct Flash
 #define KBT_FLASH MAKE_ID('F', 'L', 'A', 'S')
 
 /**
-* Convert + ASSERT from generic KFile to Flash.
+* Convert + ASSERT from generic KBlock to Flash.
 */
 INLINE Flash *FLASH_CAST(KBlock *fls)
 {
@@ -91,26 +100,23 @@ INLINE Flash *FLASH_CAST(KBlock *fls)
        return (Flash *)fls;
 }
 
-void flash_hw_init(Flash *fls);
-void flash_hw_initUnbuffered(Flash *fls);
+void flash_hw_init(Flash *fls, int flags);
+void flash_hw_initUnbuffered(Flash *fls, int flags);
 
 #include CPU_HEADER(flash)
 
-INLINE void flash_init(Flash *fls)
-{
-       flash_hw_init(fls);
+#define FLASH_WRITE_ONCE   BV(0) ///< Allow only one write per block.
+#define FLASH_UNBUFFERED   BV(1) ///< Open flash memory disabling page caching, no modification and partial write are allowed.
 
-       #if !CONFIG_FLASH_DISABLE_OLD_API
-               kfileblock_init(&fls->fdblk, &fls->blk);
-       #endif /* !CONFIG_FLASH_DISABLE_OLD_API */
-}
+#define flash_init_2(fls, flags)    (flags & FLASH_UNBUFFERED) ? \
+                                                                               flash_hw_initUnbuffered(fls, flags) : flash_hw_init(fls, flags)
 
-INLINE void flash_initUnbuffered(Flash *fls)
+#if !CONFIG_FLASH_DISABLE_OLD_API
+INLINE DEPRECATED void flash_init_1(Flash *fls)
 {
-       flash_hw_initUnbuffered(fls);
+       flash_hw_init(fls, 0);
+       kfileblock_init(&fls->fdblk, &fls->blk);
 }
-
-#include CPU_HEADER(flash)
+#endif /* !CONFIG_FLASH_DISABLE_OLD_API */
 
 #endif /* DRV_FLASH_H */
-