Azure Sphere MT3620 M4 API Reference Manual
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Function

This section provides fixed APIs (defined as Common Interface) to fully control the MediaTek I2S HW. More...

Overview

This section provides fixed APIs (defined as Common Interface) to fully control the MediaTek I2S HW.

Functions

int mtk_mhal_i2s_cfg_type (struct mtk_i2s_ctlr *ctlr, hal_i2s_initial_type i2s_initial_type)
 Configure I2S type. More...
 
int mtk_mhal_i2s_reset (struct mtk_i2s_ctlr *ctlr)
 Reset the I2S hardware. More...
 
int mtk_mhal_i2s_clk_en (struct mtk_i2s_ctlr *ctlr, i2s_fnen en)
 enable the I2S clock. More...
 
int mtk_mhal_i2s_set_config (struct mtk_i2s_ctlr *ctlr, struct hal_i2s_config *config)
 Set the I2S configuration in detail. More...
 
int mtk_mhal_i2s_enable_audio_top (struct mtk_i2s_ctlr *ctlr)
 Enable uplink FIFO and downlink FIFO of the I2S link. More...
 
int mtk_mhal_i2s_disable_audio_top (struct mtk_i2s_ctlr *ctlr)
 Disable the uplink FIFO and the downlink FIFO of I2S link. More...
 
int mtk_mhal_i2s_cfg_tx_dma_irq_enable (struct mtk_i2s_ctlr *ctlr, i2s_dma_callback_func callback_func)
 Config Tx VFIFO DMA interrupt enable. More...
 
int mtk_mhal_i2s_cfg_tx_dma_irq_disable (struct mtk_i2s_ctlr *ctlr)
 Config Tx VFIFO DMA interrupt disable. More...
 
int mtk_mhal_i2s_cfg_rx_dma_irq_enable (struct mtk_i2s_ctlr *ctlr, i2s_dma_callback_func callback_func)
 Config Rx VFIFO DMA interrupt enable. More...
 
int mtk_mhal_i2s_cfg_rx_dma_irq_disable (struct mtk_i2s_ctlr *ctlr)
 Config Rx VFIFO DMA interrupt disable. More...
 
int mtk_mhal_i2s_start_tx_vfifo (struct mtk_i2s_ctlr *ctlr, u32 *buffer, u32 threshold, u32 buffer_length)
 Start the Tx VFIFO DMA transmit operation. More...
 
int mtk_mhal_i2s_stop_tx_vfifo (struct mtk_i2s_ctlr *ctlr)
 Disable the Tx VFIFO DMA transmit operation. More...
 
int mtk_mhal_i2s_start_rx_vfifo (struct mtk_i2s_ctlr *ctlr, u32 *buffer, u32 threshold, u32 buffer_length)
 Start the Rx VFIFO DMA receive operation. More...
 
int mtk_mhal_i2s_stop_rx_vfifo (struct mtk_i2s_ctlr *ctlr)
 Disable the Rx VFIFO DMA receive operation. More...
 
int mtk_mhal_i2s_enable_tx (struct mtk_i2s_ctlr *ctlr)
 Power on the I2S the output link. More...
 
int mtk_mhal_i2s_disable_tx (struct mtk_i2s_ctlr *ctlr)
 Power off the I2S output link. More...
 
int mtk_mhal_i2s_enable_rx (struct mtk_i2s_ctlr *ctlr)
 Power on the I2S input link. More...
 
int mtk_mhal_i2s_disable_rx (struct mtk_i2s_ctlr *ctlr)
 Power off the I2S input link. More...
 
int mtk_mhal_i2s_move_tx_point (struct mtk_i2s_ctlr *ctlr, u32 buffer_length)
 Move the SW point of Tx VFIFO DMA. More...
 
int mtk_mhal_i2s_move_rx_point (struct mtk_i2s_ctlr *ctlr, u32 buffer_length)
 Move the SW point of Rx VFIFO DMA. More...
 
int mtk_mhal_i2s_alloc_vfifo_ch (struct mtk_i2s_ctlr *ctlr)
 I2S allocate DMA channel. More...
 
int mtk_mhal_i2s_release_vfifo_ch (struct mtk_i2s_ctlr *ctlr)
 I2S release DMA channel. More...
 

Function Documentation

int mtk_mhal_i2s_cfg_type ( struct mtk_i2s_ctlr ctlr,
hal_i2s_initial_type  i2s_initial_type 
)

