/** * 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 Erase EEPROM page. * * This function erases one EEPROM page, so that every location reads 0xFF. * * \param page_addr EEPROM Page address, between 0 and EEPROM_SIZE/EEPROM_PAGE_SIZE */ void nvm_eeprom_erase_page(uint8_t page_addr) { // Mark all addresses to be deleted nvm_eeprom_fill_buffer_with_value(0xff); // Erase bytes nvm_eeprom_erase_bytes_in_page(page_addr); }
/** * \brief Test EEPROM read buffer * * This test erases test page \ref TEST_READ_BUFFER_PAGE then writes four bytes * to the test page and tries to read the entire page using * nvm_eeprom_read_buffer. * It then compares the read page with what's actually in the EEPROM page. * * \param test Current test case. */ static void run_eeprom_read_buffer_test(const struct test_case *test) { uint8_t buffer[EEPROM_PAGE_SIZE]; uint8_t buffer_read[EEPROM_PAGE_SIZE]; bool success; set_buffer(buffer, EEPROM_ERASED); buffer[0] = 0x11; buffer[1] = 0xaa; buffer[2] = 0xee; buffer[3] = 0x22; // Erase page nvm_eeprom_erase_bytes_in_page(TEST_READ_BUFFER_PAGE); // Write 4 bytes into page: nvm_eeprom_write_byte(TEST_READ_BUFFER_PAGE * EEPROM_PAGE_SIZE + 0, buffer[0]); nvm_eeprom_write_byte(TEST_READ_BUFFER_PAGE * EEPROM_PAGE_SIZE + 1, buffer[1]); nvm_eeprom_write_byte(TEST_READ_BUFFER_PAGE * EEPROM_PAGE_SIZE + 2, buffer[2]); nvm_eeprom_write_byte(TEST_READ_BUFFER_PAGE * EEPROM_PAGE_SIZE + 3, buffer[3]); nvm_eeprom_read_buffer(TEST_READ_BUFFER_PAGE * EEPROM_PAGE_SIZE, &buffer_read, EEPROM_PAGE_SIZE); // Check that what we have read is actually what's in EEPROM. success = is_eeprom_page_equal_to_buffer(TEST_READ_BUFFER_PAGE, buffer_read); test_assert_true(test, success, "Read buffer failed"); }
/** * \brief Test EEPROM write buffer * * This test erases test page \ref TEST_WRITE_BUFFER_PAGE then writes a buffer * to the test page, and then overwrites this with the another buffer and checks * that the last buffer written is what the page is containing. * * \param test Current test case. */ static void run_eeprom_write_buffer_test(const struct test_case *test) { uint8_t buffer[EEPROM_PAGE_SIZE]; bool success; set_buffer(buffer, EEPROM_ERASED); buffer[0] = 0x11; buffer[1] = 0xaa; buffer[2] = 0xee; buffer[3] = 0x22; // Erase page nvm_eeprom_erase_bytes_in_page(TEST_WRITE_BUFFER_PAGE); // Write buffer to EEPROM nvm_eeprom_erase_and_write_buffer(TEST_WRITE_BUFFER_PAGE * EEPROM_PAGE_SIZE, &buffer, EEPROM_PAGE_SIZE); /* Write another buffer to EEPROM to make sure EEPROM is deleted before * written to. */ buffer[0] = 0x33; buffer[1] = 0x11; buffer[2] = 0xee; buffer[3] = 0xaa; nvm_eeprom_erase_and_write_buffer(TEST_WRITE_BUFFER_PAGE * EEPROM_PAGE_SIZE, &buffer, EEPROM_PAGE_SIZE); // Check that what we have written is in EEPROM. success = is_eeprom_page_equal_to_buffer(TEST_WRITE_BUFFER_PAGE, buffer); test_assert_true(test, success, "Write buffer failed"); }
/** * \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"); }