Microchip® Advanced Software Framework

spi_xdmac_example.c File Reference

Serial Peripheral Interface (SPI) XDMAC example for SAMV71/SAME70.

Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.

#include "asf.h"
#include "stdio_serial.h"
#include "conf_board.h"
#include "conf_clock.h"
#include "conf_spi_example.h"

Macros

#define BUFFER_SIZE   100
 The buffer size for transfer. More...
 
#define MASTER_MODE   0
 spi mode definition More...
 
#define NUM_SPCK_CONFIGURATIONS   4
 
#define SLAVE_MODE   1
 
#define SPI0_XDMAC_RX_CH_NUM   2
 
#define SPI0_XDMAC_TX_CH_NUM   1
 XDMAC channel HW Interface number for SPI0,refer to datasheet. More...
 
#define SPI_CHIP_PCS   spi_get_pcs(SPI_CHIP_SEL)
 
#define SPI_CHIP_SEL   0
 
#define SPI_CLK_PHASE   0
 
#define SPI_CLK_POLARITY   0
 
#define SPI_DLYBCT   0x10
 
#define SPI_DLYBS   0x40
 
#define STRING_EOL   "\r"
 
#define STRING_HEADER
 
#define XDMAC_RX_CH   1
 
#define XDMAC_TX_CH   0
 XDMAC channel used in this example. More...
 

Functions

static void configure_console (void)
 Configure the Console UART. More...
 
static void display_menu (void)
 Display the user menu on the terminal. More...
 
int main (void)
 Application entry point for SPI example. More...
 
static void spi_disable_xdmac (void)
 disable XDMAC for spi and forbidden transmit and receive by XDMAC. More...
 
static void spi_master_go (void)
 Start SPI transfer test. More...
 
static void spi_master_initialize (void)
 Initialize SPI as master. More...
 
static void spi_set_clock_configuration (uint8_t configuration)
 Set the specified SPI clock configuration. More...
 
static void spi_slave_initialize (void)
 Initialize SPI as slave. More...
 
static void spi_xdmac_configure (Spi *const pspi)
 configure xdmac for spi and ready to transfer/receive. More...
 
void XDMAC_Handler (void)
 XDMAC interrupt handler. More...
 

Variables

uint32_t g_size = sizeof(tx_buffer)
 
uint32_t g_uc_role
 
static const uint32_t gs_ul_clock_configurations []
 
static uint32_t gs_ul_spi_clock = 500000
 
uint8_t rx_buffer [BUFFER_SIZE] = "0"
 
uint8_t tx_buffer [] = "This is message from SPI master transferred by XDMAC test"
 
static xdmac_channel_config_t xdmac_rx_cfg
 
static xdmac_channel_config_t xdmac_tx_cfg
 XDMAC channel configuration. More...
 

#define BUFFER_SIZE   100

The buffer size for transfer.

#define MASTER_MODE   0

spi mode definition

Referenced by spi_master_initialize().

#define NUM_SPCK_CONFIGURATIONS   4

Referenced by display_menu(), and main().

#define SLAVE_MODE   1
#define SPI0_XDMAC_RX_CH_NUM   2

Referenced by spi_xdmac_configure().

#define SPI0_XDMAC_TX_CH_NUM   1

XDMAC channel HW Interface number for SPI0,refer to datasheet.

Referenced by spi_xdmac_configure().

#define SPI_CHIP_PCS   spi_get_pcs(SPI_CHIP_SEL)
#define SPI_CHIP_SEL   0
#define SPI_CLK_PHASE   0
#define SPI_CLK_POLARITY   0
#define SPI_DLYBCT   0x10

Referenced by spi_master_initialize().

#define SPI_DLYBS   0x40

Referenced by spi_master_initialize().

#define STRING_EOL   "\r"
#define STRING_HEADER
Value:
"--Spi XDMAC Example --\r\n" \
"-- "BOARD_NAME" --\r\n" \
"-- Compiled: "__DATE__" "__TIME__" --"STRING_EOL
#define BOARD_NAME
Definition: fatfs_access_example.c:112
#define STRING_EOL
Definition: spi_xdmac_example.c:148

Referenced by main().

#define XDMAC_RX_CH   1
#define XDMAC_TX_CH   0

XDMAC channel used in this example.

Referenced by spi_disable_xdmac(), and spi_xdmac_configure().

static void configure_console ( void  )
static

Configure the Console UART.

References uart_rs232_options::baudrate, and stdio_serial_init().

Referenced by main().

static void display_menu ( void  )
static

Display the user menu on the terminal.

References NUM_SPCK_CONFIGURATIONS.

Referenced by main().

int main ( void  )
static void spi_disable_xdmac ( void  )
static

disable XDMAC for spi and forbidden transmit and receive by XDMAC.

References xdmac_channel_disable(), xdmac_channel_disable_interrupt(), xdmac_disable_interrupt(), XDMAC_RX_CH, and XDMAC_TX_CH.

Referenced by main(), and spi_set_clock_configuration().

static void spi_master_go ( void  )
static

Start SPI transfer test.

Configure xdamc for spi0 and ready to transfer

References spi_master_initialize(), and spi_xdmac_configure().

Referenced by main().

static void spi_set_clock_configuration ( uint8_t  configuration)
static

Set the specified SPI clock configuration.

Parameters
configurationIndex of the configuration to set.

References spi_disable_xdmac(), spi_master_initialize(), and spi_xdmac_configure().

Referenced by main().

void XDMAC_Handler ( void  )

XDMAC interrupt handler.

re-configure receiver for next reception

References SLAVE_MODE, spi_disable(), spi_xdmac_configure(), xdmac_channel_get_interrupt_status(), and XDMAC_RX_CH.

uint32_t g_size = sizeof(tx_buffer)

Referenced by spi_xdmac_configure().

uint32_t g_uc_role
const uint32_t gs_ul_clock_configurations[]
static
Initial value:
=
{ 500000, 1000000, 2000000, 5000000 }
uint32_t gs_ul_spi_clock = 500000
static
uint8_t rx_buffer[BUFFER_SIZE] = "0"
uint8_t tx_buffer[] = "This is message from SPI master transferred by XDMAC test"
xdmac_channel_config_t xdmac_rx_cfg
static
xdmac_channel_config_t xdmac_tx_cfg
static

XDMAC channel configuration.