OSDN Git Service

[UI][v2.0] Configurable update-time.Backport from v1.0.
[openi2cradio/OpenI2CRadio.git] / eeprom.c
index d3ff8cf..1d56b74 100644 (file)
--- a/eeprom.c
+++ b/eeprom.c
  *  the executable file might be covered by the GNU General Public License.
  */
 
+#if defined(__SDCC)
 #include <sdcc-lib.h>
 #include <pic18fregs.h> /* ONLY FOR PIC18x */
+#else
+#include <xc.h>
+#endif
 #include <signal.h>
 #include "iodef.h"
 #include "ui.h"
@@ -64,14 +68,18 @@ unsigned char eeprom_writebyte(unsigned int offset, unsigned char data)
     EECON1bits.CFGS  = 0;
     EECON1bits.WREN = 1;
 
-    INTCONbits.GIE = 0; // Disable Interrupt
+//    INTCONbits.GIE = 0; // Disable Interrupt
     // Dummy write , needs from datasheet.
     EECON2 = 0x55;
     EECON2 = 0xaa;
     EECON1bits.WR = 1;
 
     do {
+#ifdef __SDCC
         delay1ktcy(8);
+#else
+        __delay_ms(1);
+#endif 
     } while(EECON1bits.WR != 0);
   //  if(EECON1bits.WRERR != 0){
         // Write-Error occured.
@@ -80,24 +88,25 @@ unsigned char eeprom_writebyte(unsigned int offset, unsigned char data)
   //     return 0; // Error
   //  }
     // Write OK.
-    INTCONbits.GIE = 1; // Enable Interrupt
+//    INTCONbits.GIE = 1; // Enable Interrupt
     EECON1bits.WREN = 0;
     return 0xff;
 }
 
-unsigned char readbyte_eeprom(unsigned int p, unsigned int *sum)
+unsigned char readbyte_eeprom(unsigned int *p, unsigned int *sum)
 {
     unsigned char b;
 
     ClrWdt();
 
-    b = eeprom_readbyte(p);
+    b = eeprom_readbyte(*p);
     *sum = calcsum_byte(*sum, b);
+    *p = *p + 1;
 
     return b;
 }
 
-unsigned int readword_eeprom(unsigned int p, unsigned int *sum)
+unsigned int readword_eeprom(unsigned int *p, unsigned int *sum)
 {
     unsigned char h,l;
     unsigned int s;
@@ -105,7 +114,7 @@ unsigned int readword_eeprom(unsigned int p, unsigned int *sum)
 //    ClrWdt();
 
     h = readbyte_eeprom(p, sum);
-    l = readbyte_eeprom(p + 1, sum);
+    l = readbyte_eeprom(p, sum);
 
     s = (h << 8) | l;
     return s;
@@ -136,19 +145,20 @@ unsigned char checksum_eeprom(unsigned int seed, unsigned int offset, unsigned i
     return 0xff;
 }
 
-unsigned int writebyte_eeprom(unsigned int p, unsigned int *sum, unsigned char b)
+unsigned int writebyte_eeprom(unsigned int *p, unsigned int *sum, unsigned char b)
 {
     ClrWdt();
-    if(eeprom_writebyte(p, b) == 0) return p; // Error
+    if(eeprom_writebyte(*p, b) == 0) return *p; // Error
     *sum = calcsum_byte(*sum, b);
+    *p = *p + 1;
     return 0xffff;
 }
 
-unsigned int writeword_eeprom(unsigned int p, unsigned int *sum, unsigned int word)
+unsigned int writeword_eeprom(unsigned int *p, unsigned int *sum, unsigned int word)
 {
 //    ClrWdt();
-    if(writebyte_eeprom(p, sum, word >> 8) == 0) return p; // Error
-    if(writebyte_eeprom(p + 1, sum, word & 0xff) == 0) return p + 1; // Error
+    if(writebyte_eeprom(p, sum, word >> 8) == 0) return *p; // Error
+    if(writebyte_eeprom(p, sum, word & 0xff) == 0) return *p; // Error
     return 0xffff;
 }
 
@@ -168,6 +178,6 @@ unsigned int format_eeprom(unsigned int start, unsigned int bytes)
 //        p = p + 1;
     }
     _CLS();
-    _LOCATE(0,0);
+//    _LOCATE(0,0);
     return 0xffff; // Normal end
 }