Move flash related flags to the flash driver; refactor accordingly.
authorbatt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 28 Oct 2010 15:59:24 +0000 (15:59 +0000)
committerbatt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 28 Oct 2010 15:59:24 +0000 (15:59 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4478 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/cpu/arm/drv/flash_at91.c
bertos/cpu/arm/drv/flash_lpc2.c
bertos/cpu/avr/drv/flash_avr.c
bertos/cpu/cortex-m3/drv/flash_lm3s.c
bertos/cpu/cortex-m3/drv/flash_stm32.c
bertos/drv/flash.h
bertos/io/kblock.h

index 1cdf6b788e0e8678ea6a7a5fc6609aa640a6c72e..514d54e4326811042b4ea7dcafcf0e1f5e815857 100644 (file)
@@ -222,21 +222,20 @@ static void common_init(Flash *fls)
        fls->blk.blk_cnt = FLASH_MEM_SIZE / FLASH_PAGE_SIZE_BYTES;
 }
 
-void flash_hw_init(Flash *fls, int flags)
+void flash_hw_init(Flash *fls, UNUSED_ARG(int, flags))
 {
        common_init(fls);
        fls->blk.priv.vt = &flash_at91_buffered_vt;
-       fls->blk.priv.flags |= KB_BUFFERED | KB_PARTIAL_WRITE | flags;
+       fls->blk.priv.flags |= KB_BUFFERED | KB_PARTIAL_WRITE;
        fls->blk.priv.buf = flash_buf;
 
        /* Load the first block in the cache */
        memcpy(fls->blk.priv.buf, (void *)(FLASH_BASE), fls->blk.blk_size);
 }
 
-void flash_hw_initUnbuffered(Flash *fls, int flags)
+void flash_hw_initUnbuffered(Flash *fls, UNUSED_ARG(int, flags))
 {
        common_init(fls);
        fls->blk.priv.vt = &flash_at91_unbuffered_vt;
-       fls->blk.priv.flags |= flags;
 }
 
index a78ade27c8bfe111e560d10a4a165071d3cc37c4..e1a3391bf7bbc39a1deec9a8728228f5af300854 100644 (file)
@@ -90,6 +90,7 @@ typedef enum IapCommands
 struct FlashHardware
 {
        uint8_t status;
+       int flags;
 };
 
 #define FLASH_PAGE_CNT  FLASH_MEM_SIZE / FLASH_PAGE_SIZE_BYTES
