Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

Overview

This section describes the programming interface of the SAI HAL driver.

Files

file  fsl_sai_hal.h
 

Data Structures

struct  sai_clock_setting_t
 SAI clock configuration structure. More...
 

Enumerations

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
}
 

Module control

void SAI_HAL_TxInit (I2S_Type *base)
 Initializes the SAI transmit. More...
 
void SAI_HAL_RxInit (I2S_Type *base)
 Initializes the SAI receive. More...
 
void SAI_HAL_TxSetProtocol (I2S_Type *base, sai_protocol_t protocol)
 Sets transmit protocol relevant settings. More...
 
void SAI_HAL_RxSetProtocol (I2S_Type *base, sai_protocol_t protocol)
 Sets receive protocol relevant settings. More...
 
void SAI_HAL_TxSetMasterSlave (I2S_Type *base, sai_master_slave_t master_slave_mode)
 Sets master or slave mode. More...
 
void SAI_HAL_RxSetMasterSlave (I2S_Type *base, sai_master_slave_t master_slave_mode)
 Sets master or slave mode. More...
 

Overall Clock configuration

void SAI_HAL_TxClockSetup (I2S_Type *base, sai_clock_setting_t *clk_config)
 Sets up the clock for the SAI transmit. More...
 
void SAI_HAL_RxClockSetup (I2S_Type *base, sai_clock_setting_t *clk_config)
 Sets up the clock for the SAI receive. More...
 

Master clock configuration

static void SAI_HAL_SetMclkSrc (I2S_Type *base, sai_mclk_source_t source)
 Sets the master clock source. More...
 
static uint32_t SAI_HAL_GetMclkSrc (I2S_Type *base)
 Gets the master clock source. More...
 
static void SAI_HAL_SetMclkDividerCmd (I2S_Type *base, bool enable)
 Enables or disables the MCLK internal. More...
 

Bit clock configuration

static void SAI_HAL_TxSetBclkSrc (I2S_Type *base, sai_bclk_source_t source)
 Sets the bit clock source of transmit. More...
 
static void SAI_HAL_RxSetBclkSrc (I2S_Type *base, sai_bclk_source_t source)
 Sets bit clock source of the receive. More...
 
static uint32_t SAI_HAL_TxGetBclkSrc (I2S_Type *base)
 Gets the bit clock source of transmit. More...
 
static uint32_t SAI_HAL_RxGetBclkSrc (I2S_Type *base)
 Gets bit clock source of the receive. More...
 
static void SAI_HAL_TxSetBclkDiv (I2S_Type *base, uint32_t divider)
 Sets the transmit bit clock divider value. More...
 
static void SAI_HAL_RxSetBclkDiv (I2S_Type *base, uint32_t divider)
 Sets the receive bit clock divider value. More...
 
static void SAI_HAL_TxSetBclkInputCmd (I2S_Type *base, bool enable)
 Enables or disables the transmit bit clock input bit. More...
 
static void SAI_HAL_RxSetBclkInputCmd (I2S_Type *base, bool enable)
 Enables or disables the receive bit clock input bit. More...
 
static void SAI_HAL_TxSetSwapBclkCmd (I2S_Type *base, bool enable)
 Sets the transmit bit clock swap. More...
 
static void SAI_HAL_RxSetSwapBclkCmd (I2S_Type *base, bool enable)
 Sets the receive bit clock swap. More...
 

Mono or stereo configuration

void SAI_HAL_TxSetMonoStereo (I2S_Type *base, sai_mono_stereo_t mono_stereo)
 Sets the transmit audio channel number. More...
 
void SAI_HAL_RxSetMonoStereo (I2S_Type *base, sai_mono_stereo_t mono_stereo)
 Sets the receive audio channel number. More...
 

Word configurations

void SAI_HAL_TxSetWordWidth (I2S_Type *base, sai_protocol_t protocol, uint32_t bits)
 Sets the transmit word width. More...
 
void SAI_HAL_RxSetWordWidth (I2S_Type *base, sai_protocol_t protocol, uint32_t bits)
 Sets the receive word width. More...
 

