projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add timer support for ATMega 1280 (contributed by Fabio Bizzi)
[bertos.git]
/
bertos
/
drv
/
eeprom.c
diff --git
a/bertos/drv/eeprom.c
b/bertos/drv/eeprom.c
index f92091487ae0cc9daeb2fb7cf7bcbd210a2f8d1a..cc9b5292ba15c34af47822c37c6d61090149ecab 100644
(file)
--- a/
bertos/drv/eeprom.c
+++ b/
bertos/drv/eeprom.c
@@
-26,22
+26,19
@@
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
- * Copyright 2003, 2004, 2005 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 2003, 2004, 2005
, 2010
Develer S.r.l. (http://www.develer.com/)
*
* -->
*
* \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/cfg_i2c.h"
#include <cfg/macros.h> // MIN()
#include <cfg/debug.h>
#include <cfg/macros.h> // MIN()
#include <cfg/debug.h>
@@
-72,6
+69,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,11
+93,19
@@
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 */
};
STATIC_ASSERT(countof(mem_info) == EEPROM_CNT);
/* Add other memories here */
};
STATIC_ASSERT(countof(mem_info) == EEPROM_CNT);
+#if !CONFIG_I2C_DISABLE_OLD_API
/**
* Copy \a size bytes from buffer \a buf to
/**
* Copy \a size bytes from buffer \a buf to
@@
-113,7
+124,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)
@@
-177,7
+188,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
+224,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;
@@
-240,22
+251,14
@@
static size_t eeprom_read(struct KFile *_fd, void *_buf, size_t size)
return 0;
}
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();
return rd_len;
}
return rd_len;
}
@@
-389,4
+392,4
@@
void eeprom_init(Eeprom *fd, EepromType type, e2dev_addr_t addr, bool verify)
fd->fd.seek = kfile_genericSeek;
}
fd->fd.seek = kfile_genericSeek;
}
-#endif
+#endif
/* !CONFIG_I2C_DISABLE_OLD_API */