/** * \brief Test the read and write byte operations on the DataFlash * * This function will test the read and write functionalities of the DataFlash * using byte access. It will first write a known pattern on the 2 first * consecutive sectors and read it back by testing each value read.\n * In addition to test the data integrity and the byte read / write * functions, this will also test the continuity of the sectors as well as the * auto-incrementation of the DataFlash address. * * \param test Current test case. */ static void run_byte_access_test(const struct test_case *test) { uint32_t i; bool status; uint8_t byte; /* Write bytes one by one to the 2 first continuous sectors */ status = at45dbx_write_byte_open(0); test_assert_true(test, status == true, "Cannot open the DataFlash memory for write access"); for (i=0; i<AT45DBX_SECTOR_SIZE * 2; i++) { status = at45dbx_write_byte(BYTE_PATTERN1(i)); test_assert_true(test, status == true, "Write byte operation error @ 0x%08x", i); } at45dbx_write_close(); /* Read back the 2 first sectors of the DataFlash and check the values */ status = at45dbx_read_byte_open(0); test_assert_true(test, status == true, "Cannot open the DataFlash memory for read access"); for (i=0; i<AT45DBX_SECTOR_SIZE * 2; i++) { byte = at45dbx_read_byte(); test_assert_true(test, byte == BYTE_PATTERN1(i), "Read byte operation error @ 0x%08x" " (read: 0x%02x, expected: 0x%02x)", i, byte, BYTE_PATTERN1(i)); } at45dbx_read_close(); }
/** * \brief Test the read and write sector operations on the SD/MMC card * * This function will test the read and write functionalities of the SD/MMC SPI * component using sector access. It will first fill the last sector of the * device with a known pattern and read it back by testing each value read. * * \param test Current test case. */ static void run_sector_access_test(const struct test_case *test) { uint32_t i; bool status; /* Fills a ram sector with a known pattern */ for (i=0; i<MMC_SECTOR_SIZE; i++) { sector_buf[i] = BYTE_PATTERN1(i); } /* Compute the SD card capacity to retrieve the last sector address */ sd_mmc_spi_get_capacity(); /* Write the ram sector to the SD/MMC card */ status = sd_mmc_spi_write_open(sd_mmc_spi_last_block_address); test_assert_true(test, status == true, "Cannot open the SD/MMC memory for write access"); status = sd_mmc_spi_write_sector_from_ram(sector_buf); test_assert_true(test, status == true, "Write sector operation error"); sd_mmc_spi_write_close(); /* Clear the ram sector buffer */ for (i=0; i<MMC_SECTOR_SIZE; i++) { sector_buf[i] = 0; } /* Read back the sector from the SD/MMC card */ status = sd_mmc_spi_read_open(sd_mmc_spi_last_block_address); test_assert_true(test, status == true, "Cannot open the SD/MMC memory for read access"); status = sd_mmc_spi_read_sector_to_ram(sector_buf); test_assert_true(test, status == true, "Read sector operation error"); sd_mmc_spi_read_close(); /* Compare the values read from the SD/MMC card with the expected values */ for (i=0; i<MMC_SECTOR_SIZE; i++) { test_assert_true(test, sector_buf[i] == BYTE_PATTERN1(i), "Value not expected @ 0x%08x (read: 0x%02x," " expected: 0x%02x)", i, sector_buf[i], BYTE_PATTERN1(i)); } }
/** * \brief Test NVM update * * This test modifies first half of the test page with different pattern, * reads it back and checks whether the values are updated * * \param test Current test case. */ static void run_nvm_update_test(const struct test_case *test) { uint8_t buffer[NVMCTRL_PAGE_SIZE], i; enum status_code status; /* Skip test if NVM initialization failed */ test_assert_true(test, nvm_init_success == true, "NVM initialization failed, skipping test"); /* Fill half of the buffer with pattern 2 */ for (i = 0; i < (NVMCTRL_PAGE_SIZE / 2); i++) { buffer[i] = BYTE_PATTERN2(i); } /* Update first half of the test page with new data */ status = nvm_update_buffer(TEST_PAGE_ADDR, buffer, 0, (NVMCTRL_PAGE_SIZE / 2)); /* Validate whether the update operation is complete */ test_assert_true(test, status == STATUS_OK, "Update operation error"); /* Flush the buffer */ for (i = 0; i < NVMCTRL_PAGE_SIZE; i++) { buffer[i] = 0; } /* Read the NVM contents at test address to buffer */ status = nvm_read_buffer(TEST_PAGE_ADDR, buffer, NVMCTRL_PAGE_SIZE); /* Validate whether the read operation is complete */ test_assert_true(test, status == STATUS_OK, "Read operation error"); /* Check the integrity of data in NVM */ for (i = 0; i < (NVMCTRL_PAGE_SIZE / 2); i++) { test_assert_true(test, buffer[i] == BYTE_PATTERN2(i), "Value not expected @ byte %d (read: 0x%02x," " expected: 0x%02x)", i, buffer[i], BYTE_PATTERN2(i)); } for (i = (NVMCTRL_PAGE_SIZE / 2); i < NVMCTRL_PAGE_SIZE; i++) { test_assert_true(test, buffer[i] == BYTE_PATTERN1(i), "Value not expected @ byte %d (read: 0x%02x," " expected: 0x%02x)", i, buffer[i], BYTE_PATTERN1(i)); } }
/** * \brief Test the read and write byte operations on the NVM * * This function will test the read and write functionalities of the NVM * using byte access. It will first write a known pattern on the 2 * consecutive addresses and read it back by testing each value read.\n * * \param test Current test case. */ static void run_byte_access_test(const struct test_case *test) { status_code_t status; uint8_t read_data[4], i; /* Write four bytes one by one from the given address */ for (i = 0; i < 4; i++) { status = nvm_write_char(INT_FLASH, (uint32_t)TEST_ADDRESS + i, BYTE_PATTERN1( i)); test_assert_true(test, status == STATUS_OK, "Write byte operation error @ byte %d", i); } /* Read back the four bytes one by one */ for (i = 0; i < 4; i++) { nvm_read_char(INT_FLASH, (uint32_t)TEST_ADDRESS + i, &read_data[i]); test_assert_true(test, read_data[i] == BYTE_PATTERN1(i), "Read byte operation error @ byte %d" " (read: 0x%02x, expected: 0x%02x)", i, read_data[i], BYTE_PATTERN1(i)); } }