nRF5 SDK v15.2.0
Modules | Data Structures | Macros | Typedefs | Functions
SPI transaction manager

Module for scheduling SPI transactions. More...

Modules

 SPI transaction manager configuration
 

Data Structures

struct  nrf_spi_mngr_transfer_t
 SPI transfer descriptor. More...
 
struct  nrf_spi_mngr_transaction_t
 SPI transaction descriptor. More...
 
struct  nrf_spi_mngr_cb_t
 SPI instance control block. More...
 
struct  nrf_spi_mngr_t
 SPI transaction manager instance. More...
 

Macros

#define NRF_SPI_MNGR_TRANSFER(_p_tx_data, _tx_length, _p_rx_data, _rx_length)
 Macro for creating a simple SPI transfer. More...
 
#define NRF_SPI_MNGR_DEF(_nrf_spi_mngr_name, _queue_size, _spi_idx)
 Macro for simplifying the defining of an SPI transaction manager instance. More...
 

Typedefs

typedef void(* nrf_spi_mngr_callback_end_t )(ret_code_t result, void *p_user_data)
 SPI transaction end callback prototype. More...
 
typedef void(* nrf_spi_mngr_callback_begin_t )(void *p_user_data)
 SPI transaction begin callback prototype. More...
 

Functions

ret_code_t nrf_spi_mngr_init (nrf_spi_mngr_t const *p_nrf_spi_mngr, nrf_drv_spi_config_t const *p_default_spi_config)
 Function for initializing an SPI transaction manager instance. More...
 
void nrf_spi_mngr_uninit (nrf_spi_mngr_t const *p_nrf_spi_mngr)
 Function for uninitializing an SPI transaction manager instance. More...
 
ret_code_t nrf_spi_mngr_schedule (nrf_spi_mngr_t const *p_nrf_spi_mngr, nrf_spi_mngr_transaction_t const *p_transaction)
 Function for scheduling an SPI transaction. More...
 
ret_code_t nrf_spi_mngr_perform (nrf_spi_mngr_t const *p_nrf_spi_mngr, nrf_drv_spi_config_t const *p_config, nrf_spi_mngr_transfer_t const *p_transfers, uint8_t number_of_transfers, void(*user_function)(void))
 Function for scheduling a transaction and waiting until it is finished. More...
 
__STATIC_INLINE bool nrf_spi_mngr_is_idle (nrf_spi_mngr_t const *p_nrf_spi_mngr)
 Function for getting the current state of an SPI transaction manager instance. More...
 

Detailed Description

Module for scheduling SPI transactions.

Macro Definition Documentation

#define NRF_SPI_MNGR_DEF (   _nrf_spi_mngr_name,
  _queue_size,
  _spi_idx 
)
Value:
_nrf_spi_mngr_name##_queue, \
(_queue_size), \
static nrf_spi_mngr_cb_t CONCAT_2(_nrf_spi_mngr_name, _cb); \
static const nrf_spi_mngr_t _nrf_spi_mngr_name = \
{ \
.p_nrf_spi_mngr_cb = &CONCAT_2(_nrf_spi_mngr_name, _cb), \
.p_queue = &_nrf_spi_mngr_name##_queue, \
.spi = NRF_DRV_SPI_INSTANCE(_spi_idx) \
}

Macro for simplifying the defining of an SPI transaction manager instance.

This macro allocates a static buffer for the transaction queue. Therefore, it should be used in only one place in the code for a given instance.

Note
The queue size is the maximum number of pending transactions not counting the one that is currently realized. This means that for an empty queue with size of for example 4 elements, it is possible to schedule up to 5 transactions.
Parameters
[in]_nrf_spi_mngr_nameName of instance to be created.
[in]_queue_sizeSize of the transaction queue (maximum number of pending transactions).
[in]_spi_idxIndex of hardware SPI instance to be used.
#define NRF_SPI_MNGR_TRANSFER (   _p_tx_data,
  _tx_length,
  _p_rx_data,
  _rx_length 
)
Value:
{ \
.p_tx_data = (uint8_t const *)_p_tx_data, \
.tx_length = (uint8_t) _tx_length, \
.p_rx_data = (uint8_t *) _p_rx_data, \
.rx_length = (uint8_t) _rx_length, \
}

