eeprom_erase(): New function.
authorbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 10 Aug 2004 06:57:22 +0000 (06:57 +0000)
committerbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 10 Aug 2004 06:57:22 +0000 (06:57 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@126 38d2e660-2303-0410-9eaa-f027e97ec537

drv/eeprom.c
drv/eeprom.h

index 85b2e20de5457d795b100cbba8893df145915bac..718a52deed541506eabe4a2740083ec5acde8a1a 100755 (executable)
@@ -17,6 +17,9 @@
 
 /*
  * $Log$
+ * 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.
  *
@@ -31,6 +34,7 @@
 #include <mware/byteorder.h> /* cpu_to_be16() */
 #include <drv/kdebug.h>
 #include <hw.h>
+#include <string.h> // memset()
 
 #include <avr/twi.h>
 
@@ -326,6 +330,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.
  */
index 287a9ce31d8fdd2d79a3ac3cd3874ca705f949fa..e1793c284c6ea25bd207460991de831cffe131dc 100755 (executable)
@@ -15,6 +15,9 @@
 
 /*
  * $Log$
+ * Revision 1.3  2004/08/10 06:57:22  bernie
+ * eeprom_erase(): New function.
+ *
  * Revision 1.2  2004/07/29 22:57:09  bernie
  * Add 24LC16 support.
  *
@@ -53,6 +56,7 @@ bool eeprom_write(e2addr_t addr, const void *buf, size_t count);
 bool eeprom_read(e2addr_t addr, void *buf, size_t count);
 bool eeprom_write_char(e2addr_t addr, char c);
 int eeprom_read_char(e2addr_t addr);
+void eeprom_erase(e2addr_t addr, size_t count);
 void eeprom_init(void);
 void eeprom_test(void);