Macros | Typedefs | Enumerations | Functions
drivers/spi/spi.h File Reference

Serial Peripheral Interface (SPI) driver for SAM. More...

#include "compiler.h"
Include dependency graph for drivers/spi/spi.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define spi_get_pcs(chip_sel_id)   ((~(1u<<(chip_sel_id)))&0xF)
 Generate Peripheral Chip Select Value from Chip Select ID. More...
 
#define SPI_TIMEOUT   15000
 

Typedefs

typedef enum spi_cs_behavior spi_cs_behavior_t
 

Enumerations

enum  spi_cs_behavior { SPI_CS_KEEP_LOW = SPI_CSR_CSAAT, SPI_CS_RISE_NO_TX = 0, SPI_CS_RISE_FORCED = SPI_CSR_CSNAAT }
 
enum  spi_status_t {
  SPI_ERROR = -1, SPI_OK = 0, SPI_ERROR_TIMEOUT = 1, SPI_ERROR_ARGUMENT,
  SPI_ERROR_OVERRUN, SPI_ERROR_MODE_FAULT, SPI_ERROR_OVERRUN_AND_MODE_FAULT
}
 

Functions

int16_t spi_calc_baudrate_div (const uint32_t baudrate, uint32_t mck)
 Calculate the baudrate divider. More...
 
void spi_configure_cs_behavior (Spi *p_spi, uint32_t ul_pcs_ch, uint32_t ul_cs_behavior)
 Configure CS behavior for SPI transfer (spi_cs_behavior_t). More...
 
static void spi_disable (Spi *p_spi)
 Disable SPI. More...
 
void spi_disable_clock (Spi *p_spi)
 Disable SPI clock. More...
 
static void spi_disable_interrupt (Spi *p_spi, uint32_t ul_sources)
 Disable SPI interrupts. More...
 
static void spi_disable_loopback (Spi *p_spi)
 Disable loopback mode. More...
 
static void spi_disable_mode_fault_detect (Spi *p_spi)
 Disable Mode Fault Detection. More...
 
static void spi_disable_peripheral_select_decode (Spi *p_spi)
 Disable Peripheral Select Decode. More...
 
static void spi_disable_tx_on_rx_empty (Spi *p_spi)
 Disable waiting RX_EMPTY before transfer starts. More...
 
static void spi_enable (Spi *p_spi)
 Enable SPI. More...
 
void spi_enable_clock (Spi *p_spi)
 Enable SPI clock. More...
 
static void spi_enable_interrupt (Spi *p_spi, uint32_t ul_sources)
 Enable SPI interrupts. More...
 
static void spi_enable_loopback (Spi *p_spi)
 Enable loopback mode. More...
 
static void spi_enable_mode_fault_detect (Spi *p_spi)
 Enable Mode Fault Detection. More...
 
static void spi_enable_peripheral_select_decode (Spi *p_spi)
 Enable Peripheral Select Decode. More...
 
static void spi_enable_tx_on_rx_empty (Spi *p_spi)
 Enable waiting RX_EMPTY before transfer starts. More...
 
static uint16_t spi_get (Spi *p_spi)
 Get one data to a SPI peripheral. More...
 
static uint32_t spi_get_mode (Spi *p_spi)
 Get SPI work mode. More...
 
static uint32_t spi_get_mode_fault_detect_setting (Spi *p_spi)
 Check if mode fault detection is enabled. More...
 
static uint32_t spi_get_peripheral_select_decode_setting (Spi *p_spi)
 Get Peripheral Select Decode mode. More...
 
static uint32_t spi_get_peripheral_select_mode (Spi *p_spi)
 Get Peripheral Select mode. More...
 
static uint32_t spi_get_tx_on_rx_empty_setting (Spi *p_spi)
 Check if SPI waits RX_EMPTY before transfer starts. More...
 
uint32_t spi_get_writeprotect_status (Spi *p_spi)
 Indicate write protect status. More...
 
static uint32_t spi_is_enabled (Spi *p_spi)
 Test if the SPI is enabled. More...
 
static uint32_t spi_is_rx_full (Spi *p_spi)
 Check if the SPI contains a received character. More...
 
static uint32_t spi_is_rx_ready (Spi *p_spi)
 Check if all receptions are ready. More...
 
static uint32_t spi_is_tx_empty (Spi *p_spi)
 Check if all transmissions are complete. More...
 
static uint32_t spi_is_tx_ready (Spi *p_spi)
 Check if all transmissions are ready. More...
 
static void spi_put (Spi *p_spi, uint16_t data)
 Put one data to a SPI peripheral. More...
 
spi_status_t spi_read (Spi *p_spi, uint16_t *us_data, uint8_t *p_pcs)
 Read the received data and it's peripheral chip select value. While SPI works in fixed peripheral select mode, the peripheral chip select value is meaningless. More...
 
