void eeprom_emulator_configure(void) { /* Setup EEPROM emulator service */ enum status_code error_code = eeprom_emulator_init(); if (error_code == STATUS_ERR_NO_MEMORY) { while (true) { /* No EEPROM section has been set in the device's fuses */ } } 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(); } }
/** * \internal * \brief Test for EEPROM emulator initialization. * * This test initializes the EEPROM emulator. If no memory was set * for EEPROM in the fuses then all test will be skipped. * During initialization it will format the EEPROM memory if it was * not done previously. * * It also checks the get parameter functionality. * * \param test Current test case. */ static void run_eeprom_init_test(const struct test_case *test) { enum status_code status; init_success = true; /* Initialize the EEPROM emulator */ status = eeprom_emulator_init(); if (status == STATUS_ERR_NO_MEMORY) { init_success = false; } test_assert_true(test, init_success, "No EEPROM memory section has been set in the device's fuses"); /* Format memory if needed */ if (status != STATUS_OK) { eeprom_emulator_erase_memory(); status = eeprom_emulator_init(); if (status != STATUS_OK) { init_success = false; } } test_assert_true(test, status == STATUS_OK, "EEPROM emulator initialization failed"); /* Get parameter check */ status = eeprom_emulator_get_parameters(&ee_params); if (status != STATUS_OK) { init_success = false; } test_assert_true(test, status == STATUS_OK, "EEPROM parameter retrieve failed"); test_assert_true(test, ee_params.page_size == EEPROM_PAGE_SIZE, "Get parameter returned wrong page size" "Expected %d - Returned %d", EEPROM_PAGE_SIZE, ee_params.page_size); }