| Kinetis SDK API Reference Manual 1.0.0-beta Freescale Semiconductor, Inc.

- Introduction
- Related Pages
- API Usage

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Macros | Enumerations | Functions
SAI HAL driver
Synchronous Audio Interface (SAI)

The section describes the programming interface of the SAI HAL driver. More...

## Macros
#define | SAI_BIT_MIN 8
#define | SAI_BIT_MAX 32
#define | SAI_WORD_MAX FSL_FEATURE_I2S_MAX_WORDS_PER_FRAME
#define | SAI_FRACT_MAX 256
#define | SAI_DIV_MAX 4096
#define | SAI_WATERMARK_MAX FSL_FEATURE_I2S_FIFO_COUNT
#define | SAI_FIFO_LEN FSL_FEATURE_I2S_FIFO_COUNT

## Enumerations
enum | sai_bus_t { kSaiBusI2SLeft = 0x0, kSaiBusI2SRight = 0x1, kSaiBusI2SType = 0x2 }
| Defines the SAI bus type. More...
enum | sai_io_mode_t { kSaiIOModeTransmit = 0x0, kSaiIOModeReceive = 0x1, kSaiIOModeDuplex = 0x2 }
| Transmits or receives data; Reads and writes at the same time. More...
enum | sai_master_slave_t { kSaiMaster = 0x0, kSaiSlave = 0x1 }
| Master or slave mode. More...
enum | sai_sync_mode_t { kSaiModeAsync = 0x0, kSaiModeSync = 0x1, kSaiModeSyncWithOtherTx = 0x2, kSaiModeSyncWithOtherRx = 0x3 }
| Synchronous or asynchronous mode. More...
enum | sai_mclk_source_t { kSaiMclkSourceSysclk = 0x0, kSaiMclkSourceExtal = 0x1, kSaiMclkSourceAltclk = 0x2, kSaiMclkSourcePllout = 0x3 }
| Mater clock source. More...
enum | sai_bclk_source_t { kSaiBclkSourceBusclk = 0x0, kSaiBclkSourceMclkDiv = 0x1, kSaiBclkSourceOtherSai0 = 0x2, kSaiBclkSourceOtherSai1 = 0x3 }
| Bit clock source. More...
enum | sai_interrupt_request_t { kSaiIntrequestWordStart = 0x0, kSaiIntrequestSyncError = 0x1, kSaiIntrequestFIFOWarning = 0x2, kSaiIntrequestFIFOError = 0x3, kSaiIntrequestFIFORequest = 0x4 }
| The SAI state flag. More...
enum | sai_dma_request_t { kSaiDmaReqFIFOWarning = 0x0, kSaiDmaReqFIFORequest = 0x1 }
| The DMA request sources. More...
enum | sai_state_flag_t { kSaiStateFlagWordStart = 0x0, kSaiStateFlagSyncError = 0x1, kSaiStateFlagFIFOError = 0x2, kSaiStateFlagSoftReset = 0x3 }
| The SAI state flag. More...
enum | sai_reset_type_t { kSaiResetTypeSoftware = 0x0, kSaiResetTypeFIFO = 0x1 }
| The reset type. More...
enum | sai_mode_t { kSaiRunModeDebug = 0x0, kSaiRunModeStop = 0x1 }

