![]() |
Kinetis SDK v.1.2 API Reference Manual
Rev. 0
Freescale Semiconductor, Inc.
|
This section describes the programming interface of the SAI Peripheral driver. The SAI driver initializes, configures, starts, and stops the SAI. The SAI driver also implements configuration functions, sends, and receives data.
To initialize SAI, call the SAI_DRV_TxInit() or SAI_DRV_RxInit() functions and pass the SAI instance and SAI configuration structure parameters. The function opens the clock gate and initializes the SAI modules according to the structure information.
Configuration is implemented by the SAI_DRV_TxConfigDataFormat() function. To use this function, transfer the audio data format to the SAI module.
To use the SAI driver, follow these steps and use Tx as an example:
This is example code to initialize and configure the SAI driver in the DMA mode:
Files | |
file | fsl_sai_driver.h |
Data Structures | |
struct | sai_data_format_t |
Defines the PCM data format. More... | |
struct | sai_state_t |
SAI internal state Users should allocate and transfer memory to the PD during the initialization function. More... | |
struct | sai_user_config_t |
The description structure for the SAI TX/RX module. More... | |
Typedefs | |
typedef void(* | sai_callback_t )(void *parameter) |
SAI callback function. | |
Enumerations | |
enum | sai_status_t { kStatus_SAI_Success = 0U, kStatus_SAI_Fail = 1U, kStatus_SAI_DeviceBusy = 2U } |
Status structure for SAI. | |
Functions | |
sai_status_t | SAI_DRV_TxInit (uint32_t instance, sai_user_config_t *config, sai_state_t *state) |
Initializes the SAI module. More... | |
sai_status_t | SAI_DRV_RxInit (uint32_t instance, sai_user_config_t *config, sai_state_t *state) |
Initializes the SAI receive module. More... | |
void | SAI_DRV_TxGetDefaultSetting (sai_user_config_t *config) |
Gets the default setting of the user configuration. More... | |
void | SAI_DRV_RxGetDefaultSetting (sai_user_config_t *config) |
Gets the default setting of the user configuration. More... | |
sai_status_t | SAI_DRV_TxDeinit (uint32_t instance) |
De-initializes the SAI transmit module. More... | |
sai_status_t | SAI_DRV_RxDeinit (uint32_t instance) |
De-initializes the SAI receive module. More... | |
sai_status_t | SAI_DRV_TxConfigDataFormat (uint32_t instance, sai_data_format_t *format) |
Configures audio data format of the transmit. More... | |
sai_status_t | SAI_DRV_RxConfigDataFormat (uint32_t instance, sai_data_format_t *format) |
Configures audio data format of the receive. More... | |
void | SAI_DRV_TxStartModule (uint32_t instance) |
Starts the transmit transfer. More... | |
void | SAI_DRV_RxStartModule (uint32_t instance) |
Starts the receive process. More... | |
static void | SAI_DRV_TxStopModule (uint32_t instance) |
Stops writing data to FIFO to disable the DMA or the interrupt request bit. More... | |
static void | SAI_DRV_RxStopModule (uint32_t instance) |
Stops receiving data from FIFO to disable the DMA or the interrupt request bit. More... | |
static void | SAI_DRV_TxSetIntCmd (uint32_t instance, bool enable) |
Enables or disables the transmit interrupt source. More... | |
static void | SAI_DRV_RxSetIntCmd (uint32_t instance, bool enable) |
Enables or disables the receive interrupt source. More... | |
static void | SAI_DRV_TxSetDmaCmd (uint32_t instance, bool enable) |
Enables or disables the transmit DMA source. More... | |
static void | SAI_DRV_RxSetDmaCmd (uint32_t instance, bool enable) |
Enables or disables the receive interrupt source. More... | |
static uint32_t | SAI_DRV_TxGetFifoAddr (uint32_t instance, uint32_t fifo_channel) |
Gets the transmit FIFO address of the data channel. More... | |
static uint32_t | SAI_DRV_RxGetFifoAddr (uint32_t instance, uint32_t fifo_channel) |
Gets the receive FIFO address of the data channel. More... | |
uint32_t | SAI_DRV_SendDataInt (uint32_t instance, uint8_t *addr, uint32_t len) |
Sends data using interrupts. More... | |
uint32_t | SAI_DRV_ReceiveDataInt (uint32_t instance, uint8_t *addr, uint32_t len) |
Receives data a certain length using interrupt way. More... | |
uint32_t | SAI_DRV_SendDataDma (uint32_t instance, uint8_t *addr, uint32_t len) |
Sends data of a certain length using the DMA way. More... | |
uint32_t | SAI_DRV_ReceiveDataDma (uint32_t instance, uint8_t *addr, uint32_t len) |
Receives data using the DMA. More... | |
void | SAI_DRV_TxRegisterCallback (uint32_t instance, sai_callback_t callback, void *callback_param) |
Registers the callback function after completing a send. More... | |
void | SAI_DRV_RxRegisterCallback (uint32_t instance, sai_callback_t callback, void *callback_param) |
Registers the callback function after completing a receive. More... | |
void | SAI_DRV_TxIRQHandler (uint32_t instance) |
Default SAI transmit interrupt handler. More... | |
void | SAI_DRV_RxIRQHandler (uint32_t instance) |
Default SAI receive interrupt handler. More... | |
Variables | |
I2S_Type *const | g_saiBase [I2S_INSTANCE_COUNT] |
const IRQn_Type | g_saiTxIrqId [I2S_INSTANCE_COUNT] |
const IRQn_Type | g_saiRxIrqId [I2S_INSTANCE_COUNT] |
struct sai_data_format_t |
Data Fields | |
uint32_t | sample_rate |
Sample rate of the PCM file. | |
uint32_t | mclk |
Master clock frequency. | |
uint8_t | bits |
How many bits in a word. | |
sai_mono_stereo_t | mono_stereo |
How many word in a frame. | |
struct sai_state_t |
Note: During the SAI execution, users should not free the state. Otherwise, the driver malfunctions.
Data Fields | |
sai_data_format_t | format |
uint8_t * | address |
uint32_t | len |
uint32_t | count |
sai_callback_t | callback |
void * | callback_param |
sai_sync_mode_t | sync_mode |
uint32_t | fifo_channel |
sai_master_slave_t | master_slave |
sai_protocol_t | protocol |
dma_channel_t | chn |
semaphore_t | sem |
bool | use_dma |
uint32_t | dma_source |
struct sai_user_config_t |
Data Fields | |
sai_mclk_source_t | mclk_source |
Master clock source. | |
uint8_t | channel |
Which FIFO is used to transfer. | |
sai_sync_mode_t | sync_mode |
Synchronous or asynchronous. | |
sai_protocol_t | protocol |
I2S left, I2S right or I2S type. | |
sai_master_slave_t | slave_master |
Master or slave. | |
sai_bclk_source_t | bclk_source |
Bit clock from master clock or other modules. | |
uint32_t | dma_source |
Dma request source. | |
sai_status_t SAI_DRV_TxInit | ( | uint32_t | instance, |
sai_user_config_t * | config, | ||
sai_state_t * | state | ||
) |
This function initializes the SAI registers according to the configuration structure. This function also initializes the basic SAI settings including board-relevant settings. Notice: This function does not initialize an entire SAI instance. It only initializes the transmit according to the value in the handler.
instance | SAI module instance. |
config | The configuration structure of SAI. |
state | Pointer of SAI run state structure. |
sai_status_t SAI_DRV_RxInit | ( | uint32_t | instance, |
sai_user_config_t * | config, | ||
sai_state_t * | state | ||
) |
This function initializes the SAI registers according to the configuration structure. This function also initializes the basic SAI settings including board-relevant settings. Note that this function does not initialize an entire SAI instance. This function only initializes the transmit according to the value in the handler.
instance | SAI module instance. |
config | The configuration structure of SAI. |
state | Pointer of SAI run state structure. |
void SAI_DRV_TxGetDefaultSetting | ( | sai_user_config_t * | config | ) |
The default settings for SAI are:
config | Pointer of user configure structure. |
void SAI_DRV_RxGetDefaultSetting | ( | sai_user_config_t * | config | ) |
The default settings for SAI are: Audio protocol is I2S format Watermark is 4 Use SAI0 Data channel is channel0 SAI as master MCLK from system core clock Receive is in synchronous way
config | Pointer of user configure structure. |
sai_status_t SAI_DRV_TxDeinit | ( | uint32_t | instance | ) |
This function closes the SAI transmit device. It does not close the entire SAI instance. It only closes the clock gate while both transmit and receive are closed in the same instance.
instance | SAI module instance. |
sai_status_t SAI_DRV_RxDeinit | ( | uint32_t | instance | ) |
This function closes the SAI receive device. It does not close the entire SAI instance. It only closes the clock gate while both transmit and receive are closed in the same instance.
instance | SAI module instance. |
sai_status_t SAI_DRV_TxConfigDataFormat | ( | uint32_t | instance, |
sai_data_format_t * | format | ||
) |
The function configures an audio sample rate, data bits, and a channel number.
instance | SAI module instance. |
format | PCM data format structure pointer. |
sai_status_t SAI_DRV_RxConfigDataFormat | ( | uint32_t | instance, |
sai_data_format_t * | format | ||
) |
The function configures an audio sample rate, data bits, and a channel number.
instance | SAI module instance of the SAI module. |
format | PCM data format structure pointer. |
void SAI_DRV_TxStartModule | ( | uint32_t | instance | ) |
The function enables the interrupt/DMA request source and the transmit channel.
instance | SAI module instance. |
void SAI_DRV_RxStartModule | ( | uint32_t | instance | ) |
The function enables the interrupt/DMA request source and the transmit channel.
instance | SAI module instance of the SAI module. |
|
inlinestatic |
This function provides the method to pause writing data.
instance | SAI module instance. |
|
inlinestatic |
This function provides the method to pause writing data.
instance | SAI module instance. |
|
inlinestatic |
instance | SAI module instance. |
enable | True means enable interrupt source, false means disable interrupt source. |
|
inlinestatic |
instance | SAI module instance. |
enable | True means enable interrupt source, false means disable interrupt source. |
|
inlinestatic |
instance | SAI module instance. |
enable | True means enable DMA source, false means disable DMA source. |
|
inlinestatic |
instance | SAI module instance. |
enable | True means enable DMA source, false means disable DMA source. |
|
inlinestatic |
This function is mainly used for the DMA settings which the DMA configuration needs for the SAI source/destination address.
instance | SAI module instance of the SAI module. |
fifo_channel | FIFO channel of SAI transmit. |
|
inlinestatic |
This function is mainly used for the DMA settings which the DMA configuration needs for the SAI source/destination address.
instance | SAI module instance of the SAI module. |
fifo_channel | FIFO channel of SAI receive. |
uint32_t SAI_DRV_SendDataInt | ( | uint32_t | instance, |
uint8_t * | addr, | ||
uint32_t | len | ||
) |
This function sends data to the transmit FIFO. This function starts the transfer, and, while finishing the transfer, calls the callback function registered by users. This function is an un-blocking function.
instance | SAI module instance of the SAI module. |
addr | Address of the data which needs to be transferred. |
len | The number of bytes which need to be sent. |
uint32_t SAI_DRV_ReceiveDataInt | ( | uint32_t | instance, |
uint8_t * | addr, | ||
uint32_t | len | ||
) |
This function receives the data from the receive FIFO. This function starts the transfer, and, while finishing the transfer, calls the callback function registered by the user. This function is an un-blocking function.
instance | SAI module instance. |
addr | Address of the data which needs to be transferred. |
len | The number of bytes to receive. |
uint32_t SAI_DRV_SendDataDma | ( | uint32_t | instance, |
uint8_t * | addr, | ||
uint32_t | len | ||
) |
This function sends the data to the transmit FIFO. This function starts the transfer, and, while finishing the transfer, calls the callback function registered by users. This function is an a-sync function.
instance | SAI module instance of the SAI module. |
addr | Address of the data which needs to be transferred. |
len | The number of bytes which need to be sent. |
uint32_t SAI_DRV_ReceiveDataDma | ( | uint32_t | instance, |
uint8_t * | addr, | ||
uint32_t | len | ||
) |
This function receives the data from the receive FIFO. This function starts the transfer, and, while finishing the transfer, calls the callback function registered by the user. This function is an a-sync function.
instance | SAI module instance. |
addr | Address of the data which needs to be transferred. |
len | The number of bytes to receive. |
void SAI_DRV_TxRegisterCallback | ( | uint32_t | instance, |
sai_callback_t | callback, | ||
void * | callback_param | ||
) |
This function tells the SAI which function needs to be called after a period length sending. This callback function is used for non-blocking sending.
instance | SAI module instance. |
callback | Callback function defined by users. |
callback_param | The parameter of the callback function. |
void SAI_DRV_RxRegisterCallback | ( | uint32_t | instance, |
sai_callback_t | callback, | ||
void * | callback_param | ||
) |
This function tells the SAI which function needs to be called after a period length receive. This callback function is used for non-blocking receiving.
instance | SAI module instance. |
callback | Callback function defined by users. |
callback_param | The parameter of the callback function. |
void SAI_DRV_TxIRQHandler | ( | uint32_t | instance | ) |
This function sends data in the interrupt and checks the FIFO error.
instance | SAI module instance. |
void SAI_DRV_RxIRQHandler | ( | uint32_t | instance | ) |
This function receives data in the interrupt and checks the FIFO error.
instance | SAI module instance. |