Add IRQ_RUNNING() implementation for ARM7.
[bertos.git] / bertos / drv / eeprom.c
index f66135fc0865bdbcc0552ea3e662f4cb0c095a38..82fb9590f6126524ce8d63a76290df2ab1f706b9 100644 (file)
@@ -82,6 +82,24 @@ static const EepromInfo mem_info[] =
                .blk_size = 0x10,
                .e2_size = 0x800,
        },
+       {
+               /* 24XX32 */
+               .has_dev_addr = true,
+               .blk_size = 0x20,
+               .e2_size = 0x1000,
+       },
+       {
+               /* 24XX64 */
+               .has_dev_addr = true,
+               .blk_size = 0x20,
+               .e2_size = 0x2000,
+       },
+       {
+               /* 24XX128 */
+               .has_dev_addr = true,
+               .blk_size = 0x40,
+               .e2_size = 0x4000,
+       },
        {
                /* 24XX256 */
                .has_dev_addr = true,
@@ -108,6 +126,12 @@ STATIC_ASSERT(countof(mem_info) == EEPROM_CNT);
 
 #define CHUNCK_SIZE     16
 
+/**
+ * Erase EEPROM.
+ * \param eep is the Kblock context.
+ * \param addr eeprom address where start to erase
+ * \param size number of byte to erase
+ */
 bool eeprom_erase(Eeprom *eep, e2addr_t addr, e2_size_t size)
 {
        uint8_t tmp[CHUNCK_SIZE] = { [0 ... (CHUNCK_SIZE - 1)] = 0xFF };
@@ -127,6 +151,13 @@ bool eeprom_erase(Eeprom *eep, e2addr_t addr, e2_size_t size)
        return true;
 }
 
+/**
+ * Verify EEPROM.
+ * \param eep is the Kblock context.
+ * \param addr eeprom address where start to verify.
+ * \param buf buffer of data to compare with eeprom data read.
+ * \param size number of byte to verify.
+ */
 bool eeprom_verify(Eeprom *eep, e2addr_t addr, const void *buf, size_t size)
 {
     uint8_t verify_buf[CHUNCK_SIZE];
@@ -168,9 +199,8 @@ static size_t eeprom_write(KBlock *blk, block_idx_t idx, const void *buf, size_t
 
        STATIC_ASSERT(countof(addr_buf) <= sizeof(e2addr_t));
 
-
        /* clamp size to memory limit (otherwise may roll back) */
-       ASSERT(idx <= blk->blk_cnt);
+       ASSERT(idx < blk->priv.blk_start + blk->blk_cnt);
        size = MIN(size, blk->blk_size - offset);
 
        if (mem_info[eep->type].has_dev_addr)
@@ -217,7 +247,7 @@ static size_t eeprom_readDirect(struct KBlock *_blk, block_idx_t idx, void *_buf
        STATIC_ASSERT(countof(addr_buf) <= sizeof(e2addr_t));
 
        /* clamp size to memory limit (otherwise may roll back) */
-       ASSERT(idx <= blk->blk.blk_cnt);
+       ASSERT(idx < blk->blk.priv.blk_start + blk->blk.blk_cnt);
        size = MIN(size, blk->blk.blk_size - offset);
 
        e2dev_addr_t dev_addr;
@@ -313,10 +343,11 @@ static const KBlockVTable eeprom_unbuffered_vt =
 
 /**
  * Initialize EEPROM module.
- * \param b is the Kblock context.
+ * \param eep is the Kblock context.
  * \param type is the eeprom device we want to initialize (\see EepromType)
  * \param i2c context for i2c channel
  * \param addr is the i2c devide address (usually pins A0, A1, A2).
+ * \param verify enable the write check.
  */
 void eeprom_init_5(Eeprom *eep, I2c *i2c, EepromType type, e2dev_addr_t addr, bool verify)
 {