mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Apr 03 11:45:06 2014 +0100
Revision:
149:1fb5f62b92bd
Parent:
targets/hal/TARGET_Freescale/TARGET_KSDK_MCUS/TARGET_KSDK_CODE/hal/sai/fsl_sai_hal.h@146:f64d43ff0c18
Child:
324:406fd2029f23
Synchronized with git revision 220c0bb39ceee40016e1e86350c058963d01ed42

Full URL: https://github.com/mbedmicro/mbed/commit/220c0bb39ceee40016e1e86350c058963d01ed42/

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 146:f64d43ff0c18 1 /*
mbed_official 146:f64d43ff0c18 2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
mbed_official 146:f64d43ff0c18 3 * All rights reserved.
mbed_official 146:f64d43ff0c18 4 *
mbed_official 146:f64d43ff0c18 5 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 146:f64d43ff0c18 6 * are permitted provided that the following conditions are met:
mbed_official 146:f64d43ff0c18 7 *
mbed_official 146:f64d43ff0c18 8 * o Redistributions of source code must retain the above copyright notice, this list
mbed_official 146:f64d43ff0c18 9 * of conditions and the following disclaimer.
mbed_official 146:f64d43ff0c18 10 *
mbed_official 146:f64d43ff0c18 11 * o Redistributions in binary form must reproduce the above copyright notice, this
mbed_official 146:f64d43ff0c18 12 * list of conditions and the following disclaimer in the documentation and/or
mbed_official 146:f64d43ff0c18 13 * other materials provided with the distribution.
mbed_official 146:f64d43ff0c18 14 *
mbed_official 146:f64d43ff0c18 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
mbed_official 146:f64d43ff0c18 16 * contributors may be used to endorse or promote products derived from this
mbed_official 146:f64d43ff0c18 17 * software without specific prior written permission.
mbed_official 146:f64d43ff0c18 18 *
mbed_official 146:f64d43ff0c18 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
mbed_official 146:f64d43ff0c18 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
mbed_official 146:f64d43ff0c18 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 146:f64d43ff0c18 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
mbed_official 146:f64d43ff0c18 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
mbed_official 146:f64d43ff0c18 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
mbed_official 146:f64d43ff0c18 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
mbed_official 146:f64d43ff0c18 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
mbed_official 146:f64d43ff0c18 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
mbed_official 146:f64d43ff0c18 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 146:f64d43ff0c18 29 */
mbed_official 146:f64d43ff0c18 30
mbed_official 146:f64d43ff0c18 31 #ifndef __FSL_SAI_HAL_H__
mbed_official 146:f64d43ff0c18 32 #define __FSL_SAI_HAL_H__
mbed_official 146:f64d43ff0c18 33
mbed_official 146:f64d43ff0c18 34
mbed_official 146:f64d43ff0c18 35 #include <string.h>
mbed_official 146:f64d43ff0c18 36 #include <stdbool.h>
mbed_official 146:f64d43ff0c18 37 #include <assert.h>
mbed_official 146:f64d43ff0c18 38 #include "fsl_device_registers.h"
mbed_official 146:f64d43ff0c18 39 #include "fsl_sai_features.h"
mbed_official 146:f64d43ff0c18 40
mbed_official 146:f64d43ff0c18 41
mbed_official 146:f64d43ff0c18 42 /*!
mbed_official 146:f64d43ff0c18 43 * @addtogroup sai_hal
mbed_official 146:f64d43ff0c18 44 * @{
mbed_official 146:f64d43ff0c18 45 */
mbed_official 146:f64d43ff0c18 46
mbed_official 146:f64d43ff0c18 47 /*! @file */
mbed_official 146:f64d43ff0c18 48
mbed_official 146:f64d43ff0c18 49 /*******************************************************************************
mbed_official 146:f64d43ff0c18 50 * Definitions
mbed_official 146:f64d43ff0c18 51 ******************************************************************************/
mbed_official 146:f64d43ff0c18 52
mbed_official 146:f64d43ff0c18 53 /* Defines the bit limits of in a word*/
mbed_official 146:f64d43ff0c18 54 #define SAI_BIT_MIN 8
mbed_official 146:f64d43ff0c18 55 #define SAI_BIT_MAX 32
mbed_official 146:f64d43ff0c18 56
mbed_official 146:f64d43ff0c18 57 /* Defines the limits of word number per frame */
mbed_official 146:f64d43ff0c18 58 #define SAI_WORD_MAX FSL_FEATURE_I2S_MAX_WORDS_PER_FRAME
mbed_official 146:f64d43ff0c18 59
mbed_official 146:f64d43ff0c18 60 /* Defines the maximum div and fract value for master clock divider. */
mbed_official 146:f64d43ff0c18 61 #define SAI_FRACT_MAX 256
mbed_official 146:f64d43ff0c18 62 #define SAI_DIV_MAX 4096
mbed_official 146:f64d43ff0c18 63
mbed_official 146:f64d43ff0c18 64 /* Defines the maximum value for watermark setting. */
mbed_official 146:f64d43ff0c18 65 #define SAI_WATERMARK_MAX FSL_FEATURE_I2S_FIFO_COUNT
mbed_official 146:f64d43ff0c18 66 #define SAI_FIFO_LEN FSL_FEATURE_I2S_FIFO_COUNT
mbed_official 146:f64d43ff0c18 67
mbed_official 146:f64d43ff0c18 68 /*! @brief Defines the SAI bus type. */
mbed_official 146:f64d43ff0c18 69 typedef enum _sai_bus
mbed_official 146:f64d43ff0c18 70 {
mbed_official 146:f64d43ff0c18 71 kSaiBusI2SLeft = 0x0,/*!< Use I2S left aligned format */
mbed_official 146:f64d43ff0c18 72 kSaiBusI2SRight = 0x1,/*!< Use I2S right aligned format */
mbed_official 146:f64d43ff0c18 73 kSaiBusI2SType = 0x2,/*!< Use I2S format */
mbed_official 146:f64d43ff0c18 74 } sai_bus_t;
mbed_official 146:f64d43ff0c18 75
mbed_official 146:f64d43ff0c18 76 /*! @brief Transmits or receives data; Reads and writes at the same time.*/
mbed_official 146:f64d43ff0c18 77 typedef enum _sai_io_mode
mbed_official 146:f64d43ff0c18 78 {
mbed_official 146:f64d43ff0c18 79 kSaiIOModeTransmit = 0x0,/*!< Write data to FIFO */
mbed_official 146:f64d43ff0c18 80 kSaiIOModeReceive = 0x1,/*!< Read data from FIFO */
mbed_official 146:f64d43ff0c18 81 kSaiIOModeDuplex = 0x2/*!< Read data and write data at the same time */
mbed_official 146:f64d43ff0c18 82 } sai_io_mode_t;
mbed_official 146:f64d43ff0c18 83
mbed_official 146:f64d43ff0c18 84 /*! @brief Master or slave mode */
mbed_official 146:f64d43ff0c18 85 typedef enum _sai_master_slave
mbed_official 146:f64d43ff0c18 86 {
mbed_official 146:f64d43ff0c18 87 kSaiMaster = 0x0,/*!< Master mode */
mbed_official 146:f64d43ff0c18 88 kSaiSlave = 0x1/*!< Slave mode */
mbed_official 146:f64d43ff0c18 89 } sai_master_slave_t;
mbed_official 146:f64d43ff0c18 90
mbed_official 146:f64d43ff0c18 91 /*! @brief Synchronous or asynchronous mode */
mbed_official 146:f64d43ff0c18 92 typedef enum _sai_sync_mode
mbed_official 146:f64d43ff0c18 93 {
mbed_official 146:f64d43ff0c18 94 kSaiModeAsync = 0x0,/*!< Asynchronous mode */
mbed_official 146:f64d43ff0c18 95 kSaiModeSync = 0x1,/*!< Synchronous mode (with receiver or transmit) */
mbed_official 146:f64d43ff0c18 96 kSaiModeSyncWithOtherTx = 0x2,/*!< Synchronous with another SAI transmit */
mbed_official 146:f64d43ff0c18 97 kSaiModeSyncWithOtherRx = 0x3/*!< Synchronous with another SAI receiver */
mbed_official 146:f64d43ff0c18 98 } sai_sync_mode_t;
mbed_official 146:f64d43ff0c18 99
mbed_official 146:f64d43ff0c18 100 /*! @brief Mater clock source */
mbed_official 146:f64d43ff0c18 101 typedef enum _sai_mclk_source
mbed_official 146:f64d43ff0c18 102 {
mbed_official 146:f64d43ff0c18 103 kSaiMclkSourceSysclk = 0x0,/*!< Master clock from the system clock */
mbed_official 146:f64d43ff0c18 104 kSaiMclkSourceExtal = 0x1,/*!< Master clock from the extal */
mbed_official 146:f64d43ff0c18 105 kSaiMclkSourceAltclk = 0x2,/*!< Master clock from the ALT */
mbed_official 146:f64d43ff0c18 106 kSaiMclkSourcePllout = 0x3/*!< Master clock from the PLL */
mbed_official 146:f64d43ff0c18 107 } sai_mclk_source_t;
mbed_official 146:f64d43ff0c18 108
mbed_official 146:f64d43ff0c18 109 /*! @brief Bit clock source */
mbed_official 146:f64d43ff0c18 110 typedef enum _sai_bclk_source
mbed_official 146:f64d43ff0c18 111 {
mbed_official 146:f64d43ff0c18 112 kSaiBclkSourceBusclk = 0x0,/*!< Bit clock using bus clock */
mbed_official 146:f64d43ff0c18 113 kSaiBclkSourceMclkDiv = 0x1,/*!< Bit clock using master clock divider */
mbed_official 146:f64d43ff0c18 114 kSaiBclkSourceOtherSai0 = 0x2,/*!< Bit clock from other SAI device */
mbed_official 146:f64d43ff0c18 115 kSaiBclkSourceOtherSai1 = 0x3/*!< Bit clock from other SAI device */
mbed_official 146:f64d43ff0c18 116 } sai_bclk_source_t;
mbed_official 146:f64d43ff0c18 117
mbed_official 146:f64d43ff0c18 118 /*! @brief The SAI state flag.*/
mbed_official 146:f64d43ff0c18 119 typedef enum _sai_interrupt_request
mbed_official 146:f64d43ff0c18 120 {
mbed_official 146:f64d43ff0c18 121 kSaiIntrequestWordStart = 0x0,/*!< Word start flag, means the first word in a frame detected */
mbed_official 146:f64d43ff0c18 122 kSaiIntrequestSyncError = 0x1,/*!< Sync error flag, means the sync error is detected */
mbed_official 146:f64d43ff0c18 123 kSaiIntrequestFIFOWarning = 0x2,/*!< FIFO warning flag, means the FIFO is empty */
mbed_official 146:f64d43ff0c18 124 kSaiIntrequestFIFOError = 0x3,/*!< FIFO error flag */
mbed_official 146:f64d43ff0c18 125 kSaiIntrequestFIFORequest = 0x4/*!< FIFO request, means reached watermark */
mbed_official 146:f64d43ff0c18 126 } sai_interrupt_request_t;
mbed_official 146:f64d43ff0c18 127
mbed_official 146:f64d43ff0c18 128
mbed_official 146:f64d43ff0c18 129 /*! @brief The DMA request sources */
mbed_official 146:f64d43ff0c18 130 typedef enum _sai_dma_type
mbed_official 146:f64d43ff0c18 131 {
mbed_official 146:f64d43ff0c18 132 kSaiDmaReqFIFOWarning = 0x0,/*!< FIFO warning caused by the DMA request */
mbed_official 146:f64d43ff0c18 133 kSaiDmaReqFIFORequest = 0x1/*!< FIFO request caused by the DMA request */
mbed_official 146:f64d43ff0c18 134 } sai_dma_request_t;
mbed_official 146:f64d43ff0c18 135
mbed_official 146:f64d43ff0c18 136 /*! @brief The SAI state flag*/
mbed_official 146:f64d43ff0c18 137 typedef enum _sai_state_flag
mbed_official 146:f64d43ff0c18 138 {
mbed_official 146:f64d43ff0c18 139 kSaiStateFlagWordStart = 0x0,/*!< Word start flag, means the first word in a frame detected. */
mbed_official 146:f64d43ff0c18 140 kSaiStateFlagSyncError = 0x1,/*!< Sync error flag, means the sync error is detected */
mbed_official 146:f64d43ff0c18 141 kSaiStateFlagFIFOError = 0x2,/*!< FIFO error flag */
mbed_official 146:f64d43ff0c18 142 kSaiStateFlagSoftReset = 0x3 /*!< Software reset flag */
mbed_official 146:f64d43ff0c18 143 } sai_state_flag_t;
mbed_official 146:f64d43ff0c18 144
mbed_official 146:f64d43ff0c18 145 /*! @brief The reset type */
mbed_official 146:f64d43ff0c18 146 typedef enum _sai_reset
mbed_official 146:f64d43ff0c18 147 {
mbed_official 146:f64d43ff0c18 148 kSaiResetTypeSoftware = 0x0,/*!< Software reset, reset the logic state */
mbed_official 146:f64d43ff0c18 149 kSaiResetTypeFIFO = 0x1/*!< FIFO reset, reset the FIFO read and write pointer */
mbed_official 146:f64d43ff0c18 150 } sai_reset_type_t;
mbed_official 146:f64d43ff0c18 151
mbed_official 146:f64d43ff0c18 152 /*
mbed_official 146:f64d43ff0c18 153 * @brief The SAI running mode
mbed_official 146:f64d43ff0c18 154 * The mode includes normal mode, debug mode, and stop mode.
mbed_official 146:f64d43ff0c18 155 */
mbed_official 146:f64d43ff0c18 156 typedef enum _sai_running_mode
mbed_official 146:f64d43ff0c18 157 {
mbed_official 146:f64d43ff0c18 158 kSaiRunModeDebug = 0x0,/*!< In debug mode */
mbed_official 146:f64d43ff0c18 159 kSaiRunModeStop = 0x1/*!< In stop mode */
mbed_official 146:f64d43ff0c18 160 } sai_mode_t;
mbed_official 146:f64d43ff0c18 161
mbed_official 146:f64d43ff0c18 162 /*******************************************************************************
mbed_official 146:f64d43ff0c18 163 * API
mbed_official 146:f64d43ff0c18 164 ******************************************************************************/
mbed_official 146:f64d43ff0c18 165
mbed_official 146:f64d43ff0c18 166 #if defined(__cplusplus)
mbed_official 146:f64d43ff0c18 167 extern "C" {
mbed_official 146:f64d43ff0c18 168 #endif
mbed_official 146:f64d43ff0c18 169
mbed_official 146:f64d43ff0c18 170 /*!
mbed_official 146:f64d43ff0c18 171 * @brief Initializes the SAI device.
mbed_official 146:f64d43ff0c18 172 *
mbed_official 146:f64d43ff0c18 173 * The initialization resets the SAI module by setting the SR bit of TCSR and the RCSR register.
mbed_official 146:f64d43ff0c18 174 * Note that the function would write 0 to every control registers.
mbed_official 146:f64d43ff0c18 175 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 176 */
mbed_official 146:f64d43ff0c18 177 void sai_hal_init(uint8_t instance);
mbed_official 146:f64d43ff0c18 178
mbed_official 146:f64d43ff0c18 179 /*!
mbed_official 146:f64d43ff0c18 180 * @brief Sets the bus protocol relevant settings for Tx.
mbed_official 146:f64d43ff0c18 181 *
mbed_official 146:f64d43ff0c18 182 * The bus mode means which protocol SAI uses. It can be I2S left, right, and so on. Each protocol
mbed_official 146:f64d43ff0c18 183 * would have different configuration on bit clock and frame sync.
mbed_official 146:f64d43ff0c18 184 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 185 * @param bus_mode The protocol selection, it can be I2S left aligned, I2S right aligned, etc.
mbed_official 146:f64d43ff0c18 186 */
mbed_official 146:f64d43ff0c18 187 void sai_hal_set_tx_bus(uint8_t instance, sai_bus_t bus_mode);
mbed_official 146:f64d43ff0c18 188
mbed_official 146:f64d43ff0c18 189 /*!
mbed_official 146:f64d43ff0c18 190 * @brief Sets the bus protocol relevant settings for Rx.
mbed_official 146:f64d43ff0c18 191 *
mbed_official 146:f64d43ff0c18 192 * The bus mode means which protocol SAI uses. It can be I2S left, right and so on. Each protocol
mbed_official 146:f64d43ff0c18 193 * has a different configuration on bit clock and frame sync.
mbed_official 146:f64d43ff0c18 194 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 195 * @param bus_mode The protocol selection, it can be I2S left aligned, I2S right aligned, etc.
mbed_official 146:f64d43ff0c18 196 */
mbed_official 146:f64d43ff0c18 197 void sai_hal_set_rx_bus(uint8_t instance, sai_bus_t bus_mode);
mbed_official 146:f64d43ff0c18 198
mbed_official 146:f64d43ff0c18 199 /*!
mbed_official 146:f64d43ff0c18 200 * @brief Sets the master clock source.
mbed_official 146:f64d43ff0c18 201 *
mbed_official 146:f64d43ff0c18 202 * The source of the clock can be: PLL_OUT, ALT_CLK, EXTAL, SYS_CLK.
mbed_official 146:f64d43ff0c18 203 * This function sets the clock source for SAI master clock source.
mbed_official 146:f64d43ff0c18 204 * Master clock is used to produce the bit clock for the data transfer.
mbed_official 146:f64d43ff0c18 205 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 206 * @param source Mater clock source
mbed_official 146:f64d43ff0c18 207 */
mbed_official 146:f64d43ff0c18 208 static inline void sai_hal_set_mclk_source(uint8_t instance, sai_mclk_source_t source)
mbed_official 146:f64d43ff0c18 209 {
mbed_official 146:f64d43ff0c18 210 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 211 BW_I2S_MCR_MICS(instance,source);
mbed_official 146:f64d43ff0c18 212 }
mbed_official 146:f64d43ff0c18 213
mbed_official 146:f64d43ff0c18 214 /*!
mbed_official 146:f64d43ff0c18 215 * @brief Sets the divider of the master clock.
mbed_official 146:f64d43ff0c18 216 *
mbed_official 146:f64d43ff0c18 217 * Using the divider to get the master clock frequency wanted from the source.
mbed_official 146:f64d43ff0c18 218 * mclk = clk_source * fract/divide. The input is the master clock frequency needed and the source clock frequency.
mbed_official 146:f64d43ff0c18 219 * The master clock is decided by the sample rate and the multi-clock number.
mbed_official 146:f64d43ff0c18 220 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 221 * @param mclk Master clock frequency needed.
mbed_official 146:f64d43ff0c18 222 * @param src_clk The source clock frequency.
mbed_official 146:f64d43ff0c18 223 */
mbed_official 146:f64d43ff0c18 224 void sai_hal_set_mclk_divider(uint8_t instance, uint32_t mclk, uint32_t src_clk);
mbed_official 146:f64d43ff0c18 225
mbed_official 146:f64d43ff0c18 226 /*!
mbed_official 146:f64d43ff0c18 227 * @brief Sets the bit clock source of Tx. It is generated by the master clock, bus clock, and other devices.
mbed_official 146:f64d43ff0c18 228 *
mbed_official 146:f64d43ff0c18 229 * The function sets the source of the bit clock. The bit clock can be produced by the master
mbed_official 146:f64d43ff0c18 230 * clock, and from the bus clock or other SAI Tx/Rx. Tx and Rx in the SAI module can use the same bit
mbed_official 146:f64d43ff0c18 231 * clock either from Tx or Rx.
mbed_official 146:f64d43ff0c18 232 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 233 * @param source Bit clock source.
mbed_official 146:f64d43ff0c18 234 */
mbed_official 146:f64d43ff0c18 235 static inline void sai_hal_set_tx_bclk_source(uint8_t instance, sai_bclk_source_t source)
mbed_official 146:f64d43ff0c18 236 {
mbed_official 146:f64d43ff0c18 237 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 238 BW_I2S_TCR2_MSEL(instance,source);
mbed_official 146:f64d43ff0c18 239 }
mbed_official 146:f64d43ff0c18 240
mbed_official 146:f64d43ff0c18 241 /*!
mbed_official 146:f64d43ff0c18 242 * @brief Sets the bit clock source of Rx. It is generated by the master clock, bus clock, and other devices.
mbed_official 146:f64d43ff0c18 243 *
mbed_official 146:f64d43ff0c18 244 * The function sets the source of the Rx bit clock. The bit clock can be produced by the master
mbed_official 146:f64d43ff0c18 245 * clock and from the bus clock or other SAI Tx/Rx. Tx and Rx in the SAI module use the same bit
mbed_official 146:f64d43ff0c18 246 * clock either from Tx or Rx.
mbed_official 146:f64d43ff0c18 247 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 248 * @param source Bit clock source.
mbed_official 146:f64d43ff0c18 249 */
mbed_official 146:f64d43ff0c18 250 static inline void sai_hal_set_rx_bclk_source(uint8_t instance, sai_bclk_source_t source)
mbed_official 146:f64d43ff0c18 251 {
mbed_official 146:f64d43ff0c18 252 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 253 BW_I2S_RCR2_MSEL(instance,source);
mbed_official 146:f64d43ff0c18 254 }
mbed_official 146:f64d43ff0c18 255
mbed_official 146:f64d43ff0c18 256 /*!
mbed_official 146:f64d43ff0c18 257 * @brief Sets the bit clock divider value of Tx.
mbed_official 146:f64d43ff0c18 258 *
mbed_official 146:f64d43ff0c18 259 * bclk = mclk / divider. At the same time, bclk = sample_rate * channel * bits. This means
mbed_official 146:f64d43ff0c18 260 * how much time is needed to transfer one bit.
mbed_official 146:f64d43ff0c18 261 * Notice: The function is called while the bit clock source is the master clock.
mbed_official 146:f64d43ff0c18 262 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 263 * @param div The divide number of bit clock.
mbed_official 146:f64d43ff0c18 264 */
mbed_official 146:f64d43ff0c18 265 static inline void sai_hal_set_tx_blck_divider(uint8_t instance, uint32_t divider)
mbed_official 146:f64d43ff0c18 266 {
mbed_official 146:f64d43ff0c18 267 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 268 assert(divider);
mbed_official 146:f64d43ff0c18 269 BW_I2S_TCR2_DIV(instance,divider/2 -1);
mbed_official 146:f64d43ff0c18 270 }
mbed_official 146:f64d43ff0c18 271
mbed_official 146:f64d43ff0c18 272 /*!
mbed_official 146:f64d43ff0c18 273 * @brief Sets the bit clock divider value of Tx.
mbed_official 146:f64d43ff0c18 274 *
mbed_official 146:f64d43ff0c18 275 * bclk = mclk / divider. At the same time, bclk = sample_rate * channel * bits. This means
mbed_official 146:f64d43ff0c18 276 * how much time is needed to transfer one bit.
mbed_official 146:f64d43ff0c18 277 * Notice: The function is called while the bit clock source is the master clock.
mbed_official 146:f64d43ff0c18 278 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 279 * @param div The divide number of bit clock.
mbed_official 146:f64d43ff0c18 280 */
mbed_official 146:f64d43ff0c18 281 static inline void sai_hal_set_rx_blck_divider(uint8_t instance, uint32_t divider)
mbed_official 146:f64d43ff0c18 282 {
mbed_official 146:f64d43ff0c18 283 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 284 assert(divider);
mbed_official 146:f64d43ff0c18 285 BW_I2S_RCR2_DIV(instance,divider/2 -1);
mbed_official 146:f64d43ff0c18 286 }
mbed_official 146:f64d43ff0c18 287
mbed_official 146:f64d43ff0c18 288 /*!
mbed_official 146:f64d43ff0c18 289 * @brief Sets the frame size for Tx.
mbed_official 146:f64d43ff0c18 290 *
mbed_official 146:f64d43ff0c18 291 * The frame size means how many words are in a frame. For example 2-channel
mbed_official 146:f64d43ff0c18 292 * audio data, the frame size is 2. This means there are 2 words in a frame.
mbed_official 146:f64d43ff0c18 293 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 294 * @param size Words number in a frame.
mbed_official 146:f64d43ff0c18 295 */
mbed_official 146:f64d43ff0c18 296 static inline void sai_hal_set_tx_frame_size(uint8_t instance, uint8_t size)
mbed_official 146:f64d43ff0c18 297 {
mbed_official 146:f64d43ff0c18 298 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 299 assert(size <= SAI_WORD_MAX);
mbed_official 146:f64d43ff0c18 300 BW_I2S_TCR4_FRSZ(instance,size-1);
mbed_official 146:f64d43ff0c18 301 }
mbed_official 146:f64d43ff0c18 302
mbed_official 146:f64d43ff0c18 303 /*!
mbed_official 146:f64d43ff0c18 304 * @brief Set the frame size for rx.
mbed_official 146:f64d43ff0c18 305 *
mbed_official 146:f64d43ff0c18 306 * The frame size means how many words in a frame. In the usual case, for example 2-channel
mbed_official 146:f64d43ff0c18 307 * audio data, the frame size is 2, means 2 words in a frame.
mbed_official 146:f64d43ff0c18 308 * @param instance The sai peripheral instance number.
mbed_official 146:f64d43ff0c18 309 * @param size Words number in a frame.
mbed_official 146:f64d43ff0c18 310 */
mbed_official 146:f64d43ff0c18 311 static inline void sai_hal_set_rx_frame_size(uint8_t instance, uint8_t size)
mbed_official 146:f64d43ff0c18 312 {
mbed_official 146:f64d43ff0c18 313 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 314 assert(size <= SAI_WORD_MAX);
mbed_official 146:f64d43ff0c18 315 BW_I2S_RCR4_FRSZ(instance,size-1);
mbed_official 146:f64d43ff0c18 316 }
mbed_official 146:f64d43ff0c18 317
mbed_official 146:f64d43ff0c18 318 /*!
mbed_official 146:f64d43ff0c18 319 * @brief Set the word size for tx.
mbed_official 146:f64d43ff0c18 320 *
mbed_official 146:f64d43ff0c18 321 * The word size means the quantization level of audio file.
mbed_official 146:f64d43ff0c18 322 * Generally, there are 8bit, 16bit, 24bit, 32bit format which sai would all support.
mbed_official 146:f64d43ff0c18 323 * @param instance The sai peripheral instance number.
mbed_official 146:f64d43ff0c18 324 * @param bits How many bits in a word.
mbed_official 146:f64d43ff0c18 325 */
mbed_official 146:f64d43ff0c18 326 static inline void sai_hal_set_tx_word_size(uint8_t instance, uint8_t bits)
mbed_official 146:f64d43ff0c18 327 {
mbed_official 146:f64d43ff0c18 328 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 329 assert((bits >= SAI_BIT_MIN) && (bits <= SAI_BIT_MAX));
mbed_official 146:f64d43ff0c18 330 BW_I2S_TCR5_WNW(instance,bits-1);
mbed_official 146:f64d43ff0c18 331 }
mbed_official 146:f64d43ff0c18 332
mbed_official 146:f64d43ff0c18 333 /*!
mbed_official 146:f64d43ff0c18 334 * @brief Sets the word size for Rx.
mbed_official 146:f64d43ff0c18 335 *
mbed_official 146:f64d43ff0c18 336 * The word size means the quantization level of the audio file.
mbed_official 146:f64d43ff0c18 337 * Generally, SAI supports 8 bit, 16 bit, 24 bit, and 32 bit formats.
mbed_official 146:f64d43ff0c18 338 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 339 * @param bits How many bits in a word.
mbed_official 146:f64d43ff0c18 340 */
mbed_official 146:f64d43ff0c18 341 static inline void sai_hal_set_rx_word_size(uint8_t instance, uint8_t bits)
mbed_official 146:f64d43ff0c18 342 {
mbed_official 146:f64d43ff0c18 343 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 344 assert((bits >= SAI_BIT_MIN) && (bits <= SAI_BIT_MAX));
mbed_official 146:f64d43ff0c18 345 BW_I2S_RCR5_WNW(instance,bits-1);
mbed_official 146:f64d43ff0c18 346 }
mbed_official 146:f64d43ff0c18 347
mbed_official 146:f64d43ff0c18 348 /*!
mbed_official 146:f64d43ff0c18 349 * @brief Sets the size of the first word of the frame for Tx.
mbed_official 146:f64d43ff0c18 350 *
mbed_official 146:f64d43ff0c18 351 * In I2S protocol, the size of the first word is the same as the size of other words. In some protocols,
mbed_official 146:f64d43ff0c18 352 * for example, AC'97, the size of the first word is not the same as other sizes. This function
mbed_official 146:f64d43ff0c18 353 * sets the length of the first word which is, in most situations, the same as others.
mbed_official 146:f64d43ff0c18 354 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 355 * @param size The length of frame head word.
mbed_official 146:f64d43ff0c18 356 */
mbed_official 146:f64d43ff0c18 357 static inline void sai_hal_set_tx_word_zero_size(uint8_t instance, uint8_t size)
mbed_official 146:f64d43ff0c18 358 {
mbed_official 146:f64d43ff0c18 359 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 360 assert((size >= SAI_BIT_MIN) && (size <= SAI_BIT_MAX));
mbed_official 146:f64d43ff0c18 361 BW_I2S_TCR5_W0W(instance,size-1);
mbed_official 146:f64d43ff0c18 362 }
mbed_official 146:f64d43ff0c18 363
mbed_official 146:f64d43ff0c18 364 /*!
mbed_official 146:f64d43ff0c18 365 * @brief Sets the size of the first word of the frame for Rx.
mbed_official 146:f64d43ff0c18 366 *
mbed_official 146:f64d43ff0c18 367 * In I2S protocol, the size of the first word is the same as the size of other words. In some protocols,
mbed_official 146:f64d43ff0c18 368 * for example, AC'97, the first word is not the same size as others. This function
mbed_official 146:f64d43ff0c18 369 * sets the length of the first word, which is, in most situations, the same as others.
mbed_official 146:f64d43ff0c18 370 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 371 * @param size The length of frame head word.
mbed_official 146:f64d43ff0c18 372 */
mbed_official 146:f64d43ff0c18 373 static inline void sai_hal_set_rx_word_zero_size(uint8_t instance, uint8_t size)
mbed_official 146:f64d43ff0c18 374 {
mbed_official 146:f64d43ff0c18 375 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 376 assert((size >= SAI_BIT_MIN) && (size <= SAI_BIT_MAX));
mbed_official 146:f64d43ff0c18 377 BW_I2S_RCR5_W0W(instance,size-1);
mbed_official 146:f64d43ff0c18 378 }
mbed_official 146:f64d43ff0c18 379
mbed_official 146:f64d43ff0c18 380 /*!
mbed_official 146:f64d43ff0c18 381 * @brief Sets the sync width for Tx.
mbed_official 146:f64d43ff0c18 382 *
mbed_official 146:f64d43ff0c18 383 * A sync is the number of bit clocks of a frame. The sync width cannot be longer than the
mbed_official 146:f64d43ff0c18 384 * length of the first word of the frame.
mbed_official 146:f64d43ff0c18 385 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 386 * @param width How many bit clock in a sync.
mbed_official 146:f64d43ff0c18 387 */
mbed_official 146:f64d43ff0c18 388 static inline void sai_hal_set_tx_sync_width(uint8_t instance, uint8_t width)
mbed_official 146:f64d43ff0c18 389 {
mbed_official 146:f64d43ff0c18 390 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 391 assert(width <= SAI_BIT_MAX);
mbed_official 146:f64d43ff0c18 392 BW_I2S_TCR4_SYWD(instance,width-1);
mbed_official 146:f64d43ff0c18 393 }
mbed_official 146:f64d43ff0c18 394
mbed_official 146:f64d43ff0c18 395 /*!
mbed_official 146:f64d43ff0c18 396 * @brief Sets the sync width for Rx.
mbed_official 146:f64d43ff0c18 397 *
mbed_official 146:f64d43ff0c18 398 * A sync is the number of bit clocks of a frame. The sync width cannot be longer than the
mbed_official 146:f64d43ff0c18 399 * length of the first word of the frame.
mbed_official 146:f64d43ff0c18 400 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 401 * @param width How many bit clock in a sync.
mbed_official 146:f64d43ff0c18 402 */
mbed_official 146:f64d43ff0c18 403 static inline void sai_hal_set_rx_sync_width(uint8_t instance, uint8_t width)
mbed_official 146:f64d43ff0c18 404 {
mbed_official 146:f64d43ff0c18 405 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 406 assert(width <= SAI_BIT_MAX);
mbed_official 146:f64d43ff0c18 407 BW_I2S_RCR4_SYWD(instance,width-1);
mbed_official 146:f64d43ff0c18 408 }
mbed_official 146:f64d43ff0c18 409
mbed_official 146:f64d43ff0c18 410 /*!
mbed_official 146:f64d43ff0c18 411 * @brief Sets the watermark value for Tx FIFO.
mbed_official 146:f64d43ff0c18 412 *
mbed_official 146:f64d43ff0c18 413 * While the value in the Tx FIFO is less or equal to the watermark , it generates an interrupt
mbed_official 146:f64d43ff0c18 414 * request or a DMA request. The watermark value cannot be greater than the depth of FIFO.
mbed_official 146:f64d43ff0c18 415 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 416 * @param watermark Watermark value of a FIFO.
mbed_official 146:f64d43ff0c18 417 */
mbed_official 146:f64d43ff0c18 418 static inline void sai_hal_set_tx_watermark(uint8_t instance, uint8_t watermark)
mbed_official 146:f64d43ff0c18 419 {
mbed_official 146:f64d43ff0c18 420 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 421 assert(watermark < SAI_WATERMARK_MAX);
mbed_official 146:f64d43ff0c18 422 BW_I2S_TCR1_TFW(instance,watermark);
mbed_official 146:f64d43ff0c18 423 }
mbed_official 146:f64d43ff0c18 424
mbed_official 146:f64d43ff0c18 425 /*!
mbed_official 146:f64d43ff0c18 426 * @brief Sets the watermark value for Rx FIFO.
mbed_official 146:f64d43ff0c18 427 *
mbed_official 146:f64d43ff0c18 428 * While the value in Rx FIFO is larger or equal to the watermark , it generates an interrupt
mbed_official 146:f64d43ff0c18 429 * request or a DMA request. The watermark value cannot be greater than the depth of FIFO.
mbed_official 146:f64d43ff0c18 430 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 431 * @param watermark Watermark value of a FIFO.
mbed_official 146:f64d43ff0c18 432 */
mbed_official 146:f64d43ff0c18 433 static inline void sai_hal_set_rx_watermark(uint8_t instance, uint8_t watermark)
mbed_official 146:f64d43ff0c18 434 {
mbed_official 146:f64d43ff0c18 435 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 436 assert(watermark < SAI_WATERMARK_MAX);
mbed_official 146:f64d43ff0c18 437 BW_I2S_RCR1_RFW(instance,watermark);
mbed_official 146:f64d43ff0c18 438 }
mbed_official 146:f64d43ff0c18 439
mbed_official 146:f64d43ff0c18 440 /*!
mbed_official 146:f64d43ff0c18 441 * @brief Sets the master or slave mode of Tx.
mbed_official 146:f64d43ff0c18 442 *
mbed_official 146:f64d43ff0c18 443 * The function sets the Tx mode to either master or slave. The master mode provides its
mbed_official 146:f64d43ff0c18 444 * own clock and slave mode uses the external clock.
mbed_official 146:f64d43ff0c18 445 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 446 * @param master_slave_mode Mater or slave mode.
mbed_official 146:f64d43ff0c18 447 */
mbed_official 146:f64d43ff0c18 448 void sai_hal_set_tx_master_slave(uint8_t instance, sai_master_slave_t master_slave_mode);
mbed_official 146:f64d43ff0c18 449
mbed_official 146:f64d43ff0c18 450 /*!
mbed_official 146:f64d43ff0c18 451 * @brief Sets the Rx master or slave mode.
mbed_official 146:f64d43ff0c18 452 *
mbed_official 146:f64d43ff0c18 453 * The function sets the Rx mode to either master or slave. Master mode provides its
mbed_official 146:f64d43ff0c18 454 * own clock and slave mode uses the external clock.
mbed_official 146:f64d43ff0c18 455 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 456 * @param master_slave_mode Mater or slave mode.
mbed_official 146:f64d43ff0c18 457 */
mbed_official 146:f64d43ff0c18 458 void sai_hal_set_rx_master_slave(uint8_t instance, sai_master_slave_t master_slave_mode);
mbed_official 146:f64d43ff0c18 459
mbed_official 146:f64d43ff0c18 460 /*!
mbed_official 146:f64d43ff0c18 461 * @brief Transmits the mode setting.
mbed_official 146:f64d43ff0c18 462 *
mbed_official 146:f64d43ff0c18 463 * The mode can be asynchronous mode, synchronous, or synchronous with another SAI device.
mbed_official 146:f64d43ff0c18 464 * When configured for a synchronous mode of operation, the receiver must be configured for the asynchronous operation.
mbed_official 146:f64d43ff0c18 465 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 466 * @param sync_mode Synchronous mode or Asynchronous mode.
mbed_official 146:f64d43ff0c18 467 */
mbed_official 146:f64d43ff0c18 468 void sai_hal_set_tx_sync_mode(uint8_t instance, sai_sync_mode_t sync_mode);
mbed_official 146:f64d43ff0c18 469
mbed_official 146:f64d43ff0c18 470 /*!
mbed_official 146:f64d43ff0c18 471 * @brief Receives the mode setting.
mbed_official 146:f64d43ff0c18 472 *
mbed_official 146:f64d43ff0c18 473 * The mode can be asynchronous mode, synchronous, synchronous with another SAI device.
mbed_official 146:f64d43ff0c18 474 * When configured for a synchronous mode of operation, the receiver must be configured for the asynchronous operation.
mbed_official 146:f64d43ff0c18 475 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 476 * @param sync_mode Synchronous mode or Asynchronous mode.
mbed_official 146:f64d43ff0c18 477 */
mbed_official 146:f64d43ff0c18 478 void sai_hal_set_rx_sync_mode(uint8_t instance, sai_sync_mode_t sync_mode);
mbed_official 146:f64d43ff0c18 479
mbed_official 146:f64d43ff0c18 480 /*!
mbed_official 146:f64d43ff0c18 481 * @brief Gets the FIFO read pointer.
mbed_official 146:f64d43ff0c18 482 *
mbed_official 146:f64d43ff0c18 483 * It is used to judge whether the FIFO is full or empty and know how much space there is for FIFO.
mbed_official 146:f64d43ff0c18 484 * If read_ptr == write_ptr, the FIFO is empty. While the bit of the read_ptr and the write_ptr are
mbed_official 146:f64d43ff0c18 485 * equal except for the MSB, the FIFO is full.
mbed_official 146:f64d43ff0c18 486 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 487 * @param io_mode Transmit or receive data.
mbed_official 146:f64d43ff0c18 488 * @param fifo_channel FIFO channel selected.
mbed_official 146:f64d43ff0c18 489 * @return FIFO read pointer value.
mbed_official 146:f64d43ff0c18 490 */
mbed_official 146:f64d43ff0c18 491 uint8_t sai_hal_get_fifo_read_pointer(uint8_t instance, sai_io_mode_t io_mode, uint8_t fifo_channel);
mbed_official 146:f64d43ff0c18 492
mbed_official 146:f64d43ff0c18 493 /*!
mbed_official 146:f64d43ff0c18 494 * @brief Gets the FIFO read pointer.
mbed_official 146:f64d43ff0c18 495 *
mbed_official 146:f64d43ff0c18 496 * It is used to judge whether the FIFO is full or empty and know how much space there is for FIFO.
mbed_official 146:f64d43ff0c18 497 * If the read_ptr == write_ptr, the FIFO is empty. While the bit of the read_ptr and write_ptr are
mbed_official 146:f64d43ff0c18 498 * equal except for the MSB, the FIFO is full.
mbed_official 146:f64d43ff0c18 499 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 500 * @param io_mode Transmit or receive data.
mbed_official 146:f64d43ff0c18 501 * @param fifo_channel FIFO channel selected.
mbed_official 146:f64d43ff0c18 502 * @return FIFO write pointer value
mbed_official 146:f64d43ff0c18 503 */
mbed_official 146:f64d43ff0c18 504 uint8_t sai_hal_get_fifo_write_pointer(uint8_t instance, sai_io_mode_t io_mode,uint8_t fifo_channel);
mbed_official 146:f64d43ff0c18 505
mbed_official 146:f64d43ff0c18 506 /*!
mbed_official 146:f64d43ff0c18 507 * @brief Gets the TDR/RDR register address.
mbed_official 146:f64d43ff0c18 508 *
mbed_official 146:f64d43ff0c18 509 * This function is for DMA transfer because it needs to know the dest/src address of the DMA transfer.
mbed_official 146:f64d43ff0c18 510 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 511 * @param io_mode Transmit or receive data.
mbed_official 146:f64d43ff0c18 512 * @param fifo_channel FIFO channel selected.
mbed_official 146:f64d43ff0c18 513 * @return TDR register or RDR register address
mbed_official 146:f64d43ff0c18 514 */
mbed_official 146:f64d43ff0c18 515 uint32_t* sai_hal_get_fifo_address(uint8_t instance, sai_io_mode_t io_mode, uint8_t fifo_channel);
mbed_official 146:f64d43ff0c18 516
mbed_official 146:f64d43ff0c18 517 /*!
mbed_official 146:f64d43ff0c18 518 * @brief Enables the Tx transmit.
mbed_official 146:f64d43ff0c18 519 *
mbed_official 146:f64d43ff0c18 520 * Enables the transmitter. This function enables both the bit clock and the transfer channel.
mbed_official 146:f64d43ff0c18 521 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 522 */
mbed_official 146:f64d43ff0c18 523 static inline void sai_hal_enable_tx(uint8_t instance)
mbed_official 146:f64d43ff0c18 524 {
mbed_official 146:f64d43ff0c18 525 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 526 BW_I2S_TCSR_BCE(instance,1);
mbed_official 146:f64d43ff0c18 527 BW_I2S_TCSR_TE(instance,1);
mbed_official 146:f64d43ff0c18 528 }
mbed_official 146:f64d43ff0c18 529
mbed_official 146:f64d43ff0c18 530 /*!
mbed_official 146:f64d43ff0c18 531 * @brief Enables the Rx receive.
mbed_official 146:f64d43ff0c18 532 *
mbed_official 146:f64d43ff0c18 533 * Enables the receiver. This function enables both the bit clock and the receive channel.
mbed_official 146:f64d43ff0c18 534 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 535 */
mbed_official 146:f64d43ff0c18 536 static inline void sai_hal_enable_rx(uint8_t instance)
mbed_official 146:f64d43ff0c18 537 {
mbed_official 146:f64d43ff0c18 538 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 539 BW_I2S_RCSR_BCE(instance,1);
mbed_official 146:f64d43ff0c18 540 BW_I2S_RCSR_RE(instance,1);
mbed_official 146:f64d43ff0c18 541 }
mbed_official 146:f64d43ff0c18 542
mbed_official 146:f64d43ff0c18 543 /*!
mbed_official 146:f64d43ff0c18 544 * @brief Disables the Tx transmit.
mbed_official 146:f64d43ff0c18 545 *
mbed_official 146:f64d43ff0c18 546 * Disables the transmitter. This function disables both the bit clock and the transfer channel.
mbed_official 146:f64d43ff0c18 547 * When software clears this field, the transmitter remains enabled, and this bit remains set, until
mbed_official 146:f64d43ff0c18 548 * the end of the current frame.
mbed_official 146:f64d43ff0c18 549 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 550 */
mbed_official 146:f64d43ff0c18 551 static inline void sai_hal_disable_tx(uint8_t instance)
mbed_official 146:f64d43ff0c18 552 {
mbed_official 146:f64d43ff0c18 553 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 554 BW_I2S_TCSR_TE(instance,0);
mbed_official 146:f64d43ff0c18 555 BW_I2S_TCSR_BCE(instance,0);
mbed_official 146:f64d43ff0c18 556 }
mbed_official 146:f64d43ff0c18 557
mbed_official 146:f64d43ff0c18 558 /*!
mbed_official 146:f64d43ff0c18 559 * @brief Disables the Rx receive.
mbed_official 146:f64d43ff0c18 560 *
mbed_official 146:f64d43ff0c18 561 * Disables the receiver. This function disables both the bit clock and the transfer channel.
mbed_official 146:f64d43ff0c18 562 * When software clears this field, the receiver remains enabled, and this bit remains set, until
mbed_official 146:f64d43ff0c18 563 * the end of the current frame.
mbed_official 146:f64d43ff0c18 564 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 565 */
mbed_official 146:f64d43ff0c18 566 static inline void sai_hal_disable_rx(uint8_t instance)
mbed_official 146:f64d43ff0c18 567 {
mbed_official 146:f64d43ff0c18 568 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 569 BW_I2S_RCSR_RE(instance,0);
mbed_official 146:f64d43ff0c18 570 BW_I2S_RCSR_BCE(instance,0);
mbed_official 146:f64d43ff0c18 571 }
mbed_official 146:f64d43ff0c18 572
mbed_official 146:f64d43ff0c18 573 /*!
mbed_official 146:f64d43ff0c18 574 * @brief Enables the Tx interrupt from different interrupt sources.
mbed_official 146:f64d43ff0c18 575 *
mbed_official 146:f64d43ff0c18 576 * The interrupt source can be : Word start flag, Sync error flag, FIFO error flag, FIFO warning flag, FIFO request flag.
mbed_official 146:f64d43ff0c18 577 * This function sets which flag causes an interrupt request.
mbed_official 146:f64d43ff0c18 578 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 579 * @param source SAI interrupt request source.
mbed_official 146:f64d43ff0c18 580 */
mbed_official 146:f64d43ff0c18 581 void sai_hal_enable_tx_interrupt(uint8_t instance, sai_interrupt_request_t source);
mbed_official 146:f64d43ff0c18 582
mbed_official 146:f64d43ff0c18 583 /*!
mbed_official 146:f64d43ff0c18 584 * @brief Enables the Rx interrupt from different sources.
mbed_official 146:f64d43ff0c18 585 *
mbed_official 146:f64d43ff0c18 586 * The interrupt source can be : Word start flag, Sync error flag, FIFO error flag, FIFO warning flag, FIFO request flag.
mbed_official 146:f64d43ff0c18 587 * This function sets which flag causes an interrupt request.
mbed_official 146:f64d43ff0c18 588 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 589 * @param source SAI interrupt request source.
mbed_official 146:f64d43ff0c18 590 */
mbed_official 146:f64d43ff0c18 591 void sai_hal_enable_rx_interrupt(uint8_t instance, sai_interrupt_request_t source);
mbed_official 146:f64d43ff0c18 592
mbed_official 146:f64d43ff0c18 593 /*!
mbed_official 146:f64d43ff0c18 594 * @brief Disables the Tx interrupts from different interrupt sources.
mbed_official 146:f64d43ff0c18 595 *
mbed_official 146:f64d43ff0c18 596 * This function disables the interrupt requests from the interrupt request source of SAI.
mbed_official 146:f64d43ff0c18 597 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 598 * @param source SAI interrupt request source.
mbed_official 146:f64d43ff0c18 599 */
mbed_official 146:f64d43ff0c18 600 void sai_hal_disable_tx_interrupt(uint8_t instance, sai_interrupt_request_t source);
mbed_official 146:f64d43ff0c18 601
mbed_official 146:f64d43ff0c18 602 /*!
mbed_official 146:f64d43ff0c18 603 * @brief Disables Rx interrupts from different interrupt sources.
mbed_official 146:f64d43ff0c18 604 *
mbed_official 146:f64d43ff0c18 605 * This function disables the interrupt requests from interrupt request source of SAI.
mbed_official 146:f64d43ff0c18 606 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 607 * @param source SAI interrupt request source.
mbed_official 146:f64d43ff0c18 608 */
mbed_official 146:f64d43ff0c18 609 void sai_hal_disable_rx_interrupt(uint8_t instance, sai_interrupt_request_t source);
mbed_official 146:f64d43ff0c18 610
mbed_official 146:f64d43ff0c18 611 /*!
mbed_official 146:f64d43ff0c18 612 * @brief Enables the Tx DMA request from different sources.
mbed_official 146:f64d43ff0c18 613 *
mbed_official 146:f64d43ff0c18 614 * The DMA sources can be FIFO warning and FIFO request.
mbed_official 146:f64d43ff0c18 615 * This function enables the DMA request from different DMA request sources.
mbed_official 146:f64d43ff0c18 616 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 617 * @param source SAI DMA request source.
mbed_official 146:f64d43ff0c18 618 */
mbed_official 146:f64d43ff0c18 619 void sai_hal_enable_tx_dma(uint8_t instance, sai_dma_request_t request);
mbed_official 146:f64d43ff0c18 620
mbed_official 146:f64d43ff0c18 621 /*!
mbed_official 146:f64d43ff0c18 622 * @brief Enables the Rx DMA request from different sources.
mbed_official 146:f64d43ff0c18 623 *
mbed_official 146:f64d43ff0c18 624 * The DMA sources can be: FIFO warning and FIFO request.
mbed_official 146:f64d43ff0c18 625 * This function enables the DMA request from different DMA request sources.
mbed_official 146:f64d43ff0c18 626 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 627 * @param source SAI DMA request source.
mbed_official 146:f64d43ff0c18 628 */
mbed_official 146:f64d43ff0c18 629 void sai_hal_enable_rx_dma(uint8_t instance, sai_dma_request_t request);
mbed_official 146:f64d43ff0c18 630
mbed_official 146:f64d43ff0c18 631 /*!
mbed_official 146:f64d43ff0c18 632 * @brief Disables the Tx DMA request from different sources.
mbed_official 146:f64d43ff0c18 633 *
mbed_official 146:f64d43ff0c18 634 * The function disables the DMA request of Tx in SAI. DMA request can from FIFO warning or FIFO
mbed_official 146:f64d43ff0c18 635 * request which means FIFO is empty or reach the watermark.
mbed_official 146:f64d43ff0c18 636 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 637 * @param source SAI DMA request source.
mbed_official 146:f64d43ff0c18 638 */
mbed_official 146:f64d43ff0c18 639 void sai_hal_disable_tx_dma(uint8_t instance, sai_dma_request_t request);
mbed_official 146:f64d43ff0c18 640
mbed_official 146:f64d43ff0c18 641 /*!
mbed_official 146:f64d43ff0c18 642 * @brief Disables the Rx DMA request from different sources.
mbed_official 146:f64d43ff0c18 643 *
mbed_official 146:f64d43ff0c18 644 * The function disables the DMA request of Tx in SAI. DMA request can from FIFO warning or FIFO
mbed_official 146:f64d43ff0c18 645 * request which means FIFO is empty or reach the watermark.
mbed_official 146:f64d43ff0c18 646 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 647 * @param source SAI DMA request source.
mbed_official 146:f64d43ff0c18 648 */
mbed_official 146:f64d43ff0c18 649 void sai_hal_disable_rx_dma(uint8_t instance, sai_dma_request_t request);
mbed_official 146:f64d43ff0c18 650
mbed_official 146:f64d43ff0c18 651 /*!
mbed_official 146:f64d43ff0c18 652 * @brief Clears the Tx state flags.
mbed_official 146:f64d43ff0c18 653 *
mbed_official 146:f64d43ff0c18 654 * The function is used to clear the flags manually. It can clear word start, FIFO warning, FIFO error, and
mbed_official 146:f64d43ff0c18 655 * FIFO request flag.
mbed_official 146:f64d43ff0c18 656 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 657 * @param flag SAI state flag type. The flag can be word start, sync error, FIFO error/warning.
mbed_official 146:f64d43ff0c18 658 */
mbed_official 146:f64d43ff0c18 659 void sai_hal_clear_tx_state_flag(uint8_t instance, sai_state_flag_t flag);
mbed_official 146:f64d43ff0c18 660
mbed_official 146:f64d43ff0c18 661 /*!
mbed_official 146:f64d43ff0c18 662 * @brief Clears the state flags for Rx.
mbed_official 146:f64d43ff0c18 663 *
mbed_official 146:f64d43ff0c18 664 * The function clears the flags manually. It can clear word start, FIFO warning, FIFO error, and
mbed_official 146:f64d43ff0c18 665 * FIFO request flag.
mbed_official 146:f64d43ff0c18 666 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 667 * @param flag SAI state flag type. The flag can be word start, sync error, FIFO error/warning.
mbed_official 146:f64d43ff0c18 668 */
mbed_official 146:f64d43ff0c18 669 void sai_hal_clear_rx_state_flag(uint8_t instance, sai_state_flag_t flag);
mbed_official 146:f64d43ff0c18 670
mbed_official 146:f64d43ff0c18 671 /*!
mbed_official 146:f64d43ff0c18 672 * @brief Resets the Tx.
mbed_official 146:f64d43ff0c18 673 *
mbed_official 146:f64d43ff0c18 674 * There are two kinds of reset: Software reset and FIFO reset.
mbed_official 146:f64d43ff0c18 675 * Software reset: resets all transmitter internal logic, including the bit clock generation, status flags and FIFO pointers. It does not reset the
mbed_official 146:f64d43ff0c18 676 * configuration registers.
mbed_official 146:f64d43ff0c18 677 * 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
mbed_official 146:f64d43ff0c18 678 * after the Transmit FIFO Error Flag is set, and before the FIFO is re-initialized and the Error Flag is cleared.
mbed_official 146:f64d43ff0c18 679 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 680 * @param mode SAI reset type.
mbed_official 146:f64d43ff0c18 681 */
mbed_official 146:f64d43ff0c18 682 void sai_hal_reset_tx(uint8_t instance, sai_reset_type_t mode);
mbed_official 146:f64d43ff0c18 683
mbed_official 146:f64d43ff0c18 684 /*!
mbed_official 146:f64d43ff0c18 685 * @brief Resets the Rx.
mbed_official 146:f64d43ff0c18 686 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 687 * @param mode SAI reset type.
mbed_official 146:f64d43ff0c18 688 */
mbed_official 146:f64d43ff0c18 689 void sai_hal_reset_rx(uint8_t instance, sai_reset_type_t mode);
mbed_official 146:f64d43ff0c18 690
mbed_official 146:f64d43ff0c18 691 /*!
mbed_official 146:f64d43ff0c18 692 * @brief Sets the mask word of the frame in Tx.
mbed_official 146:f64d43ff0c18 693 *
mbed_official 146:f64d43ff0c18 694 * Each bit number represent the mask word index. For example, 0 represents mask the 0th word, 3 represents mask 0th and 1st word.
mbed_official 146:f64d43ff0c18 695 * The TMR register can be different from frame to frame. If the user wants a mono audio, set the mask to 0/1.
mbed_official 146:f64d43ff0c18 696 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 697 * @param mask Which bits need to be masked in a frame.
mbed_official 146:f64d43ff0c18 698 */
mbed_official 146:f64d43ff0c18 699 static inline void sai_hal_set_tx_word_mask(uint8_t instance, uint32_t mask)
mbed_official 146:f64d43ff0c18 700 {
mbed_official 146:f64d43ff0c18 701 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 702 HW_I2S_TMR_WR(instance,mask);
mbed_official 146:f64d43ff0c18 703 }
mbed_official 146:f64d43ff0c18 704
mbed_official 146:f64d43ff0c18 705 /*!
mbed_official 146:f64d43ff0c18 706 * @brief Sets the mask word of the frame in Rx.
mbed_official 146:f64d43ff0c18 707 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 708 * @param mask Which bits need to be masked in a frame.
mbed_official 146:f64d43ff0c18 709 */
mbed_official 146:f64d43ff0c18 710 static inline void sai_hal_set_rx_word_mask(uint8_t instance, uint32_t mask)
mbed_official 146:f64d43ff0c18 711 {
mbed_official 146:f64d43ff0c18 712 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 713 HW_I2S_RMR_WR(instance,mask);
mbed_official 146:f64d43ff0c18 714 }
mbed_official 146:f64d43ff0c18 715
mbed_official 146:f64d43ff0c18 716 /*!
mbed_official 146:f64d43ff0c18 717 * @brief Sets the FIFO Tx channel.
mbed_official 146:f64d43ff0c18 718 *
mbed_official 146:f64d43ff0c18 719 * A SAI instance includes a Tx and a Rx. Each has several channels according to
mbed_official 146:f64d43ff0c18 720 * different platforms. A channel means a path for the audio data input/output.
mbed_official 146:f64d43ff0c18 721 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 722 * @param fifo_channel FIFO channel number.
mbed_official 146:f64d43ff0c18 723 */
mbed_official 146:f64d43ff0c18 724 static inline void sai_hal_set_tx_fifo_channel(uint8_t instance, uint8_t fifo_channel)
mbed_official 146:f64d43ff0c18 725 {
mbed_official 146:f64d43ff0c18 726 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 727 BW_I2S_TCR3_TCE(instance,fifo_channel + 1);
mbed_official 146:f64d43ff0c18 728 }
mbed_official 146:f64d43ff0c18 729
mbed_official 146:f64d43ff0c18 730 /*!
mbed_official 146:f64d43ff0c18 731 * @brief Sets the Rx FIFO channel.
mbed_official 146:f64d43ff0c18 732 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 733 * @param fifo_channel FIFO channel number.
mbed_official 146:f64d43ff0c18 734 */
mbed_official 146:f64d43ff0c18 735 static inline void sai_hal_set_rx_fifo_channel(uint8_t instance, uint8_t fifo_channel)
mbed_official 146:f64d43ff0c18 736 {
mbed_official 146:f64d43ff0c18 737 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 738 BW_I2S_RCR3_RCE(instance,fifo_channel + 1);
mbed_official 146:f64d43ff0c18 739 }
mbed_official 146:f64d43ff0c18 740
mbed_official 146:f64d43ff0c18 741 /*!
mbed_official 146:f64d43ff0c18 742 * @brief Sets the running mode. There is a debug mode, stop mode and a normal mode.
mbed_official 146:f64d43ff0c18 743 *
mbed_official 146:f64d43ff0c18 744 * This function can set the working mode of the SAI instance. Stop mode is always
mbed_official 146:f64d43ff0c18 745 * used in low power cases, and the debug mode disables the SAI after the current
mbed_official 146:f64d43ff0c18 746 * transmit/receive is completed.
mbed_official 146:f64d43ff0c18 747 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 748 * @param mode SAI running mode.
mbed_official 146:f64d43ff0c18 749 */
mbed_official 146:f64d43ff0c18 750 void sai_hal_set_tx_mode(uint8_t instance, sai_mode_t mode);
mbed_official 146:f64d43ff0c18 751
mbed_official 146:f64d43ff0c18 752 /*!
mbed_official 146:f64d43ff0c18 753 * @brief Sets the Rx running mode.
mbed_official 146:f64d43ff0c18 754 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 755 * @param mode SAI running mode.
mbed_official 146:f64d43ff0c18 756 */
mbed_official 146:f64d43ff0c18 757 void sai_hal_set_rx_mode(uint8_t instance, sai_mode_t mode);
mbed_official 146:f64d43ff0c18 758
mbed_official 146:f64d43ff0c18 759 /*!
mbed_official 146:f64d43ff0c18 760 * @brief Set Tx bit clock swap.
mbed_official 146:f64d43ff0c18 761 *
mbed_official 146:f64d43ff0c18 762 * While set in asynchronous mode, the transmitter is clocked by the receiver bit clock. When set in
mbed_official 146:f64d43ff0c18 763 * synchronous mode, the transmitter is clocked by the transmitter bit clock, but uses the receiver frame
mbed_official 146:f64d43ff0c18 764 * sync. This bit has no effect when synchronous with another SAI peripheral.
mbed_official 146:f64d43ff0c18 765 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 766 * @param ifswap If swap bit clock.
mbed_official 146:f64d43ff0c18 767 */
mbed_official 146:f64d43ff0c18 768 void sai_hal_set_tx_bclk_swap(uint8_t instance, bool ifswap);
mbed_official 146:f64d43ff0c18 769
mbed_official 146:f64d43ff0c18 770 /*!
mbed_official 146:f64d43ff0c18 771 * @brief Sets the Rx bit clock swap.
mbed_official 146:f64d43ff0c18 772 *
mbed_official 146:f64d43ff0c18 773 * When set in asynchronous mode, the receiver is clocked by the transmitter bit clock. When set in
mbed_official 146:f64d43ff0c18 774 * synchronous mode, the receiver is clocked by the receiver bit clock, but uses the transmitter frame sync.
mbed_official 146:f64d43ff0c18 775 * This bit has no effect when synchronous with another SAI peripheral.
mbed_official 146:f64d43ff0c18 776 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 777 * @param ifswap If swap bit clock.
mbed_official 146:f64d43ff0c18 778 */
mbed_official 146:f64d43ff0c18 779 void sai_hal_set_rx_bclk_swap(uint8_t instance, bool ifswap);
mbed_official 146:f64d43ff0c18 780
mbed_official 146:f64d43ff0c18 781 /*!
mbed_official 146:f64d43ff0c18 782 * @brief Configures on which word the start of the word flag is set.
mbed_official 146:f64d43ff0c18 783 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 784 * @param index Which word triggers the word start flag.
mbed_official 146:f64d43ff0c18 785 */
mbed_official 146:f64d43ff0c18 786 static inline void sai_hal_set_tx_word_start_index(uint8_t instance, uint8_t index)
mbed_official 146:f64d43ff0c18 787 {
mbed_official 146:f64d43ff0c18 788 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 789 assert(index <= SAI_WORD_MAX);
mbed_official 146:f64d43ff0c18 790 BW_I2S_TCR3_WDFL(instance,index);
mbed_official 146:f64d43ff0c18 791 }
mbed_official 146:f64d43ff0c18 792
mbed_official 146:f64d43ff0c18 793 /*!
mbed_official 146:f64d43ff0c18 794 * @brief Configures on which word the start of the word flag is set.
mbed_official 146:f64d43ff0c18 795 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 796 * @param index Which word would trigger word start flag.
mbed_official 146:f64d43ff0c18 797 */
mbed_official 146:f64d43ff0c18 798 static inline void sai_hal_set_rx_word_start_index(uint8_t instance, uint8_t index)
mbed_official 146:f64d43ff0c18 799 {
mbed_official 146:f64d43ff0c18 800 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 801 assert(index <= SAI_WORD_MAX);
mbed_official 146:f64d43ff0c18 802 BW_I2S_RCR3_WDFL(instance,index);
mbed_official 146:f64d43ff0c18 803 }
mbed_official 146:f64d43ff0c18 804
mbed_official 146:f64d43ff0c18 805 /*!
mbed_official 146:f64d43ff0c18 806 * @brief Sets the index in FIFO for the first bit data .
mbed_official 146:f64d43ff0c18 807 *
mbed_official 146:f64d43ff0c18 808 * The FIFO is 32-bit in SAI, but not all audio data is 32-bit. Mostly they are 16-bit.
mbed_official 146:f64d43ff0c18 809 * In this situation, the Codec needs to know which bit of the FIFO marks the valid audio data.
mbed_official 146:f64d43ff0c18 810 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 811 * @param index First bit shifted in FIFO.
mbed_official 146:f64d43ff0c18 812 */
mbed_official 146:f64d43ff0c18 813 static inline void sai_hal_set_tx_fbt(uint8_t instance, uint8_t index)
mbed_official 146:f64d43ff0c18 814 {
mbed_official 146:f64d43ff0c18 815 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 816 assert(index <= SAI_BIT_MAX);
mbed_official 146:f64d43ff0c18 817 BW_I2S_TCR5_FBT(instance,index);
mbed_official 146:f64d43ff0c18 818 }
mbed_official 146:f64d43ff0c18 819
mbed_official 146:f64d43ff0c18 820 /*!
mbed_official 146:f64d43ff0c18 821 * @brief Sets the index in FIFO for the first bit data.
mbed_official 146:f64d43ff0c18 822 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 823 * @param index First bit shifted in FIFO.
mbed_official 146:f64d43ff0c18 824 */
mbed_official 146:f64d43ff0c18 825 static inline void sai_hal_set_rx_fbt(uint8_t instance, uint8_t index)
mbed_official 146:f64d43ff0c18 826 {
mbed_official 146:f64d43ff0c18 827 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 828 assert(index <= SAI_BIT_MAX);
mbed_official 146:f64d43ff0c18 829 BW_I2S_RCR5_FBT(instance,index);
mbed_official 146:f64d43ff0c18 830 }
mbed_official 146:f64d43ff0c18 831
mbed_official 146:f64d43ff0c18 832 /*!
mbed_official 146:f64d43ff0c18 833 * @brief Flags whether the master clock divider is re-divided.
mbed_official 146:f64d43ff0c18 834 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 835 * @return True if the divider updated otherwise false.
mbed_official 146:f64d43ff0c18 836 */
mbed_official 146:f64d43ff0c18 837 bool sai_hal_mclk_divider_is_update(uint8_t instance);
mbed_official 146:f64d43ff0c18 838
mbed_official 146:f64d43ff0c18 839 /*!
mbed_official 146:f64d43ff0c18 840 * @brief Word start is detected.
mbed_official 146:f64d43ff0c18 841 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 842 * @param io_mode Transmit or receive data.
mbed_official 146:f64d43ff0c18 843 * @return True if detect word start otherwise false.
mbed_official 146:f64d43ff0c18 844 */
mbed_official 146:f64d43ff0c18 845 bool sai_hal_word_start_is_detected(uint8_t instance, sai_io_mode_t io_mode);
mbed_official 146:f64d43ff0c18 846
mbed_official 146:f64d43ff0c18 847 /*!
mbed_official 146:f64d43ff0c18 848 * @brief Sync error is detected.
mbed_official 146:f64d43ff0c18 849 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 850 * @param io_mode Transmit or receive data.
mbed_official 146:f64d43ff0c18 851 * @return True if detect sync error otherwise false.
mbed_official 146:f64d43ff0c18 852 */
mbed_official 146:f64d43ff0c18 853 bool sai_hal_sync_error_is_detected(uint8_t instance, sai_io_mode_t io_mode);
mbed_official 146:f64d43ff0c18 854
mbed_official 146:f64d43ff0c18 855 /*!
mbed_official 146:f64d43ff0c18 856 * @brief FIFO warning is detected.
mbed_official 146:f64d43ff0c18 857 *
mbed_official 146:f64d43ff0c18 858 * FIFO warning means that the FIFO is empty in Tx. While in Tx, FIFO warning means that
mbed_official 146:f64d43ff0c18 859 * the FIFO is empty and it needs data.
mbed_official 146:f64d43ff0c18 860 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 861 * @param io_mode Transmit or receive data.
mbed_official 146:f64d43ff0c18 862 * @return True if detect FIFO warning otherwise false.
mbed_official 146:f64d43ff0c18 863 */
mbed_official 146:f64d43ff0c18 864 bool sai_hal_fifo_warning_is_detected(uint8_t instance, sai_io_mode_t io_mode);
mbed_official 146:f64d43ff0c18 865
mbed_official 146:f64d43ff0c18 866 /*!
mbed_official 146:f64d43ff0c18 867 * @brief FIFO error is detected.
mbed_official 146:f64d43ff0c18 868 *
mbed_official 146:f64d43ff0c18 869 * FIFO error means that the FIFO has no data and the Codec is still transferring data.
mbed_official 146:f64d43ff0c18 870 * While in Rx, FIFO error means that the data is still in but the FIFO is full.
mbed_official 146:f64d43ff0c18 871 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 872 * @param io_mode Transmit or receive data.
mbed_official 146:f64d43ff0c18 873 * @return True if detects FIFO error otherwise false.
mbed_official 146:f64d43ff0c18 874 */
mbed_official 146:f64d43ff0c18 875 bool sai_hal_fifo_error_is_detected(uint8_t instance, sai_io_mode_t io_mode);
mbed_official 146:f64d43ff0c18 876
mbed_official 146:f64d43ff0c18 877 /*!
mbed_official 146:f64d43ff0c18 878 * @brief FIFO request is detected.
mbed_official 146:f64d43ff0c18 879 *
mbed_official 146:f64d43ff0c18 880 * FIFO request means that the data in FIFO is less than the watermark in Tx and more than the watermark in Rx.
mbed_official 146:f64d43ff0c18 881 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 882 * @param io_mode Transmit or receive data.
mbed_official 146:f64d43ff0c18 883 * @return True if detects FIFO request otherwise false.
mbed_official 146:f64d43ff0c18 884 */
mbed_official 146:f64d43ff0c18 885 bool sai_hal_fifo_request_is_detected(uint8_t instance, sai_io_mode_t io_mode);
mbed_official 146:f64d43ff0c18 886
mbed_official 146:f64d43ff0c18 887 /*!
mbed_official 146:f64d43ff0c18 888 * @brief Receives the data from FIFO.
mbed_official 146:f64d43ff0c18 889 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 890 * @param rx_channel Rx FIFO channel.
mbed_official 146:f64d43ff0c18 891 * @param data Pointer to the address to be written in.
mbed_official 146:f64d43ff0c18 892 */
mbed_official 146:f64d43ff0c18 893 static inline void sai_hal_receive_data(uint8_t instance, uint8_t rx_channel, uint32_t *data)
mbed_official 146:f64d43ff0c18 894 {
mbed_official 146:f64d43ff0c18 895 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 896 assert(rx_channel < FSL_FEATURE_I2S_CHANNEL_COUNT);
mbed_official 146:f64d43ff0c18 897 assert(data);
mbed_official 146:f64d43ff0c18 898
mbed_official 146:f64d43ff0c18 899 *data = HW_I2S_RDRn_RD(instance, rx_channel);
mbed_official 146:f64d43ff0c18 900 }
mbed_official 146:f64d43ff0c18 901
mbed_official 146:f64d43ff0c18 902 /*!
mbed_official 146:f64d43ff0c18 903 * @brief Transmits data to the FIFO.
mbed_official 146:f64d43ff0c18 904 * @param instance The SAI peripheral instance number.
mbed_official 146:f64d43ff0c18 905 * @param tx_channel Tx FIFO channel.
mbed_official 146:f64d43ff0c18 906 * @param data Data value which needs to be written into FIFO.
mbed_official 146:f64d43ff0c18 907 */
mbed_official 146:f64d43ff0c18 908 static inline void sai_hal_transmit_data(uint8_t instance, uint8_t tx_channel, uint32_t data)
mbed_official 146:f64d43ff0c18 909 {
mbed_official 146:f64d43ff0c18 910 assert(instance < HW_I2S_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 911 assert(tx_channel < FSL_FEATURE_I2S_CHANNEL_COUNT);
mbed_official 146:f64d43ff0c18 912
mbed_official 146:f64d43ff0c18 913 HW_I2S_TDRn_WR(instance,tx_channel,data);
mbed_official 146:f64d43ff0c18 914 }
mbed_official 146:f64d43ff0c18 915
mbed_official 146:f64d43ff0c18 916 #if defined(__cplusplus)
mbed_official 146:f64d43ff0c18 917 }
mbed_official 146:f64d43ff0c18 918 #endif
mbed_official 146:f64d43ff0c18 919
mbed_official 146:f64d43ff0c18 920 /*! @} */
mbed_official 146:f64d43ff0c18 921
mbed_official 146:f64d43ff0c18 922 #endif /* __FSL_SAI_HAL_H__ */
mbed_official 146:f64d43ff0c18 923 /*******************************************************************************
mbed_official 146:f64d43ff0c18 924 * EOF
mbed_official 146:f64d43ff0c18 925 *******************************************************************************/
mbed_official 146:f64d43ff0c18 926