REVISION
Definition in file GEN_eeprom.c.
#include "../SYSTEM/sys_hardware.h"
#include "generic.h"
#include "eeprom.h"
Include dependency graph for GEN_eeprom.c:

Go to the source code of this file.
Enumerations | |
| enum | EEPROM_CMD |
| EEPROM command enumerations. | |
Functions | |
| int | GEN_eepromFormat (int Force) |
| Function checks to format the EEPROM. | |
| int | GEN_eepromRead (int Address, int Length, int *ptr) |
| Function reads the specified number of bytes from EEPROM. | |
| int | GEN_eepromWrite (int Address, int Length, int *ptr) |
| Function reads the specified number of bytes from EEPROM. | |
|
|
Function checks to format the EEPROM.
Definition at line 58 of file GEN_eeprom.c. References GEN_eepromRead(), and GEN_eepromWrite(). Referenced by SYS_loadParams(). 00059 {
00060 int Data;
00061 int i;
00062 unsigned long timeout = TIME_OUT;
00063 unsigned long lData;
00064
00065 GEN_eepromRead(0, 2, &Data);
00066 if( ( Data != 0xdead ) || (Force != 0) )
00067 {
00068 lData = (ULONG)EEPROM_WREN<<16;
00069 EEPROM__spi(EE_UNPROTECT, &lData);
00070 do
00071 {
00072 timeout--;
00073
00074 lData = (ULONG)EEPROM_RDSR<<16;
00075 EEPROM__spi(EE_READSTATUS, &lData);
00076 while (!(lData &0x80000000L)); // wait until valid data
00077
00078 // wait here until write enabled.
00079 // keep doing this until we time out or ready bit is set.
00080 } while ( (!(lData&0x2))&&(timeout) );
00081
00082 if(0 == timeout) return -1;
00083
00084 Data = 0;
00085 for (i = EEPROM_FORMAT_BEGIN; i < EEPROM_FORMAT_END; i++)
00086 {
00087 GEN_eepromWrite(i, 1, &Data);
00088 }
00089
00090 Data = 0xdead;
00091 GEN_eepromWrite(0, 2, &Data);
00092 }
00093 return(0);
00094 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Function reads the specified number of bytes from EEPROM. bytes are big-endian aligned in a word buffer.
Definition at line 117 of file GEN_eeprom.c. Referenced by BAT_calibrate(), GEN_eepromFormat(), MENU__createPropertiesMenu(), SYS_checkRegistration(), SYS_loadParams(), SYS_regist(), and SYS_serialNumber(). 00118 {
00119 unsigned long lData;
00120 int hiByte = 0;
00121
00122 while (Length--)
00123 {
00124 lData = ((unsigned long)EEPROM_READ<<16);
00125 lData |= (((unsigned long)Address & 0xff)<<8);
00126 lData |= (((unsigned long)Address & 0x100)<<3);
00127
00128 EEPROM__spi(EE_READ, &lData);
00129 while(!(lData&0x80000000L));
00130
00131 hiByte ^= 1;
00132
00133 if(hiByte) *ptr = (unsigned int)(lData << 8) & 0xFF00;
00134 else *ptr++ |= (unsigned int)(lData & 0x00FF);
00135
00136 Address++;
00137 }
00138
00139 return(0);
00140 }
|
|
||||||||||||||||
|
Function reads the specified number of bytes from EEPROM. bytes are big-endian aligned in a word buffer.
Definition at line 156 of file GEN_eeprom.c. Referenced by GEN_eepromFormat(), SYS_regist(), SYS_saveParams(), and SYS_serialNumber(). 00157 {
00158 int byte;
00159 int hiByte = 0;
00160 unsigned long lData;
00161 unsigned long timeout = TIME_OUT;
00162
00163 // read the status register and see if it's ok to write
00164 // for reads from EEPROM, the MSBit of the word indicates valid data.
00165 // only the D0-D7 is valid, however when D15 goes high
00166 while (Length--)
00167 {
00168 lData = (ULONG)EEPROM_WREN<<16;
00169 EEPROM__spi(EE_UNPROTECT, &lData);
00170 // Wait till busy is cleared.
00171 do
00172 {
00173 timeout--;
00174
00175 lData = (ULONG)EEPROM_RDSR<<16;
00176 EEPROM__spi(EE_READSTATUS, &lData);
00177 while (!(lData &0x80000000L)); // wait until valid data
00178 // wait here until write enabled.
00179 // keep doing this until we time out or ready bit is set.
00180 } while ( ((lData&0x01)||(!(lData&0x2)))&&(timeout) );
00181
00182 if(0 == timeout) return -1;
00183 timeout = TIME_OUT;
00184
00185 hiByte ^= 1;
00186
00187 byte = (hiByte == 1)? (*ptr) >> 8 : *ptr++ ;
00188
00189 lData = ((unsigned long)EEPROM_WRITE<<16);
00190 lData |= ((unsigned long)Address&0xff)<<8;
00191 lData |= ((unsigned long)Address &0x100)<<3;
00192
00193 lData |= (byte&0x0FF);
00194
00195 EEPROM__spi(EE_WRITE, &lData);
00196 Address++;
00197
00198 do
00199 {
00200 timeout--;
00201
00202 lData = (ULONG)EEPROM_RDSR<<16;
00203 EEPROM__spi(EE_READSTATUS, &lData);
00204 while (!(lData &0x80000000L)); // wait until valid data
00205
00206 // wait here until write enabled.
00207 // keep doing this until we time out or ready bit is set.
00208 //} while ( ((lData&0x01)||(!(lData&0x2)))&&(timeout) );
00209 } while ( (lData&0x01)&&(timeout) );
00210
00211 if(0 == timeout) return -1;
00212 timeout = TIME_OUT;
00213 }
00214
00215 timeout = TIME_OUT;
00216 lData = (unsigned long)EEPROM_WRDI<<16;
00217 EEPROM__spi(EE_PROTECT, &lData);
00218 do
00219 {
00220 timeout--;
00221 lData = (unsigned long)EEPROM_RDSR<<16;
00222 EEPROM__spi(EE_READSTATUS, &lData);
00223 while (!(lData &0x80000000)); // wait until valid data
00224 // keep doing this until we time out or ready bit is set.
00225 } while( ((lData&0x1) && (lData&0x2))&&(timeout) );
00226 if(0 == timeout) return -1;
00227
00228 return(0);
00229 }
|
1.3.9.1