## Functions
void | sai_hal_init (uint8_t instance)
| Initializes the SAI device. More...
void | sai_hal_set_tx_bus (uint8_t instance, sai_bus_t bus_mode)
| Sets the bus protocol relevant settings for Tx. More...
void | sai_hal_set_rx_bus (uint8_t instance, sai_bus_t bus_mode)
| Sets the bus protocol relevant settings for Rx. More...
static void | sai_hal_set_mclk_source (uint8_t instance, sai_mclk_source_t source)
| Sets the master clock source. More...
void | sai_hal_set_mclk_divider (uint8_t instance, uint32_t mclk, uint32_t src_clk)
| Sets the divider of the master clock. More...
static void | sai_hal_set_tx_bclk_source (uint8_t instance, sai_bclk_source_t source)
| Sets the bit clock source of Tx. More...
static void | sai_hal_set_rx_bclk_source (uint8_t instance, sai_bclk_source_t source)
| Sets the bit clock source of Rx. More...
static void | sai_hal_set_tx_blck_divider (uint8_t instance, uint32_t divider)
| Sets the bit clock divider value of Tx. More...
static void | sai_hal_set_rx_blck_divider (uint8_t instance, uint32_t divider)
| Sets the bit clock divider value of Tx. More...
static void | sai_hal_set_tx_frame_size (uint8_t instance, uint8_t size)
| Sets the frame size for Tx. More...
static void | sai_hal_set_rx_frame_size (uint8_t instance, uint8_t size)
| Set the frame size for rx. More...
static void | sai_hal_set_tx_word_size (uint8_t instance, uint8_t bits)
| Set the word size for tx. More...
static void | sai_hal_set_rx_word_size (uint8_t instance, uint8_t bits)
| Sets the word size for Rx. More...
static void | sai_hal_set_tx_word_zero_size (uint8_t instance, uint8_t size)
| Sets the size of the first word of the frame for Tx. More...
static void | sai_hal_set_rx_word_zero_size (uint8_t instance, uint8_t size)
| Sets the size of the first word of the frame for Rx. More...
static void | sai_hal_set_tx_sync_width (uint8_t instance, uint8_t width)
| Sets the sync width for Tx. More...
static void | sai_hal_set_rx_sync_width (uint8_t instance, uint8_t width)
| Sets the sync width for Rx. More...
static void | sai_hal_set_tx_watermark (uint8_t instance, uint8_t watermark)
| Sets the watermark value for Tx FIFO. More...
static void | sai_hal_set_rx_watermark (uint8_t instance, uint8_t watermark)
| Sets the watermark value for Rx FIFO. More...
void | sai_hal_set_tx_master_slave (uint8_t instance, sai_master_slave_t master_slave_mode)
| Sets the master or slave mode of Tx. More...
void | sai_hal_set_rx_master_slave (uint8_t instance, sai_master_slave_t master_slave_mode)
| Sets the Rx master or slave mode. More...
void | sai_hal_set_tx_sync_mode (uint8_t instance, sai_sync_mode_t sync_mode)
| Transmits the mode setting. More...
void | sai_hal_set_rx_sync_mode (uint8_t instance, sai_sync_mode_t sync_mode)
| Receives the mode setting. More...
uint8_t | sai_hal_get_fifo_read_pointer (uint8_t instance, sai_io_mode_t io_mode, uint8_t fifo_channel)
| Gets the FIFO read pointer. More...
uint8_t | sai_hal_get_fifo_write_pointer (uint8_t instance, sai_io_mode_t io_mode, uint8_t fifo_channel)
| Gets the FIFO read pointer. More...
uint32_t * | sai_hal_get_fifo_address (uint8_t instance, sai_io_mode_t io_mode, uint8_t fifo_channel)
| Gets the TDR/RDR register address. More...
static void | sai_hal_enable_tx (uint8_t instance)
| Enables the Tx transmit. More...
static void | sai_hal_enable_rx (uint8_t instance)
| Enables the Rx receive. More...
static void | sai_hal_disable_tx (uint8_t instance)
| Disables the Tx transmit. More...
static void | sai_hal_disable_rx (uint8_t instance)
| Disables the Rx receive. More...
void | sai_hal_enable_tx_interrupt (uint8_t instance, sai_interrupt_request_t source)
| Enables the Tx interrupt from different interrupt sources. More...
void | sai_hal_enable_rx_interrupt (uint8_t instance, sai_interrupt_request_t source)
| Enables the Rx interrupt from different sources. More...
void | sai_hal_disable_tx_interrupt (uint8_t instance, sai_interrupt_request_t source)
| Disables the Tx interrupts from different interrupt sources. More...
void | sai_hal_disable_rx_interrupt (uint8_t instance, sai_interrupt_request_t source)
| Disables Rx interrupts from different interrupt sources. More...
void | sai_hal_enable_tx_dma (uint8_t instance, sai_dma_request_t request)
| Enables the Tx DMA request from different sources. More...
void | sai_hal_enable_rx_dma (uint8_t instance, sai_dma_request_t request)
| Enables the Rx DMA request from different sources. More...
void | sai_hal_disable_tx_dma (uint8_t instance, sai_dma_request_t request)
| Disables the Tx DMA request from different sources. More...
void | sai_hal_disable_rx_dma (uint8_t instance, sai_dma_request_t request)
| Disables the Rx DMA request from different sources. More...
void | sai_hal_clear_tx_state_flag (uint8_t instance, sai_state_flag_t flag)
| Clears the Tx state flags. More...
void | sai_hal_clear_rx_state_flag (uint8_t instance, sai_state_flag_t flag)
| Clears the state flags for Rx. More...
void | sai_hal_reset_tx (uint8_t instance, sai_reset_type_t mode)
| Resets the Tx. More...
void | sai_hal_reset_rx (uint8_t instance, sai_reset_type_t mode)
| Resets the Rx. More...
static void | sai_hal_set_tx_word_mask (uint8_t instance, uint32_t mask)
| Sets the mask word of the frame in Tx. More...
static void | sai_hal_set_rx_word_mask (uint8_t instance, uint32_t mask)
| Sets the mask word of the frame in Rx. More...
static void | sai_hal_set_tx_fifo_channel (uint8_t instance, uint8_t fifo_channel)
| Sets the FIFO Tx channel. More...
static void | sai_hal_set_rx_fifo_channel (uint8_t instance, uint8_t fifo_channel)
| Sets the Rx FIFO channel. More...
void | sai_hal_set_tx_mode (uint8_t instance, sai_mode_t mode)
| Sets the running mode. More...
void | sai_hal_set_rx_mode (uint8_t instance, sai_mode_t mode)
| Sets the Rx running mode. More...
void | sai_hal_set_tx_bclk_swap (uint8_t instance, bool ifswap)
| Set Tx bit clock swap. More...
void | sai_hal_set_rx_bclk_swap (uint8_t instance, bool ifswap)
| Sets the Rx bit clock swap. More...
static void | sai_hal_set_tx_word_start_index (uint8_t instance, uint8_t index)
| Configures on which word the start of the word flag is set. More...
static void | sai_hal_set_rx_word_start_index (uint8_t instance, uint8_t index)
| Configures on which word the start of the word flag is set. More...
static void | sai_hal_set_tx_fbt (uint8_t instance, uint8_t index)
| Sets the index in FIFO for the first bit data . More...
static void | sai_hal_set_rx_fbt (uint8_t instance, uint8_t index)
| Sets the index in FIFO for the first bit data. More...
bool | sai_hal_mclk_divider_is_update (uint8_t instance)
| Flags whether the master clock divider is re-divided. More...
bool | sai_hal_word_start_is_detected (uint8_t instance, sai_io_mode_t io_mode)
| Word start is detected. More...
bool | sai_hal_sync_error_is_detected (uint8_t instance, sai_io_mode_t io_mode)
| Sync error is detected. More...
bool | sai_hal_fifo_warning_is_detected (uint8_t instance, sai_io_mode_t io_mode)
| FIFO warning is detected. More...
bool | sai_hal_fifo_error_is_detected (uint8_t instance, sai_io_mode_t io_mode)
| FIFO error is detected. More...
bool | sai_hal_fifo_request_is_detected (uint8_t instance, sai_io_mode_t io_mode)
| FIFO request is detected. More...
static void | sai_hal_receive_data (uint8_t instance, uint8_t rx_channel, uint32_t *data)
| Receives the data from FIFO. More...
static void | sai_hal_transmit_data (uint8_t instance, uint8_t tx_channel, uint32_t data)
| Transmits data to the FIFO. More...