Data Structure Documentation

struct sai_clock_setting_t

Data Fields

sai_mclk_source_t mclk_src
 Master clock source. More...
 
sai_bclk_source_t bclk_src
 Bit clock source. More...
 
uint32_t mclk_src_freq
 Master clock source frequency. More...
 
uint32_t mclk
 Master clock frequency. More...
 
uint32_t bclk
 Bit clock frequency. More...
 

Field Documentation

sai_mclk_source_t sai_clock_setting_t::mclk_src
sai_bclk_source_t sai_clock_setting_t::bclk_src
uint32_t sai_clock_setting_t::mclk_src_freq
uint32_t sai_clock_setting_t::mclk
uint32_t sai_clock_setting_t::bclk

Enumeration Type Documentation

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.

Function Documentation

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
baseRegister 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
baseRegister 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
baseRegister base address of SAI module.
protocolThe 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
baseRegister base address of SAI module.
protocolThe protocol selection. It can be I2S left aligned, I2S right aligned, and so on.
void SAI_HAL_TxSetMasterSlave ( I2S_Type *  base,
sai_master_slave_t  master_slave_mode 
)

The function determines master or slave mode. Master mode provides its own clock and slave mode uses an external clock.

Parameters
baseRegister base address of SAI module.
master_slave_modeMater or slave mode.
void SAI_HAL_RxSetMasterSlave ( I2S_Type *  base,
sai_master_slave_t  master_slave_mode 
)

The function determines master or slave mode. Master mode provides its own clock and slave mode uses external clock.

Parameters
baseRegister base address of SAI module.
master_slave_modeMater or slave mode.
void SAI_HAL_TxClockSetup ( I2S_Type *  base,
sai_clock_setting_t clk_config 
)

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
baseRegister base address of SAI module.
clk_configPointer to SAI clock configuration structure.
void SAI_HAL_RxClockSetup ( I2S_Type *  base,
sai_clock_setting_t clk_config 
)

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
baseRegister base address of SAI module.
clk_configPointer to SAI clock configuration structure.
static void SAI_HAL_SetMclkSrc ( I2S_Type *  base,
sai_mclk_source_t  source 
)
inlinestatic

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
baseRegister base address of SAI module.
sourceMater 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
baseRegister 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
baseRegister base address of SAI module.
enableTrue means enable, false means disable.
static void SAI_HAL_TxSetBclkSrc ( I2S_Type *  base,
sai_bclk_source_t  source 
)
inlinestatic

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
baseRegister base address of SAI module.
sourceBit clock source.
static void SAI_HAL_RxSetBclkSrc ( I2S_Type *  base,
sai_bclk_source_t  source 
)
inlinestatic

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
baseRegister base address of SAI module.
sourceBit 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
baseRegister 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
baseRegister 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
baseRegister base address of SAI module.
dividerThe 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
baseRegister base address of SAI module.
dividerThe divide number of bit clock.
static void SAI_HAL_TxSetBclkInputCmd ( I2S_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseRegister base address of SAI module.
enableTrue means enable, false means disable.
static void SAI_HAL_RxSetBclkInputCmd ( I2S_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseRegister base address of SAI module.
enableTrue 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
baseRegister base address of SAI module.
enableTrue 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
baseRegister base address of SAI module.
enableTrue means swap bit clock; false means no swap.
void SAI_HAL_TxSetMonoStereo ( I2S_Type *  base,
sai_mono_stereo_t  mono_stereo 
)

The channel can be mono or stereo.

Parameters
baseRegister base address of SAI module.
mono_stereoMono or stereo mode.
void SAI_HAL_RxSetMonoStereo ( I2S_Type *  base,
sai_mono_stereo_t  mono_stereo 
)

The channel can be mono or stereo.

Parameters
baseRegister base address of SAI module.
mono_stereoMono 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
baseRegister base address of SAI module.
protocolProtocol used for transmit now.
bitstransmit 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
baseRegister base address of SAI module.
protocolProtocol used for receive now.
bitsreceive word width.