/*#*
*#* $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.
*#*
#include <mware/byteorder.h> /* cpu_to_be16() */
#include <debug.h>
#include <hw.h>
+#include <cpu.h> // IRQ_SAVE_DISABLE(), IRQ_RESTORE()
#include <config.h> // CONFIG_EEPROM_VERIFY
#include <macros.h> // MIN()
buf = ((const char *)buf) + size;
}
+ if (!result)
+ TRACEMSG("Write error!");
return result;
}
/*!
* 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)
{
{
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;
}
twi_stop();
+ if (!res)
+ TRACEMSG("Read error!");
return res;
}
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);
* 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);
}