### SAI HAL Driver

# Overview

The SAI HAL driver is used to mask the hardware and provide user a comprehensible way to use sai.

## Enumeration Type Documentation

enum sai_bus_t

Enumerator
kSaiBusI2SLeft | Use I2S left aligned format.
kSaiBusI2SRight | Use I2S right aligned format.
kSaiBusI2SType | Use I2S format.

enum sai_io_mode_t

Enumerator
kSaiIOModeTransmit | Write data to FIFO.
kSaiIOModeReceive | Read data from FIFO.
kSaiIOModeDuplex | Read data and write data at the same time.

enum sai_master_slave_t

Enumerator
kSaiMaster | Master mode.
kSaiSlave | Slave mode.

enum sai_sync_mode_t

Enumerator
kSaiModeAsync | Asynchronous mode.
kSaiModeSync | Synchronous mode (with receiver or transmit)
kSaiModeSyncWithOtherTx | Synchronous with another SAI transmit.
kSaiModeSyncWithOtherRx | Synchronous with another SAI receiver.

enum sai_mclk_source_t

Enumerator
kSaiMclkSourceSysclk | Master clock from the system clock.
kSaiMclkSourceExtal | Master clock from the extal.
kSaiMclkSourceAltclk | Master clock from the ALT.
kSaiMclkSourcePllout | Master clock from the PLL.