Configure I2S type.

Usage: OS-HAL driver should call it in the initialization flow.

Parameters
[in]ctlr: I2S port and base address.
[in]i2s_initial_type: Initial configuration type.
Example
struct hal_i2s_config i2s_config;
struct mtk_i2s_ctlr i2s_ctrl;
// set I2S0 as external mode
i2s_ctrl.base = i2s0_baseaddr;
i2s_ctrl.i2s_port = MHAL_I2S0;
// configure Rx settings
i2s_config.i2s_in.sample_rate = MHAL_I2S_SAMPLE_RATE_8K;
i2s_config.rx_down_rate=MHAL_I2S_RX_DOWN_RATE_DISABLE;
........
// configure Tx settings
i2s_config.i2s_out.sample_rate = MHAL_I2S_SAMPLE_RATE_8K;
i2s_config.i2s_out.channel_number = MHAL_I2S_STEREO;
........
result = mtk_mhal_i2s_set_config(&i2s_ctrl, &i2s_config);
Returns
Return "0" if parameter setting is sucessfully.
Return -I2S_EPTR if the ctlr or config is NULL.
Note
Set i2s_initial_type as MHAL_I2S_TYPE_EXTERNAL_MODE when using external codec component in the application.
int mtk_mhal_i2s_reset ( struct mtk_i2s_ctlr ctlr)

Reset the I2S hardware.

Usage: OS-HAL driver can use this function to reset I2S HW before the initialization flow or after disabling I2S.

Parameters
[in]ctlr: I2S port and base address.
Returns
Return "0" if I2S reset is sucessfully.
Return -I2S_EPTR if the ctlr is NULL.
int mtk_mhal_i2s_clk_en ( struct mtk_i2s_ctlr ctlr,
i2s_fnen  en 
)

enable the I2S clock.

Usage: OS-HAL driver can use this function to enable or disable MCLK output, I2S out and I2S in clock.
MCLK output, I2S out and I2S in clock will be enable after step3 on section How to Use This Driver.

Parameters
[in]ctlr: I2S port and base address.
[in]en: enable or disable clock.
Returns
Return "0" if I2S reset is sucessfully.
Return -I2S_EPTR if the ctlr is NULL.
int mtk_mhal_i2s_set_config ( struct mtk_i2s_ctlr ctlr,
struct hal_i2s_config config 
)

Set the I2S configuration in detail.

Usage: OS-HAL driver can call this function to configure I2S.
The mtk_mhal_i2s_set_config() function configures the I2S settings providing the respective sample rate and channel number for Tx and Rx links as well as the clock mode for the whole I2S.

Parameters
[in]ctlr: I2S port and base address.
[in]config: Link configuration of the I2S module.
Returns
Return "0" if configure I2S HW is sucessfully.
Return -I2S_EPTR if the ctlr is NULL or configuration parameter is invalid.
int mtk_mhal_i2s_enable_audio_top ( struct mtk_i2s_ctlr ctlr)

Enable uplink FIFO and downlink FIFO of the I2S link.

Usage: OS-HAL driver can use this function to enable I2S FIFO.
The function should be called before hal_i2s_enable_tx() and hal_i2s_enable_rx()

Parameters
[in]ctlr: I2S port and base address.
Returns
Return "0" if enable I2S top is sucessfully.
Return -I2S_EPTR if the ctlr is NULL.
int mtk_mhal_i2s_disable_audio_top ( struct mtk_i2s_ctlr ctlr)

Disable the uplink FIFO and the downlink FIFO of I2S link.

Usage: OS-HAL driver can use this function to disable I2S FIFO.
The function should be called before hal_i2s_disable_tx() and hal_i2s_disable_rx()

Parameters
[in]ctlr: I2S port and base address.
Returns
Return "0" if disable I2S top is sucessfully.
Return -I2S_EPTR if the ctlr is NULL.
int mtk_mhal_i2s_cfg_tx_dma_irq_enable ( struct mtk_i2s_ctlr ctlr,
i2s_dma_callback_func  callback_func 
)

Config Tx VFIFO DMA interrupt enable.

Usage: OS-HAL driver can use this function to enable I2S Tx DMA interrupt and register callback. The Tx VFIFO DMA will trigger an interrupt when the amount of the output data in Tx VFIFO is lower than that in the Tx VFIFO threshold.
For the use of the DMA interrupt handle, please refer to the section - Driver_Usage_Chapter.

