Microchip® Advanced Software Framework

spi_dmac_slave_example.c File Reference

Serial Peripheral Interface (SPI) DMA slave example for SAM.

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

#include <asf.h>
#include "conf_example.h"

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
#define BOARD_SPI_DMAC_TX_CH   1
#define CMD_DATA   0x29380000
#define CMD_DATA_MSK   0xFFFF0000
#define CMD_END   0x68390484
#define CMD_STATUS   0x68390384

Referenced by spi_master_go().

#define CMD_TEST   0x10101010
#define COMM_BUFFER_SIZE   64
#define DATA_BLOCK_MSK   0x0000FFFF
#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
#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

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
Value:
"-- Spi DMA Slave Example --\r\n" \
"-- "BOARD_NAME" --\r\n" \
"-- Compiled: "__DATE__" "__TIME__" --"STRING_EOL
#define BOARD_NAME
Definition: sam3x_ek.h:81
#define STRING_EOL
Definition: spi_dmac_slave_example.c:167

Referenced by main().

#define UART_BAUDRATE   115200

static void configure_console ( void  )
static
static void display_menu ( void  )
static

Display the user menu on the terminal.

References NUM_SPCK_CONFIGURATIONS, and SPI_MASTER.

Referenced by main().

uint32_t main ( void  )
static void spi_master_transfer ( void *  p_buf,
uint32_t  ul_size 
)
static
static void spi_set_clock_configuration ( uint8_t  configuration)
static

Set the specified SPI clock configuration.

Parameters
configurationIndex of the configuration to set.

Referenced by main().

uint8_t g_uc_role
uint8_t g_uc_spi_buffer[COMM_BUFFER_SIZE]
const uint32_t g_ul_clock_configurations[]
Initial value:
=
{ 500000, 1000000, 2000000, 5000000 }
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