enum sai_bclk_source_t

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.

enum sai_interrupt_request_t

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.

enum sai_dma_request_t

Enumerator
kSaiDmaReqFIFOWarning | FIFO warning caused by the DMA request.
kSaiDmaReqFIFORequest | FIFO request caused by the DMA request.

enum sai_state_flag_t

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.
kSaiStateFlagSoftReset | Software reset flag.

enum sai_reset_type_t

Enumerator
kSaiResetTypeSoftware | Software reset, reset the logic state.
kSaiResetTypeFIFO | FIFO reset, reset the FIFO read and write pointer.

enum sai_mode_t

Enumerator
kSaiRunModeDebug | In debug mode.
kSaiRunModeStop | In stop mode.

## Function Documentation

void sai_hal_init | ( | uint8_t | instance | ) |

The initialization resets the SAI module by setting the SR bit of TCSR and the RCSR register. Note that the function would write 0 to every control registers.

Parameters

  instance | The SAI peripheral instance number.

void sai_hal_set_tx_bus | ( | uint8_t | instance,
|  | sai_bus_t | bus_mode
| ) |  |

The bus mode means which protocol SAI uses. It can be I2S left, right, and so on. Each protocol would have different configuration on bit clock and frame sync.

Parameters

  instance | The SAI peripheral instance number.
  bus_mode | The protocol selection, it can be I2S left aligned, I2S right aligned, etc.

void sai_hal_set_rx_bus | ( | uint8_t | instance,
|  | sai_bus_t | bus_mode
| ) |  |

The bus mode means 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

  instance | The SAI peripheral instance number.
  bus_mode | The protocol selection, it can be I2S left aligned, I2S right aligned, etc.

static void sai_hal_set_mclk_source | ( | uint8_t | instance,
|  | sai_mclk_source_t | source
| ) |  |
| inline static

The source of the clock can be: PLL_OUT, ALT_CLK, EXTAL, SYS_CLK. This function sets the clock source for SAI master clock source. Master clock is used to produce the bit clock for the data transfer.

Parameters

  instance | The SAI peripheral instance number.
  source | Mater clock source

void sai_hal_set_mclk_divider | ( | uint8_t | instance,
|  | uint32_t | mclk,
|  | uint32_t | src_clk
| ) |  |

Using the divider to get the master clock frequency wanted from the source. mclk = clk_source * fract/divide. The input is the master clock frequency needed and the source clock frequency. The master clock is decided by the sample rate and the multi-clock number.

Parameters

  instance | The SAI peripheral instance number.
  mclk | Master clock frequency needed.
  src_clk | The source clock frequency.

static void sai_hal_set_tx_bclk_source | ( | uint8_t | instance,
|  | sai_bclk_source_t | source
| ) |  |
| inline static

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 Tx/Rx. Tx and Rx in the SAI module can use the same bit clock either from Tx or Rx.

Parameters

  instance | The SAI peripheral instance number.
  source | Bit clock source.

static void sai_hal_set_rx_bclk_source | ( | uint8_t | instance,
|  | sai_bclk_source_t | source
| ) |  |
| inline static

It is generated by the master clock, bus clock, and other devices.

The function sets the source of the Rx bit clock. The bit clock can be produced by the master clock and from the bus clock or other SAI Tx/Rx. Tx and Rx in the SAI module use the same bit clock either from Tx or Rx.

Parameters

  instance | The SAI peripheral instance number.
  source | Bit clock source.

static void sai_hal_set_tx_blck_divider | ( | uint8_t | instance,
|  | uint32_t | divider
| ) |  |
| inline static

bclk = mclk / divider. At the same time, bclk = sample_rate * channel * bits. This means how much time is needed to transfer one bit. Notice: The function is called while the bit clock source is the master clock.

Parameters

  instance | The SAI peripheral instance number.
  div | The divide number of bit clock.

