projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Modify the module selection page
[bertos.git]
/
bertos
/
drv
/
eeprom.c
diff --git
a/bertos/drv/eeprom.c
b/bertos/drv/eeprom.c
index 6f0f8b59a96e6737e940d2a89ed5cce01337f2ec..f92091487ae0cc9daeb2fb7cf7bcbd210a2f8d1a 100644
(file)
--- a/
bertos/drv/eeprom.c
+++ b/
bertos/drv/eeprom.c
@@
-41,14
+41,14
@@
#include "eeprom.h"
#warning TODO:Test and complete this module for arm platform.
#include "eeprom.h"
#warning TODO:Test and complete this module for arm platform.
+#if !CPU_ARM
-#if 0
#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>
@@
-102,7
+102,7
@@
STATIC_ASSERT(countof(mem_info) == EEPROM_CNT);
*/
static size_t eeprom_writeRaw(struct KFile *_fd, const void *buf, size_t size)
{
*/
static size_t eeprom_writeRaw(struct KFile *_fd, const void *buf, size_t size)
{
- Eeprom *fd = EEPROM(_fd);
+ Eeprom *fd = EEPROM
_CAST
(_fd);
e2dev_addr_t dev_addr;
uint8_t addr_buf[2];
uint8_t addr_len;
e2dev_addr_t dev_addr;
uint8_t addr_buf[2];
uint8_t addr_len;
@@
-114,7
+114,7
@@
static size_t eeprom_writeRaw(struct KFile *_fd, const void *buf, size_t size)
/* clamp size to memory limit (otherwise may roll back) */
ASSERT(_fd->seek_pos + size <= (kfile_off_t)_fd->size);
/* clamp size to memory limit (otherwise may roll back) */
ASSERT(_fd->seek_pos + size <= (kfile_off_t)_fd->size);
- size = MIN((kfile_
size
_t)size, _fd->size - _fd->seek_pos);
+ size = MIN((kfile_
off
_t)size, _fd->size - _fd->seek_pos);
if (mem_info[fd->type].has_dev_addr)
{
if (mem_info[fd->type].has_dev_addr)
{
@@
-147,15
+147,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;
@@
-175,7
+175,7
@@
static size_t eeprom_writeRaw(struct KFile *_fd, const void *buf, size_t size)
*/
static size_t eeprom_writeVerify(struct KFile *_fd, const void *_buf, size_t size)
{
*/
static size_t eeprom_writeVerify(struct KFile *_fd, const void *_buf, size_t size)
{
- Eeprom *fd = EEPROM(_fd);
+ Eeprom *fd = EEPROM
_CAST
(_fd);
int retries = 5;
size_t wr_len;
int retries = 5;
size_t wr_len;
@@
-204,7
+204,7
@@
static size_t eeprom_writeVerify(struct KFile *_fd, const void *_buf, size_t siz
*/
static size_t eeprom_read(struct KFile *_fd, void *_buf, size_t size)
{
*/
static size_t eeprom_read(struct KFile *_fd, void *_buf, size_t size)
{
- Eeprom *fd = EEPROM(_fd);
+ Eeprom *fd = EEPROM
_CAST
(_fd);
uint8_t addr_buf[2];
uint8_t addr_len;
size_t rd_len = 0;
uint8_t addr_buf[2];
uint8_t addr_len;
size_t rd_len = 0;
@@
-214,7
+214,7
@@
static size_t eeprom_read(struct KFile *_fd, void *_buf, size_t size)
/* clamp size to memory limit (otherwise may roll back) */
ASSERT(_fd->seek_pos + size <= (kfile_off_t)_fd->size);
/* clamp size to memory limit (otherwise may roll back) */
ASSERT(_fd->seek_pos + size <= (kfile_off_t)_fd->size);
- size = MIN((kfile_
size
_t)size, _fd->size - _fd->seek_pos);
+ size = MIN((kfile_
off
_t)size, _fd->size - _fd->seek_pos);
e2dev_addr_t dev_addr;
if (mem_info[fd->type].has_dev_addr)
e2dev_addr_t dev_addr;
if (mem_info[fd->type].has_dev_addr)
@@
-232,21
+232,21
@@
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;
}
while (size--)
{
/*
return 0;
}
while (size--)
{
/*
- * The last byte read does not ha
s
an ACK
+ * The last byte read does not ha
ve
an ACK
* to stop communication.
*/
* to stop communication.
*/
- int c =
twi
_get(size);
+ int c =
i2c
_get(size);
if (c == EOF)
break;
if (c == EOF)
break;
@@
-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,3
+388,5
@@
void eeprom_init(Eeprom *fd, EepromType type, e2dev_addr_t addr, bool verify)
fd->fd.seek = kfile_genericSeek;
}
fd->fd.seek = kfile_genericSeek;
}
+
+#endif