/*** writeEeprom ** ** Parameters: ** address - location to be written ** data - data to be written ** ** Return Value: ** Returns true or false wether the operation was successful ** or not. ** ** Errors: ** none ** ** Description: ** Writes a data to specifed address location */ BOOL writeEeprom(uint32_t address, uint8_t data) { int i; if(address > MAX_ADDRESS) { return fFalse; } //Try writting data to flash for(i=0; i < _EEPROM_PAGE_COUNT; i++) { if(putEeprom(&eedata_addr[i][0], address, data)) { return fTrue; } } for(i=0; i < _EEPROM_PAGE_COUNT; i++) { //Put page to buffer putBuffer(&eedata_addr[i][0], tempBuffer); //Clear page NVMErasePage(&eedata_addr[i][0]); //Put buffer back to page getBuffer(&eedata_addr[i][0], tempBuffer); } //Try writting data to flash again for(i=0; i < _EEPROM_PAGE_COUNT; i++) { if(putEeprom(&eedata_addr[i][0], address, data)) { return fTrue; } } return fFalse; }
/*** writeEeprom ** ** Parameters: ** address - location to be written ** data - data to be written ** ** Return Value: ** Returns true if the operation was successful, false otherwise ** ** Errors: ** none ** ** Description: ** Writes a data to specified address location */ BOOL writeEeprom(uint32_t address, uint8_t data) { int i; if(address > max_address) { return fFalse; } //Try writing data to flash for(i=0; i < _EEPROM_PAGE_COUNT; i++) { if(putEeprom(&eedata_addr[i][0], address, data)) { return fTrue; } } //Put page to buffer putBuffer(tempBuffer); for(i=0; i < _EEPROM_PAGE_COUNT; i++) { //Clear all the pages eraseFlashPage(&eedata_addr[i][0]); } //Put buffer back to page getBuffer(tempBuffer); //Try writing data to flash again for(i=0; i < _EEPROM_PAGE_COUNT; i++) { if(putEeprom(&eedata_addr[i][0], address, data)) { return fTrue; } } return fFalse; }