static void sai_hal_set_rx_blck_divider | ( | uint8_t | instance,
|  | uint32_t | divider
| ) |  |
| inline static

bclk = mclk / divider. At the same time, bclk = sample_rate * channel * bits. This means how much time is needed to transfer one bit. Notice: The function is called while the bit clock source is the master clock.

Parameters

  instance | The SAI peripheral instance number.
  div | The divide number of bit clock.

static void sai_hal_set_tx_frame_size | ( | uint8_t | instance,
|  | uint8_t | size
| ) |  |
| inline static

The frame size means how many words are in a frame. For example 2-channel audio data, the frame size is 2. This means there are 2 words in a frame.

Parameters

  instance | The SAI peripheral instance number.
  size | Words number in a frame.

static void sai_hal_set_rx_frame_size | ( | uint8_t | instance,
|  | uint8_t | size
| ) |  |
| inline static

The frame size means how many words in a frame. In the usual case, for example 2-channel audio data, the frame size is 2, means 2 words in a frame.

Parameters

  instance | The sai peripheral instance number.
  size | Words number in a frame.

static void sai_hal_set_tx_word_size | ( | uint8_t | instance,
|  | uint8_t | bits
| ) |  |
| inline static

The word size means the quantization level of audio file. Generally, there are 8bit, 16bit, 24bit, 32bit format which sai would all support.

Parameters

  instance | The sai peripheral instance number.
  bits | How many bits in a word.

static void sai_hal_set_rx_word_size | ( | uint8_t | instance,
|  | uint8_t | bits
| ) |  |
| inline static

The word size means the quantization level of the audio file. Generally, SAI supports 8 bit, 16 bit, 24 bit, and 32 bit formats.

Parameters

  instance | The SAI peripheral instance number.
  bits | How many bits in a word.

static void sai_hal_set_tx_word_zero_size | ( | uint8_t | instance,
|  | uint8_t | size
| ) |  |
| inline static

In I2S protocol, the size of the first word is the same as the size of other words. In some protocols, for example, AC'97, the size of the first word is not the same as other sizes. This function sets the length of the first word which is, in most situations, the same as others.

Parameters

  instance | The SAI peripheral instance number.
  size | The length of frame head word.

static void sai_hal_set_rx_word_zero_size | ( | uint8_t | instance,
|  | uint8_t | size
| ) |  |
| inline static

In I2S protocol, the size of the first word is the same as the size of other words. In some protocols, for example, AC'97, the first word is not the same size as others. This function sets the length of the first word, which is, in most situations, the same as others.

Parameters

  instance | The SAI peripheral instance number.
  size | The length of frame head word.

static void sai_hal_set_tx_sync_width | ( | uint8_t | instance,
|  | uint8_t | width
| ) |  |
| inline static

A sync is the number of bit clocks of a frame. The sync width cannot be longer than the length of the first word of the frame.

Parameters

  instance | The SAI peripheral instance number.
  width | How many bit clock in a sync.

static void sai_hal_set_rx_sync_width | ( | uint8_t | instance,
|  | uint8_t | width
| ) |  |
| inline static

A sync is the number of bit clocks of a frame. The sync width cannot be longer than the length of the first word of the frame.

Parameters

  instance | The SAI peripheral instance number.
  width | How many bit clock in a sync.

static void sai_hal_set_tx_watermark | ( | uint8_t | instance,
|  | uint8_t | watermark
| ) |  |
| inline static

While the value in the Tx FIFO is less or equal to the watermark , it generates an interrupt request or a DMA request. The watermark value cannot be greater than the depth of FIFO.

Parameters

  instance | The SAI peripheral instance number.
  watermark | Watermark value of a FIFO.

static void sai_hal_set_rx_watermark | ( | uint8_t | instance,
|  | uint8_t | watermark
| ) |  |
| inline static

While the value in Rx FIFO is larger or equal to the watermark , it generates an interrupt request or a DMA request. The watermark value cannot be greater than the depth of FIFO.

Parameters

  instance | The SAI peripheral instance number.
  watermark | Watermark value of a FIFO.

void sai_hal_set_tx_master_slave | ( | uint8_t | instance,
|  | sai_master_slave_t | master_slave_mode
| ) |  |

The function sets the Tx mode to either master or slave. The master mode provides its own clock and slave mode uses the external clock.

