MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

Overview

Data Structures

struct  sai_config_t
 SAI user configuration structure. More...
 
struct  sai_transfer_format_t
 sai transfer format More...
 
struct  sai_fifo_t
 sai fifo configurations More...
 
struct  sai_bit_clock_t
 sai bit clock configurations More...
 
struct  sai_frame_sync_t
 sai frame sync configurations More...
 
struct  sai_serial_data_t
 sai serial data configurations More...
 
struct  sai_transceiver_t
 sai transceiver configurations More...
 
struct  sai_transfer_t
 SAI transfer structure. More...
 
struct  sai_handle_t
 SAI handle structure. More...
 

Macros

#define SAI_XFER_QUEUE_SIZE   (4U)
 SAI transfer queue size, user can refine it according to use case. More...
 
#define FSL_SAI_HAS_FIFO_EXTEND_FEATURE   1
 sai fifo feature
 

Typedefs

typedef void(* sai_transfer_callback_t )(I2S_Type *base, sai_handle_t *handle, status_t status, void *userData)
 SAI transfer callback prototype.
 

Enumerations

enum  {
  kStatus_SAI_TxBusy = MAKE_STATUS(kStatusGroup_SAI, 0),
  kStatus_SAI_RxBusy = MAKE_STATUS(kStatusGroup_SAI, 1),
  kStatus_SAI_TxError = MAKE_STATUS(kStatusGroup_SAI, 2),
  kStatus_SAI_RxError = MAKE_STATUS(kStatusGroup_SAI, 3),
  kStatus_SAI_QueueFull = MAKE_STATUS(kStatusGroup_SAI, 4),
  kStatus_SAI_TxIdle = MAKE_STATUS(kStatusGroup_SAI, 5),
  kStatus_SAI_RxIdle = MAKE_STATUS(kStatusGroup_SAI, 6)
}
 _sai_status_t, SAI return status. More...
 
enum  {
  kSAI_Channel0Mask = 1 << 0U,
  kSAI_Channel1Mask = 1 << 1U,
  kSAI_Channel2Mask = 1 << 2U,
  kSAI_Channel3Mask = 1 << 3U,
  kSAI_Channel4Mask = 1 << 4U,
  kSAI_Channel5Mask = 1 << 5U,
  kSAI_Channel6Mask = 1 << 6U,
  kSAI_Channel7Mask = 1 << 7U
}
 _sai_channel_mask,.sai channel mask value, actual channel numbers is depend soc specific More...
 
enum  sai_protocol_t {
  kSAI_BusLeftJustified = 0x0U,
  kSAI_BusRightJustified,
  kSAI_BusI2S,
  kSAI_BusPCMA,
  kSAI_BusPCMB
}
 Define the SAI bus type. More...
 
enum  sai_master_slave_t {
  kSAI_Master = 0x0U,
  kSAI_Slave = 0x1U,
  kSAI_Bclk_Master_FrameSync_Slave = 0x2U,
  kSAI_Bclk_Slave_FrameSync_Master = 0x3U
}
 Master or slave mode. More...
 
enum  sai_mono_stereo_t {
  kSAI_Stereo = 0x0U,
  kSAI_MonoRight,
  kSAI_MonoLeft
}
 Mono or stereo audio format. More...
 
enum  sai_data_order_t {
  kSAI_DataLSB = 0x0U,
  kSAI_DataMSB
}
 SAI data order, MSB or LSB. More...
 
enum  sai_clock_polarity_t {
  kSAI_PolarityActiveHigh = 0x0U,
  kSAI_PolarityActiveLow = 0x1U,
  kSAI_SampleOnFallingEdge = 0x0U,
  kSAI_SampleOnRisingEdge = 0x1U
}
 SAI clock polarity, active high or low. More...
 
enum  sai_sync_mode_t {
  kSAI_ModeAsync = 0x0U,
  kSAI_ModeSync
}
 Synchronous or asynchronous mode. More...
 
enum  sai_bclk_source_t {
  kSAI_BclkSourceBusclk = 0x0U,
  kSAI_BclkSourceMclkOption1 = 0x1U,
  kSAI_BclkSourceMclkOption2 = 0x2U,
  kSAI_BclkSourceMclkOption3 = 0x3U,
  kSAI_BclkSourceMclkDiv = 0x1U,
  kSAI_BclkSourceOtherSai0 = 0x2U,
  kSAI_BclkSourceOtherSai1 = 0x3U
}
 Bit clock source. More...
 
enum  {
  kSAI_WordStartInterruptEnable,
  kSAI_SyncErrorInterruptEnable = I2S_TCSR_SEIE_MASK,
  kSAI_FIFOWarningInterruptEnable = I2S_TCSR_FWIE_MASK,
  kSAI_FIFOErrorInterruptEnable = I2S_TCSR_FEIE_MASK,
  kSAI_FIFORequestInterruptEnable = I2S_TCSR_FRIE_MASK
}
 _sai_interrupt_enable_t, The SAI interrupt enable flag More...
 
enum  {
  kSAI_FIFOWarningDMAEnable = I2S_TCSR_FWDE_MASK,
  kSAI_FIFORequestDMAEnable = I2S_TCSR_FRDE_MASK
}
 _sai_dma_enable_t, The DMA request sources More...
 
enum  {
  kSAI_WordStartFlag = I2S_TCSR_WSF_MASK,
  kSAI_SyncErrorFlag = I2S_TCSR_SEF_MASK,
  kSAI_FIFOErrorFlag = I2S_TCSR_FEF_MASK,
  kSAI_FIFORequestFlag = I2S_TCSR_FRF_MASK,
  kSAI_FIFOWarningFlag = I2S_TCSR_FWF_MASK
}
 _sai_flags, The SAI status flag More...
 
enum  sai_reset_type_t {
  kSAI_ResetTypeSoftware = I2S_TCSR_SR_MASK,
  kSAI_ResetTypeFIFO = I2S_TCSR_FR_MASK,
  kSAI_ResetAll = I2S_TCSR_SR_MASK | I2S_TCSR_FR_MASK
}
 The reset type. More...
 
enum  sai_fifo_packing_t {
  kSAI_FifoPackingDisabled = 0x0U,
  kSAI_FifoPacking8bit = 0x2U,
  kSAI_FifoPacking16bit = 0x3U
}
 The SAI packing mode The mode includes 8 bit and 16 bit packing. More...
 
enum  sai_sample_rate_t {
  kSAI_SampleRate8KHz = 8000U,
  kSAI_SampleRate11025Hz = 11025U,
  kSAI_SampleRate12KHz = 12000U,
  kSAI_SampleRate16KHz = 16000U,
  kSAI_SampleRate22050Hz = 22050U,
  kSAI_SampleRate24KHz = 24000U,
  kSAI_SampleRate32KHz = 32000U,
  kSAI_SampleRate44100Hz = 44100U,
  kSAI_SampleRate48KHz = 48000U,
  kSAI_SampleRate96KHz = 96000U,
  kSAI_SampleRate192KHz = 192000U,
  kSAI_SampleRate384KHz = 384000U
}
 Audio sample rate. More...
 
enum  sai_word_width_t {
  kSAI_WordWidth8bits = 8U,
  kSAI_WordWidth16bits = 16U,
  kSAI_WordWidth24bits = 24U,
  kSAI_WordWidth32bits = 32U
}
 Audio word width. More...
 
