Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
fsl_sai_hal.h File Reference
#include <string.h>
#include <stdbool.h>
#include <assert.h>
#include "fsl_device_registers.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,
  kSaiIntRequestAll = 0x1F00
}
 The SAI state flag. More...
 
enum  sai_dma_request_t {
  kSaiDmaReqFIFOWarning = 0x2u,
  kSaiDmaReqFIFORequest = 0x1u,
  kSaiDmaReqAll = 0x3u
}
 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
}
 

Functions

void SAI_HAL_TxSetSyncMode (I2S_Type *base, sai_sync_mode_t sync_mode)
 SAI transmit sync mode setting. More...
 
void SAI_HAL_RxSetSyncMode (I2S_Type *base, sai_sync_mode_t sync_mode)
 SAI receive sync mode setting. More...
 
static uint32_t SAI_HAL_TxGetFifoAddr (I2S_Type *base, uint32_t fifo_channel)
 Gets the TDR register address. More...
 
static uint32_t SAI_HAL_RxGetFifoAddr (I2S_Type *base, uint32_t fifo_channel)
 Gets the RDR register address. More...
 
static void SAI_HAL_TxEnable (I2S_Type *base)
 Enables the SAI transmit module. More...
 
static void SAI_HAL_RxEnable (I2S_Type *base)
 Enables the SAI receive module. More...
 
static void SAI_HAL_TxDisable (I2S_Type *base)
 Disables the transmit module. More...
 
static void SAI_HAL_RxDisable (I2S_Type *base)
 Disables the receive module. More...
 
void SAI_HAL_TxSetIntCmd (I2S_Type *base, uint32_t source, bool enable)
 Enables the transmit interrupt from different interrupt sources. More...
 
void SAI_HAL_RxSetIntCmd (I2S_Type *base, uint32_t source, bool enable)
 Enables the receive interrupt from different interrupt sources. More...
 
void SAI_HAL_TxSetDmaCmd (I2S_Type *base, uint32_t source, bool enable)
 Enables the transmit DMA request from different sources. More...
 
void SAI_HAL_RxSetDmaCmd (I2S_Type *base, uint32_t source, bool enable)
 Enables the receive DMA request from different sources. More...
 
void SAI_HAL_TxClearStateFlag (I2S_Type *base, uint32_t flag_mask)
 Clears the transmit state flags. More...
 
void SAI_HAL_RxClearStateFlag (I2S_Type *base, uint32_t flag_mask)
 Clears the receive state flags. More...
 
void SAI_HAL_TxSetReset (I2S_Type *base, uint32_t reset_mask)
 Resets the transmit module. More...
 
void SAI_HAL_RxSetReset (I2S_Type *base, uint32_t reset_mask)
 Resets the receive module. More...
 
static void SAI_HAL_TxSetDataChn (I2S_Type *base, uint8_t fifo_channel)
 Sets the transmit FIFO channel. More...
 
static void SAI_HAL_RxSetDataChn (I2S_Type *base, uint8_t fifo_channel)
 Sets the receive FIFO channel. More...
 
void SAI_HAL_TxSetRunModeCmd (I2S_Type *base, sai_run_mode_t run_mode, bool enable)
 Sets the running mode of the transmit. More...
 
void SAI_HAL_RxSetRunModeCmd (I2S_Type *base, sai_run_mode_t run_mode, bool enable)
 Sets the running mode of the receive. More...
 
static uint32_t SAI_HAL_TxGetStateFlag (I2S_Type *base, uint32_t flag_mask)
 Gets the state of the flags in the TCSR. More...
 
static uint32_t SAI_HAL_RxGetStateFlag (I2S_Type *base, uint32_t flag_mask)
 Gets the state of the flags in the RCSR. More...
 
static uint32_t SAI_HAL_ReceiveData (I2S_Type *base, uint32_t rx_channel)
 Receives the data from the FIFO. More...
 
static void SAI_HAL_SendData (I2S_Type *base, uint32_t tx_channel, uint32_t data)
 Transmits data to the FIFO. More...
 
void SAI_HAL_ReceiveDataBlocking (I2S_Type *base, uint32_t rx_channel, uint8_t *rxBuff, uint32_t size)
 Uses blocking to receive data. More...
 
void SAI_HAL_SendDataBlocking (I2S_Type *base, uint32_t tx_channel, uint8_t *txBuff, uint32_t size)
 Uses blocking to send data. More...
 
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...
 

Function Documentation

