This section describes the programming interface of the SAI HAL driver.
|
enum | sai_protocol_t {
kSaiBusI2SLeft = 0x0u,
kSaiBusI2SRight = 0x1u,
kSaiBusI2SType = 0x2u,
kSaiBusPCMA = 0x3u,
kSaiBusPCMB = 0x4u,
kSaiBusAC97 = 0x5u
} |
| Define the SAI bus type. More...
|
|
enum | sai_master_slave_t {
kSaiMaster = 0x0u,
kSaiSlave = 0x1u
} |
| Master or slave mode. More...
|
|
enum | sai_mono_stereo_t {
kSaiMono = 0x0u,
kSaiStereo = 0x1u
} |
|
enum | sai_sync_mode_t {
kSaiModeAsync = 0x0u,
kSaiModeSync = 0x1u,
kSaiModeSyncWithOtherTx = 0x2u,
kSaiModeSyncWithOtherRx = 0x3u
} |
| Synchronous or asynchronous mode. More...
|
|
enum | sai_mclk_source_t {
kSaiMclkSourceSysclk = 0x0u,
kSaiMclkSourceSelect1 = 0x1u,
kSaiMclkSourceSelect2 = 0x2u,
kSaiMclkSourceSelect3 = 0x3u
} |
| Mater clock source. More...
|
|
enum | sai_bclk_source_t {
kSaiBclkSourceBusclk = 0x0u,
kSaiBclkSourceMclkDiv = 0x1u,
kSaiBclkSourceOtherSai0 = 0x2u,
kSaiBclkSourceOtherSai1 = 0x3u
} |
| Bit clock source. More...
|
|
enum | sai_interrupt_request_t {
kSaiIntrequestWordStart = 0x1000u,
kSaiIntrequestSyncError = 0x800u,
kSaiIntrequestFIFOWarning = 0x200u,
kSaiIntrequestFIFOError = 0x400u,
kSaiIntrequestFIFORequest = 0x100u
} |
| The SAI state flag. More...
|
|
enum | sai_dma_request_t {
kSaiDmaReqFIFOWarning = 0x2u,
kSaiDmaReqFIFORequest = 0x1u
} |
| The DMA request sources. More...
|
|
enum | sai_state_flag_t {
kSaiStateFlagWordStart = 0x100000u,
kSaiStateFlagSyncError = 0x80000u,
kSaiStateFlagFIFOError = 0x40000u,
kSaiStateFlagFIFORequest = 0x10000u,
kSaiStateFlagFIFOWarning = 0x20000u,
kSaiStateFlagSoftReset = 0x1000000u,
kSaiStateFlagAll = 0x11F0000u
} |
| The SAI state flag. More...
|
|
enum | sai_reset_type_t {
kSaiResetTypeSoftware = 0x1000000u,
kSaiResetTypeFIFO = 0x2000000u,
kSaiResetAll = 0x3000000u
} |
| The reset type. More...
|
|
enum | sai_run_mode_t {
kSaiRunModeDebug = 0x0,
kSaiRunModeStop = 0x1
} |
|
struct sai_clock_setting_t |
uint32_t sai_clock_setting_t::mclk_src_freq |
uint32_t sai_clock_setting_t::mclk |
uint32_t sai_clock_setting_t::bclk |
Enumerator |
---|
kSaiBusI2SLeft |
Uses I2S left aligned format.
|
kSaiBusI2SRight |
Uses I2S right aligned format.
|
kSaiBusI2SType |
Uses I2S format.
|
kSaiBusPCMA |
Uses I2S PCM A format.
|
kSaiBusPCMB |
Uses I2S PCM B format.
|
kSaiBusAC97 |
Uses I2S AC97 format.
|
Enumerator |
---|
kSaiMaster |
Master mode.
|
kSaiSlave |
Slave mode.
|
Enumerator |
---|
kSaiMono |
1 Channel in frame.
|
kSaiStereo |
2 Channels in frame.
|
Enumerator |
---|
kSaiModeAsync |
Asynchronous mode.
|
kSaiModeSync |
Synchronous mode (with receiver or transmit)
|
kSaiModeSyncWithOtherTx |
Synchronous with another SAI transmit.
|
kSaiModeSyncWithOtherRx |
Synchronous with another SAI receiver.
|
Enumerator |
---|
kSaiMclkSourceSysclk |
Master clock from the system clock.
|
kSaiMclkSourceSelect1 |
Master clock from source 1.
|
kSaiMclkSourceSelect2 |
Master clock from source 2.
|
kSaiMclkSourceSelect3 |
Master clock from source 3.
|
Enumerator |
---|
kSaiBclkSourceBusclk |
Bit clock using bus clock.
|
kSaiBclkSourceMclkDiv |
Bit clock using master clock divider.
|
kSaiBclkSourceOtherSai0 |
Bit clock from other SAI device.
|
kSaiBclkSourceOtherSai1 |
Bit clock from other SAI device.
|
Enumerator |
---|
kSaiIntrequestWordStart |
Word start flag, means the first word in a frame detected.
|
kSaiIntrequestSyncError |
Sync error flag, means the sync error is detected.
|
kSaiIntrequestFIFOWarning |
FIFO warning flag, means the FIFO is empty.
|
kSaiIntrequestFIFOError |
FIFO error flag.
|
kSaiIntrequestFIFORequest |
FIFO request, means reached watermark.
|
Enumerator |
---|
kSaiDmaReqFIFOWarning |
FIFO warning caused by the DMA request.
|
kSaiDmaReqFIFORequest |
FIFO request caused by the DMA request.
|
Enumerator |
---|
kSaiStateFlagWordStart |
Word start flag, means the first word in a frame detected.
|
kSaiStateFlagSyncError |
Sync error flag, means the sync error is detected.
|
kSaiStateFlagFIFOError |
FIFO error flag.
|
kSaiStateFlagFIFORequest |
FIFO request flag.
|
kSaiStateFlagFIFOWarning |
FIFO warning flag.
|
kSaiStateFlagSoftReset |
Software reset flag.
|
kSaiStateFlagAll |
All flags.
|
Enumerator |
---|
kSaiResetTypeSoftware |
Software reset, reset the logic state.
|
kSaiResetTypeFIFO |
FIFO reset, reset the FIFO read and write pointer.
|
kSaiResetAll |
All reset.
|
Enumerator |
---|
kSaiRunModeDebug |
In debug mode.
|
kSaiRunModeStop |
In stop mode.
|
void SAI_HAL_TxInit |
( |
I2S_Type * |
base | ) |
|
The initialization resets the SAI module by setting the SR bit of TCSR register. Note that the function writes 0 to every control registers.
- Parameters
-
base | Register base address of SAI module. |
void SAI_HAL_RxInit |
( |
I2S_Type * |
base | ) |
|
The initialization resets the SAI module by setting the SR bit of RCSR register. Note that the function writes 0 to every control registers.
- Parameters
-
base | Register base address of SAI module. |
void SAI_HAL_TxSetProtocol |
( |
I2S_Type * |
base, |
|
|
sai_protocol_t |
protocol |
|
) |
| |
The bus mode indicates which protocol SAI uses. It can be I2S left, right, and so on. Each protocol has a different configuration on bit clock and frame sync.
- Parameters
-
base | Register base address of SAI module. |
protocol | The protocol selection. It can be I2S left aligned, I2S right aligned, and so on. |
void SAI_HAL_RxSetProtocol |
( |
I2S_Type * |
base, |
|
|
sai_protocol_t |
protocol |
|
) |
| |
The bus mode indicates which protocol SAI uses. It can be I2S left, right, and so on. Each protocol has a different configuration on bit clock and frame sync.
- Parameters
-
base | Register base address of SAI module. |
protocol | The protocol selection. It can be I2S left aligned, I2S right aligned, and so on. |
The function determines master or slave mode. Master mode provides its own clock and slave mode uses an external clock.
- Parameters
-
base | Register base address of SAI module. |
master_slave_mode | Mater or slave mode. |
The function determines master or slave mode. Master mode provides its own clock and slave mode uses external clock.
- Parameters
-
base | Register base address of SAI module. |
master_slave_mode | Mater or slave mode. |
This function can sets the clock settings according to the configuration structure. In this configuration setting structure, users can set clock source, clock source frequency, and frequency of the master clock and bit clock. If the bit clock source is the master clock, the master clock frequency should equal to the bit clock source frequency. If the bit clock source is not the master clock, then settings of the master clock have no effect on the setting.
- Parameters
-
base | Register base address of SAI module. |
clk_config | Pointer to SAI clock configuration structure. |
This function sets the clock settings according to the configuration structure. In this configuration setting structure, users can set clock source, clock source frequency, and frequency of the master clock and bit clock. If the bit clock source is the master clock, the master clock frequency should equal to the bit clock source frequency. If the bit clock source is not the master clock, then settings of the master clock have no effect on the setting.
- Parameters
-
base | Register base address of SAI module. |
clk_config | Pointer to SAI clock configuration structure. |
The source of the clock is different in each SoC. This function sets the clock source for the SAI master clock source. The master clock produces the bit clock for the data transfer.
- Parameters
-
base | Register base address of SAI module. |
source | Mater clock source |
static uint32_t SAI_HAL_GetMclkSrc |
( |
I2S_Type * |
base | ) |
|
|
inlinestatic |
The source of the clock is different in each SoCs. This function gets the clock source for the SAI master clock source. The master clock produces the bit clock for the data transfer.
- Parameters
-
base | Register base address of SAI module. |
- Returns
- Mater clock source
static void SAI_HAL_SetMclkDividerCmd |
( |
I2S_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
This function enables or disables the internal MCLK.
- Parameters
-
base | Register base address of SAI module. |
enable | True means enable, false means disable. |
It is generated by the master clock, bus clock, and other devices.
The function sets the source of the bit clock. The bit clock can be produced by the master clock and from the bus clock or other SAI transmit/receive. Transmit and receive in the SAI module use the same bit clock either from transmit or receive.
- Parameters
-
base | Register base address of SAI module. |
source | Bit clock source. |
It is generated by the master clock, bus clock, and other devices.
The function sets the source of the bit clock. The bit clock can be produced by the master clock, and from the bus clock or other SAI transmit/receive. Transmit and receive in the SAI module use the same bit clock either from transmit or receive.
- Parameters
-
base | Register base address of SAI module. |
source | Bit clock source. |
static uint32_t SAI_HAL_TxGetBclkSrc |
( |
I2S_Type * |
base | ) |
|
|
inlinestatic |
It is generated by the master clock, bus clock, and other devices.
The function gets the source of the bit clock. The bit clock can be produced by the master clock and from the bus clock or other SAI transmit/receive. Transmit and receive in the SAI module use the same bit clock either from transmit or receive.
- Parameters
-
base | Register base address of SAI module. |
- Returns
- Bit clock source.
static uint32_t SAI_HAL_RxGetBclkSrc |
( |
I2S_Type * |
base | ) |
|
|
inlinestatic |
It is generated by the master clock, bus clock and other devices.
The function gets the source of the bit clock. The bit clock can be produced by the master clock, and from the bus clock or other SAI transmit/receive. Transmit and receive in the SAI module use the same bit clock either from transmit or receive.
- Parameters
-
base | Register base address of SAI module. |
- Returns
- Bit clock source.
static void SAI_HAL_TxSetBclkDiv |
( |
I2S_Type * |
base, |
|
|
uint32_t |
divider |
|
) |
| |
|
inlinestatic |
bclk = mclk / divider. At the same time, bclk = sample_rate * channel * bits. This means how much time is needed to transfer one bit. Note that the function is called while the bit clock source is the master clock.
- Parameters
-
base | Register base address of SAI module. |
divider | The divide number of bit clock. |
static void SAI_HAL_RxSetBclkDiv |
( |
I2S_Type * |
base, |
|
|
uint32_t |
divider |
|
) |
| |
|
inlinestatic |
bclk = mclk / divider. At the same time, bclk = sample_rate * channel * bits. This means how much time is needed to transfer one bit. Note that the function is called while the bit clock source is the master clock.
- Parameters
-
base | Register base address of SAI module. |
divider | The divide number of bit clock. |
static void SAI_HAL_TxSetBclkInputCmd |
( |
I2S_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | Register base address of SAI module. |
enable | True means enable, false means disable. |
static void SAI_HAL_RxSetBclkInputCmd |
( |
I2S_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | Register base address of SAI module. |
enable | True means enable, false means disable. |
static void SAI_HAL_TxSetSwapBclkCmd |
( |
I2S_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
This field swaps the bit clock used by the transmitter. When the transmitter is configured in asynchronous mode and this bit is set, the transmitter is clocked by the receiver bit clock. This allows the transmitter and receiver to share the same bit clock, but the transmitter continues to use the transmit frame sync (SAI_TX_SYNC). When the transmitter is configured in synchronous mode, the transmitter BCS field and receiver BCS field must be set to the same value. When both are set, the transmitter and receiver are both clocked by the transmitter bit clock (SAI_TX_BCLK) but use the receiver frame sync (SAI_RX_SYNC).
- Parameters
-
base | Register base address of SAI module. |
enable | True means swap bit clock; false means no swap. |
static void SAI_HAL_RxSetSwapBclkCmd |
( |
I2S_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
This field swaps the bit clock used by the receiver. When the receiver is configured in asynchronous mode and this bit is set, the receiver is clocked by the transmitter bit clock (SAI_TX_BCLK). This allows the transmitter and receiver to share the same bit clock, but the receiver continues to use the receiver frame sync (SAI_RX_SYNC). When the receiver is configured in synchronous mode, the transmitter BCS field and receiver BCS field must be set to the same value. When both are set, the transmitter and receiver are both clocked by the receiver bit clock (SAI_RX_BCLK) but use the transmitter frame sync (SAI_TX_SYNC).
- Parameters
-
base | Register base address of SAI module. |
enable | True means swap bit clock; false means no swap. |
The channel can be mono or stereo.
- Parameters
-
base | Register base address of SAI module. |
mono_stereo | Mono or stereo mode. |
The channel can be mono or stereo.
- Parameters
-
base | Register base address of SAI module. |
mono_stereo | Mono or stereo mode. |
void SAI_HAL_TxSetWordWidth |
( |
I2S_Type * |
base, |
|
|
sai_protocol_t |
protocol, |
|
|
uint32_t |
bits |
|
) |
| |
This interface is for I2S and PCM series protocol. It sets the width of the first word and any other word in the same manner. At the same time, for I2S series protocol, it sets the frame sync width equal to the word width.
- Parameters
-
base | Register base address of SAI module. |
protocol | Protocol used for transmit now. |
bits | transmit word width. |
void SAI_HAL_RxSetWordWidth |
( |
I2S_Type * |
base, |
|
|
sai_protocol_t |
protocol, |
|
|
uint32_t |
bits |
|
) |
| |
This interface is for I2S and PCM series protocol. It sets the width of the first word and any other word in the same manner. At the same time, for I2S series protocol, it sets the frame sync width equal to the word width.
- Parameters
-
base | Register base address of SAI module. |
protocol | Protocol used for receive now. |
bits | receive word width. |