@@ -189,7 +190,7 @@ static size_t lpc2_flash_writeDirect(struct KBlock *blk, block_idx_t idx, const
        ASSERT(FLASH_PAGE_SIZE_BYTES == size);
 
        Flash *fls = FLASH_CAST(blk);
-       if (!(fls->blk.priv.flags & KB_WRITE_ONCE))
+       if (!(fls->hw->flags & FLASH_WRITE_ONCE))
                ASSERT(sector_size(idx) <= FLASH_PAGE_SIZE_BYTES);
 
        const uint8_t *buf = (const uint8_t *)_buf;
@@ -213,7 +214,7 @@ static size_t lpc2_flash_writeDirect(struct KBlock *blk, block_idx_t idx, const
        if (res.status != CMD_SUCCESS)
                goto flash_error;
 
-       if ((fls->blk.priv.flags & KB_WRITE_ONCE) &&
+       if ((fls->hw->flags & FLASH_WRITE_ONCE) &&
                        bitarray_isRangeFull(&lpc2_bitx, idx_sector, erase_group[sector]))
        {
                kputs("blocchi pieni\n");
@@ -222,11 +223,11 @@ static size_t lpc2_flash_writeDirect(struct KBlock *blk, block_idx_t idx, const
        }
 
        bool erase = false;
-       if ((fls->blk.priv.flags & KB_WRITE_ONCE) &&
+       if ((fls->hw->flags & FLASH_WRITE_ONCE) &&
                        bitarray_isRangeEmpty(&lpc2_bitx, idx_sector, erase_group[sector]))
                erase = true;
 
-       if (!(fls->blk.priv.flags & KB_WRITE_ONCE))
+       if (!(fls->hw->flags & FLASH_WRITE_ONCE))
                erase = true;
 
        if (erase)
@@ -248,7 +249,7 @@ static size_t lpc2_flash_writeDirect(struct KBlock *blk, block_idx_t idx, const
        if (res.status != CMD_SUCCESS)
                goto flash_error;
 
-       if (fls->blk.priv.flags & KB_WRITE_ONCE)
+       if (fls->hw->flags & FLASH_WRITE_ONCE)
        {
                if (bitarray_test(&lpc2_bitx, idx))
                {
@@ -275,6 +276,7 @@ static size_t lpc2_flash_writeDirect(struct KBlock *blk, block_idx_t idx, const
        return blk->blk_size;
 
 flash_error:
+       IRQ_RESTORE(flags);
        LOG_ERR("%ld\n", res.status);
        fls->hw->status |= FLASH_WR_ERR;
        return 0;
@@ -329,12 +331,13 @@ static const KBlockVTable flash_lpc2_unbuffered_vt =
 static struct FlashHardware flash_lpc2_hw;
 static uint8_t flash_buf[FLASH_PAGE_SIZE_BYTES];
 
-static void common_init(Flash *fls)
+static void common_init(Flash *fls, int flags)
 {
        memset(fls, 0, sizeof(*fls));
        DB(fls->blk.priv.type = KBT_FLASH);
 
        fls->hw = &flash_lpc2_hw;
+       fls->hw->flags = flags;
 
        fls->blk.blk_size = FLASH_PAGE_SIZE_BYTES;
        fls->blk.blk_cnt = FLASH_MEM_SIZE / FLASH_PAGE_SIZE_BYTES;
@@ -344,11 +347,12 @@ static void common_init(Flash *fls)
 
 void flash_hw_init(Flash *fls, int flags)
 {
-       common_init(fls);
+       common_init(fls, flags);
        fls->blk.priv.vt = &flash_lpc2_buffered_vt;
-       fls->blk.priv.flags |= KB_BUFFERED | KB_PARTIAL_WRITE | flags;
+       fls->blk.priv.flags |= KB_BUFFERED | KB_PARTIAL_WRITE;
        fls->blk.priv.buf = flash_buf;
 
+
        /* Load the first block in the cache */
        void *flash_start = 0x0;
        memcpy(fls->blk.priv.buf, flash_start, fls->blk.blk_size);
@@ -356,7 +360,6 @@ void flash_hw_init(Flash *fls, int flags)
 
 void flash_hw_initUnbuffered(Flash *fls, int flags)
 {
-       common_init(fls);
+       common_init(fls, flags);
        fls->blk.priv.vt = &flash_lpc2_unbuffered_vt;
-       fls->blk.priv.flags |= flags;
 }
index 7584200ea449a6988fc90ed6fc32bb076502ada1..2c0baa1b52924bdab9bc0c51f6cff08285a93d20 100644 (file)
@@ -161,19 +161,18 @@ static void common_init(Flash *fls)
 }
 
 
-void flash_hw_init(Flash *fls, int flags)
+void flash_hw_init(Flash *fls, UNUSED_ARG(int, flags))
 {
        common_init(fls);
        fls->blk.priv.vt = &flash_avr_buffered_vt;
-       fls->blk.priv.flags |= KB_BUFFERED | KB_PARTIAL_WRITE | flags;
+       fls->blk.priv.flags |= KB_BUFFERED | KB_PARTIAL_WRITE;
        fls->blk.priv.buf = flash_buf;
 }
 
-void flash_hw_initUnbuffered(Flash *fls, int flags)
+void flash_hw_initUnbuffered(Flash *fls, UNUSED_ARG(int, flags))
 {
        common_init(fls);
        fls->blk.priv.vt = &flash_avr_unbuffered_vt;
-       fls->blk.priv.flags |= flags;
 }
 
 
index 7ca0a7cf33b126e3b8577f31e26a3e088a2be6d0..ffec0db7c0c20e94b310668aa84ae5a6e72ccd11 100644 (file)
@@ -201,11 +201,11 @@ static void common_init(Flash *fls)
 }
 
 
-void flash_hw_init(Flash *fls, int flags)
+void flash_hw_init(Flash *fls, UNUSED_ARG(int, flags))
 {
        common_init(fls);
        fls->blk.priv.vt = &flash_lm3s_buffered_vt;
-       fls->blk.priv.flags |= KB_BUFFERED | KB_PARTIAL_WRITE | flags;
+       fls->blk.priv.flags |= KB_BUFFERED | KB_PARTIAL_WRITE;
        fls->blk.priv.buf = flash_buf;
 
        /* Load the first block in the cache */
@@ -213,11 +213,10 @@ void flash_hw_init(Flash *fls, int flags)
        memcpy(fls->blk.priv.buf, flash_start, fls->blk.blk_size);
 }
 
-void flash_hw_initUnbuffered(Flash *fls, int flags)
+void flash_hw_initUnbuffered(Flash *fls, UNUSED_ARG(int, flags))
 {
        common_init(fls);
        fls->blk.priv.vt = &flash_lm3s_unbuffered_vt;
-       fls->blk.priv.flags |= flags;
 }
 
 
index 62e448f3ab35dd9d201ba78756c89b3655247d9f..816cdd58f94096f459a240f6a18f386cdc665328 100644 (file)
@@ -112,6 +112,8 @@ static bool stm32_erasePage(struct KBlock *blk, uint32_t page_add)
        return true;
 }
 
+#if 0
+// not used for now
 static bool stm32_eraseAll(struct KBlock *blk)
 {
        EMB_FLASH->CR |= CR_MER_SET;
@@ -124,6 +126,7 @@ static bool stm32_eraseAll(struct KBlock *blk)
 
        return true;
 }
+#endif
 
 static int stm32_flash_error(struct KBlock *blk)
 {
@@ -231,11 +234,11 @@ static void common_init(Flash *fls)
 }
 
 
-void flash_hw_init(Flash *fls, int flags)
+void flash_hw_init(Flash *fls, UNUSED_ARG(int, flags))
 {
        common_init(fls);
        fls->blk.priv.vt = &flash_stm32_buffered_vt;
-       fls->blk.priv.flags |= KB_BUFFERED | KB_PARTIAL_WRITE | flags;
+       fls->blk.priv.flags |= KB_BUFFERED | KB_PARTIAL_WRITE;
        fls->blk.priv.buf = flash_buf;
 
        /* Load the first block in the cache */
@@ -243,9 +246,8 @@ void flash_hw_init(Flash *fls, int flags)
        memcpy(fls->blk.priv.buf, flash_start, fls->blk.blk_size);
 }
 
-void flash_hw_initUnbuffered(Flash *fls, int flags)
+void flash_hw_initUnbuffered(Flash *fls, UNUSED_ARG(int, flags))
 {
        common_init(fls);
        fls->blk.priv.vt = &flash_stm32_unbuffered_vt;
-       fls->blk.priv.flags |= flags;
 }
index eccaf7519a6ec20e8baec1a820aadc324dc2580d..da1fa80143251cdcaf320d7a7457c69e23f4b36e 100644 (file)
@@ -55,9 +55,9 @@
 #include <cpu/attr.h>
 
 #if COMPILER_C99
-       #define flash_init(...)           PP_CAT(flash_init ## _, COUNT_PARMS(__VA_ARGS__)) (__VA_ARGS__)
+       #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)
+       #define flash_init(args...)       PP_CAT(flash_init_, COUNT_PARMS(args)) (args)
 #endif
 
 /*
@@ -92,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)
 {
@@ -105,7 +105,10 @@ void flash_hw_initUnbuffered(Flash *fls, int flags);
 
 #include CPU_HEADER(flash)
 
-#define flash_init_2(fls, flags)    (flags & KB_OPEN_UNBUFF) ? \
+#define FLASH_WRITE_ONCE   BV(0) ///< Allow only one write per block.
+#define FLASH_BUFFERED     BV(1) ///< Open flash memory using page caching, allowing the modification and partial write.
+
+#define flash_init_2(fls, flags)    (flags & FLASH_BUFFERED) ? \
                                                                                flash_hw_initUnbuffered(fls, flags) : flash_hw_init(fls, flags)
 
 #if !CONFIG_FLASH_DISABLE_OLD_API
@@ -116,7 +119,4 @@ INLINE DEPRECATED void flash_init_1(Flash *fls)
 }
 #endif /* !CONFIG_FLASH_DISABLE_OLD_API */
 
-#include CPU_HEADER(flash)
-
 #endif /* DRV_FLASH_H */
-
index 358e089919ff5df928272d81f27e11e23d80e174..f2966bafea2fd4def8512452e760a98f6e03e6c1 100644 (file)
@@ -96,9 +96,6 @@ typedef struct KBlockVTable
 #define KB_CACHE_DIRTY     BV(1) ///< Internal flag: true if the cache is dirty
 #define KB_PARTIAL_WRITE   BV(2) ///< Internal flag: true if the device allows partial block write
 
-#define KB_WRITE_ONCE      BV(3) ///< Allow only the one write on select block.
-#define KB_OPEN_BUFF       BV(4) ///< Open flash memory using page caching, allowing the modification and partial write.
-#define KB_OPEN_UNBUFF     BV(5) ///< Open flash memory whitout memory caching.
 
 /*
  * KBlock private members.