X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=drv%2Feeprom.c;h=57861376151b1151ee38817421cd8961273e169d;hb=588cab3f6529b08952f17eebcb16a2a33e43e996;hp=cf5da31ad7f2d8d3d81b993965f16648bdf2d3bb;hpb=8c175db1086a6938f3c45303715c0094ce1b7555;p=bertos.git diff --git a/drv/eeprom.c b/drv/eeprom.c index cf5da31a..57861376 100755 --- a/drv/eeprom.c +++ b/drv/eeprom.c @@ -16,6 +16,12 @@ /*#* *#* $Log$ + *#* Revision 1.14 2004/12/13 12:07:06 bernie + *#* DISABLE_IRQSAVE/ENABLE_IRQRESTORE: Convert to IRQ_SAVE_DISABLE/IRQ_RESTORE. + *#* + *#* Revision 1.13 2004/11/16 20:58:51 bernie + *#* Add write verify. + *#* *#* Revision 1.12 2004/11/02 17:50:01 bernie *#* CONFIG_EEPROM_VERIFY: New config option. *#* @@ -60,6 +66,7 @@ #include /* cpu_to_be16() */ #include #include +#include // IRQ_SAVE_DISABLE(), IRQ_RESTORE() #include // CONFIG_EEPROM_VERIFY #include // MIN() @@ -298,6 +305,8 @@ static bool eeprom_writeRaw(e2addr_t addr, const void *buf, size_t count) buf = ((const char *)buf) + size; } + if (!result) + TRACEMSG("Write error!"); return result; } @@ -306,6 +315,8 @@ static bool eeprom_writeRaw(e2addr_t addr, const void *buf, size_t count) /*! * Check that the contents of an EEPROM range * match with a provided data buffer. + * + * \return true on success. */ static bool eeprom_verify(e2addr_t addr, const void *buf, size_t count) { @@ -322,13 +333,13 @@ static bool eeprom_verify(e2addr_t addr, const void *buf, size_t count) { if (memcmp(buf, verify_buf, size) != 0) { - TRACEMSG("Data mismatch!\n"); + TRACEMSG("Data mismatch!"); result = false; } } else { - TRACEMSG("Read error!\n"); + TRACEMSG("Read error!"); result = false; } @@ -401,6 +412,8 @@ bool eeprom_read(e2addr_t addr, void *buf, size_t count) twi_stop(); + if (!res) + TRACEMSG("Read error!"); return res; } @@ -461,8 +474,15 @@ void eeprom_erase(e2addr_t addr, size_t count) void eeprom_init(void) { cpuflags_t flags; - DISABLE_IRQSAVE(flags); + IRQ_SAVE_DISABLE(flags); + /* + * This is pretty useless according to AVR's datasheet, + * but it helps us driving the TWI data lines on boards + * where the bus pull-up resistors are missing. This is + * probably due to some unwanted interaction between the + * port pin and the TWI lines. + */ #if defined(__AVR_ATmega64__) PORTD |= BV(PD0) | BV(PD1); DDRD |= BV(PD0) | BV(PD1); @@ -477,14 +497,14 @@ void eeprom_init(void) * Set speed: * F = CLOCK_FREQ / (16 + 2*TWBR * 4^TWPS) */ - #define TWI_FREQ 300000 /* 300 kHz */ + #define TWI_FREQ 100000 /* ~100 kHz */ #define TWI_PRESC 1 /* 4 ^ TWPS */ TWBR = (CLOCK_FREQ / (2 * TWI_FREQ * TWI_PRESC)) - (8 / TWI_PRESC); TWSR = 0; TWCR = BV(TWEN); - ENABLE_IRQRESTORE(flags); + IRQ_RESTORE(flags); }