EVE 1.0
nRF52 SPI bus master driver
Collaboration diagram for nRF52 SPI bus master driver:

Data Structures

struct  spi_cs_t
 
struct  spi_state_t
 
struct  spi_t
 

Macros

#define ERRATA_58
 
#define SPI_SYNC_FIFO_DEPTH   4
 
#define SPI_CS_UNINITIALIZED   ((struct spi_cs_t) { .CsUnInitialized = 1 })
 

Typedefs

typedef void(* spi_async_callback_t) (const struct spi_t *Spi, void *CallbackData)
 

Enumerations

Functions called from application programs

static bool struct spi_cs_t ChipSelect uint32_t Baudrate struct work_tWork
 
return Ret
 
void SpiInit (const struct spi_t *Spi)
 Name: SpiInit
Initializes SPI based on selected device. Master operation: Baudrate is limited to 0.5*peripheral clock. Slave operation: Not implemented. Called from main program level. More...
 
void SpiDisable (const struct spi_t *Spi)
 Name: SpiDisable
Disables SPI based on selected device. Called from main program level. More...
 
uint8_t SpiRead (const struct spi_t *Spi)
 Name: SpiRead
WARNING: SpiWrite() must be called prior to this function. Waits for data received in RX FIFO. More...
 
void SpiWrite (const struct spi_t *Spi, uint8_t DataToSend)
 Name: SpiWrite
WARNING: SpiCsEnable() must be called prior to this function. Waits for empty transmit buffer, then sends 1 byte. More...
 
uint8_t SpiWriteRead (const struct spi_t *Spi, uint8_t DataToSend)
 Name: SpiWriteRead
WARNING: SpiCsEnable() must be called prior to this function. Waits for empty transmit buffer, sends 1 byte and waits for data received in RX FIFO. More...
 
void SpiTransferAsync (const struct spi_t *Spi, const void *TxBuffer, uint32_t TxLength, void *RxBuffer, uint32_t RxLength, spi_async_callback_t Callback, void *CallbackData)
 Name: SpiTransferAsync
WARNING: SpiCsEnable() must be called prior to this function. Starts asynchronous data transfer (both transmit and receive). More...
 
void SpiTransferSync (const struct spi_t *Spi, const void *TxBuffer, uint32_t TxLength, void *RxBuffer, uint32_t RxLength, uint32_t Flags)
 Name: SpiTransferSync
WARNING: SpiCsEnable() must be called prior to this function. Does synchronous data transfer (both transmit and receive). More...
 
void SpiFlush (const struct spi_t *Spi)
 Name: SpiFlush
WARNING: SpiCsEnable() must be called prior to this function. Waits for any previously transmission to be complete, then flushes RX FIFO. More...
 
static bool SpiIsBusy (const struct spi_t *Spi)
 Name: SpiIsBusy
WARNING: SpiCsEnable() must be called prior to this function. Testes if transmitter is busy, i.e. if data in transmit buffer and/or shift register. More...
 
void SpiCsInit (struct spi_cs_t ChipSelect, uint32_t MaxBaudrate)
 Name: SpiCsInit
Initializes SPI chip select instance. Called once from main program level before first SpiCsEnable() use. More...
 
bool SpiCsEnable (const struct spi_t *Spi, struct spi_cs_t ChipSelect, uint32_t Baudrate)
 Name: SpiCsEnable
Enables peripheral clock for USART, updates SPI setting according to ChipSelect, and activates chip select pin. More...
 
void SpiCsRegisterWait (const struct spi_t *Spi, struct work_t *Work)
 Name: SpiCsRegisterWait
Registers a work to be executed when the SPI block becomes available. More...
 
