Serial Peripheral Interface (SPI) example for SAM.
Copyright (c) 2011-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"
#include "flexcom.h"
Data Structures | |
struct | status_block_t |
Macros | |
#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_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 | UART_BAUDRATE 115200 |
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... | |
void | SPI_Handler (void) |
Interrupt handler for the SPI slave. 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 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 size) |
Set SPI slave transfer. More... | |
Variables | |
static uint8_t * | gs_puc_transfer_buffer |
static struct status_block_t | gs_spi_status |
static uint8_t | gs_uc_spi_buffer [COMM_BUFFER_SIZE] |
static const uint32_t | gs_ul_clock_configurations [] |
static uint32_t | gs_ul_spi_clock = 500000 |
static uint32_t | gs_ul_spi_cmd = RC_SYN |
static uint32_t | gs_ul_spi_state = 0 |
static uint32_t | gs_ul_test_block_number |
static uint32_t | gs_ul_transfer_index |
static uint32_t | gs_ul_transfer_length |
#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 SPI_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_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 UART_BAUDRATE 115200 |
|
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_IRQn, spi_master_go(), spi_set_clock_configuration(), spi_slave_initialize(), STRING_HEADER, and sysclk_init().
void SPI_Handler | ( | void | ) |
Interrupt handler for the SPI slave.
References CMD_END, gs_spi_status, gs_ul_spi_cmd, gs_ul_transfer_index, spi_read(), spi_read_status(), SPI_SLAVE_BASE, spi_slave_command_process(), spi_slave_new_command(), spi_write(), status_block_t::ul_cmd_list, and status_block_t::ul_total_command_number.
|
static |
Start SPI transfer test.
References CMD_DATA, CMD_END, CMD_STATUS, CMD_TEST, COMM_BUFFER_SIZE, gs_spi_status, MAX_DATA_BLOCK_NUMBER, MAX_RETRY, RC_RDY, RC_SYN, spi_master_initialize(), spi_master_transfer(), 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 SAM4L, 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_pba_hz().
Referenced by spi_master_go(), and spi_set_clock_configuration().
|
static |
Perform SPI master transfer.
pbuf | Pointer to buffer to transfer. |
size | Size of the buffer. |
References SPI_MASTER_BASE, spi_read(), spi_read_status(), and spi_write().
Referenced by spi_master_go().
|
static |
Set the specified SPI clock configuration.
configuration | Index of the configuration to set. |
References spi_master_initialize().
Referenced by main().
|
static |
SPI command block process.
References CMD_DATA, CMD_DATA_MSK, CMD_END, CMD_TEST, DATA_BLOCK_MSK, gs_spi_status, SLAVE_STATE_DATA, SLAVE_STATE_END, SLAVE_STATE_IDLE, SLAVE_STATE_STATUS, SLAVE_STATE_STATUS_ENTRY, SLAVE_STATE_TEST, status_block_t::ul_total_block_number, and status_block_t::ul_total_command_number.
Referenced by SPI_Handler().
|
static |
Initialize SPI as slave.
References gs_spi_status, NB_STATUS_CMD, RC_SYN, SLAVE_STATE_IDLE, 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_enable_interrupt(), 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_BASE, spi_slave_transfer(), 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, gs_spi_status, 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(), and status_block_t::ul_total_block_number.
Referenced by SPI_Handler().
|
static |
Set SPI slave transfer.
p_buf | Pointer to buffer to transfer. |
size | Size of the buffer. |
References SPI_SLAVE_BASE, and spi_write().
Referenced by spi_slave_initialize(), and spi_slave_new_command().
|
static |
|
static |
Referenced by SPI_Handler(), spi_master_go(), spi_slave_command_process(), spi_slave_initialize(), and spi_slave_new_command().
|
static |
|
static |
|
static |
|
static |
Referenced by SPI_Handler().
|
static |
|
static |
|
static |
Referenced by SPI_Handler().
|
static |