static uint32_t spi_read_interrupt_mask (Spi *p_spi)
 Read SPI interrupt mask. More...
 
static uint32_t spi_read_status (Spi *p_spi)
 Read status register. More...
 
static void spi_reset (Spi *p_spi)
 Reset SPI and set it to Slave mode. More...
 
int16_t spi_set_baudrate_div (Spi *p_spi, uint32_t ul_pcs_ch, uint8_t uc_baudrate_divider)
 Set Serial Clock Baud Rate divider value (SCBR). More...
 
void spi_set_bits_per_transfer (Spi *p_spi, uint32_t ul_pcs_ch, uint32_t ul_bits)
 Set number of bits per transfer. More...
 
void spi_set_clock_phase (Spi *p_spi, uint32_t ul_pcs_ch, uint32_t ul_phase)
 Set Data Capture Phase. More...
 
void spi_set_clock_polarity (Spi *p_spi, uint32_t ul_pcs_ch, uint32_t ul_polarity)
 Set clock default state. More...
 
void spi_set_delay_between_chip_select (Spi *p_spi, uint32_t ul_delay)
 Set delay between chip selects (in number of MCK clocks). If DLYBCS <= 6, 6 MCK clocks will be inserted by default. More...
 
static void spi_set_fixed_peripheral_select (Spi *p_spi)
 Set Fixed Peripheral Select. Peripheral Chip Select is controlled by SPI_MR. More...
 
static void spi_set_lastxfer (Spi *p_spi)
 Issue a LASTXFER command. The next transfer is the last transfer and after that CS is de-asserted. More...
 
static void spi_set_master_mode (Spi *p_spi)
 Set SPI to Master mode. More...
 
void spi_set_peripheral_chip_select_value (Spi *p_spi, uint32_t ul_value)
 Set Peripheral Chip Select (PCS) value. More...
 
static void spi_set_slave_mode (Spi *p_spi)
 Set SPI to Slave mode. More...
 
void spi_set_transfer_delay (Spi *p_spi, uint32_t ul_pcs_ch, uint8_t uc_dlybs, uint8_t uc_dlybct)
 Configure timing for SPI transfer. More...
 
static void spi_set_variable_peripheral_select (Spi *p_spi)
 Set Variable Peripheral Select. Peripheral Chip Select can be controlled by SPI_TDR. More...
 
void spi_set_writeprotect (Spi *p_spi, uint32_t ul_enable)
 Enable or disable write protection of SPI registers. More...
 
spi_status_t spi_write (Spi *p_spi, uint16_t us_data, uint8_t uc_pcs, uint8_t uc_last)
 Write the transmitted data with specified peripheral chip select value. More...
 

Detailed Description

Serial Peripheral Interface (SPI) driver for SAM.

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

Definition in file drivers/spi/spi.h.

Macro Definition Documentation

◆ spi_get_pcs

#define spi_get_pcs (   chip_sel_id)    ((~(1u<<(chip_sel_id)))&0xF)

Generate Peripheral Chip Select Value from Chip Select ID.

Note
When chip select n is working, PCS bit n is set to low level.
Parameters
chip_sel_idThe chip select number used

Definition at line 81 of file drivers/spi/spi.h.

◆ SPI_TIMEOUT

#define SPI_TIMEOUT   15000

Time-out value (number of attempts).

Definition at line 51 of file drivers/spi/spi.h.

Typedef Documentation

◆ spi_cs_behavior_t

SPI Chip Select behavior modes while transferring.

Enumeration Type Documentation

◆ spi_cs_behavior

SPI Chip Select behavior modes while transferring.

Enumerator
SPI_CS_KEEP_LOW 

CS does not rise until a new transfer is requested on different chip select.

SPI_CS_RISE_NO_TX 

CS rises if there is no more data to transfer.

SPI_CS_RISE_FORCED 

CS is de-asserted systematically during a time DLYBCS.

Definition at line 66 of file drivers/spi/spi.h.

◆ spi_status_t

Status codes used by the SPI driver.

Enumerator
SPI_ERROR 
SPI_OK 
SPI_ERROR_TIMEOUT 
SPI_ERROR_ARGUMENT 
SPI_ERROR_OVERRUN 
SPI_ERROR_MODE_FAULT 
SPI_ERROR_OVERRUN_AND_MODE_FAULT 

Definition at line 54 of file drivers/spi/spi.h.

Function Documentation

◆ spi_disable()

static void spi_disable ( Spi p_spi)
inlinestatic

Disable SPI.

Note
CS is de-asserted, which indicates that the last data is done, and user should check TX_EMPTY before disabling SPI.
Parameters
p_spiPointer to an SPI instance.

Definition at line 111 of file drivers/spi/spi.h.