Parameters

  instance | The SAI peripheral instance number.
  master_slave_mode | Mater or slave mode.

void sai_hal_set_rx_master_slave | ( | uint8_t | instance,
|  | sai_master_slave_t | master_slave_mode
| ) |  |

The function sets the Rx mode to either master or slave. Master mode provides its own clock and slave mode uses the external clock.

Parameters

  instance | The SAI peripheral instance number.
  master_slave_mode | Mater or slave mode.

void sai_hal_set_tx_sync_mode | ( | uint8_t | instance,
|  | 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

  instance | The SAI peripheral instance number.
  sync_mode | Synchronous mode or Asynchronous mode.

void sai_hal_set_rx_sync_mode | ( | uint8_t | instance,
|  | sai_sync_mode_t | sync_mode
| ) |  |

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

Parameters

  instance | The SAI peripheral instance number.
  sync_mode | Synchronous mode or Asynchronous mode.

uint8_t sai_hal_get_fifo_read_pointer | ( | uint8_t | instance,
|  | sai_io_mode_t | io_mode,
|  | uint8_t | fifo_channel
| ) |  |

It is used to judge whether the FIFO is full or empty and know how much space there is for FIFO. If read_ptr == write_ptr, the FIFO is empty. While the bit of the read_ptr and the write_ptr are equal except for the MSB, the FIFO is full.

Parameters

  instance | The SAI peripheral instance number.
  io_mode | Transmit or receive data.
  fifo_channel | FIFO channel selected.

Returns
  FIFO read pointer value.

uint8_t sai_hal_get_fifo_write_pointer | ( | uint8_t | instance,
|  | sai_io_mode_t | io_mode,
|  | uint8_t | fifo_channel
| ) |  |

It is used to judge whether the FIFO is full or empty and know how much space there is for FIFO. If the read_ptr == write_ptr, the FIFO is empty. While the bit of the read_ptr and write_ptr are equal except for the MSB, the FIFO is full.

Parameters

  instance | The SAI peripheral instance number.
  io_mode | Transmit or receive data.
  fifo_channel | FIFO channel selected.

Returns
  FIFO write pointer value

uint32_t* sai_hal_get_fifo_address | ( | uint8_t | instance,
|  | sai_io_mode_t | io_mode,
|  | uint8_t | fifo_channel
| ) |  |

This function is for DMA transfer because it needs to know the dest/src address of the DMA transfer.

Parameters

  instance | The SAI peripheral instance number.
  io_mode | Transmit or receive data.
  fifo_channel | FIFO channel selected.

Returns
  TDR register or RDR register address

static void sai_hal_enable_tx | ( | uint8_t | instance | ) |
| inline static

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

Parameters

  instance | The SAI peripheral instance number.

static void sai_hal_enable_rx | ( | uint8_t | instance | ) |
| inline static

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

Parameters

  instance | The SAI peripheral instance number.

static void sai_hal_disable_tx | ( | uint8_t | instance | ) |
| inline static

Disables the transmitter. This function disables both the bit clock and the transfer channel. When software clears this field, the transmitter remains enabled, and this bit remains set, until the end of the current frame.

Parameters

  instance | The SAI peripheral instance number.

static void sai_hal_disable_rx | ( | uint8_t | instance | ) |
| inline static

Disables the receiver. This function disables both the bit clock and the transfer channel. When software clears this field, the receiver remains enabled, and this bit remains set, until the end of the current frame.

Parameters

  instance | The SAI peripheral instance number.

void sai_hal_enable_tx_interrupt | ( | uint8_t | instance,
|  | sai_interrupt_request_t | source
| ) |  |

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

Parameters

  instance | The SAI peripheral instance number.
  source | SAI interrupt request source.

void sai_hal_enable_rx_interrupt | ( | uint8_t | instance,
|  | sai_interrupt_request_t | source
| ) |  |

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

Parameters

  instance | The SAI peripheral instance number.
  source | SAI interrupt request source.

void sai_hal_disable_tx_interrupt | ( | uint8_t | instance,
|  | sai_interrupt_request_t | source
| ) |  |

This function disables the interrupt requests from the interrupt request source of SAI.

Parameters

  instance | The SAI peripheral instance number.
  source | SAI interrupt request source.

void sai_hal_disable_rx_interrupt | ( | uint8_t | instance,
|  | sai_interrupt_request_t | source
| ) |  |

This function disables the interrupt requests from interrupt request source of SAI.

Parameters

  instance | The SAI peripheral instance number.
  source | SAI interrupt request source.

void sai_hal_enable_tx_dma | ( | uint8_t | instance,
|  | sai_dma_request_t | request
| ) |  |

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

Parameters

  instance | The SAI peripheral instance number.
  source | SAI DMA request source.

void sai_hal_enable_rx_dma | ( | uint8_t | instance,
|  | sai_dma_request_t | request
| ) |  |

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

Parameters

  instance | The SAI peripheral instance number.
  source | SAI DMA request source.

void sai_hal_disable_tx_dma | ( | uint8_t | instance,
|  | sai_dma_request_t | request
| ) |  |

The function disables the DMA request of Tx in SAI. DMA request can from FIFO warning or FIFO request which means FIFO is empty or reach the watermark.

Parameters

  instance | The SAI peripheral instance number.
  source | SAI DMA request source.

void sai_hal_disable_rx_dma | ( | uint8_t | instance,
|  | sai_dma_request_t | request
| ) |  |

The function disables the DMA request of Tx in SAI. DMA request can from FIFO warning or FIFO request which means FIFO is empty or reach the watermark.

Parameters

  instance | The SAI peripheral instance number.
  source | SAI DMA request source.

void sai_hal_clear_tx_state_flag | ( | uint8_t | instance,
|  | sai_state_flag_t | flag
| ) |  |

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

Parameters

  instance | The SAI peripheral instance number.
  flag | SAI state flag type. The flag can be word start, sync error, FIFO error/warning.

void sai_hal_clear_rx_state_flag | ( | uint8_t | instance,
|  | sai_state_flag_t | flag
| ) |  |

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

Parameters

  instance | The SAI peripheral instance number.
  flag | SAI state flag type. The flag can be word start, sync error, FIFO error/warning.

void sai_hal_reset_tx | ( | uint8_t | instance,
|  | sai_reset_type_t | mode
| ) |  |

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

  instance | The SAI peripheral instance number.
  mode | SAI reset type.

void sai_hal_reset_rx | ( | uint8_t | instance,
|  | sai_reset_type_t | mode
| ) |  |

Parameters

  instance | The SAI peripheral instance number.
  mode | SAI reset type.

static void sai_hal_set_tx_word_mask | ( | uint8_t | instance,
|  | uint32_t | mask
| ) |  |
| inline static

Each bit number represent the mask word index. For example, 0 represents mask the 0th word, 3 represents mask 0th and 1st word. The TMR register can be different from frame to frame. If the user wants a mono audio, set the mask to 0/1.

Parameters

  instance | The SAI peripheral instance number.
  mask | Which bits need to be masked in a frame.

static void sai_hal_set_rx_word_mask | ( | uint8_t | instance,
|  | uint32_t | mask
| ) |  |
| inline static

Parameters

  instance | The SAI peripheral instance number.
  mask | Which bits need to be masked in a frame.

static void sai_hal_set_tx_fifo_channel | ( | uint8_t | instance,
|  | uint8_t | fifo_channel
| ) |  |
| inline static

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

Parameters

  instance | The SAI peripheral instance number.
  fifo_channel | FIFO channel number.

static void sai_hal_set_rx_fifo_channel | ( | uint8_t | instance,
|  | uint8_t | fifo_channel
| ) |  |
| inline static

Parameters

  instance | The SAI peripheral instance number.
  fifo_channel | FIFO channel number.

void sai_hal_set_tx_mode | ( | uint8_t | instance,
|  | sai_mode_t | mode
| ) |  |

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

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

Parameters

  instance | The SAI peripheral instance number.
  mode | SAI running mode.

void sai_hal_set_rx_mode | ( | uint8_t | instance,
|  | sai_mode_t | mode
| ) |  |

Parameters

  instance | The SAI peripheral instance number.
  mode | SAI running mode.

void sai_hal_set_tx_bclk_swap | ( | uint8_t | instance,
|  | bool | ifswap
| ) |  |

While set in asynchronous mode, the transmitter is clocked by the receiver bit clock. When set in synchronous mode, the transmitter is clocked by the transmitter bit clock, but uses the receiver frame sync. This bit has no effect when synchronous with another SAI peripheral.

Parameters

  instance | The SAI peripheral instance number.
  ifswap | If swap bit clock.

void sai_hal_set_rx_bclk_swap | ( | uint8_t | instance,
|  | bool | ifswap
| ) |  |

When set in asynchronous mode, the receiver is clocked by the transmitter bit clock. When set in synchronous mode, the receiver is clocked by the receiver bit clock, but uses the transmitter frame sync. This bit has no effect when synchronous with another SAI peripheral.

Parameters

  instance | The SAI peripheral instance number.
  ifswap | If swap bit clock.

static void sai_hal_set_tx_word_start_index | ( | uint8_t | instance,
|  | uint8_t | index
| ) |  |
| inline static

Parameters

  instance | The SAI peripheral instance number.
  index | Which word triggers the word start flag.

static void sai_hal_set_rx_word_start_index | ( | uint8_t | instance,
|  | uint8_t | index
| ) |  |
| inline static

Parameters

  instance | The SAI peripheral instance number.
  index | Which word would trigger word start flag.

static void sai_hal_set_tx_fbt | ( | uint8_t | instance,
|  | uint8_t | index
| ) |  |
| inline static

The FIFO is 32-bit in SAI, but not all audio data is 32-bit. Mostly they are 16-bit. In this situation, the Codec needs to know which bit of the FIFO marks the valid audio data.

Parameters

  instance | The SAI peripheral instance number.
  index | First bit shifted in FIFO.

static void sai_hal_set_rx_fbt | ( | uint8_t | instance,
|  | uint8_t | index
| ) |  |
| inline static

Parameters

  instance | The SAI peripheral instance number.
  index | First bit shifted in FIFO.

bool sai_hal_mclk_divider_is_update | ( | uint8_t | instance | ) |

Parameters

  instance | The SAI peripheral instance number.

Returns
  True if the divider updated otherwise false.

bool sai_hal_word_start_is_detected | ( | uint8_t | instance,
|  | sai_io_mode_t | io_mode
| ) |  |

Parameters

  instance | The SAI peripheral instance number.
  io_mode | Transmit or receive data.

Returns
  True if detect word start otherwise false.

bool sai_hal_sync_error_is_detected | ( | uint8_t | instance,
|  | sai_io_mode_t | io_mode
| ) |  |

Parameters

  instance | The SAI peripheral instance number.
  io_mode | Transmit or receive data.

Returns
  True if detect sync error otherwise false.

bool sai_hal_fifo_warning_is_detected | ( | uint8_t | instance,
|  | sai_io_mode_t | io_mode
| ) |  |

FIFO warning means that the FIFO is empty in Tx. While in Tx, FIFO warning means that the FIFO is empty and it needs data.

Parameters

  instance | The SAI peripheral instance number.
  io_mode | Transmit or receive data.

Returns
  True if detect FIFO warning otherwise false.

bool sai_hal_fifo_error_is_detected | ( | uint8_t | instance,
|  | sai_io_mode_t | io_mode
| ) |  |

FIFO error means that the FIFO has no data and the Codec is still transferring data. While in Rx, FIFO error means that the data is still in but the FIFO is full.

Parameters

  instance | The SAI peripheral instance number.
  io_mode | Transmit or receive data.

Returns
  True if detects FIFO error otherwise false.

bool sai_hal_fifo_request_is_detected | ( | uint8_t | instance,
|  | sai_io_mode_t | io_mode
| ) |  |

FIFO request means that the data in FIFO is less than the watermark in Tx and more than the watermark in Rx.

Parameters

  instance | The SAI peripheral instance number.
  io_mode | Transmit or receive data.

Returns
  True if detects FIFO request otherwise false.

static void sai_hal_receive_data | ( | uint8_t | instance,
|  | uint8_t | rx_channel,
|  | uint32_t * | data
| ) |  |
| inline static

Parameters

  instance | The SAI peripheral instance number.
  rx_channel | Rx FIFO channel.
  data | Pointer to the address to be written in.

static void sai_hal_transmit_data | ( | uint8_t | instance,
|  | uint8_t | tx_channel,
|  | uint32_t | data
| ) |  |
| inline static

Parameters

  instance | The SAI peripheral instance number.
  tx_channel | Tx FIFO channel.
  data | Data value which needs to be written into FIFO.