/** * \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 sector operations on the DataFlash * * This function will test the read and write functionalities of the DataFlash * using sector access. It will first fill a sector with a known pattern and * read it back by testing each value read.\n * * \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<AT45DBX_SECTOR_SIZE; i++) { sector_buf[i] = BYTE_PATTERN2(i); } /* Write the ram sector to the DataFlash */ status = at45dbx_write_sector_open(0); test_assert_true(test, status == true, "Cannot open the DataFlash memory for write access"); status = at45dbx_write_sector_from_ram(sector_buf); test_assert_true(test, status == true, "Write sector operation error"); at45dbx_write_close(); /* Clear the ram sector buffer */ for (i=0; i<AT45DBX_SECTOR_SIZE; i++) { sector_buf[i] = 0; } /* Read back the sector of the DataFlash */ status = at45dbx_read_sector_open(0); test_assert_true(test, status == true, "Cannot open the DataFlash memory for read access"); status = at45dbx_read_sector_to_ram(sector_buf); test_assert_true(test, status == true, "Read sector operation error"); at45dbx_read_close(); /* Compare the values read from the DataFlash with the expected values */ for (i=0; i<AT45DBX_SECTOR_SIZE; i++) { test_assert_true(test, sector_buf[i] == BYTE_PATTERN2(i), "Value not expected @ 0x%08x (read: 0x%02x," " expected: 0x%02x)", i, sector_buf[i], BYTE_PATTERN2(i)); } }
/** * \brief Test the read and write buffer operations on the NVM * * This function will test the read and write functionalities of the NVM * using buffer access. It will first fill a buffer with a known pattern and * read it back by testing each value read.\n * * \param test Current test case. */ static void run_buffer_access_test(const struct test_case *test) { status_code_t status; uint8_t i, test_buf[20]; /* Fills a test buffer with a known pattern */ for (i = 0; i < 20; i++) { test_buf[i] = BYTE_PATTERN2(i); } /* Write the buffer to the non volatile memory */ status = nvm_write(INT_FLASH, (uint32_t)TEST_ADDRESS, (void *)test_buf, sizeof(test_buf)); test_assert_true(test, status == STATUS_OK, "Write buffer operation error"); /* Clear the test buffer */ for (i = 0; i < 20; i++) { test_buf[i] = 0; } /* Read back the non volatile memory */ status = nvm_read(INT_FLASH, (uint32_t)TEST_ADDRESS, (void *)test_buf, sizeof(test_buf)); test_assert_true(test, status == STATUS_OK, "Read buffer operation error"); /* Compare the values read from the NVM with the expected values */ for (i = 0; i < 20; i++) { test_assert_true(test, test_buf[i] == BYTE_PATTERN2(i), "Value not expected @ byte %d (read: 0x%02x," " expected: 0x%02x)", i, test_buf[i], BYTE_PATTERN2(i)); } }
/** * \copybrief sd_mmc_spi_write_multiple_sector_callback * \note Used by \ref run_multiple_sector_access_test */ void sd_mmc_spi_write_multiple_sector_callback(void *psector) { uint32_t i; uint8_t value; /* This reflect the index of the current sector being accessed */ cur_sector++; /* Fills a ram sector with a known pattern */ for (i=0; i<MMC_SECTOR_SIZE; i++) { value = BYTE_PATTERN2(cur_sector * MMC_SECTOR_SIZE + i); ((uint8_t *) psector)[i] = value; } }
/** * \copybrief sd_mmc_spi_read_multiple_sector_callback * \note Used by \ref run_multiple_sector_access_test */ void sd_mmc_spi_read_multiple_sector_callback(const void *psector) { uint32_t i; uint8_t expected; /* This reflect the index of the current sector being accessed */ cur_sector++; /* Test each values of the current sector */ for (i=0; i<MMC_SECTOR_SIZE; i++) { expected = BYTE_PATTERN2(cur_sector * MMC_SECTOR_SIZE + i); test_assert_true(cur_test, ((uint8_t *) psector)[i] == expected, "Value not expected @ 0x%08x in sector # %i" " (read: 0x%02x, expected: 0x%02x)", i, cur_sector, ((uint8_t *) psector)[i], expected); } }