|
NetBurner 3.5.6
PDF Version |
Main driver class for SAI peripheral operation. More...
#include <sai.h>
Public Types | |
| enum | ctxState_t { CTX_STATE_STOPPED , CTX_STATE_INIT , CTX_STATE_TX , CTX_STATE_RX , CTX_STATE_TXRX } |
| Current operational state of the SAI driver. More... | |
Public Member Functions | |
| int | Init (const SAI_cfg_t &cfg) |
| Initialize the SAI hardware and driver context. | |
| void | Shutdown () |
| Shut down the SAI hardware and release driver resources. | |
| int | GetMaxTxBuffers () |
| Get the maximum number of transmit buffers that can be queued. | |
| int | GetMaxRxBuffers () |
| Get the maximum number of receive buffers that can be queued. | |
| int | getCurrentConfig (SAI_cfg_t &cfg) |
| Retrieve the current active configuration. | |
| ctxState_t | getState () const |
| Get the current operational state of the driver. | |
| int | TransmitBuffer (void *buffer, uint32_t bufferLen, bool waitIfNeeded, bool enableHalfNotify=false) |
| Queue a buffer for transmission. | |
| int | ReadyReceiveBuffer (void *buffer, uint32_t bufferLen, bool waitIfNeeded, bool enableHalfNotify=false) |
| Queue a buffer for receiving data. | |
| void | RegisterTxBufferCB (SAI_BufferDoneFn_t cb) |
| Register a callback for transmit buffer completion. | |
| void | RegisterRxBufferCB (SAI_BufferDoneFn_t cb) |
| Register a callback for receive buffer completion. | |
| void | clrStickyTxError () |
| Clear the sticky transmit error flag. | |
| void | clrStickyRxError () |
| Clear the sticky receive error flag. | |
| uint8_t | getStickyTxError () |
| Get the sticky transmit error status. | |
| uint8_t | getStickyRxError () |
| Get the sticky receive error status. | |
| void | dump () |
| Dump driver state and statistics to the console. | |
Main driver class for SAI peripheral operation.
SAICtx_t provides a high-level, buffer-oriented interface to the SAI peripheral. The driver manages DMA transfers, buffer chains, and provides callbacks for buffer completion events.
Driver Features
Driver States
Thread Safety
The driver uses internal semaphores to synchronize buffer operations:
Performance Considerations
| enum SAICtx_t::ctxState_t |
Current operational state of the SAI driver.
|
inline |
Clear the sticky receive error flag.
Resets the internal error flag that latches when an RX error occurs. Call this after handling an error condition to re-enable error detection.
|
inline |
Clear the sticky transmit error flag.
Resets the internal error flag that latches when a TX error occurs. Call this after handling an error condition to re-enable error detection.
| void SAICtx_t::dump | ( | ) |
Dump driver state and statistics to the console.
Prints detailed information about the driver's current state, including:
Useful for debugging and performance analysis.
| int SAICtx_t::getCurrentConfig | ( | SAI_cfg_t & | cfg | ) |
Retrieve the current active configuration.
Reads back the current hardware configuration and populates the provided configuration structure. Useful for verifying settings or creating a modified configuration based on the current state.
| [out] | cfg | Configuration structure to populate with current settings. |
|
inline |
Get the maximum number of receive buffers that can be queued.
|
inline |
Get the maximum number of transmit buffers that can be queued.
|
inline |
Get the current operational state of the driver.
|
inline |
Get the sticky receive error status.
Returns the latched error code from the most recent RX error. The value persists until cleared with clrStickyRxError().
|
inline |
Get the sticky transmit error status.
Returns the latched error code from the most recent TX error. The value persists until cleared with clrStickyTxError().
| int SAICtx_t::Init | ( | const SAI_cfg_t & | cfg | ) |
Initialize the SAI hardware and driver context.
Configures the SAI peripheral according to the provided configuration, sets up DMA channels, and prepares the driver for buffer operations.
| [in] | cfg | Configuration structure specifying all SAI parameters. Use one of the predefined configurations (SAI_I2S_SLAVE_*) or create a custom configuration. |
| int SAICtx_t::ReadyReceiveBuffer | ( | void * | buffer, |
| uint32_t | bufferLen, | ||
| bool | waitIfNeeded, | ||
| bool | enableHalfNotify = false ) |
Queue a buffer for receiving data.
Provides a buffer to the SAI driver to be filled with received data. The buffer will be added to the receive queue and automatically filled when data arrives. Up to SAI_RXBD_COUNT buffers can be queued simultaneously.
| buffer | Pointer to the buffer to be filled with received data. MUST be 32-byte aligned. |
| bufferLen | Length of the buffer in bytes. MUST be a multiple of 32 bytes. |
| waitIfNeeded | If true, blocks until space is available in the queue. If false, returns immediately with error if queue is full. |
| enableHalfNotify | If true, callback will be invoked at 50% buffer fill (with doneInvalid=0) in addition to full completion. |
| void SAICtx_t::RegisterRxBufferCB | ( | SAI_BufferDoneFn_t | cb | ) |
Register a callback for receive buffer completion.
Sets the function to be called when a receive buffer is filled or encounters an error. The callback executes in interrupt context.
| cb | Callback function pointer, or NULL to disable callbacks. |
| void SAICtx_t::RegisterTxBufferCB | ( | SAI_BufferDoneFn_t | cb | ) |
Register a callback for transmit buffer completion.
Sets the function to be called when a transmit buffer completes or encounters an error. The callback executes in interrupt context.
| cb | Callback function pointer, or NULL to disable callbacks. |
| void SAICtx_t::Shutdown | ( | ) |
Shut down the SAI hardware and release driver resources.
Stops all transfers, disables the SAI peripheral, releases DMA channels, and returns the driver to the stopped state.
| int SAICtx_t::TransmitBuffer | ( | void * | buffer, |
| uint32_t | bufferLen, | ||
| bool | waitIfNeeded, | ||
| bool | enableHalfNotify = false ) |
Queue a buffer for transmission.
Hands a buffer to the SAI driver for transmission. The buffer will be added to the transmit queue and automatically transmitted when its turn comes. Up to SAI_TXBD_COUNT buffers can be queued simultaneously.
| buffer | Pointer to the buffer containing data to transmit. MUST be 32-byte aligned (use alignas(32) or attribute((aligned(32)))). |
| bufferLen | Length of the buffer in bytes. MUST be a multiple of 32 bytes. Must also align with word width (1, 2, or 4 byte multiples). |
| waitIfNeeded | If true, blocks until space is available in the queue. If false, returns immediately with error if queue is full. |
| enableHalfNotify | If true, callback will be invoked at 50% buffer completion (with doneInvalid=0) in addition to full completion. |