00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #define _EEP_LIB_C_
00017 #include "config.h"
00018 #include "eep_drv.h"
00019 #include "eep_lib.h"
00020
00021
00022
00023
00024 #ifndef EEPROM_SIZE
00025 #error You must define EEPROM_SIZE in bytes in config.h
00026 #else
00027
00028
00029 bit eeprom_erase(void)
00030 {
00031 #if EEPROM_SIZE > 0
00032 register Uint16 addr;
00033
00034 Enable_eeprom();
00035 addr=0;
00036 do {
00037 while (eeprom_busy());
00038 eeprom_wr(addr,EEPROM_BLANK_VALUE);
00039 } while (addr++!=(EEPROM_SIZE-1));
00040 Disable_eeprom();
00041 #endif
00042 return TRUE;
00043 }
00044
00045 bit eeprom_wr_byte (Uint16 addr, Uchar value)
00046 {
00047 Enable_eeprom();
00048 while (eeprom_busy());
00049 eeprom_wr(addr,value);
00050 Disable_eeprom();
00051 return TRUE;
00052 }
00053
00054
00055 Byte eeprom_rd_byte (Uint16 addr)
00056 {
00057 register Byte b;
00058 while (eeprom_busy());
00059 Enable_eeprom();
00060 b=eeprom_rd(addr);
00061 Disable_eeprom();
00062 return b;
00063 }
00064
00065
00066
00067 bit eeprom_rd_block (Uint16 src, Byte _MemType_* dest, Byte n)
00068 {
00069 while (eeprom_busy());
00070 Enable_eeprom();
00071 for (;n--;++src) *dest++=eeprom_rd(src);
00072 Disable_eeprom();
00073 return TRUE;
00074 }
00075
00076
00077
00078 bit eeprom_wr_block (Byte _MemType_* src, Uint16 dest, Byte n)
00079 {
00080 #if EEPROM_SIZE > 0
00081
00082 Enable_eeprom();
00083 for (;n--;)
00084 {
00085 while (eeprom_busy());
00086 eeprom_wr(dest,*src++);
00087 if (dest++==(EEPROM_SIZE-1)) break;
00088 }
00089 Disable_eeprom();
00090 #endif
00091 return TRUE;
00092 }
00093
00094 #endif
00095