Microchip® Advanced Software Framework

unit_tests.c File Reference

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_casecur_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  )
static void run_check_presence_test ( const struct test_case test)
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.

Parameters
testCurrent test case.

References sd_mmc_spi_check_presence(), and test_assert_true.

Referenced by main().

static void run_memory_check_test ( const struct test_case test)
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.

Parameters
testCurrent test case.

References sd_mmc_spi_mem_check(), and test_assert_true.

Referenced by main().

static void run_multiple_sector_access_test ( const struct test_case test)
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.

Parameters
testCurrent 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 void run_sector_access_test ( const struct test_case test)
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.

Parameters
testCurrent 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().

uint32_t cur_sector = 0
static
struct test_case* cur_test
static

Test case pointer used to refer to the current test case in the function sd_mmc_spi_read_multiple_sector_callback.

uint8_t sector_buf[MMC_SECTOR_SIZE]
static

A SD/MMC sector-sized buffer for processing data in ram memory.

Referenced by run_sector_access_test().