Macro for creating a simple SPI transfer.

Parameters
[in]_p_tx_dataPointer to the data to be sent.
[in]_tx_lengthNumber of bytes to send.
[in]_p_rx_dataPointer to a buffer for received data.
[in]_rx_lengthNumber of bytes to receive.

Typedef Documentation

typedef void(* nrf_spi_mngr_callback_begin_t)(void *p_user_data)

SPI transaction begin callback prototype.

Parameters
[in]p_user_dataPointer to user data defined in transaction descriptor.
typedef void(* nrf_spi_mngr_callback_end_t)(ret_code_t result, void *p_user_data)

SPI transaction end callback prototype.

Parameters
resultResult of operation (NRF_SUCCESS on success, otherwise a relevant error code).
[in]p_user_dataPointer to user data defined in transaction descriptor.

Function Documentation

ret_code_t nrf_spi_mngr_init ( nrf_spi_mngr_t const *  p_nrf_spi_mngr,
nrf_drv_spi_config_t const *  p_default_spi_config 
)

Function for initializing an SPI transaction manager instance.

Parameters
[in]p_nrf_spi_mngrPointer to the instance to be initialized.
[in]p_default_spi_configPointer to the SPI driver configuration. This configuration will be used whenever the scheduled transaction will have p_spi_config set to NULL value.
Returns
Values returned by the nrf_drv_spi_init function.
__STATIC_INLINE bool nrf_spi_mngr_is_idle ( nrf_spi_mngr_t const *  p_nrf_spi_mngr)

Function for getting the current state of an SPI transaction manager instance.

Parameters
[in]p_nrf_spi_mngrPointer to the SPI transaction manager instance.
Return values
trueIf all scheduled transactions have been finished.
falseOtherwise.
ret_code_t nrf_spi_mngr_perform ( nrf_spi_mngr_t const *  p_nrf_spi_mngr,
nrf_drv_spi_config_t const *  p_config,
nrf_spi_mngr_transfer_t const *  p_transfers,
uint8_t  number_of_transfers,
void(*)(void)  user_function 
)

Function for scheduling a transaction and waiting until it is finished.

This function schedules a transaction that consists of one or more transfers and waits until it is finished.

Parameters
[in]p_nrf_spi_mngrPointer to the SPI transaction manager instance.
[in]p_configRequired SPI configuration.
[in]p_transfersPointer to an array of transfers to be performed.
number_of_transfersNumber of transfers to be performed.
user_functionUser-specified function to be called while waiting. NULL if such functionality is not needed.
Return values
NRF_SUCCESSIf the transfers have been successfully realized.
NRF_ERROR_BUSYIf some transfers are already being performed.
-Other error codes mean that the transaction has failed with the error reported by nrf_drv_spi_transfer().
ret_code_t nrf_spi_mngr_schedule ( nrf_spi_mngr_t const *  p_nrf_spi_mngr,
nrf_spi_mngr_transaction_t const *  p_transaction 
)

Function for scheduling an SPI transaction.

The transaction is enqueued and started as soon as the SPI bus is available, thus when all previously scheduled transactions have been finished (possibly immediately).

Note
If nrf_spi_mngr_transaction_t::p_required_spi_cfg is set to a non-NULL value the module will compare it with nrf_spi_mngr_cb_t::p_current_configuration and reinitialize hardware SPI instance with new parameters if any differences are found. If nrf_spi_mngr_transaction_t::p_required_spi_cfg is set to NULL then it will treat it as it would be set to nrf_spi_mngr_cb_t::default_configuration.
Parameters
[in]p_nrf_spi_mngrPointer to the SPI transaction manager instance.
[in]p_transactionPointer to the descriptor of the transaction to be scheduled.
Return values
NRF_SUCCESSIf the transaction has been successfully scheduled.
NRF_ERROR_NO_MEMIf the queue is full (Only if queue in NRF_QUEUE_MODE_NO_OVERFLOW).
void nrf_spi_mngr_uninit ( nrf_spi_mngr_t const *  p_nrf_spi_mngr)

Function for uninitializing an SPI transaction manager instance.

Parameters
[in]p_nrf_spi_mngrPointer to the instance to be uninitialized.

Documentation feedback | Developer Zone | Subscribe | Updated