static bool __attribute__ ((warn_unused_result)) SpiCsWait(const struct spi_t *Spi
 Name: SpiCsWait
Enables peripheral clock for USART, updates SPI setting according to ChipSelect, and activates chip select pin. More...
 
 if (!Ret) SpiCsRegisterWait(Spi
 
void SpiCsDisable (const struct spi_t *Spi, struct spi_cs_t ChipSelect)
 Name: SpiCsDisable
Waits for any ongoing transmission to end, flush RX FIFO, disables chip select pin and disables peripheral clock for USART. More...
 
static bool SpiCsIsActive (const struct spi_t *Spi, struct spi_cs_t ChipSelect)
 Name: SpiCsIsActive
Checks that the given chip select is active. More...
 
void SpiInterruptHandler (const struct spi_t *Spi)
 Name: SpiInterruptHandler
SPI interrupt handler Called from board.c at hardware interrupt context. More...
 

Detailed Description

This SPI driver provides interface to the MCU's SPI blocks.

Functionality included:

Currently only master mode is supported.

Macro Definition Documentation

#define ERRATA_58

Enables fix for errata 58

Definition at line 72 of file spi.h.

#define SPI_SYNC_FIFO_DEPTH   4

Size of the synchronous FIFO emulation buffer

Definition at line 77 of file spi.h.

#define SPI_CS_UNINITIALIZED   ((struct spi_cs_t) { .CsUnInitialized = 1 })

Uninitialized chip select structure

Definition at line 95 of file spi.h.

Typedef Documentation

typedef void(* spi_async_callback_t) (const struct spi_t *Spi, void *CallbackData)

The callback is called at completion of an asynchronous transfer.

Parameters
SpiSPI to be used
CallbackDataUser-defined data

Definition at line 137 of file spi.h.

Enumeration Type Documentation

SpiTransferSync flasg

Definition at line 86 of file spi.h.

enum spi_mode_t

spi_mode_t defines mode 0-3.

Enumerator
SPI_MODE0 

SCK active high, sample on leading edge of clock.

SPI_MODE1 

SCK active high, sample on trailing edge of clock.

SPI_MODE2 

SCK active low, sample on leading edge of clock.

SPI_MODE3 

SCK active low, sample on trailing edge of clock.

Definition at line 101 of file spi.h.

Function Documentation

void SpiInit ( const struct spi_t Spi)

Name: SpiInit
Initializes SPI based on selected device. Master operation: Baudrate is limited to 0.5*peripheral clock. Slave operation: Not implemented. Called from main program level.

Parameters
SpiSPI parameters to be used
void SpiDisable ( const struct spi_t Spi)

Name: SpiDisable
Disables SPI based on selected device. Called from main program level.

Parameters
SpiSPI parameters to be used
uint8_t SpiRead ( const struct spi_t Spi)

Name: SpiRead
WARNING: SpiWrite() must be called prior to this function. Waits for data received in RX FIFO.

Parameters
SpiSPI to be used
Returns
Received data
void SpiWrite ( const struct spi_t Spi,
uint8_t  DataToSend 
)

Name: SpiWrite
WARNING: SpiCsEnable() must be called prior to this function. Waits for empty transmit buffer, then sends 1 byte.

Parameters
SpiSPI to be used
DataToSendData to be sent
uint8_t SpiWriteRead ( const struct spi_t Spi,
uint8_t  DataToSend 
)

Name: SpiWriteRead
WARNING: SpiCsEnable() must be called prior to this function. Waits for empty transmit buffer, sends 1 byte and waits for data received in RX FIFO.

Parameters
SpiSPI to be used
DataToSendData to be sent
Returns
Received data
void SpiTransferAsync ( const struct spi_t Spi,
const void *  TxBuffer,
uint32_t  TxLength,
void *  RxBuffer,
uint32_t  RxLength,
spi_async_callback_t  Callback,
void *  CallbackData 
)

Name: SpiTransferAsync
WARNING: SpiCsEnable() must be called prior to this function. Starts asynchronous data transfer (both transmit and receive).

Parameters
SpiSPI to be used
TxBufferTransmit buffer
TxLengthAmount of bytes to be sent
RxBufferReceive buffer
RxLengthAmount of bytes to be received
CallbackPointer to the function to be called when transfer is finished
CallbackDataUser-defined data for the callback
void SpiTransferSync ( const struct spi_t Spi,
const void *  TxBuffer,
uint32_t  TxLength,
void *  RxBuffer,
uint32_t  RxLength,
uint32_t  Flags 
)

Name: SpiTransferSync
WARNING: SpiCsEnable() must be called prior to this function. Does synchronous data transfer (both transmit and receive).

Parameters
SpiSPI to be used
TxBufferTransmit buffer
TxLengthAmount of bytes to be sent
RxBufferReceive buffer
RxLengthAmount of bytes to be received
FlagsFlags of the transfer, bit combination of spi_transfer_flags_t
void SpiFlush ( const struct spi_t Spi)

Name: SpiFlush
WARNING: SpiCsEnable() must be called prior to this function. Waits for any previously transmission to be complete, then flushes RX FIFO.

Parameters
SpiSPI to be used
static bool SpiIsBusy ( const struct spi_t Spi)
inlinestatic

Name: SpiIsBusy
WARNING: SpiCsEnable() must be called prior to this function. Testes if transmitter is busy, i.e. if data in transmit buffer and/or shift register.

Parameters
SpiSPI to be used
Returns
true if busy, else false

Definition at line 296 of file spi.h.

References __attribute__(), spi_state_t::Busy, spi_state_t::ChipSelect, SpiCsDisable(), SpiCsEnable(), SpiCsInit(), SpiCsRegisterWait(), and spi_t::State.

void SpiCsInit ( struct spi_cs_t  ChipSelect,
uint32_t  MaxBaudrate 
)

Name: SpiCsInit
Initializes SPI chip select instance. Called once from main program level before first SpiCsEnable() use.

Parameters
ChipSelectCS parameters to be used
MaxBaudrateMaximal baudrate for this CS

Referenced by SpiIsBusy().

bool SpiCsEnable ( const struct spi_t Spi,
struct spi_cs_t  ChipSelect,
uint32_t  Baudrate 
)

Name: SpiCsEnable
Enables peripheral clock for USART, updates SPI setting according to ChipSelect, and activates chip select pin.

Parameters
SpiSPI to be used
ChipSelectChip select structure
BaudrateIf Baudrate = 0, default baudrate is used
Returns
false if SPI is already in use, else true

Referenced by SpiIsBusy().

void SpiCsRegisterWait ( const struct spi_t Spi,
struct work_t Work 
)

Name: SpiCsRegisterWait
Registers a work to be executed when the SPI block becomes available.

Parameters
SpiSPI to be used
WorkThe work item will be scheduled as soon as the SPI block becomes available.

Referenced by SpiIsBusy().

static bool __attribute__ ( (warn_unused_result)  ) const
inlinestatic

Name: SpiCsWait
Enables peripheral clock for USART, updates SPI setting according to ChipSelect, and activates chip select pin.

Parameters
SpiSPI to be used
ChipSelectChip select structure
BaudrateIf Baudrate = 0, default baudrate is used
WorkIf SPI is already in use, the work item will be scheduled as soon as it becomes available again.
Returns
false if SPI is already in use, else true

Referenced by SpiIsBusy().

void SpiCsDisable ( const struct spi_t Spi,
struct spi_cs_t  ChipSelect 
)

Name: SpiCsDisable
Waits for any ongoing transmission to end, flush RX FIFO, disables chip select pin and disables peripheral clock for USART.

Parameters
SpiSPI to be used
ChipSelectChip select structure

Referenced by SpiIsBusy().

static bool SpiCsIsActive ( const struct spi_t Spi,
struct spi_cs_t  ChipSelect 
)
inlinestatic

Name: SpiCsIsActive
Checks that the given chip select is active.

Parameters
SpiSPI to be used
ChipSelectChip select structure
Returns
true if the chip select is active, false otherwise

Definition at line 379 of file spi.h.

References spi_state_t::ChipSelect, SpiInterruptHandler(), and spi_t::State.

void SpiInterruptHandler ( const struct spi_t Spi)

Name: SpiInterruptHandler
SPI interrupt handler Called from board.c at hardware interrupt context.

Parameters
SpiSPI parameters to be used

Referenced by SpiCsIsActive().