projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update i2c cfg file.
[bertos.git]
/
bertos
/
drv
/
eeprom.c
diff --git
a/bertos/drv/eeprom.c
b/bertos/drv/eeprom.c
index 92ddac731cf8f7f3694233ed909e8266be073b1f..52ab70c72f7ab5f1cf8232f1b66ec818212a9905 100644
(file)
--- a/
bertos/drv/eeprom.c
+++ b/
bertos/drv/eeprom.c
@@
-32,23
+32,18
@@
*
* \brief Driver for the 24xx16 and 24xx256 I2C EEPROMS (implementation)
*
*
* \brief Driver for the 24xx16 and 24xx256 I2C EEPROMS (implementation)
*
- *
- * \version $Id$
* \author Stefano Fedrigo <aleph@develer.com>
* \author Bernie Innocenti <bernie@codewiz.org>
*/
#include "eeprom.h"
* \author Stefano Fedrigo <aleph@develer.com>
* \author Bernie Innocenti <bernie@codewiz.org>
*/
#include "eeprom.h"
-#warning TODO:Test and complete this module for arm platform.
-#if !CPU_ARM
-
#include <cfg/macros.h> // MIN()
#include <cfg/debug.h>
#include <cfg/module.h> // MOD_CHECK()
#include <cpu/attr.h>
#include <cfg/macros.h> // MIN()
#include <cfg/debug.h>
#include <cfg/module.h> // MOD_CHECK()
#include <cpu/attr.h>
-#include
CPU_HEADER(twi)
+#include
<drv/i2c.h>
#include <drv/wdt.h>
#include <drv/wdt.h>
@@
-72,6
+67,12
@@
*/
static const EepromInfo mem_info[] =
{
*/
static const EepromInfo mem_info[] =
{
+ {
+ /* 24XX08 */
+ .has_dev_addr = false,
+ .blk_size = 0x10,
+ .e2_size = 0x400,
+ },
{
/* 24XX16 */
.has_dev_addr = false,
{
/* 24XX16 */
.has_dev_addr = false,
@@
-90,6
+91,13
@@
static const EepromInfo mem_info[] =
.blk_size = 0x80,
.e2_size = 0x10000,
},
.blk_size = 0x80,
.e2_size = 0x10000,
},
+ {
+ /* 24XX1024 */
+ .has_dev_addr = true,
+ .blk_size = 0x100,
+ .e2_size = 0x20000,
+ },
+
/* Add other memories here */
};
/* 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) */
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)
size = MIN((kfile_off_t)size, _fd->size - _fd->seek_pos);
if (mem_info[fd->type].has_dev_addr)
@@
-147,15
+155,15
@@
static size_t eeprom_writeRaw(struct KFile *_fd, const void *buf, size_t size)
}
}
- if (!(
twi
_start_w(EEPROM_ADDR(dev_addr))
- &&
twi
_send(addr_buf, addr_len)
- &&
twi
_send(buf, count)))
+ if (!(
i2c
_start_w(EEPROM_ADDR(dev_addr))
+ &&
i2c
_send(addr_buf, addr_len)
+ &&
i2c
_send(buf, count)))
{
{
-
twi
_stop();
+
i2c
_stop();
return wr_len;
}
return wr_len;
}
-
twi
_stop();
+
i2c
_stop();
/* Update count and addr for next operation */
size -= count;
/* Update count and addr for next operation */
size -= count;
@@
-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;
{
Eeprom *fd = EEPROM_CAST(_fd);
int retries = 5;
- size_t wr_len;
+ size_t wr_len
= 0
;
while (retries--)
{
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) */
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;
size = MIN((kfile_off_t)size, _fd->size - _fd->seek_pos);
e2dev_addr_t dev_addr;
@@
-232,30
+240,22
@@
static size_t eeprom_read(struct KFile *_fd, void *_buf, size_t size)
}
}
- if (!(
twi
_start_w(EEPROM_ADDR(dev_addr))
- &&
twi
_send(addr_buf, addr_len)
- &&
twi
_start_r(EEPROM_ADDR(dev_addr))))
+ if (!(
i2c
_start_w(EEPROM_ADDR(dev_addr))
+ &&
i2c
_send(addr_buf, addr_len)
+ &&
i2c
_start_r(EEPROM_ADDR(dev_addr))))
{
{
-
twi
_stop();
+
i2c
_stop();
return 0;
}
return 0;
}
- while (size--)
- {
- /*
- * The last byte read does not has an ACK
- * to stop communication.
- */
- int c = twi_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();
return rd_len;
}
return rd_len;
}
@@
-368,7
+368,7
@@
bool eeprom_erase(Eeprom *fd, e2addr_t addr, e2_size_t count)
*/
void eeprom_init(Eeprom *fd, EepromType type, e2dev_addr_t addr, bool verify)
{
*/
void eeprom_init(Eeprom *fd, EepromType type, e2dev_addr_t addr, bool verify)
{
- MOD_CHECK(
twi
);
+ MOD_CHECK(
i2c
);
ASSERT(type < EEPROM_CNT);
memset(fd, 0, sizeof(*fd));
ASSERT(type < EEPROM_CNT);
memset(fd, 0, sizeof(*fd));
@@
-388,5
+388,3
@@
void eeprom_init(Eeprom *fd, EepromType type, e2dev_addr_t addr, bool verify)
fd->fd.seek = kfile_genericSeek;
}
fd->fd.seek = kfile_genericSeek;
}
-
-#endif