Unit tests for SPI driver.
Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
#include <stdint.h>
#include <stdbool.h>
#include <board.h>
#include <sysclk.h>
#include <spi.h>
#include <string.h>
#include <unit_test/suite.h>
#include <stdio_serial.h>
#include <conf_test.h>
#include <conf_board.h>
Macros | |
#define | ns_to_dlybct(ck, ns) ((((ns) / 32 * ((ck) / 1000000)) / 1000) + 1) |
Convert ns to SPI DLYBCT. More... | |
#define | ns_to_dlybs(ck, ns) ((((ns) * ((ck) / 1000000)) / 1000) + 1) |
Convert ns to SPI DLYBS. More... | |
#define | OFFSET_CSR 0x30 |
Register offset for _CSR. More... | |
#define | OFFSET_IER 0x14 |
Register offset for _IMR. More... | |
#define | OFFSET_MR 0x04 |
Register offset for _MR. More... | |
#define | SPI_CLK_PHASE 0 |
Clock phase. More... | |
#define | SPI_CLK_POLARITY 1 |
Clock polarity. More... | |
#define | SPI_DLYBCT 0x10 |
Delay between consecutive transfers. More... | |
#define | SPI_DLYBS 0x40 |
Delay before SPCK. More... | |
#define | TEST_CLOCK 10000000 |
Test SPI clock. More... | |
#define | TEST_PATTERN 0xA5 |
Byte to transfer for test. More... | |
#define | TEST_PCS ((~(1u << CONF_TEST_SPI_NPCS)) & 0xF) |
PCS to use for test. More... | |
Functions | |
void | CONF_TEST_SPI_HANDLER (void) |
Test SPI interrupt handler. More... | |
int | main (void) |
Run SPI driver unit test. More... | |
static void | run_spi_ctrl_test (const struct test_case *test) |
Test SPI setting. More... | |
static void | run_spi_trans_test (const struct test_case *test) |
Test SPI transfer. More... | |
static void | run_spi_writeprotect_test (const struct test_case *test) |
Test SPI write protection. More... | |
Variables | |
volatile bool | g_b_spi_interrupt_rx_ready = false |
RX interrupt occurred. More... | |
volatile bool | g_b_spi_interrupt_tx_ready = false |
TX interrupt occurred. More... | |
#define ns_to_dlybct | ( | ck, | |
ns | |||
) | ((((ns) / 32 * ((ck) / 1000000)) / 1000) + 1) |
Convert ns to SPI DLYBCT.
#define ns_to_dlybs | ( | ck, | |
ns | |||
) | ((((ns) * ((ck) / 1000000)) / 1000) + 1) |
Convert ns to SPI DLYBS.
#define OFFSET_CSR 0x30 |
Register offset for _CSR.
Referenced by run_spi_writeprotect_test().
#define OFFSET_IER 0x14 |
Register offset for _IMR.
#define OFFSET_MR 0x04 |
Register offset for _MR.
Referenced by run_spi_writeprotect_test().
#define SPI_CLK_PHASE 0 |
Clock phase.
Referenced by run_spi_trans_test().
#define SPI_CLK_POLARITY 1 |
Clock polarity.
Referenced by run_spi_trans_test().
#define SPI_DLYBCT 0x10 |
Delay between consecutive transfers.
Referenced by run_spi_trans_test().
#define SPI_DLYBS 0x40 |
Delay before SPCK.
Referenced by run_spi_trans_test().
#define TEST_CLOCK 10000000 |
Test SPI clock.
Referenced by run_spi_trans_test().
#define TEST_PATTERN 0xA5 |
Byte to transfer for test.
Referenced by run_spi_trans_test().
#define TEST_PCS ((~(1u << CONF_TEST_SPI_NPCS)) & 0xF) |
PCS to use for test.
Referenced by run_spi_trans_test().
void CONF_TEST_SPI_HANDLER | ( | void | ) |
Test SPI interrupt handler.
References g_b_spi_interrupt_rx_ready, g_b_spi_interrupt_tx_ready, spi_disable_interrupt(), spi_read_status(), and status.
int main | ( | void | ) |
Run SPI driver unit test.
References uart_rs232_options::baudrate, board_init(), DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, NULL, run_spi_ctrl_test(), run_spi_trans_test(), run_spi_writeprotect_test(), stdio_serial_init(), sysclk_init(), test_suite_run(), and usart_serial_options.
|
static |
Test SPI setting.
This test tests SPI reset/enable/disable.
test | Current test case. |
References SAM4L, spi_enable(), spi_enable_clock(), spi_is_enabled(), spi_reset(), and test_assert_true.
Referenced by main().
|
static |
Test SPI transfer.
This test tests SPI read/write.
test | Current test case. |
References g_b_spi_interrupt_rx_ready, g_b_spi_interrupt_tx_ready, SAM4L, SPI_CLK_PHASE, SPI_CLK_POLARITY, spi_disable(), spi_disable_interrupt(), spi_disable_loopback(), spi_disable_mode_fault_detect(), SPI_DLYBCT, SPI_DLYBS, spi_enable(), spi_enable_interrupt(), spi_enable_loopback(), SPI_ERROR_TIMEOUT, SPI_OK, spi_read(), spi_reset(), spi_set_baudrate_div(), spi_set_bits_per_transfer(), spi_set_clock_phase(), spi_set_clock_polarity(), spi_set_lastxfer(), spi_set_master_mode(), spi_set_peripheral_chip_select_value(), spi_set_transfer_delay(), spi_set_variable_peripheral_select(), spi_write(), sysclk_get_pba_hz(), test_assert_true, TEST_CLOCK, TEST_PATTERN, and TEST_PCS.
Referenced by main().
|
static |
Test SPI write protection.
test | Current test case. |
References OFFSET_CSR, OFFSET_MR, spi_get_writeprotect_status(), spi_set_writeprotect(), and test_assert_true.
Referenced by main().
RX interrupt occurred.
Referenced by CONF_TEST_SPI_HANDLER(), and run_spi_trans_test().
TX interrupt occurred.
Referenced by CONF_TEST_SPI_HANDLER(), and run_spi_trans_test().