|
SAM4SD32 (SAM4S-EK2)
|
Serial Peripheral Interface (SPI) driver for SAM. More...
#include "compiler.h"Go to the source code of this file.
Macros | |
| #define | spi_get_pcs(chip_sel_id) |
| Generate Peripheral Chip Select Value from Chip Select ID. | |
| #define | SPI_TIMEOUT 15000 |
| Time-out value (number of attempts). | |
Typedefs | |
| typedef enum spi_cs_behavior | spi_cs_behavior_t |
| SPI Chip Select behavior modes while transferring. | |
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 } |
| SPI Chip Select behavior modes while transferring. More... | |
| 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 } |
| Status codes used by the SPI driver. More... | |
Functions | |
| int16_t | spi_calc_baudrate_div (const uint32_t baudrate, uint32_t mck) |
| Calculate the baudrate divider. | |
| 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). | |
| static void | spi_disable (Spi *p_spi) |
| Disable SPI. | |
| void | spi_disable_clock (Spi *p_spi) |
| Disable SPI clock. | |
| static void | spi_disable_interrupt (Spi *p_spi, uint32_t ul_sources) |
| Disable SPI interrupts. | |
| static void | spi_disable_loopback (Spi *p_spi) |
| Disable loopback mode. | |
| static void | spi_disable_mode_fault_detect (Spi *p_spi) |
| Disable Mode Fault Detection. | |
| static void | spi_disable_peripheral_select_decode (Spi *p_spi) |
| Disable Peripheral Select Decode. | |
| static void | spi_disable_tx_on_rx_empty (Spi *p_spi) |
| Disable waiting RX_EMPTY before transfer starts. | |
| static void | spi_enable (Spi *p_spi) |
| Enable SPI. | |
| void | spi_enable_clock (Spi *p_spi) |
| Enable SPI clock. | |
| static void | spi_enable_interrupt (Spi *p_spi, uint32_t ul_sources) |
| Enable SPI interrupts. | |
| static void | spi_enable_loopback (Spi *p_spi) |
| Enable loopback mode. | |
| static void | spi_enable_mode_fault_detect (Spi *p_spi) |
| Enable Mode Fault Detection. | |
| static void | spi_enable_peripheral_select_decode (Spi *p_spi) |
| Enable Peripheral Select Decode. | |
| static void | spi_enable_tx_on_rx_empty (Spi *p_spi) |
| Enable waiting RX_EMPTY before transfer starts. | |
| static uint16_t | spi_get (Spi *p_spi) |
| Get one data to a SPI peripheral. | |
| static uint32_t | spi_get_mode (Spi *p_spi) |
| Get SPI work mode. | |
| static uint32_t | spi_get_mode_fault_detect_setting (Spi *p_spi) |
| Check if mode fault detection is enabled. | |
| static Pdc * | spi_get_pdc_base (Spi *p_spi) |
| Get PDC registers base address. | |
| static uint32_t | spi_get_peripheral_select_decode_setting (Spi *p_spi) |
| Get Peripheral Select Decode mode. | |
| static uint32_t | spi_get_peripheral_select_mode (Spi *p_spi) |
| Get Peripheral Select mode. | |
| static uint32_t | spi_get_tx_on_rx_empty_setting (Spi *p_spi) |
| Check if SPI waits RX_EMPTY before transfer starts. | |
| uint32_t | spi_get_writeprotect_status (Spi *p_spi) |
| Indicate write protect status. | |
| static uint32_t | spi_is_enabled (Spi *p_spi) |
| Test if the SPI is enabled. | |
| static uint32_t | spi_is_rx_full (Spi *p_spi) |
| Check if the SPI contains a received character. | |
| static uint32_t | spi_is_rx_ready (Spi *p_spi) |
| Check if all receptions are ready. | |
| static uint32_t | spi_is_tx_empty (Spi *p_spi) |
| Check if all transmissions are complete. | |
| static uint32_t | spi_is_tx_ready (Spi *p_spi) |
| Check if all transmissions are ready. | |
| static void | spi_put (Spi *p_spi, uint16_t data) |
| Put one data to a SPI peripheral. | |
| 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. | |
| static uint32_t | spi_read_interrupt_mask (Spi *p_spi) |
| Read SPI interrupt mask. | |
| static uint32_t | spi_read_status (Spi *p_spi) |
| Read status register. | |
| static void | spi_reset (Spi *p_spi) |
| Reset SPI and set it to Slave mode. | |
| 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). | |
| void | spi_set_bits_per_transfer (Spi *p_spi, uint32_t ul_pcs_ch, uint32_t ul_bits) |
| Set number of bits per transfer. | |
| void | spi_set_clock_phase (Spi *p_spi, uint32_t ul_pcs_ch, uint32_t ul_phase) |
| Set Data Capture Phase. | |
| void | spi_set_clock_polarity (Spi *p_spi, uint32_t ul_pcs_ch, uint32_t ul_polarity) |
| Set clock default state. | |
| void | spi_set_delay_between_chip_select (Spi *p_spi, uint32_t ul_delay) |
| Set delay between chip selects (in number of MCK clocks). | |
| static void | spi_set_fixed_peripheral_select (Spi *p_spi) |
| Set Fixed Peripheral Select. | |
| static void | spi_set_lastxfer (Spi *p_spi) |
| Issue a LASTXFER command. | |
| static void | spi_set_master_mode (Spi *p_spi) |
| Set SPI to Master mode. | |
| void | spi_set_peripheral_chip_select_value (Spi *p_spi, uint32_t ul_value) |
| Set Peripheral Chip Select (PCS) value. | |
| static void | spi_set_slave_mode (Spi *p_spi) |
| Set SPI to Slave mode. | |
| 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. | |
| static void | spi_set_variable_peripheral_select (Spi *p_spi) |
| Set Variable Peripheral Select. | |
| void | spi_set_writeprotect (Spi *p_spi, uint32_t ul_enable) |
| Enable or disable write protection of SPI registers. | |
| 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. | |
Serial Peripheral Interface (SPI) driver for SAM.
Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
\cond ASF_LICENSE
Definition in file spi.h.
| #define spi_get_pcs | ( | chip_sel_id | ) |
| #define SPI_TIMEOUT 15000 |
Time-out value (number of attempts).
Definition at line 51 of file spi.h.
Referenced by spi_read(), and spi_write().
| typedef enum spi_cs_behavior spi_cs_behavior_t |
SPI Chip Select behavior modes while transferring.
| enum spi_cs_behavior |
SPI Chip Select behavior modes while transferring.
Definition at line 66 of file spi.h.
| enum 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 | |
|
inlinestatic |
Disable SPI.
| p_spi | Pointer to an SPI instance. |
Definition at line 111 of file spi.h.
References Spi::SPI_CR, and SPI_CR_SPIDIS.
|
inlinestatic |
Disable SPI interrupts.
| p_spi | Pointer to an SPI instance. |
| ul_sources | Interrupts to be disabled. |
Definition at line 472 of file spi.h.
References Spi::SPI_IDR.
|
inlinestatic |
Disable loopback mode.
| p_spi | Pointer to an SPI instance. |
Definition at line 324 of file spi.h.
References Spi::SPI_MR, and SPI_MR_LLB.
|
inlinestatic |
Disable Mode Fault Detection.
| p_spi | Pointer to an SPI instance. |
Definition at line 252 of file spi.h.
References Spi::SPI_MR, and SPI_MR_MODFDIS.
|
inlinestatic |
Disable Peripheral Select Decode.
| p_spi | Pointer to an SPI instance. |
Definition at line 216 of file spi.h.
References Spi::SPI_MR, and SPI_MR_PCSDEC.
|
inlinestatic |
Disable waiting RX_EMPTY before transfer starts.
| p_spi | Pointer to an SPI instance. |
Definition at line 288 of file spi.h.
References Spi::SPI_MR, and SPI_MR_WDRBT.
|
inlinestatic |
Enable SPI.
| p_spi | Pointer to an SPI instance. |
Definition at line 98 of file spi.h.
References Spi::SPI_CR, and SPI_CR_SPIEN.
|
inlinestatic |
Enable SPI interrupts.
| p_spi | Pointer to an SPI instance. |
| ul_sources | Interrupts to be enabled. |
Definition at line 461 of file spi.h.
References Spi::SPI_IER.
|
inlinestatic |
Enable loopback mode.
| p_spi | Pointer to an SPI instance. |
Definition at line 314 of file spi.h.
References Spi::SPI_MR, and SPI_MR_LLB.
|
inlinestatic |
Enable Mode Fault Detection.
| p_spi | Pointer to an SPI instance. |
Definition at line 242 of file spi.h.
References Spi::SPI_MR, and SPI_MR_MODFDIS.
|
inlinestatic |
Enable Peripheral Select Decode.
| p_spi | Pointer to an SPI instance. |
Definition at line 206 of file spi.h.
References Spi::SPI_MR, and SPI_MR_PCSDEC.
|
inlinestatic |
Enable waiting RX_EMPTY before transfer starts.
| p_spi | Pointer to an SPI instance. |
Definition at line 278 of file spi.h.
References Spi::SPI_MR, and SPI_MR_WDRBT.
|
inlinestatic |
Get one data to a SPI peripheral.
| p_spi | Base address of the SPI instance. |
Definition at line 383 of file spi.h.
References Spi::SPI_RDR, and SPI_RDR_RD_Msk.
|
inlinestatic |
Get SPI work mode.
| p_spi | Pointer to an SPI instance. |
Definition at line 154 of file spi.h.
References Spi::SPI_MR, and SPI_MR_MSTR.
|
inlinestatic |
Check if mode fault detection is enabled.
| p_spi | Pointer to an SPI instance. |
Definition at line 264 of file spi.h.
References Spi::SPI_MR, and SPI_MR_MODFDIS.
|
inlinestatic |
Get PDC registers base address.
| p_spi | Pointer to an SPI instance. |
Definition at line 509 of file spi.h.
References Spi::SPI_RPR.
|
inlinestatic |
Get Peripheral Select Decode mode.
| p_spi | Pointer to an SPI instance. |
Definition at line 228 of file spi.h.
References Spi::SPI_MR, and SPI_MR_PCSDEC.
|
inlinestatic |
Get Peripheral Select mode.
| p_spi | Pointer to an SPI instance. |
Definition at line 192 of file spi.h.
References Spi::SPI_MR, and SPI_MR_PS.
Referenced by spi_read(), and spi_write().
|
inlinestatic |
Check if SPI waits RX_EMPTY before transfer starts.
| p_spi | Pointer to an SPI instance. |
Definition at line 300 of file spi.h.
References Spi::SPI_MR, and SPI_MR_WDRBT.
|
inlinestatic |
Test if the SPI is enabled.
| p_spi | Pointer to an SPI instance. |
Definition at line 356 of file spi.h.
References Spi::SPI_SR, and SPI_SR_SPIENS.
|
inlinestatic |
Check if the SPI contains a received character.
| p_spi | Pointer to an SPI instance. |
Definition at line 429 of file spi.h.
References Spi::SPI_SR, and SPI_SR_RDRF.
|
inlinestatic |
Check if all receptions are ready.
| p_spi | Pointer to an SPI instance. |
Definition at line 445 of file spi.h.
References Spi::SPI_SR, SPI_SR_RDRF, and SPI_SR_TXEMPTY.
|
inlinestatic |
Check if all transmissions are complete.
| p_spi | Pointer to an SPI instance. |
| 1 | if transmissions are complete. |
| 0 | if transmissions are not complete. |
Definition at line 396 of file spi.h.
References Spi::SPI_SR, and SPI_SR_TXEMPTY.
|
inlinestatic |
Check if all transmissions are ready.
| p_spi | Pointer to an SPI instance. |
| 1 | if transmissions are complete. |
| 0 | if transmissions are not complete. |
Definition at line 413 of file spi.h.
References Spi::SPI_SR, and SPI_SR_TDRE.
|
inlinestatic |
Put one data to a SPI peripheral.
| p_spi | Base address of the SPI instance. |
| data | The data byte to be loaded |
Definition at line 372 of file spi.h.
References Spi::SPI_TDR, and SPI_TDR_TD.
|
inlinestatic |
Read SPI interrupt mask.
| p_spi | Pointer to an SPI instance. |
Definition at line 484 of file spi.h.
References Spi::SPI_IMR.
|
inlinestatic |
Read status register.
| p_spi | Pointer to an SPI instance. |
Definition at line 344 of file spi.h.
References Spi::SPI_SR.
|
inlinestatic |
Reset SPI and set it to Slave mode.
| p_spi | Pointer to an SPI instance. |
Definition at line 88 of file spi.h.
References Spi::SPI_CR, and SPI_CR_SWRST.
|
inlinestatic |
Set Fixed Peripheral Select.
Peripheral Chip Select is controlled by SPI_MR.
| p_spi | Pointer to an SPI instance. |
Definition at line 180 of file spi.h.
References Spi::SPI_MR, and SPI_MR_PS.
|
inlinestatic |
Issue a LASTXFER command.
The next transfer is the last transfer and after that CS is de-asserted.
| p_spi | Pointer to an SPI instance. |
Definition at line 122 of file spi.h.
References Spi::SPI_CR, and SPI_CR_LASTXFER.
|
inlinestatic |
Set SPI to Master mode.
| p_spi | Pointer to an SPI instance. |
Definition at line 132 of file spi.h.
References Spi::SPI_MR, and SPI_MR_MSTR.
|
inlinestatic |
Set SPI to Slave mode.
| p_spi | Pointer to an SPI instance. |
Definition at line 142 of file spi.h.
References Spi::SPI_MR, and SPI_MR_MSTR.
|
inlinestatic |