Unit tests for SPI driver of megaRF.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
#include <asf.h>
#include <conf_test.h>
Macros | |
#define | DATA_BUFFER_SIZE 0x05 |
#define | SPI_DEVICE_SELECT IOPORT_CREATE_PIN(PORTB, 0) |
#define | SPI_MASTER_DUMMY 0xFF |
Functions | |
static void | flash_read_data (void) |
Read data from flash. More... | |
static uint8_t | get_spi_divisor (void) |
Get SPI module baudrate divisor value. More... | |
int | main (void) |
Run SPI driver unit tests. More... | |
static void | run_baudrate_set_test (const struct test_case *test) |
Test baudrate setting. More... | |
static void | run_spi_transfer_test (const struct test_case *test) |
Test SPI transfer. More... | |
static void | spi_deselect_device (void) |
Deselect given device on the SPI bus. More... | |
static status_code_t | spi_read (volatile void *spi, uint8_t *data, size_t len) |
Receive a sequence of bytes from a SPI device. More... | |
static void | spi_select_device (void) |
Select given device on the SPI bus. More... | |
static status_code_t | spi_write (volatile void *spi, const uint8_t *data, size_t len) |
Send a sequence of bytes to a SPI device. More... | |
Variables | |
static const uint8_t | data_buffer_write [] = {0x84, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05} |
static const uint8_t | data_flash_read [] = {0xd2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
static const uint8_t | data_flash_write [] = {0x83, 0x00, 0x00, 0x00} |
static uint8_t | data_received [DATA_BUFFER_SIZE] |
static const uint8_t | data_sent [] = {0x01, 0x02, 0x03, 0x04, 0x05} |
#define DATA_BUFFER_SIZE 0x05 |
Referenced by flash_read_data(), and run_spi_transfer_test().
#define SPI_DEVICE_SELECT IOPORT_CREATE_PIN(PORTB, 0) |
Referenced by spi_deselect_device(), and spi_select_device().
#define SPI_MASTER_DUMMY 0xFF |
Referenced by spi_read().
|
static |
Read data from flash.
Read command is sent to read the data from specific page of the flash
test | Current test case. |
References DATA_BUFFER_SIZE, data_flash_read, data_received, spi_deselect_device(), spi_read(), spi_select_device(), and spi_write().
Referenced by run_spi_transfer_test().
|
static |
Get SPI module baudrate divisor value.
References SPI_CLK2X_bm, SPI_PRESCALER_DIV128_gc, SPI_PRESCALER_DIV16_gc, SPI_PRESCALER_DIV4_gc, SPI_PRESCALER_DIV64_gc, and SPI_PRESCALER_gm.
Referenced by run_baudrate_set_test().
int main | ( | void | ) |
Run SPI driver unit tests.
Main function.
The SAM3X_EK, SAM3X Arduino board and SAM4C_EK use two bytes length internal address EEPROM.
References usart_rs232_options::baudrate, board_init(), DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, NULL, run_baudrate_set_test(), run_spi_transfer_test(), stdio_serial_init(), sysclk_init(), test_suite_run(), and usart_serial_options.
|
static |
Test baudrate setting.
This test sets different baudrates and test if the divisor is set as expected.
test | Current test case. |
References get_spi_divisor(), spi_enable(), spi_set_baud_div(), sysclk_enable_peripheral_clock(), and test_assert_true.
Referenced by main().
|
static |
Test SPI transfer.
In this test SPI master sends write command to write set of data and send read command to get the data back from external flash.
test | Current test case. |
References DATA_BUFFER_SIZE, data_buffer_write, data_flash_write, data_received, data_sent, flash_read_data(), spi_deselect_device(), spi_enable(), spi_enable_master_mode(), spi_select_device(), spi_set_baud_div(), spi_set_clock_mode(), spi_write(), sysclk_enable_peripheral_clock(), sysclk_get_cpu_hz(), and test_assert_true.
Referenced by main().
|
static |
Deselect given device on the SPI bus.
References ioport_set_pin_high(), and SPI_DEVICE_SELECT.
Referenced by flash_read_data(), run_spi_transfer_test(), and spi_at45dbx_mem_check().
|
static |
Receive a sequence of bytes from a SPI device.
All bytes sent out on SPI bus are sent as value 0.
spi | Base address of the SPI instance. |
data | data buffer to read |
len | Length of data |
References spi_get(), spi_is_tx_ok(), SPI_MASTER_DUMMY, spi_put(), and STATUS_OK.
Referenced by flash_read_data().
|
static |
Select given device on the SPI bus.
References ioport_set_pin_low(), and SPI_DEVICE_SELECT.
Referenced by flash_read_data(), run_spi_transfer_test(), and spi_at45dbx_mem_check().
|
static |
Send a sequence of bytes to a SPI device.
Received bytes on the SPI bus are discarded.
spi | Base address of the SPI instance. |
data | data buffer to write |
len | Length of data |
References spi_is_tx_ok(), spi_put(), and STATUS_OK.
Referenced by flash_read_data(), and run_spi_transfer_test().
|
static |
Referenced by run_spi_transfer_test().
|
static |
Referenced by flash_read_data().
|
static |
Referenced by run_spi_transfer_test().
|
static |
Referenced by flash_read_data(), and run_spi_transfer_test().
|
static |
Referenced by run_spi_transfer_test().