void SAI_HAL_TxSetSyncMode ( I2S_Type *  base,
sai_sync_mode_t  sync_mode 
)

The mode can be asynchronous mode, synchronous, or synchronous with another SAI device. When configured for a synchronous mode of operation, the receiver must be configured for the asynchronous operation.

Parameters
baseRegister base address of SAI module.
sync_modeSynchronous mode or Asynchronous mode.
void SAI_HAL_RxSetSyncMode ( I2S_Type *  base,
sai_sync_mode_t  sync_mode 
)

The mode can be asynchronous mode, synchronous, or synchronous with another SAI device. When configured for a synchronous mode of operation, the receiver must be configured for the asynchronous operation.

Parameters
baseRegister base address of SAI module.
sync_modeSynchronous mode or Asynchronous mode.
static uint32_t SAI_HAL_TxGetFifoAddr ( I2S_Type *  base,
uint32_t  fifo_channel 
)
inlinestatic

This function determines the destination/source address of the DMA transfer.

Parameters
baseRegister base address of SAI module.
fifo_channelFIFO channel selected.
Returns
TDR register or RDR register address
static uint32_t SAI_HAL_RxGetFifoAddr ( I2S_Type *  base,
uint32_t  fifo_channel 
)
inlinestatic

This function determines the destination/source address of the DMA transfer.

Parameters
baseRegister base address of SAI module.
fifo_channelFIFO channel selected.
Returns
TDR register or RDR register address
static void SAI_HAL_TxEnable ( I2S_Type *  base)
inlinestatic

Enables the transmit. This function enables both the bit clock and the transfer channel.

Parameters
baseRegister base address of SAI module.
static void SAI_HAL_RxEnable ( I2S_Type *  base)
inlinestatic

Enables the receive. This function enables both the bit clock and the receive channel.

Parameters
baseRegister base address of SAI module.
static void SAI_HAL_TxDisable ( I2S_Type *  base)
inlinestatic

Disables the transmit. This function disables both the bit clock and the transfer channel.

Parameters
baseRegister base address of SAI module.
static void SAI_HAL_RxDisable ( I2S_Type *  base)
inlinestatic

Disables the receive. This function disables both the bit clock and the receive channel.

Parameters
baseRegister base address of SAI module.
void SAI_HAL_TxSetIntCmd ( I2S_Type *  base,
uint32_t  source,
bool  enable 
)

The interrupt source can be : Word start flag, Sync error flag, FIFO error flag, FIFO warning flag, and FIFO request flag. This function sets which flag causes an interrupt request.

Parameters
baseRegister base address of SAI module.
sourceSAI interrupt request source.
enableEnable or disable.
void SAI_HAL_RxSetIntCmd ( I2S_Type *  base,
uint32_t  source,
bool  enable 
)

The interrupt source can be : Word start flag, Sync error flag, FIFO error flag, FIFO warning flag, and FIFO request flag. This function sets which flag causes an interrupt request.

Parameters
baseRegister base address of SAI module.
sourceSAI interrupt request source.
enableEnable or disable.
void SAI_HAL_TxSetDmaCmd ( I2S_Type *  base,
uint32_t  source,
bool  enable 
)

The DMA sources can be: FIFO warning and FIFO request. This function enables the DMA request from different DMA request sources.

Parameters
baseRegister base address of SAI module.
sourceSAI DMA request source.
enableEnable or disable.
void SAI_HAL_RxSetDmaCmd ( I2S_Type *  base,
uint32_t  source,
bool  enable 
)

The DMA sources can be: FIFO warning and FIFO request. This function enables the DMA request from different DMA request sources.

Parameters
baseRegister base address of SAI module.
sourceSAI DMA request source.
enableEnable or disable.
void SAI_HAL_TxClearStateFlag ( I2S_Type *  base,
uint32_t  flag_mask 
)

The function clears the flags manually. It can clear word start, FIFO warning, FIFO error, and FIFO request flag.

Parameters
baseRegister base address of SAI module.
flag_maskSAI state flag type. The flag can be word start, sync error, FIFO error/warning.
void SAI_HAL_RxClearStateFlag ( I2S_Type *  base,
uint32_t  flag_mask 
)

The function is used to clear the flags manually. It can clear word start, FIFO warning, FIFO error, and FIFO request flag.

Parameters
baseRegister base address of SAI module.
flag_maskSAI state flag type. The flag can be word start, sync error, FIFO error/warning.
void SAI_HAL_TxSetReset ( I2S_Type *  base,
uint32_t  reset_mask 
)