enum  sai_data_pin_state_t {
  kSAI_DataPinStateTriState,
  kSAI_DataPinStateOutputZero = 1U
}
 sai data pin state definition More...
 
enum  sai_transceiver_type_t {
  kSAI_Transmitter = 0U,
  kSAI_Receiver = 1U
}
 sai transceiver type More...
 
enum  sai_frame_sync_len_t {
  kSAI_FrameSyncLenOneBitClk = 0U,
  kSAI_FrameSyncLenPerWordWidth = 1U
}
 sai frame sync len More...
 

Driver version

#define FSL_SAI_DRIVER_VERSION   (MAKE_VERSION(2, 3, 0))
 Version 2.3.0.
 

Initialization and deinitialization

void SAI_TxInit (I2S_Type *base, const sai_config_t *config)
 Initializes the SAI Tx peripheral. More...
 
void SAI_RxInit (I2S_Type *base, const sai_config_t *config)
 Initializes the SAI Rx peripheral. More...
 
void SAI_TxGetDefaultConfig (sai_config_t *config)
 Sets the SAI Tx configuration structure to default values. More...
 
void SAI_RxGetDefaultConfig (sai_config_t *config)
 Sets the SAI Rx configuration structure to default values. More...
 
void SAI_Init (I2S_Type *base)
 Initializes the SAI peripheral. More...
 
void SAI_Deinit (I2S_Type *base)
 De-initializes the SAI peripheral. More...
 
void SAI_TxReset (I2S_Type *base)
 Resets the SAI Tx. More...
 
void SAI_RxReset (I2S_Type *base)
 Resets the SAI Rx. More...
 
void SAI_TxEnable (I2S_Type *base, bool enable)
 Enables/disables the SAI Tx. More...
 
void SAI_RxEnable (I2S_Type *base, bool enable)
 Enables/disables the SAI Rx. More...
 
static void SAI_TxSetBitClockDirection (I2S_Type *base, sai_master_slave_t masterSlave)
 Set Rx bit clock direction. More...
 
static void SAI_RxSetBitClockDirection (I2S_Type *base, sai_master_slave_t masterSlave)
 Set Rx bit clock direction. More...
 
static void SAI_RxSetFrameSyncDirection (I2S_Type *base, sai_master_slave_t masterSlave)
 Set Rx frame sync direction. More...
 
static void SAI_TxSetFrameSyncDirection (I2S_Type *base, sai_master_slave_t masterSlave)
 Set Tx frame sync direction. More...
 
void SAI_TxSetBitClockRate (I2S_Type *base, uint32_t sourceClockHz, uint32_t sampleRate, uint32_t bitWidth, uint32_t channelNumbers)
 Transmitter bit clock rate configurations. More...
 
void SAI_RxSetBitClockRate (I2S_Type *base, uint32_t sourceClockHz, uint32_t sampleRate, uint32_t bitWidth, uint32_t channelNumbers)
 Receiver bit clock rate configurations. More...
 
void SAI_TxSetBitclockConfig (I2S_Type *base, sai_master_slave_t masterSlave, sai_bit_clock_t *config)
 Transmitter Bit clock configurations. More...
 
void SAI_RxSetBitclockConfig (I2S_Type *base, sai_master_slave_t masterSlave, sai_bit_clock_t *config)
 Receiver Bit clock configurations. More...
 
void SAI_TxSetFifoConfig (I2S_Type *base, sai_fifo_t *config)
 SAI transmitter fifo configurations. More...
 
void SAI_RxSetFifoConfig (I2S_Type *base, sai_fifo_t *config)
 SAI receiver fifo configurations. More...
 
void SAI_TxSetFrameSyncConfig (I2S_Type *base, sai_master_slave_t masterSlave, sai_frame_sync_t *config)
 SAI transmitter Frame sync configurations. More...
 
void SAI_RxSetFrameSyncConfig (I2S_Type *base, sai_master_slave_t masterSlave, sai_frame_sync_t *config)
 SAI receiver Frame sync configurations. More...
 
void SAI_TxSetSerialDataConfig (I2S_Type *base, sai_serial_data_t *config)
 SAI transmitter Serial data configurations. More...
 
void SAI_RxSetSerialDataConfig (I2S_Type *base, sai_serial_data_t *config)
 SAI receiver Serial data configurations. More...
 
void SAI_TxSetConfig (I2S_Type *base, sai_transceiver_t *config)
 SAI transmitter configurations. More...
 
void SAI_RxSetConfig (I2S_Type *base, sai_transceiver_t *config)
 SAI receiver configurations. More...
 
void SAI_GetClassicI2SConfig (sai_transceiver_t *config, sai_word_width_t bitWidth, sai_mono_stereo_t mode, uint32_t saiChannelMask)
 Get classic I2S mode configurations. More...
 
void SAI_GetLeftJustifiedConfig (sai_transceiver_t *config, sai_word_width_t bitWidth, sai_mono_stereo_t mode, uint32_t saiChannelMask)
 Get left justified mode configurations. More...
 
void SAI_GetRightJustifiedConfig (sai_transceiver_t *config, sai_word_width_t bitWidth, sai_mono_stereo_t mode, uint32_t saiChannelMask)
 Get right justified mode configurations. More...
 
void SAI_GetTDMConfig (sai_transceiver_t *config, sai_frame_sync_len_t frameSyncWidth, sai_word_width_t bitWidth, uint32_t dataWordNum, uint32_t saiChannelMask)
 Get TDM mode configurations. More...
 
void SAI_GetDSPConfig (sai_transceiver_t *config, sai_frame_sync_len_t frameSyncWidth, sai_word_width_t bitWidth, sai_mono_stereo_t mode, uint32_t saiChannelMask)
 Get DSP mode configurations. More...
 

Status

static uint32_t SAI_TxGetStatusFlag (I2S_Type *base)
 Gets the SAI Tx status flag state. More...
 
static void SAI_TxClearStatusFlags (I2S_Type *base, uint32_t mask)
 Clears the SAI Tx status flag state. More...
 
static uint32_t SAI_RxGetStatusFlag (I2S_Type *base)
 Gets the SAI Tx status flag state. More...
 
static void SAI_RxClearStatusFlags (I2S_Type *base, uint32_t mask)
 Clears the SAI Rx status flag state. More...
 
void SAI_TxSoftwareReset (I2S_Type *base, sai_reset_type_t type)
 Do software reset or FIFO reset . More...
 
void SAI_RxSoftwareReset (I2S_Type *base, sai_reset_type_t type)
 Do software reset or FIFO reset . More...
 
void SAI_TxSetChannelFIFOMask (I2S_Type *base, uint8_t mask)
 Set the Tx channel FIFO enable mask. More...
 
void SAI_RxSetChannelFIFOMask (I2S_Type *base, uint8_t mask)
 Set the Rx channel FIFO enable mask. More...
 
void SAI_TxSetDataOrder (I2S_Type *base, sai_data_order_t order)
 Set the Tx data order. More...
 
void SAI_RxSetDataOrder (I2S_Type *base, sai_data_order_t order)
 Set the Rx data order. More...
 
void SAI_TxSetBitClockPolarity (I2S_Type *base, sai_clock_polarity_t polarity)
 Set the Tx data order. More...
 
void SAI_RxSetBitClockPolarity (I2S_Type *base, sai_clock_polarity_t polarity)
 Set the Rx data order. More...
 
