Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
Baremetal SPI abstraction (internal)

SPI Communication Driver Definitions/Declarations. More...

Collaboration diagram for Baremetal SPI abstraction (internal):

Macros

#define SPI_T_TIMEOUT   500
 Timeout for synchronous responses [ms]. More...
 
#define SPI_T_BACKOFF   10
 Backoff Time when receiving SPI_NACK [us]. More...
 
#define SPI_T_HOLD_8210   100
 Hold time before transmitting for the CA-8210 [us]. More...
 
#define SPI_T_CSHOLD   50
 Time to hold the chip select active before re-checking the IRQ [us]. More...
 
#define SPI_RX_FIFO_SIZE   7
 Maximum Size of Rx FIFO SPI_Receive_Buffer. More...
 
#define SPI_RX_FIFO_RESV   4
 Number of SPI RX FIFOs to be reserved for piggyback messages. More...
 

Functions

ca_error SPI_Exchange (const struct MAC_Message *pTxBuffer, struct ca821x_dev *pDeviceRef)
 Exchange Messages across SPI. More...
 
ca_error SPI_Send (const uint8_t *buf, u8_t *response, struct ca821x_dev *pDeviceRef)
 Send Request over SPI. More...
 
struct MAC_MessageSPI_PeekFullBuf (void)
 Get a MAC_Message buffer containing a received SPI Message. More...
 
void SPI_DequeueFullBuf (void)
 Remove a processed Full Buffer from the SPI Queue. More...
 
bool SPI_IsFifoFull (void)
 Query whether the SPI message FIFO is full or not. More...
 
bool SPI_IsFifoAlmostFull (void)
 Query whether the SPI message FIFO is almost full or not. More...
 
bool SPI_IsFifoEmpty (void)
 Query whether the SPI message FIFO is empty or not. More...
 
bool SPI_IsExchangeWithCA821xInProgress (void)
 Query whether an SPI exchange operation with the CA821x is currently in progress. More...
 
bool SPI_IsSyncChainInFlight (void)
 Query whether the SPI driver is currently locked in a Sync chain. More...
 
void SPI_StartSyncChain (struct ca821x_dev *pDeviceRef)
 Start a 'Sync Chain' For more efficient and safer chains of sync message communication with the CA821x. More...
 
void SPI_StopSyncChain (struct ca821x_dev *pDeviceRef)
 Stop the sync chain after starting with SPI_StartSyncChain. More...
 
void SPI_Initialise (void)
 Initialise SPI buffers and call BSP SPI init. More...
 
void SPI_ExchangeComplete (void)
 Function to be called from the BSP when an exchange operation has been completed. More...
 
bool SPI_GetExternallyInUseStatus (void)
 Checks if the SPI is being used by something other than the RF chip. More...
 

Detailed Description

SPI Communication Driver Definitions/Declarations.

Macro Definition Documentation

◆ SPI_RX_FIFO_RESV

#define SPI_RX_FIFO_RESV   4

Number of SPI RX FIFOs to be reserved for piggyback messages.

◆ SPI_RX_FIFO_SIZE

#define SPI_RX_FIFO_SIZE   7

Maximum Size of Rx FIFO SPI_Receive_Buffer.

◆ SPI_T_BACKOFF

#define SPI_T_BACKOFF   10

Backoff Time when receiving SPI_NACK [us].

◆ SPI_T_CSHOLD

#define SPI_T_CSHOLD   50

Time to hold the chip select active before re-checking the IRQ [us].

◆ SPI_T_HOLD_8210

#define SPI_T_HOLD_8210   100

Hold time before transmitting for the CA-8210 [us].

◆ SPI_T_TIMEOUT

#define SPI_T_TIMEOUT   500

Timeout for synchronous responses [ms].

Function Documentation

◆ SPI_DequeueFullBuf()

void SPI_DequeueFullBuf ( void  )

Remove a processed Full Buffer from the SPI Queue.

This frees up the buffer for receiving future SPI Messages and also knocks over the queue so that the next message can be processed.

RFIRQ must be enabled when calling.

◆ SPI_Exchange()

ca_error SPI_Exchange ( const struct MAC_Message pTxBuffer,
struct ca821x_dev pDeviceRef 
)

Exchange Messages across SPI.

As the SPI is operating in full duplex mode, every exchange consists of both a transmission and reception. This function transmits pTxBuffer while populating an appropriate Rx buffer with the received message.

