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 |
Referenced by spi_slave_initialize(), and XDMAC_Handler().
#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) |
Referenced by spi_master_initialize(), and spi_slave_initialize().
#define SPI_CHIP_SEL 0 |
Referenced by spi_master_initialize(), and spi_slave_initialize().
#define SPI_CLK_PHASE 0 |
Referenced by spi_master_initialize(), and spi_slave_initialize().
#define SPI_CLK_POLARITY 0 |
Referenced by spi_master_initialize(), and spi_slave_initialize().
#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 |
Referenced by main().
#define XDMAC_RX_CH 1 |
Referenced by spi_disable_xdmac(), spi_xdmac_configure(), and XDMAC_Handler().
#define XDMAC_TX_CH 0 |
XDMAC channel used in this example.
Referenced by spi_disable_xdmac(), and spi_xdmac_configure().
|
static |
Configure the Console UART.
References uart_rs232_options::baudrate, CONF_UART, CONF_UART_BAUDRATE, CONF_UART_CHAR_LENGTH, CONF_UART_PARITY, CONF_UART_STOP_BITS, and stdio_serial_init().
Referenced by main().
|
static |
int main | ( | void | ) |
Application entry point for SPI example.
References board_init(), configure_console(), display_menu(), NUM_SPCK_CONFIGURATIONS, spi_disable_xdmac(), SPI_IRQn, spi_master_go(), spi_set_clock_configuration(), spi_slave_initialize(), spi_xdmac_configure(), STRING_HEADER, and sysclk_init().
|
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 |
Start SPI transfer test.
Configure xdamc for spi0 and ready to transfer
References spi_master_initialize(), and spi_xdmac_configure().
Referenced by main().
|
static |
Initialize SPI as master.
References MASTER_MODE, SPI_CHIP_PCS, SPI_CHIP_SEL, SPI_CLK_PHASE, SPI_CLK_POLARITY, spi_disable(), spi_disable_mode_fault_detect(), SPI_DLYBCT, SPI_DLYBS, spi_enable(), spi_enable_clock(), SPI_MASTER_BASE, 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(), and sysclk_get_peripheral_hz().
Referenced by spi_master_go(), and spi_set_clock_configuration().
|
static |
Set the specified SPI clock configuration.
configuration | Index of the configuration to set. |
References spi_disable_xdmac(), SPI_IRQn, spi_master_initialize(), and spi_xdmac_configure().
Referenced by main().
|
static |
Initialize SPI as slave.
References SLAVE_MODE, SPI_CHIP_PCS, SPI_CHIP_SEL, SPI_CLK_PHASE, SPI_CLK_POLARITY, spi_disable(), spi_disable_mode_fault_detect(), spi_enable(), spi_enable_clock(), spi_reset(), spi_set_bits_per_transfer(), spi_set_clock_phase(), spi_set_clock_polarity(), spi_set_peripheral_chip_select_value(), spi_set_slave_mode(), and SPI_SLAVE_BASE.
Referenced by main().
|
static |
configure xdmac for spi and ready to transfer/receive.
pspi | Base address of the SPI |
References g_size, xdmac_channel_config_t::mbr_bc, xdmac_channel_config_t::mbr_cfg, xdmac_channel_config_t::mbr_da, xdmac_channel_config_t::mbr_ds, xdmac_channel_config_t::mbr_dus, xdmac_channel_config_t::mbr_sa, xdmac_channel_config_t::mbr_sus, xdmac_channel_config_t::mbr_ubc, pmc_enable_periph_clk(), SPI0_XDMAC_RX_CH_NUM, SPI0_XDMAC_TX_CH_NUM, xdmac_channel_enable(), xdmac_channel_enable_interrupt(), xdmac_channel_set_descriptor_control(), xdmac_configure_transfer(), xdmac_enable_interrupt(), XDMAC_RX_CH, and XDMAC_TX_CH.
Referenced by main(), spi_master_go(), spi_set_clock_configuration(), and XDMAC_Handler().
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 |
|
static |
|
static |
uint8_t rx_buffer[BUFFER_SIZE] = "0" |
uint8_t tx_buffer[] = "This is message from SPI master transferred by XDMAC test" |
|
static |
|
static |
XDMAC channel configuration.