12#define SAI_TXBD_COUNT 4
13#define SAI_RXBD_COUNT 4
42typedef void (*SAI_BufferDoneFn_t)(
void *buffer,
int doneInvalid);
193enum bufferDepletionBehavior_t
196 DEPLETED_REPEAT_LAST,
263 clkCh_t clkCh{CLK_CH_CH};
264 clkPol_t clkPol{CLK_ACTIVE_HIGH};
269 frameSyncCh_t syncCh{SYNC_CH_CH};
271 dataPacking_t dataPacking{BUFFER_WORD32_RIGHT};
272 bool unifyDataStream{
false};
296 uint32_t txClkFreq{12288000};
297 uint32_t rxClkFreq{12288000};
298 rxTxSync_t rxTxSync{RXTX_ASYNC};
346extern const SAI_cfg_t SAI_I2S_SLAVE_24_TXRX_RK;
347extern const SAI_cfg_t SAI_I2S_SLAVE_24_TXRX_TK;
348extern const SAI_cfg_t SAI_I2S_SLAVE_24_TXRX_TKRK;
349extern const SAI_cfg_t SAI_I2S_SLAVE_16_TXRX_RK;
350extern const SAI_cfg_t SAI_I2S_SLAVE_16_TXRX_TK;
351extern const SAI_cfg_t SAI_I2S_SLAVE_16_TXRX_TKRK;
352extern const SAI_cfg_t SAI_I2S_SLAVE_8_TXRX_RK;
353extern const SAI_cfg_t SAI_I2S_SLAVE_8_TXRX_TK;
354extern const SAI_cfg_t SAI_I2S_SLAVE_8_TXRX_TKRK;
356extern const SAI_cfg_t SAI_LJUST_SLAVE_24_TXRX_RK;
357extern const SAI_cfg_t SAI_LJUST_SLAVE_24_TXRX_TK;
358extern const SAI_cfg_t SAI_LJUST_SLAVE_24_TXRX_TKRK;
359extern const SAI_cfg_t SAI_LJUST_SLAVE_16_TXRX_RK;
360extern const SAI_cfg_t SAI_LJUST_SLAVE_16_TXRX_TK;
361extern const SAI_cfg_t SAI_LJUST_SLAVE_16_TXRX_TKRK;
362extern const SAI_cfg_t SAI_LJUST_SLAVE_8_TXRX_RK;
363extern const SAI_cfg_t SAI_LJUST_SLAVE_8_TXRX_TK;
364extern const SAI_cfg_t SAI_LJUST_SLAVE_8_TXRX_TKRK;
388 static DmaTcd sDmaTcd[SAI_HW_COUNT][SAI_TXBD_COUNT+SAI_RXBD_COUNT];
389 static SAICtx_t *sCtx[SAI_HW_COUNT];
390 static int sDmaIsr(
void *ctx, DmaCh *dmaCh,
bool haveError);
402 SAI_BufferDoneFn_t txBufDone;
403 SAI_BufferDoneFn_t rxBufDone;
404 uint32_t txReadyCount;
405 uint32_t rxReadyCount;
432 int validateClockSync(
const SAI_cfg_t &cfg)
const;
433 int validateCfg(
const SAI_cfg_t &cfg)
const;
434 int InitClocks(uint32_t *saiClk, uint32_t divRem);
436 DmaTcd &getFirstTxBD()
const;
437 DmaTcd &getLastTxBD()
const;
438 DmaTcd &getNextTxBD()
const;
440 DmaTcd &getFirstRxBD()
const;
441 DmaTcd &getLastRxBD()
const;
442 DmaTcd &getNextRxBD()
const;
444 DmaTcd &getFirstBD(
const DmaCh *dma)
const;
445 DmaTcd &getLastBD(
const DmaCh *dma)
const;
446 DmaTcd &getNextBD(
const DmaCh *dma)
const;
448 int queueBuffer(
void *buffer, uint32_t bufferLen,
bool waitIfNeeded,
bool enableHalfNotify, DmaCh *dma);
452 int DmaIsr(DmaCh *dma,
bool haveError);
468 inline int GetMaxTxBuffers() {
return SAI_TXBD_COUNT; }
469 inline int GetMaxRxBuffers() {
return SAI_RXBD_COUNT; }
482 inline ctxState_t
getState()
const {
return state; }
499 int TransmitBuffer(
void *buffer, uint32_t bufferLen,
bool waitIfNeeded,
bool enableHalfNotify=
false);
514 int ReadyReceiveBuffer(
void *buffer, uint32_t bufferLen,
bool waitIfNeeded,
bool enableHalfNotify =
false);
526 inline void clrStickyTxError() { stickyTxErr = 0; }
527 inline void clrStickyRxError() { stickyRxErr = 0; }
528 inline uint8_t getStickyTxError() {
return stickyTxErr; }
529 inline uint8_t getStickyRxError() {
return stickyRxErr; }
void Shutdown()
Shuts down the SAI hardware and driver.
void RegisterRxBufferCB(SAI_BufferDoneFn_t cb)
Registers a callback for when a receive buffer is finished.
int getCurrentConfig(SAI_cfg_t &cfg)
Fills in the config object with the current active configuration.
ctxState_t getState() const
Returns the current driver state.
Definition sai.h:482
void RegisterTxBufferCB(SAI_BufferDoneFn_t cb)
Registers a callback for when a transmit buffer is finished.
int ReadyReceiveBuffer(void *buffer, uint32_t bufferLen, bool waitIfNeeded, bool enableHalfNotify=false)
Hands off a buffer to be written to by the SAI driver.
int Init(const SAI_cfg_t &cfg)
Initializes the SAI hardware and driver context.
int TransmitBuffer(void *buffer, uint32_t bufferLen, bool waitIfNeeded, bool enableHalfNotify=false)
Hands off a buffer to be transmitted by the SAI driver. The driver will add this buffer to the chain ...
NetBurner Real-Time Operating System (NBRTOS) API.
Semaphores are used to control access to shared resources or or to communicate between tasks in a mul...
Definition nbrtos.h:411
Configuration structure for the SAI driver. Passed to the initialize function to configure the hardwa...
Definition sai.h:295
SAI_rxtx_cfg_t rx
Definition sai.h:302
SAI_rxtx_cfg_t tx
Definition sai.h:303
Configuration structure for a given direction (rx or tx) of the SAI module. Passed to the initialize ...
Definition sai.h:256
bool lineIdleState
Definition sai.h:274
clkGate_t clkGate
Definition sai.h:260
bufferDepletionBehavior_t depletionBehavior
Definition sai.h:278
frameEdge_t syncEdge
Definition sai.h:267
bool enable
Definition sai.h:257
clkSrc_t clkSrc
Definition sai.h:262
uint8_t startDly
Definition sai.h:258
uint8_t wordsPerFrame
Definition sai.h:270
uint8_t bitsPerWord
Definition sai.h:275
frameSyncOut_t syncOut
Definition sai.h:268
bitOrder_t bitOrder
Definition sai.h:273
clkOut_t clkOut
Definition sai.h:261
startCond_t startCond
Definition sai.h:259
uint32_t wordMask
Definition sai.h:276
uint8_t syncLen
Definition sai.h:266