X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fdrv%2Feeprom.c;h=52ab70c72f7ab5f1cf8232f1b66ec818212a9905;hb=a2a3507dbe2ed90e363fbcc9bdbafa4970b13f78;hp=7240fccad00bd4601d109be524553131d7196cd2;hpb=d027b58f316922081fa2f7291dc8e45022910a7e;p=bertos.git diff --git a/bertos/drv/eeprom.c b/bertos/drv/eeprom.c index 7240fcca..52ab70c7 100644 --- a/bertos/drv/eeprom.c +++ b/bertos/drv/eeprom.c @@ -38,9 +38,6 @@ #include "eeprom.h" -#warning TODO:Test and complete this module for arm platform. -#if !CPU_ARM - #include // MIN() #include #include // MOD_CHECK() @@ -70,6 +67,12 @@ */ static const EepromInfo mem_info[] = { + { + /* 24XX08 */ + .has_dev_addr = false, + .blk_size = 0x10, + .e2_size = 0x400, + }, { /* 24XX16 */ .has_dev_addr = false, @@ -88,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 */ }; @@ -111,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) @@ -211,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; @@ -238,20 +248,11 @@ static size_t eeprom_read(struct KFile *_fd, void *_buf, size_t size) return 0; } - while (size--) - { - /* - * The last byte read does not have an ACK - * to stop communication. - */ - int c = i2c_get(size); - - if (c == EOF) - break; - *buf++ = c; - fd->fd.seek_pos++; - rd_len++; + if (i2c_recv(buf, size)) + { + fd->fd.seek_pos += size; + rd_len += size; } i2c_stop(); @@ -387,5 +388,3 @@ void eeprom_init(Eeprom *fd, EepromType type, e2dev_addr_t addr, bool verify) fd->fd.seek = kfile_genericSeek; } - -#endif