30#ifndef BM_SPI_MNGR_H__
31#define BM_SPI_MNGR_H__
38#include <zephyr/sys/ring_buffer.h>
52#define BM_SPI_MNGR_TRANSFER(_tx_data, _tx_length, _rx_data, _rx_length) \
54 .tx_data = (const uint8_t *)(_tx_data), \
55 .tx_length = (uint8_t)(_tx_length), \
56 .rx_data = (uint8_t *)(_rx_data), \
57 .rx_length = (uint8_t)(_rx_length), \
189 struct ring_buf ring_buf;
218#define BM_SPI_MNGR_DEF(_name, _queue_size, _spim_inst) \
219 static uint8_t _name##_queue_bytes[(_queue_size) * \
220 sizeof(const struct bm_spi_mngr_transaction *)]; \
221 static nrfx_spim_t _name##_spim = NRFX_SPIM_INSTANCE(_spim_inst); \
222 static struct bm_spi_mngr _name = { \
224 .size = (_queue_size), \
225 .byte_storage = _name##_queue_bytes, \
227 .spim = &_name##_spim, \
int bm_spi_mngr_init(struct bm_spi_mngr *mgr, const nrfx_spim_config_t *default_spim_cfg)
Initialize the SPI manager and the underlying SPIM driver.
bool bm_spi_mngr_is_idle(const struct bm_spi_mngr *mgr)
Get the current state of an SPI transaction manager instance.
int bm_spi_mngr_schedule(struct bm_spi_mngr *mgr, const struct bm_spi_mngr_transaction *transaction)
Schedule an SPI transaction.
void(* bm_spi_mngr_callback_begin_t)(void *user_data)
Transaction begin callback, runs from the SPIM event handler context.
Definition bm_spi_mngr.h:76
void(* bm_spi_mngr_callback_end_t)(int result, void *user_data)
Transaction end callback.
Definition bm_spi_mngr.h:68
int bm_spi_mngr_uninit(struct bm_spi_mngr *mgr)
Uninitialize the SPI manager and SPIM.
bm_spi_mngr_callback_begin_t begin_callback
User function invoked before the first transfer of the transaction starts.
Definition bm_spi_mngr.h:120
const nrfx_spim_config_t * required_spim_cfg
Optional SPIM configuration for this transaction, NULL selects the default.
Definition bm_spi_mngr.h:146
uint8_t number_of_transfers
Number of entries in transfers.
Definition bm_spi_mngr.h:140
const struct bm_spi_mngr_transfer * transfers
Array of transfers that make up the transaction.
Definition bm_spi_mngr.h:136
bm_spi_mngr_callback_end_t end_callback
User function invoked when the transaction completes or aborts after an error.
Definition bm_spi_mngr.h:124
void * user_data
Opaque pointer passed to the optional begin and end callbacks.
Definition bm_spi_mngr.h:130
SPI transaction descriptor.
Definition bm_spi_mngr.h:116
const uint8_t * tx_data
Pointer to data to send.
Definition bm_spi_mngr.h:88
uint8_t * rx_data
Pointer to buffer for received data.
Definition bm_spi_mngr.h:96
uint8_t tx_length
Number of bytes to send.
Definition bm_spi_mngr.h:92
uint8_t rx_length
Number of bytes to receive.
Definition bm_spi_mngr.h:100
SPI transfer descriptor, one segment of a transaction.
Definition bm_spi_mngr.h:84
struct bm_spi_mngr::@125 cb
Control block (writable runtime state) for this instance.
const nrfx_spim_config_t * current_configuration
Pointer to the SPIM configuration currently applied to the instance.
Definition bm_spi_mngr.h:171
uint8_t volatile current_transfer_idx
Index of the active transfer within current_transaction.
Definition bm_spi_mngr.h:175
nrfx_spim_config_t default_configuration
Default SPIM configuration (copy of the argument to bm_spi_mngr_init)
Definition bm_spi_mngr.h:167
struct bm_spi_mngr::@126 queue
Pending transaction queue (buffer + Zephyr ring_buf).
nrfx_spim_t * spim
nrfx SPIM driver instance.
Definition bm_spi_mngr.h:201
const struct bm_spi_mngr_transaction *volatile current_transaction
Transaction currently being executed (NULL when idle).
Definition bm_spi_mngr.h:162
uint8_t * byte_storage
Buffer that ring_buf uses to store the queued transaction pointers.
Definition bm_spi_mngr.h:196
size_t size
Maximum number of pending transactions (not counting the one in progress).
Definition bm_spi_mngr.h:185
SPI transaction manager instance.
Definition bm_spi_mngr.h:154