Unit Tests of the SD/MMC SPI Component.
Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
#include <stdint.h>
#include <stdbool.h>
#include <asf.h>
#include <string.h>
#include "sd_mmc_spi.h"
#include "conf_test.h"
Macros | |
Byte pattern generator | |
#define | BYTE_PATTERN1(x) ((uint8_t) (((x) * 5 + 1) & 0xff)) |
Generates byte pattern 1 for a given address. More... | |
#define | BYTE_PATTERN2(x) ((uint8_t) (((x) * 3) & 0xff)) |
Generates byte pattern 2 for a given address. More... | |
Functions | |
int | main (void) |
Run SD/MMC SPI component unit tests. More... | |
static void | run_check_presence_test (const struct test_case *test) |
Checks the presence of the SD/MMC card. More... | |
static void | run_memory_check_test (const struct test_case *test) |
Performs a memory initialization on the SD/MMC card. More... | |
static void | run_multiple_sector_access_test (const struct test_case *test) |
Test the read and write multiple sector operations on the SD/MMC card. More... | |
static void | run_sector_access_test (const struct test_case *test) |
Test the read and write sector operations on the SD/MMC card. More... | |
void | sd_mmc_spi_read_multiple_sector_callback (const void *psector) |
void | sd_mmc_spi_write_multiple_sector_callback (void *psector) |
Variables | |
static uint32_t | cur_sector = 0 |
Index of the current sector being processed. More... | |
static struct test_case * | cur_test |
Test case pointer used to refer to the current test case in the function sd_mmc_spi_read_multiple_sector_callback. More... | |
static uint8_t | sector_buf [MMC_SECTOR_SIZE] |
A SD/MMC sector-sized buffer for processing data in ram memory. More... | |
#define BYTE_PATTERN1 | ( | x | ) | ((uint8_t) (((x) * 5 + 1) & 0xff)) |
Generates byte pattern 1 for a given address.
Referenced by run_sector_access_test().
#define BYTE_PATTERN2 | ( | x | ) | ((uint8_t) (((x) * 3) & 0xff)) |
Generates byte pattern 2 for a given address.
Referenced by sd_mmc_spi_read_multiple_sector_callback(), and sd_mmc_spi_write_multiple_sector_callback().
int main | ( | void | ) |
Run SD/MMC SPI component unit tests.
Initializes the clock system, board, serial output and SD/MMC card, then sets up the SD/MMC SPI unit test suite and runs it.
References usart_options_t::baudrate, board_init(), CONF_TEST_BAUDRATE, CONF_TEST_CHARLENGTH, CONF_TEST_PARITY, CONF_TEST_STOPBITS, CONF_TEST_USART, DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, run_check_presence_test(), run_memory_check_test(), run_multiple_sector_access_test(), run_sector_access_test(), sd_mmc_spi_board_init(), stdio_serial_init(), sysclk_init(), and test_suite_run().
|
static |
Checks the presence of the SD/MMC card.
This function will simply test the output of the function sd_mmc_spi_check_presence and returns an error in case of failure.
test | Current test case. |
References sd_mmc_spi_check_presence(), and test_assert_true.
Referenced by main().
|
static |
Performs a memory initialization on the SD/MMC card.
This function will simply test the output of the function sd_mmc_spi_mem_check and returns an error in case of failure.
test | Current test case. |
References sd_mmc_spi_mem_check(), and test_assert_true.
Referenced by main().
|
static |
Test the read and write multiple sector operations on the SD/MMC card.
This function will test the read and write functionalities of the SD/MMC SPI component using multiple sector access. It will first fill the CONF_TEST_NB_SECTORS last sectors with a known pattern and read it back to test each value.
test | Current test case. |
References CONF_TEST_NB_SECTORS, cur_sector, sd_mmc_spi_get_capacity(), sd_mmc_spi_last_block_address, sd_mmc_spi_read_close(), sd_mmc_spi_read_multiple_sector(), sd_mmc_spi_read_open(), sd_mmc_spi_write_close(), sd_mmc_spi_write_multiple_sector(), sd_mmc_spi_write_open(), and test_assert_true.
Referenced by main().
|
static |
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.
test | Current test case. |
References BYTE_PATTERN1, MMC_SECTOR_SIZE, sd_mmc_spi_get_capacity(), sd_mmc_spi_last_block_address, sd_mmc_spi_read_close(), sd_mmc_spi_read_open(), sd_mmc_spi_read_sector_to_ram(), sd_mmc_spi_write_close(), sd_mmc_spi_write_open(), sd_mmc_spi_write_sector_from_ram(), sector_buf, and test_assert_true.
Referenced by main().
|
static |
Index of the current sector being processed.
Used by run_multiple_sector_access_test
Referenced by run_multiple_sector_access_test(), sd_mmc_spi_read_multiple_sector_callback(), and sd_mmc_spi_write_multiple_sector_callback().
|
static |
Test case pointer used to refer to the current test case in the function sd_mmc_spi_read_multiple_sector_callback.
|
static |
A SD/MMC sector-sized buffer for processing data in ram memory.
Referenced by run_sector_access_test().