Commits

tswaehn committed 7dea2f3

mod: i2c_eeprom sets errorCode, return by "eepromGetError()"

  • Participants
  • Parent commits b798015
  • Branches testing

Comments (0)

Files changed (2)

File drivers/i2c_eeprom.c

  */
 #include "MiniLib.h"
 
-#define EEPROM_ADDR 0x50
 
 #define MAX_BYTE_COUNT  16
 #define EEPROM_ERASE_BYTE 0xFF
 
 uint08 bytes[MAX_BYTE_COUNT];
 
+uint08 eepromErrorCode;
 
 void eepromInit(void){
     uint08 i;
         bytes[i]= 0x00;
     }
 
+    eepromErrorCode=EEPROM_NO_ERROR;
 
 }
 
-void missingEeprom(void){
+uint08 eepromGetError(void){
 
-    //putUSBUSART( &str_missing[0], sizeof(str_missing));
+    return eepromErrorCode;
 
 }
 
     }
 
     if (eepromPresent == 0){
-        missingEeprom();
+        eepromErrorCode=EEPROM_MISSING;
         return 0;
     }
 
     // send offset address
     I2C_writeByte( addrH );
     if (I2C_requestSlaveACKN() == 0x0 ){
-        missingEeprom();
+        eepromErrorCode=EEPROM_FAILED_TO_WRITE_ADDR;
         return 0;
     }
     I2C_writeByte( addrL );
     if (I2C_requestSlaveACKN() == 0x0 ){
-        missingEeprom();
+        eepromErrorCode=EEPROM_FAILED_TO_WRITE_ADDR;
         return 0;
     }
 
     }
     
     if (eepromPresent == 0){
-        missingEeprom();
+        eepromErrorCode=EEPROM_MISSING;
         return;
     }
 
     // and write offset address
     I2C_writeByte( addrH );
     if (I2C_requestSlaveACKN() == 0x0 ){
-        missingEeprom();
+        eepromErrorCode=EEPROM_FAILED_TO_WRITE_ADDR;
         return;
     }
     I2C_writeByte( addrL );
     if (I2C_requestSlaveACKN() == 0x0 ){
-        missingEeprom();
+        eepromErrorCode=EEPROM_FAILED_TO_WRITE_ADDR;
         return;
     }
 
         I2C_writeByte( byte );
 
         if (I2C_requestSlaveACKN() == 0x0 ){
-            missingEeprom();
+            eepromErrorCode=EEPROM_FAILED_TO_WRITE_BYTE;
             return;
         }
 
 
 }
 
-void eepromClear(){
-    uint32 addr=0x0000;
+void eepromClear( uint16 addr ){
     uint08 eepromPresent=0;
     uint16 t;
     uint08 i;
     uint08 addrL;
 
 
-    for (addr=0x0000;addr<0xFFFF;addr+=EEPROM_PAGE_SIZE){
 
         // write eeprom addr
-        t=EEPROM_RETRY_WHILE_WRITING;
+        t=100*EEPROM_RETRY_WHILE_WRITING;
         while( (t>0) && (eepromPresent == 0)){
             eepromPresent = I2C_sendAddr( EEPROM_ADDR, 0x0 );
         }
 
         if (eepromPresent == 0){
-            missingEeprom();
+            eepromErrorCode=EEPROM_MISSING;
             return;
         }
 
         // and write offset address
         I2C_writeByte( addrH );
         if (I2C_requestSlaveACKN() == 0x0 ){
-            missingEeprom();
+            eepromErrorCode=EEPROM_FAILED_TO_WRITE_ADDR;
             return;
         }
         I2C_writeByte( addrL );
         if (I2C_requestSlaveACKN() == 0x0 ){
-            missingEeprom();
+            eepromErrorCode=EEPROM_FAILED_TO_WRITE_ADDR;
             return;
         }
 
             I2C_writeByte( EEPROM_ERASE_BYTE );
 
             if (I2C_requestSlaveACKN() == 0x0 ){
-                missingEeprom();
+                eepromErrorCode=EEPROM_FAILED_TO_WRITE_BYTE;
                 return;
             }
 
 
         // stop transmission
         I2C_stop();
-    }
+
 }

File drivers/i2c_eeprom.h

 #ifndef I2C_EEPROM_H
 #define	I2C_EEPROM_H
 
-#ifdef	__cplusplus
-extern "C" {
-#endif
+// --------------------------------------
+// configuration
 
-    #define EEPROM_SIZE 65536
+    #define EEPROM_SIZE 0xFFFF
     #define EEPROM_PAGE_SIZE    128
+    #define EEPROM_ADDR 0x50
+
+// --------------------------------------
+// implementation
+
+    #define EEPROM_NO_ERROR 0x00
+    #define EEPROM_MISSING  0x10
+    #define EEPROM_FAILED_TO_WRITE_ADDR 0x20
+    #define EEPROM_FAILED_TO_WRITE_BYTE 0x30
+
 
     void eepromInit(void);
     
     uint08 * eepromRead( uint16 addr, uint08 byteCount );
     void eepromWrite( uint16 addr, uint08 * pData, uint08 byteCount );
-    void eepromClear(void);
+    void eepromClear( uint16 addr );
     
+    uint08 eepromGetError(void);
 
 
-
-#ifdef	__cplusplus
-}
-#endif
-
 #endif	/* I2C_EEPROM_H */