◆ spi_disable_interrupt()

static void spi_disable_interrupt ( Spi p_spi,
uint32_t  ul_sources 
)
inlinestatic

Disable SPI interrupts.

Parameters
p_spiPointer to an SPI instance.
ul_sourcesInterrupts to be disabled.

Definition at line 472 of file drivers/spi/spi.h.

◆ spi_disable_loopback()

static void spi_disable_loopback ( Spi p_spi)
inlinestatic

Disable loopback mode.

Parameters
p_spiPointer to an SPI instance.

Definition at line 324 of file drivers/spi/spi.h.

◆ spi_disable_mode_fault_detect()

static void spi_disable_mode_fault_detect ( Spi p_spi)
inlinestatic

Disable Mode Fault Detection.

Parameters
p_spiPointer to an SPI instance.

Definition at line 252 of file drivers/spi/spi.h.

◆ spi_disable_peripheral_select_decode()

static void spi_disable_peripheral_select_decode ( Spi p_spi)
inlinestatic

Disable Peripheral Select Decode.

Parameters
p_spiPointer to an SPI instance.

Definition at line 216 of file drivers/spi/spi.h.

◆ spi_disable_tx_on_rx_empty()

static void spi_disable_tx_on_rx_empty ( Spi p_spi)
inlinestatic

Disable waiting RX_EMPTY before transfer starts.

Parameters
p_spiPointer to an SPI instance.

Definition at line 288 of file drivers/spi/spi.h.

◆ spi_enable()

static void spi_enable ( Spi p_spi)
inlinestatic

Enable SPI.

Parameters
p_spiPointer to an SPI instance.

Definition at line 98 of file drivers/spi/spi.h.

◆ spi_enable_interrupt()

static void spi_enable_interrupt ( Spi p_spi,
uint32_t  ul_sources 
)
inlinestatic

Enable SPI interrupts.

Parameters
p_spiPointer to an SPI instance.
ul_sourcesInterrupts to be enabled.

Definition at line 461 of file drivers/spi/spi.h.

◆ spi_enable_loopback()

static void spi_enable_loopback ( Spi p_spi)
inlinestatic

Enable loopback mode.

Parameters
p_spiPointer to an SPI instance.

Definition at line 314 of file drivers/spi/spi.h.

◆ spi_enable_mode_fault_detect()

static void spi_enable_mode_fault_detect ( Spi p_spi)
inlinestatic

Enable Mode Fault Detection.

Parameters
p_spiPointer to an SPI instance.

Definition at line 242 of file drivers/spi/spi.h.

◆ spi_enable_peripheral_select_decode()

static void spi_enable_peripheral_select_decode ( Spi p_spi)
inlinestatic

Enable Peripheral Select Decode.

Parameters
p_spiPointer to an SPI instance.

Definition at line 206 of file drivers/spi/spi.h.

◆ spi_enable_tx_on_rx_empty()

static void spi_enable_tx_on_rx_empty ( Spi p_spi)
inlinestatic

Enable waiting RX_EMPTY before transfer starts.

Parameters
p_spiPointer to an SPI instance.

Definition at line 278 of file drivers/spi/spi.h.

◆ spi_get()

static uint16_t spi_get ( Spi p_spi)
inlinestatic

Get one data to a SPI peripheral.

Parameters
p_spiBase address of the SPI instance.
Returns
The data byte

Definition at line 383 of file drivers/spi/spi.h.

◆ spi_get_mode()

static uint32_t spi_get_mode ( Spi p_spi)
inlinestatic

Get SPI work mode.

Parameters
p_spiPointer to an SPI instance.
Returns
1 for master mode, 0 for slave mode.

Definition at line 154 of file drivers/spi/spi.h.

◆ spi_get_mode_fault_detect_setting()

static uint32_t spi_get_mode_fault_detect_setting ( Spi p_spi)
inlinestatic

Check if mode fault detection is enabled.

Parameters
p_spiPointer to an SPI instance.
Returns
1 for disabled, 0 for enabled.

Definition at line 264 of file drivers/spi/spi.h.

◆ spi_get_peripheral_select_decode_setting()

static uint32_t spi_get_peripheral_select_decode_setting ( Spi p_spi)
inlinestatic

Get Peripheral Select Decode mode.

Parameters
p_spiPointer to an SPI instance.
Returns
1 for decode mode, 0 for direct mode.

Definition at line 228 of file drivers/spi/spi.h.

◆ spi_get_peripheral_select_mode()

static uint32_t spi_get_peripheral_select_mode ( Spi p_spi)
inlinestatic

Get Peripheral Select mode.

Parameters
p_spiPointer to an SPI instance.
Returns
1 for Variable mode, 0 for fixed mode.

Definition at line 192 of file drivers/spi/spi.h.