void SAI_TxSetFrameSyncPolarity (I2S_Type *base, sai_clock_polarity_t polarity)
 Set the Tx data order. More...
 
void SAI_RxSetFrameSyncPolarity (I2S_Type *base, sai_clock_polarity_t polarity)
 Set the Rx data order. More...
 
void SAI_TxSetFIFOPacking (I2S_Type *base, sai_fifo_packing_t pack)
 Set Tx FIFO packing feature. More...
 
void SAI_RxSetFIFOPacking (I2S_Type *base, sai_fifo_packing_t pack)
 Set Rx FIFO packing feature. More...
 
static void SAI_TxSetFIFOErrorContinue (I2S_Type *base, bool isEnabled)
 Set Tx FIFO error continue. More...
 
static void SAI_RxSetFIFOErrorContinue (I2S_Type *base, bool isEnabled)
 Set Rx FIFO error continue. More...
 

Interrupts

static void SAI_TxEnableInterrupts (I2S_Type *base, uint32_t mask)
 Enables the SAI Tx interrupt requests. More...
 
static void SAI_RxEnableInterrupts (I2S_Type *base, uint32_t mask)
 Enables the SAI Rx interrupt requests. More...
 
static void SAI_TxDisableInterrupts (I2S_Type *base, uint32_t mask)
 Disables the SAI Tx interrupt requests. More...
 
static void SAI_RxDisableInterrupts (I2S_Type *base, uint32_t mask)
 Disables the SAI Rx interrupt requests. More...
 

DMA Control

static void SAI_TxEnableDMA (I2S_Type *base, uint32_t mask, bool enable)
 Enables/disables the SAI Tx DMA requests. More...
 
static void SAI_RxEnableDMA (I2S_Type *base, uint32_t mask, bool enable)
 Enables/disables the SAI Rx DMA requests. More...
 
static uint32_t SAI_TxGetDataRegisterAddress (I2S_Type *base, uint32_t channel)
 Gets the SAI Tx data register address. More...
 
static uint32_t SAI_RxGetDataRegisterAddress (I2S_Type *base, uint32_t channel)
 Gets the SAI Rx data register address. More...
 

Bus Operations

void SAI_TxSetFormat (I2S_Type *base, sai_transfer_format_t *format, uint32_t mclkSourceClockHz, uint32_t bclkSourceClockHz)
 Configures the SAI Tx audio format. More...
 
void SAI_RxSetFormat (I2S_Type *base, sai_transfer_format_t *format, uint32_t mclkSourceClockHz, uint32_t bclkSourceClockHz)
 Configures the SAI Rx audio format. More...
 
void SAI_WriteBlocking (I2S_Type *base, uint32_t channel, uint32_t bitWidth, uint8_t *buffer, uint32_t size)
 Sends data using a blocking method. More...
 
void SAI_WriteMultiChannelBlocking (I2S_Type *base, uint32_t channel, uint32_t channelMask, uint32_t bitWidth, uint8_t *buffer, uint32_t size)
 Sends data to multi channel using a blocking method. More...
 
static void SAI_WriteData (I2S_Type *base, uint32_t channel, uint32_t data)
 Writes data into SAI FIFO. More...
 
void SAI_ReadBlocking (I2S_Type *base, uint32_t channel, uint32_t bitWidth, uint8_t *buffer, uint32_t size)
 Receives data using a blocking method. More...
 
void SAI_ReadMultiChannelBlocking (I2S_Type *base, uint32_t channel, uint32_t channelMask, uint32_t bitWidth, uint8_t *buffer, uint32_t size)
 Receives multi channel data using a blocking method. More...
 
static uint32_t SAI_ReadData (I2S_Type *base, uint32_t channel)
 Reads data from the SAI FIFO. More...
 

Transactional

void SAI_TransferTxCreateHandle (I2S_Type *base, sai_handle_t *handle, sai_transfer_callback_t callback, void *userData)
 Initializes the SAI Tx handle. More...
 
void SAI_TransferRxCreateHandle (I2S_Type *base, sai_handle_t *handle, sai_transfer_callback_t callback, void *userData)
 Initializes the SAI Rx handle. More...
 
void SAI_TransferTxSetConfig (I2S_Type *base, sai_handle_t *handle, sai_transceiver_t *config)
 SAI transmitter transfer configurations. More...
 
void SAI_TransferRxSetConfig (I2S_Type *base, sai_handle_t *handle, sai_transceiver_t *config)
 SAI receiver transfer configurations. More...
 
status_t SAI_TransferTxSetFormat (I2S_Type *base, sai_handle_t *handle, sai_transfer_format_t *format, uint32_t mclkSourceClockHz, uint32_t bclkSourceClockHz)
 Configures the SAI Tx audio format. More...
 
status_t SAI_TransferRxSetFormat (I2S_Type *base, sai_handle_t *handle, sai_transfer_format_t *format, uint32_t mclkSourceClockHz, uint32_t bclkSourceClockHz)
 Configures the SAI Rx audio format. More...
 
status_t SAI_TransferSendNonBlocking (I2S_Type *base, sai_handle_t *handle, sai_transfer_t *xfer)
 Performs an interrupt non-blocking send transfer on SAI. More...
 
status_t SAI_TransferReceiveNonBlocking (I2S_Type *base, sai_handle_t *handle, sai_transfer_t *xfer)
 Performs an interrupt non-blocking receive transfer on SAI. More...
 
status_t SAI_TransferGetSendCount (I2S_Type *base, sai_handle_t *handle, size_t *count)
 Gets a set byte count. More...
 
status_t SAI_TransferGetReceiveCount (I2S_Type *base, sai_handle_t *handle, size_t *count)
 Gets a received byte count. More...
 
void SAI_TransferAbortSend (I2S_Type *base, sai_handle_t *handle)
 Aborts the current send. More...
 
void SAI_TransferAbortReceive (I2S_Type *base, sai_handle_t *handle)
 Aborts the current IRQ receive. More...
 
void SAI_TransferTerminateSend (I2S_Type *base, sai_handle_t *handle)
 Terminate all SAI send. More...
 
void SAI_TransferTerminateReceive (I2S_Type *base, sai_handle_t *handle)
 Terminate all SAI receive. More...
 
void SAI_TransferTxHandleIRQ (I2S_Type *base, sai_handle_t *handle)
 Tx interrupt handler. More...
 
void SAI_TransferRxHandleIRQ (I2S_Type *base, sai_handle_t *handle)
 Tx interrupt handler. More...
 

Data Structure Documentation

struct sai_config_t

Data Fields

sai_protocol_t protocol
 Audio bus protocol in SAI.
 
sai_sync_mode_t syncMode
 SAI sync mode, control Tx/Rx clock sync.
 
sai_bclk_source_t bclkSource
 Bit Clock source.
 
sai_master_slave_t masterSlave
 Master or slave.
 
struct sai_transfer_format_t

Data Fields

uint32_t sampleRate_Hz
 Sample rate of audio data.
 
uint32_t bitWidth
 Data length of audio data, usually 8/16/24/32 bits.
 
sai_mono_stereo_t stereo
 Mono or stereo.
 
uint8_t watermark
 Watermark value.
 
uint8_t channel
 Transfer start channel.
 
uint8_t channelMask
 enabled channel mask value, reference _sai_channel_mask
 
uint8_t endChannel
 end channel number
 
uint8_t channelNums
 Total enabled channel numbers.
 
