/** * Test nvm_eeprom_split_write_page() * * Test procedure: * - Erase TEST_SPLIT_WRITE_PAGE page and then write 2 bytes * to TEST_SPLIT_WRITE_PAGE by using an atomic write * - Write 1 additional byte at another location using a split write * - Verify that all 3 bytes written correctly and that the rest of the page * is erased. * * \return STATUS_OK if test succeeded, otherwise ERR_BAD_DATA */ static status_code_t test_split_write(void) { /* Erase and then program two bytes into the page */ set_buffer(buffer, EEPROM_ERASED); buffer[1] = 0xaa; buffer[2] = 0x19; nvm_eeprom_load_byte_to_buffer(1, buffer[1]); nvm_eeprom_load_byte_to_buffer(2, buffer[2]); nvm_eeprom_atomic_write_page(TEST_SPLIT_WRITE_PAGE); /* * Write another value to the EEPROM and then verify that all three bytes * are present, ie. the split write does not delete the first two bytes. */ buffer[3] = 0xa7; nvm_eeprom_load_byte_to_buffer(3, buffer[3]); nvm_eeprom_split_write_page(TEST_SPLIT_WRITE_PAGE); if (is_eeprom_page_equal_to_buffer(TEST_SPLIT_WRITE_PAGE, buffer)) { return STATUS_OK; } return ERR_BAD_DATA; }
/** * \brief Test EEPROM split write * * This test writes two bytes to test page \ref TEST_SPLIT_WRITE_PAGE with an * atomic write operation, then writes a third byte to the same page with a * split write operation before verifying that the page contains all three * bytes. * * \param test Current test case. */ static void run_eeprom_split_write_test(const struct test_case *test) { uint8_t buffer[EEPROM_PAGE_SIZE]; bool success; /* Erase and then program two bytes into the page */ set_buffer(buffer, EEPROM_ERASED); buffer[1] = 0xaa; buffer[2] = 0x19; nvm_eeprom_load_byte_to_buffer(1, buffer[1]); nvm_eeprom_load_byte_to_buffer(2, buffer[2]); nvm_eeprom_atomic_write_page(TEST_SPLIT_WRITE_PAGE); /* * Write another value to the EEPROM and then verify that all three bytes * are present, ie. the split write does not delete the first two bytes. */ buffer[3] = 0xa7; nvm_eeprom_load_byte_to_buffer(3, buffer[3]); nvm_eeprom_split_write_page(TEST_SPLIT_WRITE_PAGE); success = is_eeprom_page_equal_to_buffer(TEST_SPLIT_WRITE_PAGE, buffer); test_assert_true(test, success, "Split write failed"); }