RFIRQ must be disabled when calling.

Parameters
pTxBuffer- Pointer to Transmit Buffer or NULLP
pDeviceRef- Pointer to initialised ca821x_dev struct
Returns
Status

◆ SPI_ExchangeComplete()

void SPI_ExchangeComplete ( void  )

Function to be called from the BSP when an exchange operation has been completed.

◆ SPI_GetExternallyInUseStatus()

bool SPI_GetExternallyInUseStatus ( void  )

Checks if the SPI is being used by something other than the RF chip.

Return values
trueif SPI is being used externally, false otherwise.

◆ SPI_Initialise()

void SPI_Initialise ( void  )

Initialise SPI buffers and call BSP SPI init.

◆ SPI_IsExchangeWithCA821xInProgress()

bool SPI_IsExchangeWithCA821xInProgress ( void  )

Query whether an SPI exchange operation with the CA821x is currently in progress.

This is used in the DISPATCH_ReadCA821x function to determine whether a new read operation should be started. If an exchange is currently in progress, it should not be.

Returns
True if an SPI exchange with the CA821x is already in progress. False if not.

◆ SPI_IsFifoAlmostFull()

bool SPI_IsFifoAlmostFull ( void  )

Query whether the SPI message FIFO is almost full or not.

If it is almost full, then messages should not be further read from the slave asynchronously.

This is controlled by the SPI_RX_FIFO_RESV preprocessor macro.

RFIRQ must be disabled when calling.

Return values
trueif FIFO is almost full, false if there is space for more async messages

◆ SPI_IsFifoEmpty()

bool SPI_IsFifoEmpty ( void  )

Query whether the SPI message FIFO is empty or not.

RFIRQ must be enabled when calling.

Return values
trueif FIFO is empty, false if there are any messages stored

◆ SPI_IsFifoFull()

bool SPI_IsFifoFull ( void  )

Query whether the SPI message FIFO is full or not.

If it is full, then messages should not be further read from the slave.

RFIRQ must be enabled when calling.

Return values
trueif FIFO is full, false if there is space for another message

◆ SPI_IsSyncChainInFlight()

bool SPI_IsSyncChainInFlight ( void  )

Query whether the SPI driver is currently locked in a Sync chain.

Not for application usage.

RFIRQ must be disabled when calling.

A Sync chain is a method to restrict the incoming messages from the CA-821x on a constrained platform. If this is in action, then it is important that messages are not received via IRQ. This function is used in cascoda_dispatch.c to prevent sync chain responses from being processed.

Return values
trueif sync chain is locked, false if unlocked.

◆ SPI_PeekFullBuf()

struct MAC_Message* SPI_PeekFullBuf ( void  )

Get a MAC_Message buffer containing a received SPI Message.

Calling this function does not remove the buffer from the queue, so after the buffer has been processed, SPI_DequeueFullBuffer should be used.

RFIRQ must be enabled when calling.

Return values
Afull SPI Buffer, or NULL if none are available.

◆ SPI_Send()

ca_error SPI_Send ( const uint8_t *  buf,
u8_t response,
struct ca821x_dev pDeviceRef 
)

Send Request over SPI.

This function is used by DISPATCH_ToCA821x as the downstream path to interface with the CA-821x.

RFIRQ must be enabled when calling.

Parameters
buf- Message to transmit, length is encoded in cascoda TLV form
response- Buffer to fill with response
pDeviceRef- Pointer to initialised ca821x_dev struct
Returns
Status

◆ SPI_StartSyncChain()

void SPI_StartSyncChain ( struct ca821x_dev pDeviceRef)

Start a 'Sync Chain' For more efficient and safer chains of sync message communication with the CA821x.

This function should be called before starting to send a group of synchronous messages, and SPI_StopSyncChain must be called afterwards.

Asynchronous requests MUST NOT be made while the sync chain is active. This prevents any asynchronous messages from being received, making timing and buffers more consistent.

RFIRQ must be enabled when calling.

Parameters
pDeviceRefPointer to initialised ca821x_dev struct

◆ SPI_StopSyncChain()

void SPI_StopSyncChain ( struct ca821x_dev pDeviceRef)

Stop the sync chain after starting with SPI_StartSyncChain.

RFIRQ must be enabled when calling.

Parameters
pDeviceRefPointer to initialised ca821x_dev struct