sai_protocol_t protocol
 Which audio protocol used.
 
bool isFrameSyncCompact
 True means Frame sync length is configurable according to bitWidth, false means frame sync length is 64 times of bit clock. More...
 

Field Documentation

bool sai_transfer_format_t::isFrameSyncCompact
struct sai_fifo_t

Data Fields

bool fifoContinueOneError
 fifo continues when error occur
 
sai_fifo_packing_t fifoPacking
 fifo packing mode
 
uint8_t fifoWatermark
 fifo watermark
 
struct sai_bit_clock_t

Data Fields

bool bclkSrcSwap
 bit clock source swap
 
bool bclkInputDelay
 bit clock actually used by the transmitter is delayed by the pad output delay, this has effect of decreasing the data input setup time, but increasing the data output valid time . More...
 
sai_clock_polarity_t bclkPolarity
 bit clock polarity
 
sai_bclk_source_t bclkSource
 bit Clock source
 

Field Documentation

bool sai_bit_clock_t::bclkInputDelay
struct sai_frame_sync_t

Data Fields

uint8_t frameSyncWidth
 frame sync width in number of bit clocks
 
bool frameSyncEarly
 TRUE is frame sync assert one bit before the first bit of frame FALSE is frame sync assert with the first bit of the frame.
 
sai_clock_polarity_t frameSyncPolarity
 frame sync polarity
 
struct sai_serial_data_t

Data Fields

sai_data_pin_state_t dataMode
 sai data pin state when slots masked or channel disabled
 
sai_data_order_t dataOrder
 configure whether the LSB or MSB is transmitted first
 
uint8_t dataWord0Length
 configure the number of bits in the first word in each frame
 
uint8_t dataWordNLength
 configure the number of bits in the each word in each frame, except the first word
 
uint8_t dataWordLength
 used to record the data length for dma transfer
 
uint8_t dataFirstBitShifted
 Configure the bit index for the first bit transmitted for each word in the frame.
 
uint8_t dataWordNum
 configure the number of words in each frame
 
uint32_t dataMaskedWord
 configure whether the transmit word is masked
 
struct sai_transceiver_t

Data Fields

sai_serial_data_t serialData
 serial data configurations
 
sai_frame_sync_t frameSync
 ws configurations
 
sai_bit_clock_t bitClock
 bit clock configurations
 
sai_fifo_t fifo
 fifo configurations
 
sai_master_slave_t masterSlave
 transceiver is master or slave
 
sai_sync_mode_t syncMode
 transceiver sync mode
 
uint8_t startChannel
 Transfer start channel.
 
uint8_t channelMask
 enabled channel mask value, reference _sai_channel_mask
 
uint8_t endChannel
 end channel number
 
uint8_t channelNums
 Total enabled channel numbers.
 
struct sai_transfer_t

Data Fields

uint8_t * data
 Data start address to transfer. More...
 
size_t dataSize
 Transfer size. More...
 

Field Documentation

uint8_t* sai_transfer_t::data
size_t sai_transfer_t::dataSize
struct _sai_handle

Data Fields

I2S_Type * base
 base address
 
uint32_t state
 Transfer status.
 
sai_transfer_callback_t callback
 Callback function called at transfer event.
 
void * userData
 Callback parameter passed to callback function.
 
uint8_t bitWidth
 Bit width for transfer, 8/16/24/32 bits.
 
uint8_t channel
 Transfer start channel.
 
uint8_t channelMask
 enabled channel mask value, refernece _sai_channel_mask
 
uint8_t endChannel
 end channel number
 
uint8_t channelNums
 Total enabled channel numbers.
 
sai_transfer_t saiQueue [SAI_XFER_QUEUE_SIZE]
 Transfer queue storing queued transfer.
 
size_t transferSize [SAI_XFER_QUEUE_SIZE]
 Data bytes need to transfer.
 
volatile uint8_t queueUser
 Index for user to queue transfer.
 
volatile uint8_t queueDriver
 Index for driver to get the transfer data and size.
 
uint8_t watermark
 Watermark value.
 

Macro Definition Documentation

#define SAI_XFER_QUEUE_SIZE   (4U)

Enumeration Type Documentation

anonymous enum
Enumerator
kStatus_SAI_TxBusy 

SAI Tx is busy.

kStatus_SAI_RxBusy 

SAI Rx is busy.

kStatus_SAI_TxError 

SAI Tx FIFO error.

kStatus_SAI_RxError 

SAI Rx FIFO error.

kStatus_SAI_QueueFull 

SAI transfer queue is full.

kStatus_SAI_TxIdle 

SAI Tx is idle.

kStatus_SAI_RxIdle 

SAI Rx is idle.

anonymous enum
Enumerator
kSAI_Channel0Mask 

channel 0 mask value

kSAI_Channel1Mask 

channel 1 mask value

kSAI_Channel2Mask 

channel 2 mask value

kSAI_Channel3Mask 

channel 3 mask value

kSAI_Channel4Mask 

channel 4 mask value

kSAI_Channel5Mask 

channel 5 mask value

kSAI_Channel6Mask 

channel 6 mask value

kSAI_Channel7Mask 

channel 7 mask value

Enumerator
kSAI_BusLeftJustified 

Uses left justified format.

kSAI_BusRightJustified 

Uses right justified format.

kSAI_BusI2S 

Uses I2S format.

kSAI_BusPCMA 

Uses I2S PCM A format.

kSAI_BusPCMB 

Uses I2S PCM B format.

Enumerator
kSAI_Master 

Master mode include bclk and frame sync.

kSAI_Slave 

Slave mode include bclk and frame sync.

kSAI_Bclk_Master_FrameSync_Slave 

bclk in master mode, frame sync in slave mode

kSAI_Bclk_Slave_FrameSync_Master 

bclk in slave mode, frame sync in master mode

Enumerator
kSAI_Stereo 

Stereo sound.

kSAI_MonoRight 

Only Right channel have sound.

kSAI_MonoLeft 

Only left channel have sound.

Enumerator
kSAI_DataLSB 

LSB bit transferred first.

kSAI_DataMSB 

MSB bit transferred first.

Enumerator
kSAI_PolarityActiveHigh 

Drive outputs on rising edge.

kSAI_PolarityActiveLow 

Drive outputs on falling edge.

kSAI_SampleOnFallingEdge 

Sample inputs on falling edge.

kSAI_SampleOnRisingEdge 

Sample inputs on rising edge.

Enumerator
kSAI_ModeAsync 

Asynchronous mode.

kSAI_ModeSync 

Synchronous mode (with receiver or transmit)

Enumerator
kSAI_BclkSourceBusclk 

Bit clock using bus clock.

kSAI_BclkSourceMclkOption1 

Bit clock MCLK option 1.

kSAI_BclkSourceMclkOption2 

Bit clock MCLK option2.

kSAI_BclkSourceMclkOption3 

Bit clock MCLK option3.

kSAI_BclkSourceMclkDiv 

Bit clock using master clock divider.

kSAI_BclkSourceOtherSai0 

Bit clock from other SAI device.

kSAI_BclkSourceOtherSai1 

Bit clock from other SAI device.

anonymous enum
Enumerator
kSAI_WordStartInterruptEnable 

Word start flag, means the first word in a frame detected.

kSAI_SyncErrorInterruptEnable 

Sync error flag, means the sync error is detected.

kSAI_FIFOWarningInterruptEnable 