◆ spi_get_tx_on_rx_empty_setting()

static uint32_t spi_get_tx_on_rx_empty_setting ( Spi p_spi)
inlinestatic

Check if SPI waits RX_EMPTY before transfer starts.

Parameters
p_spiPointer to an SPI instance.
Returns
1 for SPI waits, 0 for no wait.

Definition at line 300 of file drivers/spi/spi.h.

◆ spi_is_enabled()

static uint32_t spi_is_enabled ( Spi p_spi)
inlinestatic

Test if the SPI is enabled.

Parameters
p_spiPointer to an SPI instance.
Returns
1 if the SPI is enabled, otherwise 0.

Definition at line 356 of file drivers/spi/spi.h.

◆ spi_is_rx_full()

static uint32_t spi_is_rx_full ( Spi p_spi)
inlinestatic

Check if the SPI contains a received character.

Parameters
p_spiPointer to an SPI instance.
Returns
1 if the SPI Receive Holding Register is full, otherwise 0.

Definition at line 429 of file drivers/spi/spi.h.

◆ spi_is_rx_ready()

static uint32_t spi_is_rx_ready ( Spi p_spi)
inlinestatic

Check if all receptions are ready.

Parameters
p_spiPointer to an SPI instance.
Returns
1 if the SPI Receiver is ready, otherwise 0.

Definition at line 445 of file drivers/spi/spi.h.

◆ spi_is_tx_empty()

static uint32_t spi_is_tx_empty ( Spi p_spi)
inlinestatic

Check if all transmissions are complete.

Parameters
p_spiPointer to an SPI instance.
Return values
1if transmissions are complete.
0if transmissions are not complete.

Definition at line 396 of file drivers/spi/spi.h.

◆ spi_is_tx_ready()

static uint32_t spi_is_tx_ready ( Spi p_spi)
inlinestatic

Check if all transmissions are ready.

Parameters
p_spiPointer to an SPI instance.
Return values
1if transmissions are complete.
0if transmissions are not complete.

Definition at line 413 of file drivers/spi/spi.h.

◆ spi_put()

static void spi_put ( Spi p_spi,
uint16_t  data 
)
inlinestatic

Put one data to a SPI peripheral.

Parameters
p_spiBase address of the SPI instance.
dataThe data byte to be loaded

Definition at line 372 of file drivers/spi/spi.h.

◆ spi_read_interrupt_mask()

static uint32_t spi_read_interrupt_mask ( Spi p_spi)
inlinestatic

Read SPI interrupt mask.

Parameters
p_spiPointer to an SPI instance.
Returns
The interrupt mask value.

Definition at line 484 of file drivers/spi/spi.h.

◆ spi_read_status()

static uint32_t spi_read_status ( Spi p_spi)
inlinestatic

Read status register.

Parameters
p_spiPointer to an SPI instance.
Returns
SPI status register value.

Definition at line 344 of file drivers/spi/spi.h.

◆ spi_reset()

static void spi_reset ( Spi p_spi)
inlinestatic

Reset SPI and set it to Slave mode.

Parameters
p_spiPointer to an SPI instance.

Definition at line 88 of file drivers/spi/spi.h.

◆ spi_set_fixed_peripheral_select()

static void spi_set_fixed_peripheral_select ( Spi p_spi)
inlinestatic

Set Fixed Peripheral Select. Peripheral Chip Select is controlled by SPI_MR.

Parameters
p_spiPointer to an SPI instance.

Definition at line 180 of file drivers/spi/spi.h.

◆ spi_set_lastxfer()

static void spi_set_lastxfer ( Spi p_spi)
inlinestatic

Issue a LASTXFER command. The next transfer is the last transfer and after that CS is de-asserted.

Parameters
p_spiPointer to an SPI instance.

Definition at line 122 of file drivers/spi/spi.h.

◆ spi_set_master_mode()

static void spi_set_master_mode ( Spi p_spi)
inlinestatic

Set SPI to Master mode.

Parameters
p_spiPointer to an SPI instance.

Definition at line 132 of file drivers/spi/spi.h.

◆ spi_set_slave_mode()

static void spi_set_slave_mode ( Spi p_spi)
inlinestatic

Set SPI to Slave mode.

Parameters
p_spiPointer to an SPI instance.

Definition at line 142 of file drivers/spi/spi.h.

◆ spi_set_variable_peripheral_select()

static void spi_set_variable_peripheral_select ( Spi p_spi)
inlinestatic

Set Variable Peripheral Select. Peripheral Chip Select can be controlled by SPI_TDR.

Parameters
p_spiPointer to an SPI instance.

Definition at line 169 of file drivers/spi/spi.h.



inertial_sense_ros
Author(s):
autogenerated on Sat Sep 19 2020 03:19:07