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
This commit is contained in:
Peter D'Hoye 2006-08-07 22:30:12 +00:00
parent c9d66562af
commit fa02b6c239
3 changed files with 55 additions and 43 deletions

View file

@ -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;
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;
}
/* 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;
// 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;
}

View file

@ -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;

View file

@ -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