FIFO warning flag, means the FIFO is empty.

kSAI_FIFOErrorInterruptEnable 

FIFO error flag.

kSAI_FIFORequestInterruptEnable 

FIFO request, means reached watermark.

anonymous enum
Enumerator
kSAI_FIFOWarningDMAEnable 

FIFO warning caused by the DMA request.

kSAI_FIFORequestDMAEnable 

FIFO request caused by the DMA request.

anonymous enum
Enumerator
kSAI_WordStartFlag 

Word start flag, means the first word in a frame detected.

kSAI_SyncErrorFlag 

Sync error flag, means the sync error is detected.

kSAI_FIFOErrorFlag 

FIFO error flag.

kSAI_FIFORequestFlag 

FIFO request flag.

kSAI_FIFOWarningFlag 

FIFO warning flag.

Enumerator
kSAI_ResetTypeSoftware 

Software reset, reset the logic state.

kSAI_ResetTypeFIFO 

FIFO reset, reset the FIFO read and write pointer.

kSAI_ResetAll 

All reset.

Enumerator
kSAI_FifoPackingDisabled 

Packing disabled.

kSAI_FifoPacking8bit 

8 bit packing enabled

kSAI_FifoPacking16bit 

16bit packing enabled

Enumerator
kSAI_SampleRate8KHz 

Sample rate 8000 Hz.

kSAI_SampleRate11025Hz 

Sample rate 11025 Hz.

kSAI_SampleRate12KHz 

Sample rate 12000 Hz.

kSAI_SampleRate16KHz 

Sample rate 16000 Hz.

kSAI_SampleRate22050Hz 

Sample rate 22050 Hz.

kSAI_SampleRate24KHz 

Sample rate 24000 Hz.

kSAI_SampleRate32KHz 

Sample rate 32000 Hz.

kSAI_SampleRate44100Hz 

Sample rate 44100 Hz.

kSAI_SampleRate48KHz 

Sample rate 48000 Hz.

kSAI_SampleRate96KHz 

Sample rate 96000 Hz.

kSAI_SampleRate192KHz 

Sample rate 192000 Hz.

kSAI_SampleRate384KHz 

Sample rate 384000 Hz.

Enumerator
kSAI_WordWidth8bits 

Audio data width 8 bits.

kSAI_WordWidth16bits 

Audio data width 16 bits.

kSAI_WordWidth24bits 

Audio data width 24 bits.

kSAI_WordWidth32bits 

Audio data width 32 bits.

Enumerator
kSAI_DataPinStateTriState 

transmit data pins are tri-stated when slots are masked or channels are disabled

kSAI_DataPinStateOutputZero 

transmit data pins are never tri-stated and will output zero when slots are masked or channel disabled

Enumerator
kSAI_Transmitter 

sai transmitter

kSAI_Receiver 

sai receiver

Enumerator
kSAI_FrameSyncLenOneBitClk 

1 bit clock frame sync len for DSP mode

kSAI_FrameSyncLenPerWordWidth 

Frame sync length decided by word width.

Function Documentation

void SAI_TxInit ( I2S_Type *  base,
const sai_config_t config 
)

Ungates the SAI clock, resets the module, and configures SAI Tx with a configuration structure. The configuration structure can be custom filled or set with default values by SAI_TxGetDefaultConfig().

Note
This API should be called at the beginning of the application to use the SAI driver. Otherwise, accessing the SAIM module can cause a hard fault because the clock is not enabled.
Parameters
baseSAI base pointer
configSAI configuration structure.
void SAI_RxInit ( I2S_Type *  base,
const sai_config_t config 
)

Ungates the SAI clock, resets the module, and configures the SAI Rx with a configuration structure. The configuration structure can be custom filled or set with default values by SAI_RxGetDefaultConfig().

Note
This API should be called at the beginning of the application to use the SAI driver. Otherwise, accessing the SAI module can cause a hard fault because the clock is not enabled.
Parameters
baseSAI base pointer
configSAI configuration structure.
void SAI_TxGetDefaultConfig ( sai_config_t config)

This API initializes the configuration structure for use in SAI_TxConfig(). The initialized structure can remain unchanged in SAI_TxConfig(), or it can be modified before calling SAI_TxConfig(). This is an example.

Parameters
configpointer to master configuration structure
void SAI_RxGetDefaultConfig ( sai_config_t config)

This API initializes the configuration structure for use in SAI_RxConfig(). The initialized structure can remain unchanged in SAI_RxConfig() or it can be modified before calling SAI_RxConfig(). This is an example.

Parameters
configpointer to master configuration structure
void SAI_Init ( I2S_Type *  base)

This API gates the SAI clock. The SAI module can't operate unless SAI_Init is called to enable the clock.

Parameters
baseSAI base pointer.
void SAI_Deinit ( I2S_Type *  base)

This API gates the SAI clock. The SAI module can't operate unless SAI_TxInit or SAI_RxInit is called to enable the clock.

Parameters
baseSAI base pointer.
void SAI_TxReset ( I2S_Type *  base)

This function enables the software reset and FIFO reset of SAI Tx. After reset, clear the reset bit.

Parameters
baseSAI base pointer
void SAI_RxReset ( I2S_Type *  base)

This function enables the software reset and FIFO reset of SAI Rx. After reset, clear the reset bit.

Parameters
baseSAI base pointer
void SAI_TxEnable ( I2S_Type *  base,
bool  enable 
)
Parameters
baseSAI base pointer.
enableTrue means enable SAI Tx, false means disable.
void SAI_RxEnable ( I2S_Type *  base,
bool  enable 
)
Parameters
baseSAI base pointer.
enableTrue means enable SAI Rx, false means disable.
static void SAI_TxSetBitClockDirection ( I2S_Type *  base,
sai_master_slave_t  masterSlave 
)
inlinestatic

Select bit clock direction, master or slave.

Parameters
baseSAI base pointer.
masterSlavereference sai_master_slave_t.
static void SAI_RxSetBitClockDirection ( I2S_Type *  base,
sai_master_slave_t  masterSlave 
)
inlinestatic

Select bit clock direction, master or slave.

Parameters
baseSAI base pointer.
masterSlavereference sai_master_slave_t.
static void SAI_RxSetFrameSyncDirection ( I2S_Type *  base,
sai_master_slave_t  masterSlave 
)
inlinestatic

Select frame sync direction, master or slave.

Parameters
baseSAI base pointer.
masterSlavereference sai_master_slave_t.
static void SAI_TxSetFrameSyncDirection ( I2S_Type *  base,
sai_master_slave_t  masterSlave 
)
inlinestatic

Select frame sync direction, master or slave.

