SAM SPI Unit test.
Copyright (c) 2013-2020 Microchip Technology Inc. and its subsidiaries.
Macros | |
#define | BUFFER_LENGTH 256 |
#define | TEST_SPI_BAUDRATE 1000000UL |
Functions | |
static void | cdc_uart_init (void) |
Initialize the USART for unit test. More... | |
static void | cleanup_buffer_polled_write_interrupt_read_test (const struct test_case *test) |
Cleanup function: Send data by polling & receive with interrupt. More... | |
int | main (void) |
Run SPI unit tests. More... | |
static void | run_baud_test (const struct test_case *test) |
Test: Sends data at different baud rates. More... | |
static void | run_buffer_polled_write_interrupt_read_test (const struct test_case *test) |
Test: Send data by polling & receive with interrupt. More... | |
static void | run_single_byte_polled_test (const struct test_case *test) |
Test sending and receiving a byte by polling. More... | |
static void | run_spi_init_test (const struct test_case *test) |
Test initializing SPI master & slave. More... | |
static void | run_transceive_buffer_test (const struct test_case *test) |
Test: Send & receive data using transceive functions. More... | |
static void | run_transfer_9bit_test (const struct test_case *test) |
Test sending and receiving 9-bit data by polling. More... | |
static void | setup_buffer_polled_write_interrupt_read_test (const struct test_case *test) |
Setup function: Send data by polling & receive with interrupt. More... | |
static void | setup_transfer_9bit_test (const struct test_case *test) |
Setup function: Send & receive 9-bit data by polling. More... | |
static void | user_spi_callback (struct spi_module *const module) |
SPI interrupt callback function. More... | |
Variables | |
struct usart_module | cdc_uart_module |
struct spi_module | master |
uint8_t | rx_buf [BUFFER_LENGTH] |
struct spi_module | slave |
struct spi_slave_inst | slave_inst |
uint8_t | slave_rx_buf [BUFFER_LENGTH] |
uint8_t | slave_tx_buf [BUFFER_LENGTH] |
volatile bool | spi_init_success = false |
volatile bool | transfer_complete = false |
uint8_t | tx_buf [BUFFER_LENGTH] |
#define BUFFER_LENGTH 256 |
#define TEST_SPI_BAUDRATE 1000000UL |
Referenced by run_spi_init_test(), and setup_transfer_9bit_test().
|
static |
Initialize the USART for unit test.
Initializes the SERCOM USART used for sending the unit test status to the computer via the EDBG CDC gateway.
References usart_config::baudrate, cdc_uart_module, CONF_STDIO_BAUDRATE, CONF_STDIO_MUX_SETTING, CONF_STDIO_PINMUX_PAD0, CONF_STDIO_PINMUX_PAD1, CONF_STDIO_PINMUX_PAD2, CONF_STDIO_PINMUX_PAD3, usart_config::mux_setting, usart_config::pinmux_pad0, usart_config::pinmux_pad1, usart_config::pinmux_pad2, usart_config::pinmux_pad3, usart_enable(), and usart_get_config_defaults().
Referenced by main().
|
static |
Cleanup function: Send data by polling & receive with interrupt.
This function unregisters and disables callback for buffer receive completed operation. It also clears the receive buffer rx_buf.
test | Current test case. |
References BUFFER_LENGTH, i, rx_buf, slave, SPI_CALLBACK_BUFFER_RECEIVED, spi_disable_callback(), and spi_unregister_callback().
Referenced by main().
int main | ( | void | ) |
Run SPI unit tests.
Initializes the system and serial output, then sets up the SPI unit test suite and runs it.
References BUFFER_LENGTH, cdc_uart_init(), cleanup_buffer_polled_write_interrupt_read_test(), cpu_irq_enable, DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, i, NULL, run_baud_test(), run_buffer_polled_write_interrupt_read_test(), run_single_byte_polled_test(), run_spi_init_test(), run_transceive_buffer_test(), run_transfer_9bit_test(), setup_buffer_polled_write_interrupt_read_test(), setup_transfer_9bit_test(), slave_tx_buf, system_init(), test_suite_run(), and tx_buf.
|
static |
Test: Sends data at different baud rates.
This test sends (writes) a byte to the slave and receives the data at different baudrate testing up to the maximum allowed level.
Transmission and reception are carried out by polling.
test | Current test case. |
References spi_master_config::baudrate, master, spi_config::master, spi_config::mode_specific, spi_config::mux_setting, spi_config::pinmux_pad0, spi_config::pinmux_pad1, spi_config::pinmux_pad2, spi_config::pinmux_pad3, PINMUX_UNUSED, slave, slave_inst, spi_disable(), spi_enable(), spi_get_config_defaults(), spi_init(), spi_init_success, spi_read_buffer_wait(), spi_select_slave(), spi_write_buffer_wait(), and test_assert_true.
Referenced by main().
|
static |
Test: Send data by polling & receive with interrupt.
This test sends (writes) an array of data to the slave by polling and receives (reads) the buffer back with interrupt and compares.
test | Current test case. |
References BUFFER_LENGTH, i, master, rx_buf, slave, slave_inst, spi_init_success, spi_read_buffer_job(), spi_select_slave(), spi_write_buffer_wait(), test_assert_true, transfer_complete, and tx_buf.
Referenced by main().
|
static |
Test sending and receiving a byte by polling.
This test sends (writes) one byte of data to the slave and receives (reads) the data back and compares.
Writing and reading are carried out by polling.
test | Current test case. |
References master, slave, slave_inst, spi_init_success, spi_is_ready_to_read(), spi_is_ready_to_write(), spi_is_write_complete(), spi_read(), spi_select_slave(), spi_write(), and test_assert_true.
Referenced by main().
|
static |
Test initializing SPI master & slave.
This initializes the SPI master & slave.
Test passes if initialization succeeds fails otherwise.
test | Current test case. |
References spi_master_config::baudrate, spi_slave_config::frame_format, master, spi_config::master, spi_config::mode, spi_config::mode_specific, spi_config::mux_setting, spi_config::pinmux_pad0, spi_config::pinmux_pad1, spi_config::pinmux_pad2, spi_config::pinmux_pad3, PINMUX_UNUSED, spi_slave_config::preload_enable, slave, spi_config::slave, slave_inst, spi_attach_slave(), spi_enable(), SPI_FRAME_FORMAT_SPI_FRAME, spi_get_config_defaults(), spi_init(), spi_init_success, SPI_MODE_SLAVE, spi_slave_inst_get_config_defaults(), spi_slave_inst_config::ss_pin, status, STATUS_ERR_IO, STATUS_OK, test_assert_true, and TEST_SPI_BAUDRATE.
Referenced by main().
|
static |
Test: Send & receive data using transceive functions.
This test sends (writes) an array of data to the slave and receives (reads) the buffer back using transceive functions and compares.
test | Current test case. |
References BUFFER_LENGTH, i, master, rx_buf, slave, slave_inst, slave_rx_buf, slave_tx_buf, spi_init_success, spi_select_slave(), spi_transceive_buffer_job(), spi_transceive_buffer_wait(), status, STATUS_ERR_IO, STATUS_OK, test_assert_true, and tx_buf.
Referenced by main().
|
static |
Test sending and receiving 9-bit data by polling.
This test sends (writes) one 9-bit data to the slave and receives (reads) the data back and compares.
Writing and reading are carried out by polling.
test | Current test case. |
References master, slave, slave_inst, spi_init_success, spi_is_ready_to_read(), spi_is_ready_to_write(), spi_is_write_complete(), spi_read(), spi_select_slave(), spi_write(), and test_assert_true.
Referenced by main().
|
static |
Setup function: Send data by polling & receive with interrupt.
This function registers and enables callback for buffer receive completed operation.
test | Current test case. |
References slave, SPI_CALLBACK_BUFFER_RECEIVED, spi_enable_callback(), spi_register_callback(), and user_spi_callback().
Referenced by main().
|
static |
Setup function: Send & receive 9-bit data by polling.
This function configures the SPI master & slave in 9-bit mode.
test | Current test case. |
References spi_master_config::baudrate, spi_config::character_size, spi_slave_config::frame_format, master, spi_config::master, spi_config::mode, spi_config::mode_specific, spi_config::mux_setting, spi_config::pinmux_pad0, spi_config::pinmux_pad1, spi_config::pinmux_pad2, spi_config::pinmux_pad3, PINMUX_UNUSED, spi_slave_config::preload_enable, slave, spi_config::slave, SPI_CHARACTER_SIZE_9BIT, spi_disable(), spi_enable(), SPI_FRAME_FORMAT_SPI_FRAME, spi_get_config_defaults(), spi_init(), spi_init_success, SPI_MODE_SLAVE, status, STATUS_ERR_IO, STATUS_OK, test_assert_true, and TEST_SPI_BAUDRATE.
Referenced by main().
|
static |
SPI interrupt callback function.
Called by SPI driver when transmission/reception is complete.
module | SPI module causing the interrupt (not used) |
References transfer_complete.
Referenced by setup_buffer_polled_write_interrupt_read_test().
struct usart_module cdc_uart_module |
struct spi_module master |
Referenced by nm_bus_deinit(), nm_bus_init(), run_baud_test(), run_buffer_polled_write_interrupt_read_test(), run_single_byte_polled_test(), run_spi_init_test(), run_transceive_buffer_test(), run_transfer_9bit_test(), setup_transfer_9bit_test(), trx_aes_wrrd(), trx_frame_read(), trx_frame_write(), trx_reg_read(), trx_reg_write(), trx_spi_disable(), trx_spi_enable(), trx_spi_init(), trx_sram_read(), and trx_sram_write().
uint8_t rx_buf[BUFFER_LENGTH] |
struct spi_module slave |
Referenced by adp_interface_init(), adp_interface_send_start(), adp_interface_send_stop(), check_boot_mode(), cleanup_buffer_polled_write_interrupt_read_test(), configure_spi_master(), fetch_data(), get_length(), main(), run_baud_test(), run_buffer_polled_write_interrupt_read_test(), run_single_byte_polled_test(), run_spi_init_test(), run_transceive_buffer_test(), run_transfer_9bit_test(), send_ack(), setup_buffer_polled_write_interrupt_read_test(), setup_transfer_9bit_test(), trx_aes_wrrd(), trx_frame_read(), trx_frame_write(), trx_reg_read(), trx_reg_write(), trx_spi_init(), trx_sram_read(), and trx_sram_write().
struct spi_slave_inst slave_inst |
uint8_t slave_rx_buf[BUFFER_LENGTH] |
Referenced by run_transceive_buffer_test().
uint8_t slave_tx_buf[BUFFER_LENGTH] |
Referenced by main(), and run_transceive_buffer_test().
uint8_t tx_buf[BUFFER_LENGTH] |