Microchip® Advanced Software Framework

sam/drivers/spi/unit_tests/unit_tests.c File Reference

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

Test SPI setting.

This test tests SPI reset/enable/disable.

Parameters
testCurrent test case.

References SAM4L, spi_enable(), spi_enable_clock(), spi_is_enabled(), spi_reset(), and test_assert_true.

Referenced by main().

static void run_spi_writeprotect_test ( const struct test_case test)
static

Test SPI write protection.

Parameters
testCurrent test case.

References OFFSET_CSR, OFFSET_MR, spi_get_writeprotect_status(), spi_set_writeprotect(), and test_assert_true.

Referenced by main().

volatile bool g_b_spi_interrupt_rx_ready = false

RX interrupt occurred.

Referenced by CONF_TEST_SPI_HANDLER(), and run_spi_trans_test().

volatile bool g_b_spi_interrupt_tx_ready = false

TX interrupt occurred.

Referenced by CONF_TEST_SPI_HANDLER(), and run_spi_trans_test().