Parameters
baseSAI base pointer.
masterSlavereference sai_master_slave_t.
void SAI_TxSetBitClockRate ( I2S_Type *  base,
uint32_t  sourceClockHz,
uint32_t  sampleRate,
uint32_t  bitWidth,
uint32_t  channelNumbers 
)
Parameters
baseSAI base pointer.
sourceClockHz,bitclock source frequency.
sampleRateaudio data sample rate.
bitWidth,audiodata bitWidth.
channelNumbers,audiochannel numbers.
void SAI_RxSetBitClockRate ( I2S_Type *  base,
uint32_t  sourceClockHz,
uint32_t  sampleRate,
uint32_t  bitWidth,
uint32_t  channelNumbers 
)
Parameters
baseSAI base pointer.
sourceClockHz,bitclock source frequency.
sampleRateaudio data sample rate.
bitWidth,audiodata bitWidth.
channelNumbers,audiochannel numbers.
void SAI_TxSetBitclockConfig ( I2S_Type *  base,
sai_master_slave_t  masterSlave,
sai_bit_clock_t config 
)
Parameters
baseSAI base pointer.
masterSlavemaster or slave.
configbit clock other configurations, can be NULL in slave mode.
void SAI_RxSetBitclockConfig ( I2S_Type *  base,
sai_master_slave_t  masterSlave,
sai_bit_clock_t config 
)
Parameters
baseSAI base pointer.
masterSlavemaster or slave.
configbit clock other configurations, can be NULL in slave mode.
void SAI_TxSetFifoConfig ( I2S_Type *  base,
sai_fifo_t config 
)
Parameters
baseSAI base pointer.
configfifo configurations.
void SAI_RxSetFifoConfig ( I2S_Type *  base,
sai_fifo_t config 
)
Parameters
baseSAI base pointer.
configfifo configurations.
void SAI_TxSetFrameSyncConfig ( I2S_Type *  base,
sai_master_slave_t  masterSlave,
sai_frame_sync_t config 
)
Parameters
baseSAI base pointer.
masterSlavemaster or slave.
configframe sync configurations, can be NULL in slave mode.
void SAI_RxSetFrameSyncConfig ( I2S_Type *  base,
sai_master_slave_t  masterSlave,
sai_frame_sync_t config 
)
Parameters
baseSAI base pointer.
masterSlavemaster or slave.
configframe sync configurations, can be NULL in slave mode.
void SAI_TxSetSerialDataConfig ( I2S_Type *  base,
sai_serial_data_t config 
)
Parameters
baseSAI base pointer.
configserial data configurations.
void SAI_RxSetSerialDataConfig ( I2S_Type *  base,
sai_serial_data_t config 
)
Parameters
baseSAI base pointer.
configserial data configurations.
void SAI_TxSetConfig ( I2S_Type *  base,
sai_transceiver_t config 
)
Parameters
baseSAI base pointer.
configtransmitter configurations.
void SAI_RxSetConfig ( I2S_Type *  base,
sai_transceiver_t config 
)
Parameters
baseSAI base pointer.
configreceiver configurations.
void SAI_GetClassicI2SConfig ( sai_transceiver_t config,
sai_word_width_t  bitWidth,
sai_mono_stereo_t  mode,
uint32_t  saiChannelMask 
)
Parameters
configtransceiver configurations.
bitWidthaudio data bitWidth.
modeaudio data channel.
saiChannelMaskmask value of the channel to be enable.
void SAI_GetLeftJustifiedConfig ( sai_transceiver_t config,
sai_word_width_t  bitWidth,
sai_mono_stereo_t  mode,
uint32_t  saiChannelMask 
)
Parameters
configtransceiver configurations.
bitWidthaudio data bitWidth.
modeaudio data channel.
saiChannelMaskmask value of the channel to be enable.
void SAI_GetRightJustifiedConfig ( sai_transceiver_t config,
sai_word_width_t  bitWidth,
sai_mono_stereo_t  mode,
uint32_t  saiChannelMask 
)
Parameters
configtransceiver configurations.
bitWidthaudio data bitWidth.
modeaudio data channel.
saiChannelMaskmask value of the channel to be enable.
void SAI_GetTDMConfig ( sai_transceiver_t config,
sai_frame_sync_len_t  frameSyncWidth,
sai_word_width_t  bitWidth,
uint32_t  dataWordNum,
uint32_t  saiChannelMask 
)
Parameters
configtransceiver configurations.
frameSyncWidthlength of frame sync.
bitWidthaudio data word width.
dataWordNumword number in one frame.
saiChannelMaskmask value of the channel to be enable.
void SAI_GetDSPConfig ( sai_transceiver_t config,
sai_frame_sync_len_t  frameSyncWidth,
sai_word_width_t  bitWidth,
sai_mono_stereo_t  mode,
uint32_t  saiChannelMask 
)
Parameters
configtransceiver configurations.
frameSyncWidthlength of frame sync.
bitWidthaudio data bitWidth.
modeaudio data channel.
saiChannelMaskmask value of the channel to enable.
static uint32_t SAI_TxGetStatusFlag ( I2S_Type *  base)
inlinestatic
Parameters
baseSAI base pointer
Returns
SAI Tx status flag value. Use the Status Mask to get the status value needed.
static void SAI_TxClearStatusFlags ( I2S_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseSAI base pointer
maskState mask. It can be a combination of the following source if defined:
  • kSAI_WordStartFlag
  • kSAI_SyncErrorFlag
  • kSAI_FIFOErrorFlag
static uint32_t SAI_RxGetStatusFlag ( I2S_Type *  base)
inlinestatic
Parameters
baseSAI base pointer
Returns
SAI Rx status flag value. Use the Status Mask to get the status value needed.
static void SAI_RxClearStatusFlags ( I2S_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseSAI base pointer
maskState mask. It can be a combination of the following sources if defined.
  • kSAI_WordStartFlag
  • kSAI_SyncErrorFlag
  • kSAI_FIFOErrorFlag
void SAI_TxSoftwareReset ( I2S_Type *  base,
sai_reset_type_t  type 
)

FIFO reset means clear all the data in the FIFO, and make the FIFO pointer both to 0. Software reset means clear the Tx internal logic, including the bit clock, frame count etc. But software reset will not clear any configuration registers like TCR1~TCR5. This function will also clear all the error flags such as FIFO error, sync error etc.

Parameters
baseSAI base pointer
typeReset type, FIFO reset or software reset
void SAI_RxSoftwareReset ( I2S_Type *  base,
sai_reset_type_t  type 
)

FIFO reset means clear all the data in the FIFO, and make the FIFO pointer both to 0. Software reset means clear the Rx internal logic, including the bit clock, frame count etc. But software reset will not clear any configuration registers like RCR1~RCR5. This function will also clear all the error flags such as FIFO error, sync error etc.

Parameters
baseSAI base pointer
typeReset type, FIFO reset or software reset
void SAI_TxSetChannelFIFOMask ( I2S_Type *  base,
uint8_t  mask 
)
Parameters
baseSAI base pointer
maskChannel enable mask, 0 means all channel FIFO disabled, 1 means channel 0 enabled, 3 means both channel 0 and channel 1 enabled.
void SAI_RxSetChannelFIFOMask ( I2S_Type *  base,
uint8_t  mask 
)
Parameters
baseSAI base pointer
maskChannel enable mask, 0 means all channel FIFO disabled, 1 means channel 0 enabled, 3 means both channel 0 and channel 1 enabled.
void SAI_TxSetDataOrder ( I2S_Type *  base,
sai_data_order_t  order 
)
Parameters
baseSAI base pointer
orderData order MSB or LSB
void SAI_RxSetDataOrder ( I2S_Type *  base,
sai_data_order_t  order 
)
Parameters
baseSAI base pointer
orderData order MSB or LSB
void SAI_TxSetBitClockPolarity ( I2S_Type *  base,
sai_clock_polarity_t  polarity 
)
Parameters
baseSAI base pointer
orderData order MSB or LSB
void SAI_RxSetBitClockPolarity ( I2S_Type *  base,
sai_clock_polarity_t  polarity 
)
Parameters
baseSAI base pointer
orderData order MSB or LSB
void SAI_TxSetFrameSyncPolarity ( I2S_Type *  base,
sai_clock_polarity_t  polarity 
)
Parameters
baseSAI base pointer
orderData order MSB or LSB
void SAI_RxSetFrameSyncPolarity ( I2S_Type *  base,
sai_clock_polarity_t  polarity 
)
Parameters
baseSAI base pointer
orderData order MSB or LSB
void SAI_TxSetFIFOPacking ( I2S_Type *  base,
sai_fifo_packing_t  pack 
)
Parameters
baseSAI base pointer.
packFIFO pack type. It is element of sai_fifo_packing_t.
void SAI_RxSetFIFOPacking ( I2S_Type *  base,
sai_fifo_packing_t  pack 
)
Parameters
baseSAI base pointer.
packFIFO pack type. It is element of sai_fifo_packing_t.
static void SAI_TxSetFIFOErrorContinue ( I2S_Type *  base,
bool  isEnabled 
)
inlinestatic

FIFO error continue mode means SAI will keep running while FIFO error occurred. If this feature not enabled, SAI will hang and users need to clear FEF flag in TCSR register.

Parameters
baseSAI base pointer.
isEnabledIs FIFO error continue enabled, true means enable, false means disable.
static void SAI_RxSetFIFOErrorContinue ( I2S_Type *  base,
bool  isEnabled 
)
inlinestatic

FIFO error continue mode means SAI will keep running while FIFO error occurred. If this feature not enabled, SAI will hang and users need to clear FEF flag in RCSR register.

Parameters
baseSAI base pointer.
isEnabledIs FIFO error continue enabled, true means enable, false means disable.
static void SAI_TxEnableInterrupts ( I2S_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseSAI base pointer
maskinterrupt source The parameter can be a combination of the following sources if defined.
  • kSAI_WordStartInterruptEnable
  • kSAI_SyncErrorInterruptEnable
  • kSAI_FIFOWarningInterruptEnable
  • kSAI_FIFORequestInterruptEnable
  • kSAI_FIFOErrorInterruptEnable
static void SAI_RxEnableInterrupts ( I2S_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseSAI base pointer
maskinterrupt source The parameter can be a combination of the following sources if defined.
  • kSAI_WordStartInterruptEnable
  • kSAI_SyncErrorInterruptEnable
  • kSAI_FIFOWarningInterruptEnable
  • kSAI_FIFORequestInterruptEnable
  • kSAI_FIFOErrorInterruptEnable
static void SAI_TxDisableInterrupts ( I2S_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseSAI base pointer
maskinterrupt source The parameter can be a combination of the following sources if defined.
  • kSAI_WordStartInterruptEnable
  • kSAI_SyncErrorInterruptEnable
  • kSAI_FIFOWarningInterruptEnable
  • kSAI_FIFORequestInterruptEnable
  • kSAI_FIFOErrorInterruptEnable
static void SAI_RxDisableInterrupts ( I2S_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseSAI base pointer
maskinterrupt source The parameter can be a combination of the following sources if defined.
  • kSAI_WordStartInterruptEnable
  • kSAI_SyncErrorInterruptEnable
  • kSAI_FIFOWarningInterruptEnable
  • kSAI_FIFORequestInterruptEnable
  • kSAI_FIFOErrorInterruptEnable
static void SAI_TxEnableDMA ( I2S_Type *  base,
uint32_t  mask,
bool  enable 
)
inlinestatic
Parameters
baseSAI base pointer
maskDMA source The parameter can be combination of the following sources if defined.
  • kSAI_FIFOWarningDMAEnable
  • kSAI_FIFORequestDMAEnable
enableTrue means enable DMA, false means disable DMA.
static void SAI_RxEnableDMA ( I2S_Type *  base,
uint32_t  mask,
bool  enable 
)
inlinestatic
Parameters
baseSAI base pointer
maskDMA source The parameter can be a combination of the following sources if defined.
  • kSAI_FIFOWarningDMAEnable
  • kSAI_FIFORequestDMAEnable
enableTrue means enable DMA, false means disable DMA.
static uint32_t SAI_TxGetDataRegisterAddress ( I2S_Type *  base,
uint32_t  channel 
)
inlinestatic

This API is used to provide a transfer address for the SAI DMA transfer configuration.

Parameters
baseSAI base pointer.
channelWhich data channel used.
Returns
data register address.
static uint32_t SAI_RxGetDataRegisterAddress ( I2S_Type *  base,
uint32_t  channel 
)
inlinestatic

This API is used to provide a transfer address for the SAI DMA transfer configuration.

Parameters
baseSAI base pointer.
channelWhich data channel used.
Returns
data register address.
void SAI_TxSetFormat ( I2S_Type *  base,
sai_transfer_format_t format,
uint32_t  mclkSourceClockHz,
uint32_t  bclkSourceClockHz 
)

The audio format can be changed at run-time. This function configures the sample rate and audio data format to be transferred.

Parameters
baseSAI base pointer.
formatPointer to the SAI audio data format structure.
mclkSourceClockHzSAI master clock source frequency in Hz.
bclkSourceClockHzSAI bit clock source frequency in Hz. If the bit clock source is a master clock, this value should equal the masterClockHz.
void SAI_RxSetFormat ( I2S_Type *  base,
sai_transfer_format_t format,
uint32_t  mclkSourceClockHz,
uint32_t  bclkSourceClockHz 
)

The audio format can be changed at run-time. This function configures the sample rate and audio data format to be transferred.

Parameters
baseSAI base pointer.
formatPointer to the SAI audio data format structure.
mclkSourceClockHzSAI master clock source frequency in Hz.
bclkSourceClockHzSAI bit clock source frequency in Hz. If the bit clock source is a master clock, this value should equal the masterClockHz.
void SAI_WriteBlocking ( I2S_Type *  base,
uint32_t  channel,
uint32_t  bitWidth,
uint8_t *  buffer,
uint32_t  size 
)
Note
This function blocks by polling until data is ready to be sent.
Parameters
baseSAI base pointer.
channelData channel used.
bitWidthHow many bits in an audio word; usually 8/16/24/32 bits.
bufferPointer to the data to be written.
sizeBytes to be written.
void SAI_WriteMultiChannelBlocking ( I2S_Type *  base,
uint32_t  channel,
uint32_t  channelMask,
uint32_t  bitWidth,
uint8_t *  buffer,
uint32_t  size 
)
Note
This function blocks by polling until data is ready to be sent.
Parameters
baseSAI base pointer.
channelData channel used.
channelMaskchannel mask.
bitWidthHow many bits in an audio word; usually 8/16/24/32 bits.
bufferPointer to the data to be written.
sizeBytes to be written.
static void SAI_WriteData ( I2S_Type *  base,
uint32_t  channel,
uint32_t  data 
)
inlinestatic
Parameters
baseSAI base pointer.
channelData channel used.
dataData needs to be written.
void SAI_ReadBlocking ( I2S_Type *  base,
uint32_t  channel,
uint32_t  bitWidth,
uint8_t *  buffer,
uint32_t  size 
)
Note
This function blocks by polling until data is ready to be sent.
Parameters
baseSAI base pointer.
channelData channel used.
bitWidthHow many bits in an audio word; usually 8/16/24/32 bits.
bufferPointer to the data to be read.
sizeBytes to be read.
void SAI_ReadMultiChannelBlocking ( I2S_Type *  base,
uint32_t  channel,
uint32_t  channelMask,
uint32_t  bitWidth,
uint8_t *  buffer,
uint32_t  size 
)
Note
This function blocks by polling until data is ready to be sent.
Parameters
baseSAI base pointer.
channelData channel used.
channelMaskchannel mask.
bitWidthHow many bits in an audio word; usually 8/16/24/32 bits.
bufferPointer to the data to be read.
sizeBytes to be read.
static uint32_t SAI_ReadData ( I2S_Type *  base,
uint32_t  channel 
)
inlinestatic
Parameters
baseSAI base pointer.
channelData channel used.
Returns
Data in SAI FIFO.
void SAI_TransferTxCreateHandle ( I2S_Type *  base,
sai_handle_t *  handle,
sai_transfer_callback_t  callback,
void *  userData 
)

This function initializes the Tx handle for the SAI Tx transactional APIs. Call this function once to get the handle initialized.

Parameters
baseSAI base pointer
handleSAI handle pointer.
callbackPointer to the user callback function.
userDataUser parameter passed to the callback function
void SAI_TransferRxCreateHandle ( I2S_Type *  base,
sai_handle_t *  handle,
sai_transfer_callback_t  callback,
void *  userData 
)

This function initializes the Rx handle for the SAI Rx transactional APIs. Call this function once to get the handle initialized.

Parameters
baseSAI base pointer.
handleSAI handle pointer.
callbackPointer to the user callback function.
userDataUser parameter passed to the callback function.
void SAI_TransferTxSetConfig ( I2S_Type *  base,
sai_handle_t *  handle,
sai_transceiver_t config 
)

This function initializes the Tx, include bit clock, frame sync, master clock, serial data and fifo configurations.

Parameters
baseSAI base pointer.
handleSAI handle pointer.
configtranmitter configurations.
void SAI_TransferRxSetConfig ( I2S_Type *  base,
sai_handle_t *  handle,
sai_transceiver_t config 
)

This function initializes the Rx, include bit clock, frame sync, master clock, serial data and fifo configurations.

Parameters
baseSAI base pointer.
handleSAI handle pointer.
configreceiver configurations.
status_t SAI_TransferTxSetFormat ( I2S_Type *  base,
sai_handle_t *  handle,
sai_transfer_format_t format,
uint32_t  mclkSourceClockHz,
uint32_t  bclkSourceClockHz 
)

The audio format can be changed at run-time. This function configures the sample rate and audio data format to be transferred.

Parameters
baseSAI base pointer.
handleSAI handle pointer.
formatPointer to the SAI audio data format structure.
mclkSourceClockHzSAI master clock source frequency in Hz.
bclkSourceClockHzSAI bit clock source frequency in Hz. If a bit clock source is a master clock, this value should equal the masterClockHz in format.
Returns
Status of this function. Return value is the status_t.
status_t SAI_TransferRxSetFormat ( I2S_Type *  base,
sai_handle_t *  handle,
sai_transfer_format_t format,
uint32_t  mclkSourceClockHz,
uint32_t  bclkSourceClockHz 
)

The audio format can be changed at run-time. This function configures the sample rate and audio data format to be transferred.

Parameters
baseSAI base pointer.
handleSAI handle pointer.
formatPointer to the SAI audio data format structure.
mclkSourceClockHzSAI master clock source frequency in Hz.
bclkSourceClockHzSAI bit clock source frequency in Hz. If a bit clock source is a master clock, this value should equal the masterClockHz in format.
Returns
Status of this function. Return value is one of status_t.
status_t SAI_TransferSendNonBlocking ( I2S_Type *  base,
sai_handle_t *  handle,
sai_transfer_t xfer 
)
Note
This API returns immediately after the transfer initiates. Call the SAI_TxGetTransferStatusIRQ to poll the transfer status and check whether the transfer is finished. If the return status is not kStatus_SAI_Busy, the transfer is finished.
Parameters
baseSAI base pointer.
handlePointer to the sai_handle_t structure which stores the transfer state.
xferPointer to the sai_transfer_t structure.
Return values
kStatus_SuccessSuccessfully started the data receive.
kStatus_SAI_TxBusyPrevious receive still not finished.
kStatus_InvalidArgumentThe input parameter is invalid.
status_t SAI_TransferReceiveNonBlocking ( I2S_Type *  base,
sai_handle_t *  handle,
sai_transfer_t xfer 
)
Note
This API returns immediately after the transfer initiates. Call the SAI_RxGetTransferStatusIRQ to poll the transfer status and check whether the transfer is finished. If the return status is not kStatus_SAI_Busy, the transfer is finished.
Parameters
baseSAI base pointer
handlePointer to the sai_handle_t structure which stores the transfer state.
xferPointer to the sai_transfer_t structure.
Return values
kStatus_SuccessSuccessfully started the data receive.
kStatus_SAI_RxBusyPrevious receive still not finished.
kStatus_InvalidArgumentThe input parameter is invalid.
status_t SAI_TransferGetSendCount ( I2S_Type *  base,
sai_handle_t *  handle,
size_t *  count 
)
Parameters
baseSAI base pointer.
handlePointer to the sai_handle_t structure which stores the transfer state.
countBytes count sent.
Return values
kStatus_SuccessSucceed get the transfer count.
kStatus_NoTransferInProgressThere is not a non-blocking transaction currently in progress.
status_t SAI_TransferGetReceiveCount ( I2S_Type *  base,
sai_handle_t *  handle,
size_t *  count 
)
Parameters
baseSAI base pointer.
handlePointer to the sai_handle_t structure which stores the transfer state.
countBytes count received.
Return values
kStatus_SuccessSucceed get the transfer count.
kStatus_NoTransferInProgressThere is not a non-blocking transaction currently in progress.
void SAI_TransferAbortSend ( I2S_Type *  base,
sai_handle_t *  handle 
)
Note
This API can be called any time when an interrupt non-blocking transfer initiates to abort the transfer early.
Parameters
baseSAI base pointer.
handlePointer to the sai_handle_t structure which stores the transfer state.
void SAI_TransferAbortReceive ( I2S_Type *  base,
sai_handle_t *  handle 
)
Note
This API can be called when an interrupt non-blocking transfer initiates to abort the transfer early.
Parameters
baseSAI base pointer
handlePointer to the sai_handle_t structure which stores the transfer state.
void SAI_TransferTerminateSend ( I2S_Type *  base,
sai_handle_t *  handle 
)

This function will clear all transfer slots buffered in the sai queue. If users only want to abort the current transfer slot, please call SAI_TransferAbortSend.

Parameters
baseSAI base pointer.
handleSAI eDMA handle pointer.
void SAI_TransferTerminateReceive ( I2S_Type *  base,
sai_handle_t *  handle 
)

This function will clear all transfer slots buffered in the sai queue. If users only want to abort the current transfer slot, please call SAI_TransferAbortReceive.

Parameters
baseSAI base pointer.
handleSAI eDMA handle pointer.
void SAI_TransferTxHandleIRQ ( I2S_Type *  base,
sai_handle_t *  handle 
)
Parameters
baseSAI base pointer.
handlePointer to the sai_handle_t structure.
void SAI_TransferRxHandleIRQ ( I2S_Type *  base,
sai_handle_t *  handle 
)
Parameters
baseSAI base pointer.
handlePointer to the sai_handle_t structure.