Parameters
[in]ctlr: I2S port and base address.
[in]callback_func: callback function.
Returns
Return "0" if configure I2S Tx DMA interrupt enable is sucessfully.
Return -I2S_EPTR if the ctlr is NULL.
int mtk_mhal_i2s_cfg_tx_dma_irq_disable ( struct mtk_i2s_ctlr ctlr)

Config Tx VFIFO DMA interrupt disable.

Usage: OS-HAL driver can use this function to disable I2S Tx DMA interrupt.

Parameters
[in]ctlr: I2S port and base address.
Returns
Return "0" if configure I2S Rx DMA interrupt disable is sucessfully.
Return -I2S_EPTR if the ctlr is NULL.
int mtk_mhal_i2s_cfg_rx_dma_irq_enable ( struct mtk_i2s_ctlr ctlr,
i2s_dma_callback_func  callback_func 
)

Config Rx VFIFO DMA interrupt enable.

Usage: OS-HAL driver can use this function to enable I2S Rx DMA interrupt and register callback. VFIFO DMA will trigger an interrupt when the amount of the available received data in Rx VFIFO is larger than that in the Rx VFIFO threshold. For the use of the DMA interrupt handle, please refer to the section - Driver_Usage_Chapter.

Parameters
[in]ctlr: I2S port and base address.
[in]callback_func: callback function.
Returns
Return "0" if configure I2S Rx DMA interrupt enable is sucessfully.
Return -I2S_EPTR if the ctlr is NULL.
int mtk_mhal_i2s_cfg_rx_dma_irq_disable ( struct mtk_i2s_ctlr ctlr)

Config Rx VFIFO DMA interrupt disable.

Usage: OS-HAL driver can use this function to disable I2S Rx DMA interrupt.

Parameters
[in]ctlr: I2S port and base address.
Returns
Return "0" if configure I2S Rx DMA interrupt disable is sucessfully.
Return -I2S_EPTR if the ctlr is NULL.
int mtk_mhal_i2s_start_tx_vfifo ( struct mtk_i2s_ctlr ctlr,
u32 *  buffer,
u32  threshold,
u32  buffer_length 
)

Start the Tx VFIFO DMA transmit operation.

Usage: OS-HAL driver can use this function to configure the I2S Tx VFIFO DMA.
The FIFO starts to pump data from the Tx VFIFO buffer into the I2S Tx FIFO when the VFIFO DMA is configured and the I2S FIFO is enabled. The VFIFO DMA will trigger an interrupt when the amount of output data in Tx VFIFO is lower than that in the Tx VFIFO threshold.

Parameters
[in]ctlr: I2S port and base address.
[in]buffer: Pointer to memory buffer for Tx VFIFO.
[in]threshold: The value of Tx VFIFO threshold.
[in]buffer_length: The size of memory buffer for Tx VFIFO.
Returns
Return "0" if setup I2S Tx VFIFO DMA is sucessfully.
Return -I2S_EPTR if the ctlr is NULL.
Return -I2S_ELENGTH if the threshold and buffer_length is invalid.
int mtk_mhal_i2s_stop_tx_vfifo ( struct mtk_i2s_ctlr ctlr)

Disable the Tx VFIFO DMA transmit operation.

Usage: OS-HAL driver can use this function to stop the I2S Tx VFIFO DMA.
The FIFO will stop pumping data from the Tx VFIFO buffer into I2S Tx FIFO.

Parameters
[in]ctlr: I2S port and base address.
Returns
Return "0" if stop I2S Tx VFIFO DMA is sucessfully.
Return -I2S_EPTR if the ctlr is NULL.
int mtk_mhal_i2s_start_rx_vfifo ( struct mtk_i2s_ctlr ctlr,
u32 *  buffer,
u32  threshold,
u32  buffer_length 
)

Start the Rx VFIFO DMA receive operation.

Usage: OS-HAL driver can use this function to configure the I2S VFIFO DMA.
The FIFO starts to pump data from I2S Rx into the Rx VFIFO buffer when VFIFO DMA is configured and the I2S FIFO is enabled. If the I2S Rx is enabled, VFIFO DMA will trigger an interrupt when the amount of available received data in Rx VFIFO is larger than that in the Rx VFIFO threshold.

