Serial Peripheral Interface (SPI) DMA slave example for SAM.
Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
Data Structures | |
struct | status_block_t |
Macros | |
#define | BOARD_SPI_DMAC_RX_CH 0 |
DMAC receive channel of master. More... | |
#define | BOARD_SPI_DMAC_TX_CH 1 |
DMAC transmit channel of master. More... | |
#define | CMD_DATA 0x29380000 |
#define | CMD_DATA_MSK 0xFFFF0000 |
#define | CMD_END 0x68390484 |
#define | CMD_STATUS 0x68390384 |
#define | CMD_TEST 0x10101010 |
#define | COMM_BUFFER_SIZE 64 |
#define | DATA_BLOCK_MSK 0x0000FFFF |
#define | MAX_DATA_BLOCK_NUMBER 4 |
#define | MAX_RETRY 4 |
#define | NB_STATUS_CMD 20 |
#define | NUM_SPCK_CONFIGURATIONS 4 |
#define | RC_RDY 0x12345678 |
#define | RC_SYN 0x55AA55AA |
#define | SLAVE_STATE_DATA 2 |
#define | SLAVE_STATE_END 5 |
#define | SLAVE_STATE_IDLE 0 |
#define | SLAVE_STATE_STATUS 4 |
#define | SLAVE_STATE_STATUS_ENTRY 3 |
#define | SLAVE_STATE_TEST 1 |
#define | SPI_CHIP_SEL 0 |
#define | SPI_CLK_PHASE 0 |
#define | SPI_CLK_POLARITY 0 |
#define | SPI_DLYBCT 0x10 |
#define | SPI_DLYBS 0x08 |
#define | SPI_MASTER 0 |
SPI working role in the example. More... | |
#define | SPI_RX_IDX 2 |
#define | SPI_SLAVE 1 |
#define | SPI_TX_IDX 1 |
DMAC Channel HW Interface Number for SPI. More... | |
#define | STRING_EOL "\r" |
#define | STRING_HEADER |
#define | UART_BAUDRATE 115200 |
Functions | |
static void | configure_console (void) |
Configure the Console UART. More... | |
static void | configure_dmac (void) |
DMAC driver configuration. More... | |
static void | display_menu (void) |
Display the user menu on the terminal. More... | |
void | DMAC_Handler (void) |
Interrupt handler for the DMAC. More... | |
uint32_t | main (void) |
Application entry point for spi_slave example. 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_master_transfer (void *p_buf, uint32_t ul_size) |
Perform SPI master transfer. More... | |
static void | spi_set_clock_configuration (uint8_t configuration) |
Set the specified SPI clock configuration. More... | |
static void | spi_slave_command_process (void) |
SPI command block process. More... | |
static void | spi_slave_initialize (void) |
Initialize SPI as slave. More... | |
static void | spi_slave_new_command (void) |
Start waiting new command. More... | |
static void | spi_slave_transfer (void *p_buf, uint32_t ul_size) |
Set SPI slave transfer. More... | |
Variables | |
uint8_t | g_uc_role |
uint8_t | g_uc_spi_buffer [COMM_BUFFER_SIZE] |
const uint32_t | g_ul_clock_configurations [] |
uint32_t | g_ul_master_cmd |
volatile uint32_t | g_ul_master_recv_done |
uint32_t | g_ul_slave_cmd = RC_SYN |
uint32_t | g_ul_spi_clock |
uint32_t | g_ul_spi_state = 0 |
uint32_t | g_ul_test_block_number |
struct status_block_t | spi_status |
#define BOARD_SPI_DMAC_RX_CH 0 |
DMAC receive channel of master.
Referenced by configure_dmac(), DMAC_Handler(), spi_master_initialize(), spi_master_transfer(), spi_slave_initialize(), and spi_slave_transfer().
#define BOARD_SPI_DMAC_TX_CH 1 |
DMAC transmit channel of master.
Referenced by configure_dmac(), spi_master_initialize(), spi_master_transfer(), spi_slave_initialize(), and spi_slave_transfer().
#define CMD_DATA 0x29380000 |
Referenced by spi_master_go(), and spi_slave_command_process().
#define CMD_DATA_MSK 0xFFFF0000 |
Referenced by spi_slave_command_process().
#define CMD_END 0x68390484 |
Referenced by DMAC_Handler(), spi_master_go(), and spi_slave_command_process().
#define CMD_STATUS 0x68390384 |
Referenced by spi_master_go().
#define CMD_TEST 0x10101010 |
Referenced by spi_master_go(), and spi_slave_command_process().
#define COMM_BUFFER_SIZE 64 |
Referenced by spi_master_go(), and spi_slave_new_command().
#define DATA_BLOCK_MSK 0x0000FFFF |
Referenced by spi_slave_command_process().
#define MAX_DATA_BLOCK_NUMBER 4 |
Referenced by spi_master_go().
#define MAX_RETRY 4 |
Referenced by spi_master_go().
#define NB_STATUS_CMD 20 |
Referenced by spi_slave_initialize().
#define NUM_SPCK_CONFIGURATIONS 4 |
Referenced by display_menu(), and main().
#define RC_RDY 0x12345678 |
Referenced by spi_master_go(), and spi_slave_new_command().
#define RC_SYN 0x55AA55AA |
Referenced by spi_master_go(), spi_slave_initialize(), and spi_slave_new_command().
#define SLAVE_STATE_DATA 2 |
Referenced by spi_slave_command_process(), and spi_slave_new_command().
#define SLAVE_STATE_END 5 |
Referenced by spi_slave_command_process(), and spi_slave_new_command().
#define SLAVE_STATE_IDLE 0 |
Referenced by spi_slave_command_process(), spi_slave_initialize(), and spi_slave_new_command().
#define SLAVE_STATE_STATUS 4 |
Referenced by spi_slave_command_process(), and spi_slave_new_command().
#define SLAVE_STATE_STATUS_ENTRY 3 |
Referenced by spi_slave_command_process(), and spi_slave_new_command().
#define SLAVE_STATE_TEST 1 |
Referenced by spi_slave_command_process(), and spi_slave_new_command().
#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 0x08 |
Referenced by spi_master_initialize().
#define SPI_MASTER 0 |
SPI working role in the example.
Referenced by display_menu(), DMAC_Handler(), and spi_master_initialize().
#define SPI_RX_IDX 2 |
Referenced by configure_dmac().
#define SPI_SLAVE 1 |
Referenced by spi_slave_initialize().
#define SPI_TX_IDX 1 |
DMAC Channel HW Interface Number for SPI.
Referenced by configure_dmac().
#define STRING_EOL "\r" |
#define STRING_HEADER |
Referenced by main().
#define UART_BAUDRATE 115200 |
|
static |
Configure the Console UART.
References uart_rs232_options::baudrate, CONF_UART, CONF_UART_BAUDRATE, CONF_UART_PARITY, CONSOLE_UART_ID, stdio_serial_init(), and sysclk_enable_peripheral_clock().
Referenced by main().
|
static |
DMAC driver configuration.
References BOARD_SPI_DMAC_RX_CH, BOARD_SPI_DMAC_TX_CH, dmac_channel_set_configuration(), dmac_enable(), dmac_enable_interrupt(), dmac_init(), DMAC_PRIORITY_ROUND_ROBIN, dmac_set_priority_mode(), pmc_enable_periph_clk(), SPI_RX_IDX, and SPI_TX_IDX.
Referenced by main().
|
static |
Display the user menu on the terminal.
References NUM_SPCK_CONFIGURATIONS, and SPI_MASTER.
Referenced by main().
void DMAC_Handler | ( | void | ) |
Interrupt handler for the DMAC.
References BOARD_SPI_DMAC_RX_CH, CMD_END, dmac_get_status(), g_ul_slave_cmd, SPI_MASTER, spi_slave_command_process(), spi_slave_new_command(), spi_status, status_block_t::ul_cmd_list, and status_block_t::ul_total_command_number.
uint32_t main | ( | void | ) |
Application entry point for spi_slave example.
References board_init(), configure_console(), configure_dmac(), CONSOLE_UART, display_menu(), NUM_SPCK_CONFIGURATIONS, spi_master_go(), spi_master_initialize(), spi_set_clock_configuration(), spi_slave_initialize(), STRING_HEADER, sysclk_init(), and uart_read().
|
static |
Start SPI transfer test.
References CMD_DATA, CMD_END, CMD_STATUS, CMD_TEST, COMM_BUFFER_SIZE, MAX_DATA_BLOCK_NUMBER, MAX_RETRY, RC_RDY, RC_SYN, spi_master_transfer(), spi_status, status_block_t::ul_cmd_list, status_block_t::ul_total_block_number, and status_block_t::ul_total_command_number.
Referenced by main().
|
static |
Initialize SPI as master.
References BOARD_SPI_DMAC_RX_CH, BOARD_SPI_DMAC_TX_CH, dmac_channel_disable(), pmc_enable_periph_clk(), SPI_CHIP_SEL, SPI_CLK_PHASE, SPI_CLK_POLARITY, spi_disable(), spi_disable_mode_fault_detect(), SPI_DLYBCT, SPI_DLYBS, spi_enable(), spi_get_pcs, SPI_ID, SPI_MASTER, 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 main().
|
static |
Perform SPI master transfer.
pbuf | Pointer to buffer to transfer. |
ul_size | Size of the buffer. |
References BOARD_SPI_DMAC_RX_CH, BOARD_SPI_DMAC_TX_CH, dmac_channel_disable(), dmac_channel_enable(), dmac_channel_single_buf_transfer_init(), SPI_MASTER_BASE, dma_transfer_descriptor_t::ul_ctrlA, dma_transfer_descriptor_t::ul_ctrlB, dma_transfer_descriptor_t::ul_descriptor_addr, dma_transfer_descriptor_t::ul_destination_addr, and dma_transfer_descriptor_t::ul_source_addr.
Referenced by spi_master_go().
|
static |
Set the specified SPI clock configuration.
configuration | Index of the configuration to set. |
Referenced by main().
|
static |
SPI command block process.
References CMD_DATA, CMD_DATA_MSK, CMD_END, CMD_TEST, DATA_BLOCK_MSK, SLAVE_STATE_DATA, SLAVE_STATE_END, SLAVE_STATE_IDLE, SLAVE_STATE_STATUS, SLAVE_STATE_STATUS_ENTRY, SLAVE_STATE_TEST, spi_status, status_block_t::ul_total_block_number, and status_block_t::ul_total_command_number.
Referenced by DMAC_Handler().
|
static |
Initialize SPI as slave.
References BOARD_SPI_DMAC_RX_CH, BOARD_SPI_DMAC_TX_CH, dmac_channel_disable(), NB_STATUS_CMD, pmc_enable_periph_clk(), RC_SYN, SLAVE_STATE_IDLE, SPI_CHIP_SEL, SPI_CLK_PHASE, SPI_CLK_POLARITY, spi_disable(), spi_disable_mode_fault_detect(), spi_enable(), spi_get_pcs, SPI_ID, 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(), SPI_SLAVE, SPI_SLAVE_BASE, spi_slave_transfer(), spi_status, status_block_t::ul_cmd_list, status_block_t::ul_total_block_number, and status_block_t::ul_total_command_number.
Referenced by main().
|
static |
Start waiting new command.
References COMM_BUFFER_SIZE, RC_RDY, RC_SYN, SLAVE_STATE_DATA, SLAVE_STATE_END, SLAVE_STATE_IDLE, SLAVE_STATE_STATUS, SLAVE_STATE_STATUS_ENTRY, SLAVE_STATE_TEST, spi_slave_transfer(), spi_status, and status_block_t::ul_total_block_number.
Referenced by DMAC_Handler().
|
static |
Set SPI slave transfer.
p_buf | Pointer to buffer to transfer. |
ul_size | Size of the buffer. |
References BOARD_SPI_DMAC_RX_CH, BOARD_SPI_DMAC_TX_CH, dmac_channel_disable(), dmac_channel_enable(), dmac_channel_single_buf_transfer_init(), SPI_SLAVE_BASE, dma_transfer_descriptor_t::ul_ctrlA, dma_transfer_descriptor_t::ul_ctrlB, dma_transfer_descriptor_t::ul_descriptor_addr, dma_transfer_descriptor_t::ul_destination_addr, and dma_transfer_descriptor_t::ul_source_addr.
Referenced by spi_slave_initialize(), and spi_slave_new_command().
uint8_t g_uc_role |
uint8_t g_uc_spi_buffer[COMM_BUFFER_SIZE] |
const uint32_t g_ul_clock_configurations[] |
uint32_t g_ul_master_cmd |
volatile uint32_t g_ul_master_recv_done |
uint32_t g_ul_slave_cmd = RC_SYN |
Referenced by DMAC_Handler().
uint32_t g_ul_spi_clock |
uint32_t g_ul_spi_state = 0 |
uint32_t g_ul_test_block_number |
struct status_block_t spi_status |
Referenced by DMAC_Handler(), spi_master_go(), spi_slave_command_process(), spi_slave_initialize(), and spi_slave_new_command().