28.8.1.2.3 Workflow
- Attempt to initialize the EEPROM emulator service, storing the error code from the initialization function into a temporary variable.
enum
status_code error_code = eeprom_emulator_init();
- Check if the emulator failed to initialize due to the device fuses not being configured to reserve enough of the main FLASH memory rows for emulated EEPROM usage - abort if the fuses are mis-configured.
if
(error_code == STATUS_ERR_NO_MEMORY) {
while
(
true
) {
/* No EEPROM section has been set in the device's fuses */
}
}
- Check if the emulator service failed to initialize for any other reason; if so assume the emulator physical memory is unformatted or corrupt and erase/re-try initialization.
Config BOD to give an early warning, so that we could prevent data loss.else
if
(error_code != STATUS_OK) {
/* Erase the emulated EEPROM memory (assume it is unformatted or
* irrecoverably corrupt) */
eeprom_emulator_erase_memory();
eeprom_emulator_init();
}
configure_bod();