nRF5 SDK for Thread v0.9.0
Typedefs | Functions

This module includes the platform abstraction for SPI slave communication. More...

Typedefs

typedef void(* otPlatSpiSlaveTransactionCompleteCallback )(void *aContext, uint8_t *anOutputBuf, uint16_t anOutputBufLen, uint8_t *anInputBuf, uint16_t anInputBufLen, uint16_t aTransactionLength)
 

Functions

ThreadError otPlatSpiSlaveEnable (otPlatSpiSlaveTransactionCompleteCallback aCallback, void *aContext)
 
void otPlatSpiSlaveDisable (void)
 
ThreadError otPlatSpiSlavePrepareTransaction (uint8_t *anOutputBuf, uint16_t anOutputBufLen, uint8_t *anInputBuf, uint16_t anInputBufLen, bool aRequestTransactionFlag)
 

Detailed Description

This module includes the platform abstraction for SPI slave communication.

Typedef Documentation

typedef void(* otPlatSpiSlaveTransactionCompleteCallback)(void *aContext, uint8_t *anOutputBuf, uint16_t anOutputBufLen, uint8_t *anInputBuf, uint16_t anInputBufLen, uint16_t aTransactionLength)

Indicates that a SPI transaction has completed with the given length. The data written to the slave has been written to the pointer indicated by the anInputBuf argument to the previous call to otPlatSpiSlavePrepareTransaction().

Once this function is called, otPlatSpiSlavePrepareTransaction() is invalid and must be called again for the next transaction to be valid.

Note that this function is always called at the end of a transaction, even if otPlatSpiSlavePrepareTransaction() has not yet been called. In such cases, anOutputBufLen and anInputBufLen will be zero.

Parameters
[in]aContextContext pointer passed into otPlatSpiSlaveEnable()
[in]anOutputBufValue of anOutputBuf from last call to otPlatSpiSlavePrepareTransaction()
[in]anOutputBufLenValue of anOutputBufLen from last call to otPlatSpiSlavePrepareTransaction()
[in]anInputBufValue of anInputBuf from last call to otPlatSpiSlavePrepareTransaction()
[in]anInputBufLenValue of anInputBufLen from last call to otPlatSpiSlavePrepareTransaction()
[in]aTransactionLengthLength of the completed transaction, in bytes

Function Documentation

void otPlatSpiSlaveDisable ( void  )

Shutdown and disable the SPI slave interface.

ThreadError otPlatSpiSlaveEnable ( otPlatSpiSlaveTransactionCompleteCallback  aCallback,
void *  aContext 
)

Initialize the SPI slave interface.

Note that the SPI slave is not fully ready until a transaction is prepared using otPlatSPISlavePrepareTransaction().

If otPlatSPISlavePrepareTransaction() is not called before the master begins a transaction, the resulting SPI transaction will send all 0xFF bytes and discard all received bytes.

Parameters
[in]aCallbackPointer to transaction complete callback
[in]aContextContext pointer to be passed to transaction complete callback
Return values
::kThreadError_NoneSuccessfully enabled the SPI Slave interface.
::kThreadError_AlreadySPI Slave interface is already enabled.
::kThreadError_FailedFailed to enable the SPI Slave interface.
ThreadError otPlatSpiSlavePrepareTransaction ( uint8_t *  anOutputBuf,
uint16_t  anOutputBufLen,
uint8_t *  anInputBuf,
uint16_t  anInputBufLen,
bool  aRequestTransactionFlag 
)

Prepare data for the next SPI transaction. Data pointers MUST remain valid until the transaction complete callback is called by the SPI slave driver, or until after the next call to otPlatSpiSlavePrepareTransaction().

This function may be called more than once before the SPI master initiates the transaction. Each successful call to this function will cause the previous values from earlier calls to be discarded.

Not calling this function after a completed transaction is the same as if this function was previously called with both buffer lengths set to zero and aRequestTransactionFlag set to false.

Once anOutputBufLen bytes of anOutputBuf has been clocked out, the MISO pin shall be set high until the master finishes the SPI transaction. This is the functional equivalent of padding the end of anOutputBuf with 0xFF bytes out to the length of the transaction.

Once anInputBufLen bytes of anInputBuf have been clocked in from MOSI, all subsequent values from the MOSI pin are ignored until the SPI master finishes the transaction.

Note that even if anInputBufLen or anOutputBufLen (or both) are exhausted before the SPI master finishes a transaction, the ongoing size of the transaction must still be kept track of to be passed to the transaction complete callback. For example, if anInputBufLen is equal to 10 and anOutputBufLen equal to 20 and the SPI master clocks out 30 bytes, the value 30 is passed to the transaction complete callback.

Any call to this function while a transaction is in progress will cause all of the arguments to be ignored and the return value to be ::kThreadError_Busy.

Parameters
[in]anOutputBufData to be written to MISO pin
[in]anOutputBufLenSize of the output buffer, in bytes
[in]anInputBufData to be read from MOSI pin
[in]anInputBufLenSize of the input buffer, in bytes
[in]aRequestTransactionFlagSet to true if host interrupt should be set
Return values
::kThreadError_NoneTransaction was successfully prepared.
::kThreadError_BusyA transaction is currently in progress.
::kThreadError_InvalidStateotPlatSpiSlaveEnable() hasn't been called.

Documentation feedback | Developer Zone | Subscribe | Updated