/** * \brief Erase entire EEPROM memory. * * This function erases the entire EEPROM memory block to 0xFF. */ void nvm_eeprom_erase_all(void) { // Mark all addresses to be deleted nvm_eeprom_fill_buffer_with_value(0xff); // Erase all pages nvm_eeprom_erase_bytes_in_all_pages(); }
/** * Test nvm_eeprom_erase_bytes_in_page() and * nvm_eeprom_erase_bytes_in_all_pages() * * Test procedure: * - Write two bytes into page TEST_ERASE_BYTES_PAGE_1 and * TEST_ERASE_BYTES_PAGE_2 * - Load value to page buffer in the address of the first byte * - Erase first byte of TEST_ERASE_BYTES_PAGE_1 * - Verify that first byte is deleted in TEST_ERASE_BYTES_PAGE_1 * - Load value to page buffer in the address of the first byte * - Erase first byte of all pages * - Verify that first byte is deleted in TEST_ERASE_BYTES_PAGE_2 * * \return STATUS_OK if test succeeded, otherwise ERR_BAD_DATA */ static status_code_t test_erase_bytes(void) { set_buffer(buffer, EEPROM_ERASED); buffer[0] = 0xaa; buffer[1] = 0xaf; /* Write two bytes into first page */ nvm_eeprom_write_byte(TEST_ERASE_BYTES_PAGE_1 * EEPROM_PAGE_SIZE + 0, buffer[0]); nvm_eeprom_write_byte(TEST_ERASE_BYTES_PAGE_1 * EEPROM_PAGE_SIZE + 1, buffer[1]); /* Write two bytes into second page */ nvm_eeprom_write_byte(TEST_ERASE_BYTES_PAGE_2 * EEPROM_PAGE_SIZE + 0, buffer[0]); nvm_eeprom_write_byte(TEST_ERASE_BYTES_PAGE_2 * EEPROM_PAGE_SIZE + 1, buffer[1]); /* Erase first byte of the first page */ nvm_eeprom_load_byte_to_buffer(0, 0xff); nvm_eeprom_erase_bytes_in_page(TEST_ERASE_BYTES_PAGE_1); buffer[0] = EEPROM_ERASED; if (is_eeprom_page_equal_to_buffer(TEST_ERASE_BYTES_PAGE_1, buffer)) { /* Erase first byte of all pages */ nvm_eeprom_load_byte_to_buffer(0, 0xff); nvm_eeprom_erase_bytes_in_all_pages(); if (is_eeprom_page_equal_to_buffer(TEST_ERASE_BYTES_PAGE_2, buffer)) { return STATUS_OK; } } return ERR_BAD_DATA; }
/** * \brief Test EEPROM byte erase * * This test writes two bytes to test pages \ref TEST_ERASE_BYTES_PAGE_1 and * \ref TEST_ERASE_BYTES_PAGE_2, then tries to erase one of them in the first * page before verifying the erase, then in all pages before verifying that the * second page was also erased. * * \param test Current test case. */ static void run_eeprom_erase_byte_test(const struct test_case *test) { uint8_t buffer[EEPROM_PAGE_SIZE]; bool success; set_buffer(buffer, EEPROM_ERASED); buffer[0] = 0xaa; buffer[1] = 0xaf; /* Write two bytes into first page */ nvm_eeprom_write_byte(TEST_ERASE_BYTES_PAGE_1 * EEPROM_PAGE_SIZE + 0, buffer[0]); nvm_eeprom_write_byte(TEST_ERASE_BYTES_PAGE_1 * EEPROM_PAGE_SIZE + 1, buffer[1]); /* Write two bytes into second page */ nvm_eeprom_write_byte(TEST_ERASE_BYTES_PAGE_2 * EEPROM_PAGE_SIZE + 0, buffer[0]); nvm_eeprom_write_byte(TEST_ERASE_BYTES_PAGE_2 * EEPROM_PAGE_SIZE + 1, buffer[1]); /* Erase first byte of the first page */ nvm_eeprom_load_byte_to_buffer(0, 0xff); nvm_eeprom_erase_bytes_in_page(TEST_ERASE_BYTES_PAGE_1); buffer[0] = EEPROM_ERASED; success = is_eeprom_page_equal_to_buffer(TEST_ERASE_BYTES_PAGE_1, buffer); test_assert_true(test, success, "Byte erase in single page failed"); /* Erase first byte of all pages */ nvm_eeprom_load_byte_to_buffer(0, 0xff); nvm_eeprom_erase_bytes_in_all_pages(); success = is_eeprom_page_equal_to_buffer(TEST_ERASE_BYTES_PAGE_2, buffer); test_assert_true(test, success, "Byte erase in all pages failed"); }