X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fdrv%2Feeprom.c;h=470d85cd903d24c46a0571d1c247da50d1e0b05e;hb=bc8b61afa24c8ccecb748ba1aebc5c45ff70cc17;hp=f92091487ae0cc9daeb2fb7cf7bcbd210a2f8d1a;hpb=2ec062d0fa64791fc844d8385a8cf06e8df5dab6;p=bertos.git diff --git a/bertos/drv/eeprom.c b/bertos/drv/eeprom.c index f9209148..470d85cd 100644 --- a/bertos/drv/eeprom.c +++ b/bertos/drv/eeprom.c @@ -32,17 +32,12 @@ * * \brief Driver for the 24xx16 and 24xx256 I2C EEPROMS (implementation) * - * - * \version $Id$ * \author Stefano Fedrigo * \author Bernie Innocenti */ #include "eeprom.h" -#warning TODO:Test and complete this module for arm platform. -#if !CPU_ARM - #include // MIN() #include #include // MOD_CHECK() @@ -72,6 +67,12 @@ */ static const EepromInfo mem_info[] = { + { + /* 24XX08 */ + .has_dev_addr = false, + .blk_size = 0x10, + .e2_size = 0x400, + }, { /* 24XX16 */ .has_dev_addr = false, @@ -90,6 +91,13 @@ static const EepromInfo mem_info[] = .blk_size = 0x80, .e2_size = 0x10000, }, + { + /* 24XX1024 */ + .has_dev_addr = true, + .blk_size = 0x100, + .e2_size = 0x20000, + }, + /* Add other memories here */ }; @@ -113,7 +121,7 @@ static size_t eeprom_writeRaw(struct KFile *_fd, const void *buf, size_t size) STATIC_ASSERT(countof(addr_buf) <= sizeof(e2addr_t)); /* clamp size to memory limit (otherwise may roll back) */ - ASSERT(_fd->seek_pos + size <= (kfile_off_t)_fd->size); + ASSERT(_fd->seek_pos + (kfile_off_t)size <= (kfile_off_t)_fd->size); size = MIN((kfile_off_t)size, _fd->size - _fd->seek_pos); if (mem_info[fd->type].has_dev_addr) @@ -177,7 +185,7 @@ static size_t eeprom_writeVerify(struct KFile *_fd, const void *_buf, size_t siz { Eeprom *fd = EEPROM_CAST(_fd); int retries = 5; - size_t wr_len; + size_t wr_len = 0; while (retries--) { @@ -213,7 +221,7 @@ static size_t eeprom_read(struct KFile *_fd, void *_buf, size_t size) STATIC_ASSERT(countof(addr_buf) <= sizeof(e2addr_t)); /* clamp size to memory limit (otherwise may roll back) */ - ASSERT(_fd->seek_pos + size <= (kfile_off_t)_fd->size); + ASSERT(_fd->seek_pos + (kfile_off_t)size <= (kfile_off_t)_fd->size); size = MIN((kfile_off_t)size, _fd->size - _fd->seek_pos); e2dev_addr_t dev_addr; @@ -256,6 +264,7 @@ static size_t eeprom_read(struct KFile *_fd, void *_buf, size_t size) rd_len++; } + i2c_stop(); return rd_len; } @@ -388,5 +397,3 @@ void eeprom_init(Eeprom *fd, EepromType type, e2dev_addr_t addr, bool verify) fd->fd.seek = kfile_genericSeek; } - -#endif