summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2006-08-07 22:30:12 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2006-08-07 22:30:12 +0000
commitfa02b6c239469325e594386f472546a89dae5878 (patch)
treeddcf2ef9af85071f7b1b4a53ffffc957d7216dbc
parentc9d66562afc15de210854b32f30976859bce2023 (diff)
downloadrockbox-fa02b6c239469325e594386f472546a89dae5878.zip
rockbox-fa02b6c239469325e594386f472546a89dae5878.tar.gz
rockbox-fa02b6c239469325e594386f472546a89dae5878.tar.bz2
rockbox-fa02b6c239469325e594386f472546a89dae5878.tar.xz
Let eeprom driver return the error number. This is just a cover-up commit to hide the fact that I broke the eeprom dump in my previous commit. Some code cleanup as bonus.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10480 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/drivers/eeprom_24cxx.c86
-rw-r--r--firmware/eeprom_settings.c8
-rw-r--r--firmware/export/eeprom_24cxx.h6
3 files changed, 56 insertions, 44 deletions
diff --git a/firmware/drivers/eeprom_24cxx.c b/firmware/drivers/eeprom_24cxx.c
index 33c02f1..75521ce 100644
--- a/firmware/drivers/eeprom_24cxx.c
+++ b/firmware/drivers/eeprom_24cxx.c
@@ -103,9 +103,9 @@ static void sw_i2c_ack(void)
DELAY;
}
-static int sw_i2c_getack(void)
+static bool sw_i2c_getack(void)
{
- int ret = 1;
+ bool ret = true;
int count = 10;
SCL_LO;
@@ -119,7 +119,7 @@ static int sw_i2c_getack(void)
if (SDA)
/* ack failed */
- ret = 0;
+ ret = false;
SCL_LO;
SCL_OUTPUT;
@@ -132,22 +132,23 @@ static int sw_i2c_getack(void)
static void sw_i2c_outb(unsigned char byte)
{
- int i;
-
- /* clock out each bit, MSB first */
- for ( i=0x80; i; i>>=1 ) {
- SCL_LO;
- DELAY;
- if ( i & byte )
- SDA_HI;
- else
- SDA_LO;
- DELAY;
- SCL_HI;
- DELAY;
- }
+ int i;
- // SDA_LO;
+ /* clock out each bit, MSB first */
+ for ( i=0x80; i; i>>=1 )
+ {
+ SCL_LO;
+ DELAY;
+ if ( i & byte )
+ SDA_HI;
+ else
+ SDA_LO;
+ DELAY;
+ SCL_HI;
+ DELAY;
+ }
+
+ // SDA_LO;
}
static unsigned char sw_i2c_inb(void)
@@ -274,7 +275,7 @@ void eeprom_24cxx_init(void)
sw_i2c_init();
}
-bool eeprom_24cxx_read_byte(unsigned int address, char *c)
+int eeprom_24cxx_read_byte(unsigned int address, char *c)
{
int ret;
char byte;
@@ -283,29 +284,31 @@ bool eeprom_24cxx_read_byte(unsigned int address, char *c)
if (address >= EEPROM_SIZE)
{
logf("EEPROM address: %d", address);
- return false;
+ return -9;
}
*c = 0;
- do {
+ do
+ {
ret = sw_i2c_read(address, &byte);
if (ret < 0)
{
+ /* keep between {} as logf is whitespace in normal builds */
logf("EEPROM Fail: %d/%d", ret, address);
}
- } while (ret < 0 && count--) ;
+ } while (ret < 0 && count--);
if (ret < 0)
{
logf("EEPROM RFail: %d/%d", ret, address);
- return false;
+ return ret;
}
*c = byte;
- return true;
+ return 0;
}
-bool eeprom_24cxx_write_byte(unsigned int address, char c)
+int eeprom_24cxx_write_byte(unsigned int address, char c)
{
int ret;
int count = 100;
@@ -313,41 +316,50 @@ bool eeprom_24cxx_write_byte(unsigned int address, char c)
if (address >= EEPROM_SIZE)
{
logf("EEPROM address: %d", address);
- return false;
+ return -9;
}
- do {
+ do
+ {
ret = sw_i2c_write_byte(address, c);
+ if (ret < 0)
+ {
+ /* keep between {} as logf is whitespace in normal builds */
+ logf("EEPROM Fail: %d/%d", ret, address);
+ }
} while (ret < 0 && count--) ;
if (ret < 0)
{
logf("EEPROM WFail: %d/%d", ret, address);
- return false;
+ return ret;
}
- return true;
+ return 0;
}
-bool eeprom_24cxx_read(unsigned char address, void *dest, int length)
+int eeprom_24cxx_read(unsigned char address, void *dest, int length)
{
char *buf = (char *)dest;
+ int ret = 0;
int i;
for (i = 0; i < length; i++)
{
- if (!eeprom_24cxx_read_byte(address+i, &buf[i]))
- return false;
+ ret = eeprom_24cxx_read_byte(address+i, &buf[i]);
+ if (ret < 0)
+ return ret;
}
- return true;
+ return ret;
}
-bool eeprom_24cxx_write(unsigned char address, const void *src, int length)
+int eeprom_24cxx_write(unsigned char address, const void *src, int length)
{
const char *buf = (const char *)src;
int count = 10;
- int i, ok;
+ int i;
+ bool ok;
while (count-- > 0)
{
@@ -369,9 +381,9 @@ bool eeprom_24cxx_write(unsigned char address, const void *src, int length)
}
if (ok)
- return true;
+ return 0;
}
- return false;
+ return -1;
}
diff --git a/firmware/eeprom_settings.c b/firmware/eeprom_settings.c
index 43f519d..e472f4d 100644
--- a/firmware/eeprom_settings.c
+++ b/firmware/eeprom_settings.c
@@ -37,7 +37,7 @@ static void reset_config(void)
bool eeprom_settings_init(void)
{
- bool ret;
+ int ret;
uint32_t sum;
eeprom_24cxx_init();
@@ -54,7 +54,7 @@ bool eeprom_settings_init(void)
ret = eeprom_24cxx_read(0, &firmware_settings,
sizeof(struct eeprom_settings));
- if (!ret)
+ if (ret < 0)
{
memset(&firmware_settings, 0, sizeof(struct eeprom_settings));
firmware_settings.initialized = false;
@@ -92,7 +92,7 @@ bool eeprom_settings_init(void)
bool eeprom_settings_store(void)
{
- bool ret;
+ int ret;
uint32_t sum;
if (!firmware_settings.initialized || !detect_flashed_rockbox())
@@ -108,7 +108,7 @@ bool eeprom_settings_store(void)
ret = eeprom_24cxx_write(0, &firmware_settings,
sizeof(struct eeprom_settings));
- if (!ret)
+ if (ret < 0)
firmware_settings.initialized = false;
return ret;
diff --git a/firmware/export/eeprom_24cxx.h b/firmware/export/eeprom_24cxx.h
index d4f0081..bc0f444 100644
--- a/firmware/export/eeprom_24cxx.h
+++ b/firmware/export/eeprom_24cxx.h
@@ -24,9 +24,9 @@
#define EEPROM_SIZE 128
void eeprom_24cxx_init(void);
-bool eeprom_24cxx_read_byte(unsigned int address, char *c);
-bool eeprom_24cxx_read(unsigned char address, void *dest, int length);
-bool eeprom_24cxx_write(unsigned char address, const void *src, int length);
+int eeprom_24cxx_read_byte(unsigned int address, char *c);
+int eeprom_24cxx_read(unsigned char address, void *dest, int length);
+int eeprom_24cxx_write(unsigned char address, const void *src, int length);
#endif