Parameters
[in]ctlr: I2S port and base address.
[in]buffer: The pointer to memory buffer for Rx VFIFO.
[in]threshold: The value of Rx VFIFO threshold.
[in]buffer_length: The size of array to memory buffer for Rx VFIFO.
Returns
Return "0" if setup I2S Rx VFIFO DMA is sucessfully.
Return -I2S_EPTR if the ctlr is NULL.
Return -I2S_ELENGTH if the threshold and buffer_length is invalid.
int mtk_mhal_i2s_stop_rx_vfifo ( struct mtk_i2s_ctlr ctlr)

Disable the Rx VFIFO DMA receive operation.

Usage: OS-HAL driver can use this function to stop I2S Rx VFIFO DMA.
The FIFO will stop to pump data from the I2S Rx into the Rx VFIFO buffer.

Parameters
[in]ctlr: I2S port and base address.
Returns
Return "0" if stop I2S Rx VFIFO DMA is sucessfully.
Return -I2S_EPTR if the ctlr is NULL.
int mtk_mhal_i2s_enable_tx ( struct mtk_i2s_ctlr ctlr)

Power on the I2S the output link.

Usage: OS-HAL driver can use this function to enable I2S Tx to transmit data.

Parameters
[in]ctlr: I2S port and base address.
Returns
Return "0" if enable I2S Tx is sucessfully.
Return -I2S_EPTR if the ctlr is NULL.
int mtk_mhal_i2s_disable_tx ( struct mtk_i2s_ctlr ctlr)

Power off the I2S output link.

Usage: OS-HAL driver can use this function to disable I2S Tx to transmit data.

Parameters
[in]ctlr: I2S port and base address.
Returns
Return "0" if disable I2S Tx is sucessfully.
Return -I2S_EPTR if the ctlr is NULL.
int mtk_mhal_i2s_enable_rx ( struct mtk_i2s_ctlr ctlr)

Power on the I2S input link.

Usage: OS-HAL driver can use this function to enable I2S Rx to receive data.

Parameters
[in]ctlr: I2S port and base address.
Returns
Return "0" if enable I2S Rx is sucessfully.
Return -I2S_EPTR if the ctlr is NULL.
int mtk_mhal_i2s_disable_rx ( struct mtk_i2s_ctlr ctlr)

Power off the I2S input link.

Usage: OS-HAL driver can use this function to disable I2S Rx to receive data.

Parameters
[in]ctlr: I2S port and base address.
Returns
Return "0" if disable I2S Rx is sucessfully.
Return -I2S_EPTR if the ctlr is NULL.
int mtk_mhal_i2s_move_tx_point ( struct mtk_i2s_ctlr ctlr,
u32  buffer_length 
)

Move the SW point of Tx VFIFO DMA.

Usage: OS-HAL driver can use this function to move DMA SW point when the output data in Tx VFIFO is lower than threshold.

Parameters
[in]ctlr: I2S port and base address.
[in]buffer_length: move pointer count.
Returns
Return "0" if setup I2S Tx VFIFO DMA is sucessfully.
Return -I2S_EPTR if the ctlr is NULL.
int mtk_mhal_i2s_move_rx_point ( struct mtk_i2s_ctlr ctlr,
u32  buffer_length 
)

Move the SW point of Rx VFIFO DMA.

Usage: OS-HAL driver can use this function to move DMA SW point when the input data in Rx VFIFO is larger than threshold.

Parameters
[in]ctlr: I2S port and base address.
[in]buffer_length: move pointer count.
Returns
Return "0" if setup I2S Rx VFIFO DMA is sucessfully.
Return -I2S_EPTR if the ctlr is NULL.
int mtk_mhal_i2s_alloc_vfifo_ch ( struct mtk_i2s_ctlr ctlr)

I2S allocate DMA channel.

Usage: OS-HAL driver can use this function to allocate DMA channel.

Parameters
[in]ctlr: I2S port and base address.
Returns
Return "0" if allocate memory sucessfully.
Return -I2S_EPTR if allocate channel fail or the ctlr is NULL.
int mtk_mhal_i2s_release_vfifo_ch ( struct mtk_i2s_ctlr ctlr)

I2S release DMA channel.

Usage: OS-HAL driver can use this function to release DMA channel.

Parameters
[in]ctlr: I2S port and base address.
Returns
Return "0" if allocate memory sucessfully.
Return -I2S_EPTR if release channel fail or the ctlr is NULL.