Include <macros.h>.
[bertos.git] / drv / eeprom.c
index 85b2e20de5457d795b100cbba8893df145915bac..ebffc596aec464722056f26e691ec6eaa84718ee 100755 (executable)
 
 /*
  * $Log$
+ * Revision 1.5  2004/08/24 13:46:48  bernie
+ * Include <macros.h>.
+ *
+ * Revision 1.4  2004/08/10 06:57:22  bernie
+ * eeprom_erase(): New function.
+ *
  * Revision 1.3  2004/07/29 22:57:09  bernie
  * Add 24LC16 support.
  *
  * Import into DevLib.
  *
  */
+
 #include "eeprom.h"
+
 #include <mware/byteorder.h> /* cpu_to_be16() */
 #include <drv/kdebug.h>
 #include <hw.h>
+#include <macros.h>
+
+#include <string.h> // memset()
 
 #include <avr/twi.h>
 
+
 /* Wait for TWINT flag set: bus is ready */
 #define WAIT_TWI_READY  do {} while (!(TWCR & BV(TWINT)))
 
@@ -326,6 +338,28 @@ int eeprom_read_char(e2addr_t addr)
 }
 
 
+/*!
+ * Erase specified part of eeprom, writing 0xFF.
+ *
+ * \param addr  starting address
+ * \param len   length of block to erase
+ */
+void eeprom_erase(e2addr_t addr, size_t count)
+{
+       uint8_t buf[EEPROM_BLKSIZE];
+       memset(buf, 0xFF, sizeof buf);
+
+       // Clear all but struct hw_info at start of eeprom
+       while (count)
+       {
+               size_t size = MIN(count, sizeof buf);
+               eeprom_write(addr, buf, size);
+               addr += size;
+               count -= size;
+       }
+}
+
+
 /*!
  * Initialize TWI module.
  */