There are two kinds of reset: software reset and FIFO reset. Software reset: resets all transmitter internal logic, including the bit clock generation, status flags, and FIFO pointers. It does not reset the configuration registers. FIFO reset: synchronizes the FIFO write pointer to the same value as the FIFO read pointer. This empties the FIFO contents and is to be used after the Transmit FIFO Error Flag is set, and before the FIFO is re-initialized and the Error Flag is cleared.

Parameters
baseRegister base address of SAI module.
reset_maskSAI reset mask.
void SAI_HAL_RxSetReset ( I2S_Type *  base,
uint32_t  reset_mask 
)

There are two kinds of reset: software reset and FIFO reset. Software reset: resets all transmitter internal logic, including the bit clock generation, status flags and FIFO pointers. It does not reset the configuration registers. FIFO reset: synchronizes the FIFO write pointer to the same value as the FIFO read pointer. This empties the FIFO contents and is to be used after the Transmit FIFO Error Flag is set, and before the FIFO is re-initialized and the Error Flag is cleared.

Parameters
baseRegister base address of SAI module.
reset_maskSAI reset mask.
static void SAI_HAL_TxSetDataChn ( I2S_Type *  base,
uint8_t  fifo_channel 
)
inlinestatic

A SAI base includes a transmit and an receive. Each has several channels according to different platforms. A channel means a path for the audio data input/output.

Parameters
baseRegister base address of SAI module.
fifo_channelFIFO channel number.
static void SAI_HAL_RxSetDataChn ( I2S_Type *  base,
uint8_t  fifo_channel 
)
inlinestatic

A SAI base includes a transmit and a receive. Each has several channels according to different platforms. A channel means a path for the audio data input/output.

Parameters
baseRegister base address of SAI module.
fifo_channelFIFO channel number.
void SAI_HAL_TxSetRunModeCmd ( I2S_Type *  base,
sai_run_mode_t  run_mode,
bool  enable 
)

There is a debug mode, stop mode, and a normal mode.

This function can set the working mode of the SAI base. Stop mode is always used in low power cases, and the debug mode disables the SAI after the current transmit/receive is completed.

Parameters
baseRegister base address of SAI module.
run_modeSAI running mode.
enableEnable or disable a mode.
void SAI_HAL_RxSetRunModeCmd ( I2S_Type *  base,
sai_run_mode_t  run_mode,
bool  enable 
)

There is a debug mode, stop mode, and a normal mode.

This function can set the working mode of the SAI base. Stop mode is always used in low power cases, and the debug mode disables the SAI after the current transmit/receive is completed.

Parameters
baseRegister base address of SAI module.
run_modeSAI running mode.
enableEnable or disable a mode.
static uint32_t SAI_HAL_TxGetStateFlag ( I2S_Type *  base,
uint32_t  flag_mask 
)
inlinestatic
Parameters
baseRegister base address of SAI module.
flag_maskState flag type, it can be FIFO error, FIFO warning and so on.
Returns
True if detect word start otherwise false.
static uint32_t SAI_HAL_RxGetStateFlag ( I2S_Type *  base,
uint32_t  flag_mask 
)
inlinestatic
Parameters
baseRegister base address of SAI module.
flag_maskState flag type, it can be FIFO error, FIFO warning and so on.
Returns
True if detect word start otherwise false.
static uint32_t SAI_HAL_ReceiveData ( I2S_Type *  base,
uint32_t  rx_channel 
)
inlinestatic
Parameters
baseRegister base address of SAI module.
rx_channelreceive FIFO channel.
dataPointer to the address to be written in.
Returns
Received data.
static void SAI_HAL_SendData ( I2S_Type *  base,
uint32_t  tx_channel,
uint32_t  data 
)
inlinestatic
Parameters
baseRegister base address of SAI module.
tx_channeltransmit FIFO channel.
dataData value which needs to be written into FIFO.
void SAI_HAL_ReceiveDataBlocking ( I2S_Type *  base,
uint32_t  rx_channel,
uint8_t *  rxBuff,
uint32_t  size 
)
Parameters
baseThe SAI base.
rx_channelreceive FIFO channel.
rxBuffreceive data buffer.
sizereceive data size.
void SAI_HAL_SendDataBlocking ( I2S_Type *  base,
uint32_t  tx_channel,
uint8_t *  txBuff,
uint32_t  size 
)
Parameters
baseThe SAI base.
tx_channeltransmit FIFO channel.
txBufftransmit data buffer.
sizetransmit data size.