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 Sep 18 14:00:17 2014 +0100
Revision:
324:406fd2029f23
Parent:
149:1fb5f62b92bd
Synchronized with git revision a73f28e6fbca9559fbed2726410eeb4c0534a4a5

Full URL: https://github.com/mbedmicro/mbed/commit/a73f28e6fbca9559fbed2726410eeb4c0534a4a5/

Extended #476, which does not break ethernet for K64F

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 324:406fd2029f23 53 /* Define 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 324:406fd2029f23 57 /* Define the max div and fract value for master clock divider. */
mbed_official 146:f64d43ff0c18 58 #define SAI_FRACT_MAX 256
mbed_official 146:f64d43ff0c18 59 #define SAI_DIV_MAX 4096
mbed_official 146:f64d43ff0c18 60
mbed_official 324:406fd2029f23 61 /*! @brief Define the bus type of sai */
mbed_official 324:406fd2029f23 62 typedef enum _sai_protocol
mbed_official 146:f64d43ff0c18 63 {
mbed_official 324:406fd2029f23 64 kSaiBusI2SLeft = 0x0,
mbed_official 324:406fd2029f23 65 kSaiBusI2SRight = 0x1,
mbed_official 324:406fd2029f23 66 kSaiBusI2SType = 0x2,
mbed_official 324:406fd2029f23 67 kSaiBusPCMA = 0x3,
mbed_official 324:406fd2029f23 68 kSaiBusPCMB = 0x4,
mbed_official 324:406fd2029f23 69 kSaiBusAC97 = 0x5
mbed_official 324:406fd2029f23 70 } sai_protocol_t;
mbed_official 146:f64d43ff0c18 71
mbed_official 146:f64d43ff0c18 72 /*! @brief Master or slave mode */
mbed_official 146:f64d43ff0c18 73 typedef enum _sai_master_slave
mbed_official 146:f64d43ff0c18 74 {
mbed_official 146:f64d43ff0c18 75 kSaiMaster = 0x0,/*!< Master mode */
mbed_official 146:f64d43ff0c18 76 kSaiSlave = 0x1/*!< Slave mode */
mbed_official 146:f64d43ff0c18 77 } sai_master_slave_t;
mbed_official 146:f64d43ff0c18 78
mbed_official 324:406fd2029f23 79 /*! @brief Polarity of SAI clock. */
mbed_official 324:406fd2029f23 80 typedef enum _sai_clk_polarity
mbed_official 324:406fd2029f23 81 {
mbed_official 324:406fd2029f23 82 kSaiClkPolarityHigh = 0x0, /*!< Clock active high */
mbed_official 324:406fd2029f23 83 kSaiClkPolarityLow = 0x1 /*!< Clock active low */
mbed_official 324:406fd2029f23 84 } sai_clk_polarity_t;
mbed_official 324:406fd2029f23 85
mbed_official 324:406fd2029f23 86 /*! @brief Clock generate direction. */
mbed_official 324:406fd2029f23 87 typedef enum _sai_clk_direction
mbed_official 324:406fd2029f23 88 {
mbed_official 324:406fd2029f23 89 kSaiClkInternal = 0x0, /*!< Clock generated internal. */
mbed_official 324:406fd2029f23 90 kSaiClkExternal = 0x1 /*!< Clock generated external. */
mbed_official 324:406fd2029f23 91 } sai_clk_direction_t;
mbed_official 324:406fd2029f23 92
mbed_official 324:406fd2029f23 93 /*! @brief Data transfer polarity, means MSB first of LSB first.*/
mbed_official 324:406fd2029f23 94 typedef enum _sai_data_order
mbed_official 324:406fd2029f23 95 {
mbed_official 324:406fd2029f23 96 kSaiLSBFirst = 0x0, /*!< Least significant bit transferred first. */
mbed_official 324:406fd2029f23 97 kSaiMSBFirst = 0x1 /*!< Most significant bit transferred first. */
mbed_official 324:406fd2029f23 98 } sai_data_order_t;
mbed_official 324:406fd2029f23 99
mbed_official 146:f64d43ff0c18 100 /*! @brief Synchronous or asynchronous mode */
mbed_official 146:f64d43ff0c18 101 typedef enum _sai_sync_mode
mbed_official 146:f64d43ff0c18 102 {
mbed_official 146:f64d43ff0c18 103 kSaiModeAsync = 0x0,/*!< Asynchronous mode */
mbed_official 146:f64d43ff0c18 104 kSaiModeSync = 0x1,/*!< Synchronous mode (with receiver or transmit) */
mbed_official 146:f64d43ff0c18 105 kSaiModeSyncWithOtherTx = 0x2,/*!< Synchronous with another SAI transmit */
mbed_official 146:f64d43ff0c18 106 kSaiModeSyncWithOtherRx = 0x3/*!< Synchronous with another SAI receiver */
mbed_official 146:f64d43ff0c18 107 } sai_sync_mode_t;
mbed_official 146:f64d43ff0c18 108
mbed_official 146:f64d43ff0c18 109 /*! @brief Mater clock source */
mbed_official 146:f64d43ff0c18 110 typedef enum _sai_mclk_source
mbed_official 146:f64d43ff0c18 111 {
mbed_official 146:f64d43ff0c18 112 kSaiMclkSourceSysclk = 0x0,/*!< Master clock from the system clock */
mbed_official 324:406fd2029f23 113 kSaiMclkSourceSelect1 = 0x1,/*!< Master clock from source 1 */
mbed_official 324:406fd2029f23 114 kSaiMclkSourceSelect2 = 0x2,/*!< Master clock from source 2 */
mbed_official 324:406fd2029f23 115 kSaiMclkSourceSelect3 = 0x3/*!< Master clock from source 3 */
mbed_official 146:f64d43ff0c18 116 } sai_mclk_source_t;
mbed_official 146:f64d43ff0c18 117
mbed_official 146:f64d43ff0c18 118 /*! @brief Bit clock source */
mbed_official 146:f64d43ff0c18 119 typedef enum _sai_bclk_source
mbed_official 146:f64d43ff0c18 120 {
mbed_official 146:f64d43ff0c18 121 kSaiBclkSourceBusclk = 0x0,/*!< Bit clock using bus clock */
mbed_official 146:f64d43ff0c18 122 kSaiBclkSourceMclkDiv = 0x1,/*!< Bit clock using master clock divider */
mbed_official 146:f64d43ff0c18 123 kSaiBclkSourceOtherSai0 = 0x2,/*!< Bit clock from other SAI device */
mbed_official 146:f64d43ff0c18 124 kSaiBclkSourceOtherSai1 = 0x3/*!< Bit clock from other SAI device */
mbed_official 146:f64d43ff0c18 125 } sai_bclk_source_t;
mbed_official 146:f64d43ff0c18 126
mbed_official 324:406fd2029f23 127 /*! @brief The SAI state flag. */
mbed_official 146:f64d43ff0c18 128 typedef enum _sai_interrupt_request
mbed_official 146:f64d43ff0c18 129 {
mbed_official 146:f64d43ff0c18 130 kSaiIntrequestWordStart = 0x0,/*!< Word start flag, means the first word in a frame detected */
mbed_official 146:f64d43ff0c18 131 kSaiIntrequestSyncError = 0x1,/*!< Sync error flag, means the sync error is detected */
mbed_official 146:f64d43ff0c18 132 kSaiIntrequestFIFOWarning = 0x2,/*!< FIFO warning flag, means the FIFO is empty */
mbed_official 146:f64d43ff0c18 133 kSaiIntrequestFIFOError = 0x3,/*!< FIFO error flag */
mbed_official 146:f64d43ff0c18 134 kSaiIntrequestFIFORequest = 0x4/*!< FIFO request, means reached watermark */
mbed_official 146:f64d43ff0c18 135 } sai_interrupt_request_t;
mbed_official 146:f64d43ff0c18 136
mbed_official 146:f64d43ff0c18 137
mbed_official 146:f64d43ff0c18 138 /*! @brief The DMA request sources */
mbed_official 324:406fd2029f23 139 typedef enum _sai_dma_request
mbed_official 146:f64d43ff0c18 140 {
mbed_official 146:f64d43ff0c18 141 kSaiDmaReqFIFOWarning = 0x0,/*!< FIFO warning caused by the DMA request */
mbed_official 146:f64d43ff0c18 142 kSaiDmaReqFIFORequest = 0x1/*!< FIFO request caused by the DMA request */
mbed_official 146:f64d43ff0c18 143 } sai_dma_request_t;
mbed_official 146:f64d43ff0c18 144
mbed_official 324:406fd2029f23 145 /*! @brief The SAI state flag */
mbed_official 146:f64d43ff0c18 146 typedef enum _sai_state_flag
mbed_official 146:f64d43ff0c18 147 {
mbed_official 146:f64d43ff0c18 148 kSaiStateFlagWordStart = 0x0,/*!< Word start flag, means the first word in a frame detected. */
mbed_official 146:f64d43ff0c18 149 kSaiStateFlagSyncError = 0x1,/*!< Sync error flag, means the sync error is detected */
mbed_official 146:f64d43ff0c18 150 kSaiStateFlagFIFOError = 0x2,/*!< FIFO error flag */
mbed_official 324:406fd2029f23 151 kSaiStateFlagFIFORequest = 0x3,
mbed_official 324:406fd2029f23 152 kSaiStateFlagFIFOWarning = 0x4,
mbed_official 324:406fd2029f23 153 kSaiStateFlagSoftReset = 0x5 /*!< Software reset flag */
mbed_official 146:f64d43ff0c18 154 } sai_state_flag_t;
mbed_official 146:f64d43ff0c18 155
mbed_official 146:f64d43ff0c18 156 /*! @brief The reset type */
mbed_official 324:406fd2029f23 157 typedef enum _sai_reset_type
mbed_official 146:f64d43ff0c18 158 {
mbed_official 146:f64d43ff0c18 159 kSaiResetTypeSoftware = 0x0,/*!< Software reset, reset the logic state */
mbed_official 146:f64d43ff0c18 160 kSaiResetTypeFIFO = 0x1/*!< FIFO reset, reset the FIFO read and write pointer */
mbed_official 146:f64d43ff0c18 161 } sai_reset_type_t;
mbed_official 146:f64d43ff0c18 162
mbed_official 146:f64d43ff0c18 163 /*
mbed_official 324:406fd2029f23 164 * @brief The SAI running mode
mbed_official 146:f64d43ff0c18 165 * The mode includes normal mode, debug mode, and stop mode.
mbed_official 146:f64d43ff0c18 166 */
mbed_official 146:f64d43ff0c18 167 typedef enum _sai_running_mode
mbed_official 146:f64d43ff0c18 168 {
mbed_official 146:f64d43ff0c18 169 kSaiRunModeDebug = 0x0,/*!< In debug mode */
mbed_official 146:f64d43ff0c18 170 kSaiRunModeStop = 0x1/*!< In stop mode */
mbed_official 324:406fd2029f23 171 } sai_run_mode_t;
mbed_official 324:406fd2029f23 172
mbed_official 324:406fd2029f23 173 #if FSL_FEATURE_SAI_HAS_FIFO_PACKING
mbed_official 324:406fd2029f23 174
mbed_official 324:406fd2029f23 175 /*
mbed_official 324:406fd2029f23 176 * @brief The SAI packing mode
mbed_official 324:406fd2029f23 177 * The mode includes 8 bit and 16 bit packing.
mbed_official 324:406fd2029f23 178 */
mbed_official 324:406fd2029f23 179 typedef enum _sai_fifo_packing
mbed_official 324:406fd2029f23 180 {
mbed_official 324:406fd2029f23 181 kSaiFifoPackingDisabled = 0x0, /*!< Packing disabled. */
mbed_official 324:406fd2029f23 182 kSaiFifoPacking8bit = 0x2,/*!< 8 bit packing enabled. */
mbed_official 324:406fd2029f23 183 kSaiFifoPacking16bit = 0x3 /*!< 16bit packing enabled. */
mbed_official 324:406fd2029f23 184 } sai_fifo_packing_t;
mbed_official 324:406fd2029f23 185
mbed_official 324:406fd2029f23 186 #endif
mbed_official 146:f64d43ff0c18 187
mbed_official 146:f64d43ff0c18 188 /*******************************************************************************
mbed_official 146:f64d43ff0c18 189 * API
mbed_official 146:f64d43ff0c18 190 ******************************************************************************/
mbed_official 146:f64d43ff0c18 191
mbed_official 146:f64d43ff0c18 192 #if defined(__cplusplus)
mbed_official 146:f64d43ff0c18 193 extern "C" {
mbed_official 146:f64d43ff0c18 194 #endif
mbed_official 146:f64d43ff0c18 195
mbed_official 146:f64d43ff0c18 196 /*!
mbed_official 324:406fd2029f23 197 * @name Module control
mbed_official 324:406fd2029f23 198 * @{
mbed_official 324:406fd2029f23 199 */
mbed_official 146:f64d43ff0c18 200
mbed_official 146:f64d43ff0c18 201 /*!
mbed_official 324:406fd2029f23 202 * @brief Initializes the SAI Tx.
mbed_official 146:f64d43ff0c18 203 *
mbed_official 324:406fd2029f23 204 * The initialization resets the SAI module by setting the SR bit of TCSR register.
mbed_official 324:406fd2029f23 205 * Note that the function writes 0 to every control registers.
mbed_official 324:406fd2029f23 206 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 207 */
mbed_official 324:406fd2029f23 208 void SAI_HAL_TxInit(uint32_t saiBaseAddr);
mbed_official 146:f64d43ff0c18 209
mbed_official 146:f64d43ff0c18 210 /*!
mbed_official 324:406fd2029f23 211 * @brief Initializes the SAI Rx.
mbed_official 324:406fd2029f23 212 *
mbed_official 324:406fd2029f23 213 * The initialization resets the SAI module by setting the SR bit of RCSR register.
mbed_official 324:406fd2029f23 214 * Note that the function writes 0 to every control registers.
mbed_official 324:406fd2029f23 215 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 216 */
mbed_official 324:406fd2029f23 217 void SAI_HAL_RxInit(uint32_t saiBaseAddr);
mbed_official 324:406fd2029f23 218
mbed_official 324:406fd2029f23 219 /*!
mbed_official 324:406fd2029f23 220 * @brief Sets Tx protocol relevant settings.
mbed_official 146:f64d43ff0c18 221 *
mbed_official 146:f64d43ff0c18 222 * The bus mode means which protocol SAI uses. It can be I2S left, right and so on. Each protocol
mbed_official 146:f64d43ff0c18 223 * has a different configuration on bit clock and frame sync.
mbed_official 324:406fd2029f23 224 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 225 * @param protocol The protocol selection. It can be I2S left aligned, I2S right aligned, etc.
mbed_official 324:406fd2029f23 226 */
mbed_official 324:406fd2029f23 227 void SAI_HAL_TxSetProtocol(uint32_t saiBaseAddr, sai_protocol_t protocol);
mbed_official 324:406fd2029f23 228
mbed_official 324:406fd2029f23 229 /*!
mbed_official 324:406fd2029f23 230 * @brief Sets Rx protocol relevant settings.
mbed_official 324:406fd2029f23 231 *
mbed_official 324:406fd2029f23 232 * The bus mode means which protocol SAI uses. It can be I2S left, right and so on. Each protocol
mbed_official 324:406fd2029f23 233 * has a different configuration on bit clock and frame sync.
mbed_official 324:406fd2029f23 234 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 235 * @param protocol The protocol selection. It can be I2S left aligned, I2S right aligned, etc.
mbed_official 146:f64d43ff0c18 236 */
mbed_official 324:406fd2029f23 237 void SAI_HAL_RxSetProtocol(uint32_t saiBaseAddr, sai_protocol_t protocol);
mbed_official 324:406fd2029f23 238
mbed_official 324:406fd2029f23 239 /*!
mbed_official 324:406fd2029f23 240 * @brief Sets master or slave mode.
mbed_official 324:406fd2029f23 241 *
mbed_official 324:406fd2029f23 242 * The function determines master or slave mode. Master mode provides its
mbed_official 324:406fd2029f23 243 * own clock and slave mode uses an external clock.
mbed_official 324:406fd2029f23 244 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 245 * @param master_slave_mode Mater or slave mode.
mbed_official 324:406fd2029f23 246 */
mbed_official 324:406fd2029f23 247 void SAI_HAL_TxSetMasterSlave(uint32_t saiBaseAddr, sai_master_slave_t master_slave_mode);
mbed_official 324:406fd2029f23 248
mbed_official 324:406fd2029f23 249 /*!
mbed_official 324:406fd2029f23 250 * @brief Sets master or slave mode.
mbed_official 324:406fd2029f23 251 *
mbed_official 324:406fd2029f23 252 * The function determines master or slave mode. Master mode provides its
mbed_official 324:406fd2029f23 253 * own clock and slave mode uses external clock.
mbed_official 324:406fd2029f23 254 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 255 * @param master_slave_mode Mater or slave mode.
mbed_official 324:406fd2029f23 256 */
mbed_official 324:406fd2029f23 257 void SAI_HAL_RxSetMasterSlave(uint32_t saiBaseAddr, sai_master_slave_t master_slave_mode);
mbed_official 324:406fd2029f23 258
mbed_official 324:406fd2029f23 259 /*! @}*/
mbed_official 324:406fd2029f23 260
mbed_official 324:406fd2029f23 261 /*!
mbed_official 324:406fd2029f23 262 * @name Master clock configuration
mbed_official 324:406fd2029f23 263 * @{
mbed_official 324:406fd2029f23 264 */
mbed_official 146:f64d43ff0c18 265
mbed_official 146:f64d43ff0c18 266 /*!
mbed_official 146:f64d43ff0c18 267 * @brief Sets the master clock source.
mbed_official 146:f64d43ff0c18 268 *
mbed_official 324:406fd2029f23 269 * The source of the clock is different from socs.
mbed_official 324:406fd2029f23 270 * This function sets the clock source for SAI master clock source.
mbed_official 146:f64d43ff0c18 271 * Master clock is used to produce the bit clock for the data transfer.
mbed_official 324:406fd2029f23 272 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 273 * @param source Mater clock source
mbed_official 146:f64d43ff0c18 274 */
mbed_official 324:406fd2029f23 275 static inline void SAI_HAL_SetMclkSrc(uint32_t saiBaseAddr, sai_mclk_source_t source)
mbed_official 146:f64d43ff0c18 276 {
mbed_official 324:406fd2029f23 277 BW_I2S_MCR_MICS(saiBaseAddr,source);
mbed_official 324:406fd2029f23 278 }
mbed_official 324:406fd2029f23 279
mbed_official 324:406fd2029f23 280 /*!
mbed_official 324:406fd2029f23 281 * @brief Gets the master clock source.
mbed_official 324:406fd2029f23 282 *
mbed_official 324:406fd2029f23 283 * The source of the clock is different from socs.
mbed_official 324:406fd2029f23 284 * This function gets the clock source for SAI master clock source.
mbed_official 324:406fd2029f23 285 * Master clock is used to produce the bit clock for the data transfer.
mbed_official 324:406fd2029f23 286 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 287 * @return Mater clock source
mbed_official 324:406fd2029f23 288 */
mbed_official 324:406fd2029f23 289 static inline uint32_t SAI_HAL_GetMclkSrc(uint32_t saiBaseAddr)
mbed_official 324:406fd2029f23 290 {
mbed_official 324:406fd2029f23 291 return BR_I2S_MCR_MICS(saiBaseAddr);
mbed_official 324:406fd2029f23 292 }
mbed_official 324:406fd2029f23 293
mbed_official 324:406fd2029f23 294 /*!
mbed_official 324:406fd2029f23 295 * @brief Sets the direction of the SAI master clock.
mbed_official 324:406fd2029f23 296 *
mbed_official 324:406fd2029f23 297 * This function would decides the direction of bit clock generated.
mbed_official 324:406fd2029f23 298 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 299 * @param enable True means enable, false means disable.
mbed_official 324:406fd2029f23 300 */
mbed_official 324:406fd2029f23 301 static inline void SAI_HAL_SetMclkDividerCmd(uint32_t saiBaseAddr, bool enable)
mbed_official 324:406fd2029f23 302 {
mbed_official 324:406fd2029f23 303 BW_I2S_MCR_MOE(saiBaseAddr,enable);
mbed_official 146:f64d43ff0c18 304 }
mbed_official 146:f64d43ff0c18 305
mbed_official 146:f64d43ff0c18 306 /*!
mbed_official 146:f64d43ff0c18 307 * @brief Sets the divider of the master clock.
mbed_official 146:f64d43ff0c18 308 *
mbed_official 146:f64d43ff0c18 309 * Using the divider to get the master clock frequency wanted from the source.
mbed_official 146:f64d43ff0c18 310 * mclk = clk_source * fract/divide. The input is the master clock frequency needed and the source clock frequency.
mbed_official 146:f64d43ff0c18 311 * The master clock is decided by the sample rate and the multi-clock number.
mbed_official 324:406fd2029f23 312 * Notice that mclk should less than src_clk, or it would do hang as the HW refuses to write in this situation.
mbed_official 324:406fd2029f23 313 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 314 * @param mclk Master clock frequency needed.
mbed_official 146:f64d43ff0c18 315 * @param src_clk The source clock frequency.
mbed_official 146:f64d43ff0c18 316 */
mbed_official 324:406fd2029f23 317 void SAI_HAL_SetMclkDiv(uint32_t saiBaseAddr, uint32_t mclk, uint32_t src_clk);
mbed_official 324:406fd2029f23 318
mbed_official 324:406fd2029f23 319 /*!
mbed_official 324:406fd2029f23 320 * @brief Flag to see if the master clock divider is re-divided.
mbed_official 324:406fd2029f23 321 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 322 * @return True if the divider updated otherwise false.
mbed_official 324:406fd2029f23 323 */
mbed_official 324:406fd2029f23 324 static inline bool SAI_HAL_GetMclkDivUpdatingCmd(uint32_t saiBaseAddr)
mbed_official 324:406fd2029f23 325 {
mbed_official 324:406fd2029f23 326 return BR_I2S_MCR_DUF(saiBaseAddr);
mbed_official 324:406fd2029f23 327 }
mbed_official 324:406fd2029f23 328
mbed_official 324:406fd2029f23 329 /*! @}*/
mbed_official 324:406fd2029f23 330
mbed_official 324:406fd2029f23 331 /*!
mbed_official 324:406fd2029f23 332 * @name Bit clock configuration
mbed_official 324:406fd2029f23 333 * @{
mbed_official 324:406fd2029f23 334 */
mbed_official 324:406fd2029f23 335
mbed_official 324:406fd2029f23 336 /*!
mbed_official 324:406fd2029f23 337 * @brief Sets the bit clock source of Tx. It is generated by the master clock, bus clock and other devices.
mbed_official 324:406fd2029f23 338 *
mbed_official 324:406fd2029f23 339 * The function sets the source of the bit clock. The bit clock can be produced by the master
mbed_official 324:406fd2029f23 340 * clock and from the bus clock or other SAI Tx/Rx. Tx and Rx in the SAI module use the same bit
mbed_official 324:406fd2029f23 341 * clock either from Tx or Rx.
mbed_official 324:406fd2029f23 342 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 343 * @param source Bit clock source.
mbed_official 324:406fd2029f23 344 */
mbed_official 324:406fd2029f23 345 static inline void SAI_HAL_TxSetBclkSrc(uint32_t saiBaseAddr, sai_bclk_source_t source)
mbed_official 324:406fd2029f23 346 {
mbed_official 324:406fd2029f23 347 BW_I2S_TCR2_MSEL(saiBaseAddr,source);
mbed_official 324:406fd2029f23 348 }
mbed_official 146:f64d43ff0c18 349
mbed_official 146:f64d43ff0c18 350 /*!
mbed_official 324:406fd2029f23 351 * @brief Sets bit clock source of the Rx. It is generated by the master clock, bus clock and other devices.
mbed_official 146:f64d43ff0c18 352 *
mbed_official 324:406fd2029f23 353 * The function sets the source of the bit clock. The bit clock can be produced by the master
mbed_official 324:406fd2029f23 354 * 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 355 * clock either from Tx or Rx.
mbed_official 324:406fd2029f23 356 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 357 * @param source Bit clock source.
mbed_official 146:f64d43ff0c18 358 */
mbed_official 324:406fd2029f23 359 static inline void SAI_HAL_RxSetBclkSrc(uint32_t saiBaseAddr, sai_bclk_source_t source)
mbed_official 324:406fd2029f23 360 {
mbed_official 324:406fd2029f23 361 BW_I2S_RCR2_MSEL(saiBaseAddr,source);
mbed_official 324:406fd2029f23 362 }
mbed_official 324:406fd2029f23 363
mbed_official 324:406fd2029f23 364 /*!
mbed_official 324:406fd2029f23 365 * @brief Gets the bit clock source of Tx. It is generated by the master clock, bus clock and other devices.
mbed_official 324:406fd2029f23 366 *
mbed_official 324:406fd2029f23 367 * The function gets the source of the bit clock. The bit clock can be produced by the master
mbed_official 324:406fd2029f23 368 * clock and from the bus clock or other SAI Tx/Rx. Tx and Rx in the SAI module use the same bit
mbed_official 324:406fd2029f23 369 * clock either from Tx or Rx.
mbed_official 324:406fd2029f23 370 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 371 * @return Bit clock source.
mbed_official 324:406fd2029f23 372 */
mbed_official 324:406fd2029f23 373 static inline uint32_t SAI_HAL_TxGetBclkSrc(uint32_t saiBaseAddr)
mbed_official 146:f64d43ff0c18 374 {
mbed_official 324:406fd2029f23 375 return BR_I2S_TCR2_MSEL(saiBaseAddr);
mbed_official 324:406fd2029f23 376 }
mbed_official 324:406fd2029f23 377
mbed_official 324:406fd2029f23 378 /*!
mbed_official 324:406fd2029f23 379 * @brief Gets bit clock source of the Rx. It is generated by the master clock, bus clock and other devices.
mbed_official 324:406fd2029f23 380 *
mbed_official 324:406fd2029f23 381 * The function gets the source of the bit clock. The bit clock can be produced by the master
mbed_official 324:406fd2029f23 382 * clock, and from the bus clock or other SAI Tx/Rx. Tx and Rx in the SAI module use the same bit
mbed_official 324:406fd2029f23 383 * clock either from Tx or Rx.
mbed_official 324:406fd2029f23 384 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 385 * @return Bit clock source.
mbed_official 324:406fd2029f23 386 */
mbed_official 324:406fd2029f23 387 static inline uint32_t SAI_HAL_RxGetBclkSrc(uint32_t saiBaseAddr)
mbed_official 324:406fd2029f23 388 {
mbed_official 324:406fd2029f23 389 return BR_I2S_RCR2_MSEL(saiBaseAddr);
mbed_official 324:406fd2029f23 390 }
mbed_official 324:406fd2029f23 391
mbed_official 324:406fd2029f23 392 /*!
mbed_official 324:406fd2029f23 393 * @brief Sets the Tx bit clock divider value.
mbed_official 324:406fd2029f23 394 *
mbed_official 324:406fd2029f23 395 * bclk = mclk / divider. At the same time, bclk = sample_rate * channel * bits. This means
mbed_official 324:406fd2029f23 396 * how much time is needed to transfer one bit.
mbed_official 324:406fd2029f23 397 * Notice: The function is called while the bit clock source is the master clock.
mbed_official 324:406fd2029f23 398 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 399 * @param divider The divide number of bit clock.
mbed_official 324:406fd2029f23 400 */
mbed_official 324:406fd2029f23 401 static inline void SAI_HAL_TxSetBclkDiv(uint32_t saiBaseAddr, uint32_t divider)
mbed_official 324:406fd2029f23 402 {
mbed_official 324:406fd2029f23 403 BW_I2S_TCR2_DIV(saiBaseAddr,divider/2 -1);
mbed_official 146:f64d43ff0c18 404 }
mbed_official 146:f64d43ff0c18 405
mbed_official 146:f64d43ff0c18 406 /*!
mbed_official 324:406fd2029f23 407 * @brief Sets the Rx bit clock divider value.
mbed_official 146:f64d43ff0c18 408 *
mbed_official 324:406fd2029f23 409 * bclk = mclk / divider. At the same time, bclk = sample_rate * channel * bits. This means
mbed_official 324:406fd2029f23 410 * how much time is needed to transfer one bit.
mbed_official 324:406fd2029f23 411 * Notice: The function is called while the bit clock source is the master clock.
mbed_official 324:406fd2029f23 412 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 413 * @param divider The divide number of bit clock.
mbed_official 324:406fd2029f23 414 */
mbed_official 324:406fd2029f23 415 static inline void SAI_HAL_RxSetBclkDiv(uint32_t saiBaseAddr, uint32_t divider)
mbed_official 324:406fd2029f23 416 {
mbed_official 324:406fd2029f23 417 BW_I2S_RCR2_DIV(saiBaseAddr,divider/2 -1);
mbed_official 324:406fd2029f23 418 }
mbed_official 324:406fd2029f23 419
mbed_official 324:406fd2029f23 420 /*!
mbed_official 324:406fd2029f23 421 * @brief Enables or disables the Tx bit clock.
mbed_official 324:406fd2029f23 422 *
mbed_official 324:406fd2029f23 423 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 424 * @param enable True means enable, false means disable.
mbed_official 146:f64d43ff0c18 425 */
mbed_official 324:406fd2029f23 426 static inline void SAI_HAL_TxSetBclkCmd(uint32_t saiBaseAddr, bool enable)
mbed_official 324:406fd2029f23 427 {
mbed_official 324:406fd2029f23 428 BW_I2S_TCSR_BCE(saiBaseAddr,enable);
mbed_official 324:406fd2029f23 429 }
mbed_official 324:406fd2029f23 430
mbed_official 324:406fd2029f23 431 /*!
mbed_official 324:406fd2029f23 432 * @brief Enables or disables the Rx bit clock.
mbed_official 324:406fd2029f23 433 *
mbed_official 324:406fd2029f23 434 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 435 * @param enable True means enable, false means disable.
mbed_official 324:406fd2029f23 436 */
mbed_official 324:406fd2029f23 437 static inline void SAI_HAL_RxSetBclkCmd(uint32_t saiBaseAddr, bool enable)
mbed_official 146:f64d43ff0c18 438 {
mbed_official 324:406fd2029f23 439 BW_I2S_RCSR_BCE(saiBaseAddr, enable);
mbed_official 324:406fd2029f23 440 }
mbed_official 324:406fd2029f23 441
mbed_official 324:406fd2029f23 442 /*!
mbed_official 324:406fd2029f23 443 * @brief Enables or disables the Tx bit clock input bit.
mbed_official 324:406fd2029f23 444 *
mbed_official 324:406fd2029f23 445 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 446 * @param enable True means enable, false means disable.
mbed_official 324:406fd2029f23 447 */
mbed_official 324:406fd2029f23 448 static inline void SAI_HAL_TxSetBclkInputCmd(uint32_t saiBaseAddr, bool enable)
mbed_official 324:406fd2029f23 449 {
mbed_official 324:406fd2029f23 450 BW_I2S_TCR2_BCI(saiBaseAddr,enable);
mbed_official 146:f64d43ff0c18 451 }
mbed_official 146:f64d43ff0c18 452
mbed_official 146:f64d43ff0c18 453 /*!
mbed_official 324:406fd2029f23 454 * @brief Enables or disables the Rx bit clock input bit.
mbed_official 324:406fd2029f23 455 *
mbed_official 324:406fd2029f23 456 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 457 * @param enable True means enable, false means disable.
mbed_official 324:406fd2029f23 458 */
mbed_official 324:406fd2029f23 459 static inline void SAI_HAL_RxSetBclkInputCmd(uint32_t saiBaseAddr, bool enable)
mbed_official 324:406fd2029f23 460 {
mbed_official 324:406fd2029f23 461 BW_I2S_RCR2_BCI(saiBaseAddr,enable);
mbed_official 324:406fd2029f23 462 }
mbed_official 324:406fd2029f23 463
mbed_official 324:406fd2029f23 464 /*!
mbed_official 324:406fd2029f23 465 * @brief Sets the Tx bit clock swap.
mbed_official 146:f64d43ff0c18 466 *
mbed_official 324:406fd2029f23 467 * This field swaps the bit clock used by the transmitter. When the transmitter is configured in
mbed_official 324:406fd2029f23 468 * asynchronous mode and this bit is set, the transmitter is clocked by the receiver bit clock.
mbed_official 324:406fd2029f23 469 * This allows the transmitter and receiver to share the same bit clock, but the transmitter
mbed_official 324:406fd2029f23 470 * continues to use the transmit frame sync (SAI_TX_SYNC).
mbed_official 324:406fd2029f23 471 * When the transmitter is configured in synchronous mode, the transmitter BCS field and receiver
mbed_official 324:406fd2029f23 472 * BCS field must be set to the same value. When both are set, the transmitter and receiver are both
mbed_official 324:406fd2029f23 473 * clocked by the transmitter bit clock (SAI_TX_BCLK) but use the receiver frame sync (SAI_RX_SYNC).
mbed_official 324:406fd2029f23 474 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 475 * @param enable True means swap bit closk, false means no swap.
mbed_official 146:f64d43ff0c18 476 */
mbed_official 324:406fd2029f23 477 static inline void SAI_HAL_TxSetSwapBclkCmd(uint32_t saiBaseAddr, bool enable)
mbed_official 146:f64d43ff0c18 478 {
mbed_official 324:406fd2029f23 479 BW_I2S_TCR2_BCS(saiBaseAddr,enable);
mbed_official 324:406fd2029f23 480 }
mbed_official 324:406fd2029f23 481
mbed_official 324:406fd2029f23 482 /*!
mbed_official 324:406fd2029f23 483 * @brief Sets the Rx bit clock swap.
mbed_official 324:406fd2029f23 484 *
mbed_official 324:406fd2029f23 485 * This field swaps the bit clock used by the receiver. When the receiver is configured in
mbed_official 324:406fd2029f23 486 * asynchronous mode and this bit is set, the receiver is clocked by the transmitter bit clock
mbed_official 324:406fd2029f23 487 * (SAI_TX_BCLK). This allows the transmitter and receiver to share the same bit clock, but the
mbed_official 324:406fd2029f23 488 * receiver continues to use the receiver frame sync (SAI_RX_SYNC).
mbed_official 324:406fd2029f23 489 * When the receiver is configured in synchronous mode, the transmitter BCS field and receiver BCS
mbed_official 324:406fd2029f23 490 * field must be set to the same value. When both are set, the transmitter and receiver are both
mbed_official 324:406fd2029f23 491 * clocked by the receiver bit clock (SAI_RX_BCLK) but use the transmitter frame sync (SAI_TX_SYNC).
mbed_official 324:406fd2029f23 492 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 493 * @param enable True means swap bit closk, false means no swap.
mbed_official 324:406fd2029f23 494 */
mbed_official 324:406fd2029f23 495 static inline void SAI_HAL_RxSetSwapBclkCmd(uint32_t saiBaseAddr, bool enable)
mbed_official 324:406fd2029f23 496 {
mbed_official 324:406fd2029f23 497 BW_I2S_RCR2_BCS(saiBaseAddr, enable);
mbed_official 324:406fd2029f23 498 }
mbed_official 324:406fd2029f23 499
mbed_official 324:406fd2029f23 500 /*!
mbed_official 324:406fd2029f23 501 * @brief Sets the direction of the Tx SAI bit clock.
mbed_official 324:406fd2029f23 502 *
mbed_official 324:406fd2029f23 503 * This function sets the direction of the bit clock generated.
mbed_official 324:406fd2029f23 504 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 505 * @param direction Bit clock generated internal or external.
mbed_official 324:406fd2029f23 506 */
mbed_official 324:406fd2029f23 507 static inline void SAI_HAL_TxSetBclkDir(uint32_t saiBaseAddr, sai_clk_direction_t direction)
mbed_official 324:406fd2029f23 508 {
mbed_official 324:406fd2029f23 509 BW_I2S_TCR2_BCD(saiBaseAddr,direction);
mbed_official 146:f64d43ff0c18 510 }
mbed_official 146:f64d43ff0c18 511
mbed_official 146:f64d43ff0c18 512 /*!
mbed_official 324:406fd2029f23 513 * @brief Sets the direction of the Rx SAI bit clock.
mbed_official 324:406fd2029f23 514 *
mbed_official 324:406fd2029f23 515 * This function sets the direction of the bit clock generated.
mbed_official 324:406fd2029f23 516 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 517 * @param direction Bit clock generated internal or external.
mbed_official 324:406fd2029f23 518 */
mbed_official 324:406fd2029f23 519 static inline void SAI_HAL_RxSetBclkDir(uint32_t saiBaseAddr, sai_clk_direction_t direction)
mbed_official 324:406fd2029f23 520 {
mbed_official 324:406fd2029f23 521 BW_I2S_RCR2_BCD(saiBaseAddr,direction);
mbed_official 324:406fd2029f23 522 }
mbed_official 324:406fd2029f23 523
mbed_official 324:406fd2029f23 524 /*!
mbed_official 324:406fd2029f23 525 * @brief Sets the polarity of the Tx SAI bit clock.
mbed_official 324:406fd2029f23 526 *
mbed_official 324:406fd2029f23 527 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 528 * @param pol Polarity of the SAI bit clock, which can be configured to active high or low.
mbed_official 324:406fd2029f23 529 */
mbed_official 324:406fd2029f23 530 static inline void SAI_HAL_TxSetBclkPolarity(uint32_t saiBaseAddr, sai_clk_polarity_t pol)
mbed_official 324:406fd2029f23 531 {
mbed_official 324:406fd2029f23 532 BW_I2S_TCR2_BCP(saiBaseAddr, pol);
mbed_official 324:406fd2029f23 533 }
mbed_official 324:406fd2029f23 534
mbed_official 324:406fd2029f23 535 /*!
mbed_official 324:406fd2029f23 536 * @brief Sets the polarity of the Rx SAI bit clock.
mbed_official 324:406fd2029f23 537 *
mbed_official 324:406fd2029f23 538 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 539 * @param pol Polarity of SAI bit clock, which can be configured to active high or low.
mbed_official 324:406fd2029f23 540 */
mbed_official 324:406fd2029f23 541 static inline void SAI_HAL_RxSetBclkPolarity(uint32_t saiBaseAddr, sai_clk_polarity_t pol)
mbed_official 324:406fd2029f23 542 {
mbed_official 324:406fd2029f23 543 BW_I2S_RCR2_BCP(saiBaseAddr, pol);
mbed_official 324:406fd2029f23 544 }
mbed_official 324:406fd2029f23 545 /*! @} */
mbed_official 324:406fd2029f23 546
mbed_official 324:406fd2029f23 547 /*!
mbed_official 324:406fd2029f23 548 * @name Frame sync configuration
mbed_official 324:406fd2029f23 549 * @{
mbed_official 324:406fd2029f23 550 */
mbed_official 324:406fd2029f23 551
mbed_official 324:406fd2029f23 552 /*!
mbed_official 324:406fd2029f23 553 * @brief Sets the Tx frame size.
mbed_official 146:f64d43ff0c18 554 *
mbed_official 324:406fd2029f23 555 * The frame size means how many words are in a frame. For example 2-channel
mbed_official 324:406fd2029f23 556 * audio data, the frame size is 2, which means 2 words in a frame.
mbed_official 324:406fd2029f23 557 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 558 * @param size Words number in a frame.
mbed_official 324:406fd2029f23 559 */
mbed_official 324:406fd2029f23 560 static inline void SAI_HAL_TxSetFrameSize(uint32_t saiBaseAddr, uint32_t size)
mbed_official 324:406fd2029f23 561 {
mbed_official 324:406fd2029f23 562 BW_I2S_TCR4_FRSZ(saiBaseAddr,size -1);
mbed_official 324:406fd2029f23 563 }
mbed_official 324:406fd2029f23 564
mbed_official 324:406fd2029f23 565 /*!
mbed_official 324:406fd2029f23 566 * @brief Sets the Rx frame size.
mbed_official 324:406fd2029f23 567 *
mbed_official 324:406fd2029f23 568 * The frame size means how many words are in a frame. For example 2-channel
mbed_official 324:406fd2029f23 569 * audio data, the frame size is 2, which means 2 words in a frame.
mbed_official 324:406fd2029f23 570 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 571 * @param size Words number in a frame.
mbed_official 146:f64d43ff0c18 572 */
mbed_official 324:406fd2029f23 573 static inline void SAI_HAL_RxSetFrameSize(uint32_t saiBaseAddr, uint32_t size)
mbed_official 324:406fd2029f23 574 {
mbed_official 324:406fd2029f23 575 BW_I2S_RCR4_FRSZ(saiBaseAddr,size - 1);
mbed_official 324:406fd2029f23 576 }
mbed_official 324:406fd2029f23 577
mbed_official 324:406fd2029f23 578 /*!
mbed_official 324:406fd2029f23 579 * @brief Gets the Tx frame size.
mbed_official 324:406fd2029f23 580 *
mbed_official 324:406fd2029f23 581 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 582 */
mbed_official 324:406fd2029f23 583 static inline uint32_t SAI_HAL_TxGetFrameSize(uint32_t saiBaseAddr)
mbed_official 146:f64d43ff0c18 584 {
mbed_official 324:406fd2029f23 585 return BR_I2S_TCR4_FRSZ(saiBaseAddr);
mbed_official 324:406fd2029f23 586 }
mbed_official 324:406fd2029f23 587
mbed_official 324:406fd2029f23 588 /*!
mbed_official 324:406fd2029f23 589 * @brief Gets the Tx frame size.
mbed_official 324:406fd2029f23 590 *
mbed_official 324:406fd2029f23 591 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 592 */
mbed_official 324:406fd2029f23 593 static inline uint32_t SAI_HAL_RxGetFrameSize(uint32_t saiBaseAddr)
mbed_official 324:406fd2029f23 594 {
mbed_official 324:406fd2029f23 595 return BR_I2S_RCR4_FRSZ(saiBaseAddr);
mbed_official 324:406fd2029f23 596 }
mbed_official 324:406fd2029f23 597
mbed_official 324:406fd2029f23 598 /*!
mbed_official 324:406fd2029f23 599 * @brief Sets the Tx sync width.
mbed_official 324:406fd2029f23 600 *
mbed_official 324:406fd2029f23 601 * A sync is the number of bit clocks of a frame. The sync width cannot be longer than the
mbed_official 324:406fd2029f23 602 * length of the first word of the frame.
mbed_official 324:406fd2029f23 603 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 604 * @param width How many bit clock in a sync.
mbed_official 324:406fd2029f23 605 */
mbed_official 324:406fd2029f23 606 static inline void SAI_HAL_TxSetFrameSyncWidth(uint32_t saiBaseAddr, uint32_t width)
mbed_official 324:406fd2029f23 607 {
mbed_official 324:406fd2029f23 608 BW_I2S_TCR4_SYWD(saiBaseAddr, width -1);
mbed_official 146:f64d43ff0c18 609 }
mbed_official 146:f64d43ff0c18 610
mbed_official 146:f64d43ff0c18 611 /*!
mbed_official 324:406fd2029f23 612 * @brief Sets the Rx sync width.
mbed_official 324:406fd2029f23 613 *
mbed_official 324:406fd2029f23 614 * A sync is the number of bit clocks of a frame. The sync width cannot be longer than the
mbed_official 324:406fd2029f23 615 * length of the first word of the frame.
mbed_official 324:406fd2029f23 616 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 617 * @param width How many bit clock in a sync.
mbed_official 324:406fd2029f23 618 */
mbed_official 324:406fd2029f23 619 static inline void SAI_HAL_RxSetFrameSyncWidth(uint32_t saiBaseAddr, uint32_t width)
mbed_official 324:406fd2029f23 620 {
mbed_official 324:406fd2029f23 621 BW_I2S_RCR4_SYWD(saiBaseAddr, width -1);
mbed_official 324:406fd2029f23 622 }
mbed_official 324:406fd2029f23 623
mbed_official 324:406fd2029f23 624 /*!
mbed_official 324:406fd2029f23 625 * @brief Sets the polarity of the Tx frame sync.
mbed_official 324:406fd2029f23 626 *
mbed_official 324:406fd2029f23 627 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 628 * @param pol Polarity of sai frame sync, can be configured to active high or low.
mbed_official 324:406fd2029f23 629 */
mbed_official 324:406fd2029f23 630 static inline void SAI_HAL_TxSetFrameSyncPolarity(uint32_t saiBaseAddr, sai_clk_polarity_t pol)
mbed_official 324:406fd2029f23 631 {
mbed_official 324:406fd2029f23 632 BW_I2S_TCR4_FSP(saiBaseAddr,pol);
mbed_official 324:406fd2029f23 633 }
mbed_official 324:406fd2029f23 634
mbed_official 324:406fd2029f23 635 /*!
mbed_official 324:406fd2029f23 636 * @brief Sets the polarity of the Rx frame sync.
mbed_official 146:f64d43ff0c18 637 *
mbed_official 324:406fd2029f23 638 * @param saiBaseAddr Register base address of SAI module..
mbed_official 324:406fd2029f23 639 * @param pol Polarity of SAI frame sync, can be configured to active high or low.
mbed_official 324:406fd2029f23 640 */
mbed_official 324:406fd2029f23 641 static inline void SAI_HAL_RxSetFrameSyncPolarity(uint32_t saiBaseAddr, sai_clk_polarity_t pol)
mbed_official 324:406fd2029f23 642 {
mbed_official 324:406fd2029f23 643 BW_I2S_RCR4_FSP(saiBaseAddr,pol);
mbed_official 324:406fd2029f23 644 }
mbed_official 324:406fd2029f23 645
mbed_official 324:406fd2029f23 646 /*!
mbed_official 324:406fd2029f23 647 * @brief Sets the direction of the SAI Tx frame sync.
mbed_official 324:406fd2029f23 648 *
mbed_official 324:406fd2029f23 649 * This function sets the direction of frame sync.
mbed_official 324:406fd2029f23 650 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 651 * @param direction Frame sync generated internal or external.
mbed_official 146:f64d43ff0c18 652 */
mbed_official 324:406fd2029f23 653 static inline void SAI_HAL_TxSetFrameSyncDir(uint32_t saiBaseAddr,sai_clk_direction_t direction)
mbed_official 146:f64d43ff0c18 654 {
mbed_official 324:406fd2029f23 655 BW_I2S_TCR4_FSD(saiBaseAddr,direction);
mbed_official 324:406fd2029f23 656 }
mbed_official 324:406fd2029f23 657
mbed_official 324:406fd2029f23 658 /*!
mbed_official 324:406fd2029f23 659 * @brief Sets the direction of the SAI Rx frame sync.
mbed_official 324:406fd2029f23 660 *
mbed_official 324:406fd2029f23 661 * This function sets the direction of frame sync.
mbed_official 324:406fd2029f23 662 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 663 * @param direction Frame sync generated internal or external.
mbed_official 324:406fd2029f23 664 */
mbed_official 324:406fd2029f23 665 static inline void SAI_HAL_RxSetFrameSyncDir(uint32_t saiBaseAddr,sai_clk_direction_t direction)
mbed_official 324:406fd2029f23 666 {
mbed_official 324:406fd2029f23 667 BW_I2S_RCR4_FSD(saiBaseAddr,direction);
mbed_official 146:f64d43ff0c18 668 }
mbed_official 146:f64d43ff0c18 669
mbed_official 146:f64d43ff0c18 670 /*!
mbed_official 324:406fd2029f23 671 * @brief Sets the Tx data transfer order.
mbed_official 146:f64d43ff0c18 672 *
mbed_official 324:406fd2029f23 673 * This function sets the data transfer order. It can be set to MSB first or LSB first.
mbed_official 324:406fd2029f23 674 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 675 * @param order MSB transmit first or LSB transmit first.
mbed_official 146:f64d43ff0c18 676 */
mbed_official 324:406fd2029f23 677 static inline void SAI_HAL_TxSetBitOrder(uint32_t saiBaseAddr, sai_data_order_t order)
mbed_official 146:f64d43ff0c18 678 {
mbed_official 324:406fd2029f23 679 BW_I2S_TCR4_MF(saiBaseAddr,order);
mbed_official 324:406fd2029f23 680 }
mbed_official 324:406fd2029f23 681
mbed_official 324:406fd2029f23 682 /*!
mbed_official 324:406fd2029f23 683 * @brief Sets the Rx data transfer order.
mbed_official 324:406fd2029f23 684 *
mbed_official 324:406fd2029f23 685 * This function sets the data transfer order. It can be set to MSB first or LSB first.
mbed_official 324:406fd2029f23 686 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 687 * @param order MSB transmit first or LSB transmit first.
mbed_official 324:406fd2029f23 688 */
mbed_official 324:406fd2029f23 689 static inline void SAI_HAL_RxSetBitOrder(uint32_t saiBaseAddr, sai_data_order_t order)
mbed_official 324:406fd2029f23 690 {
mbed_official 324:406fd2029f23 691 BW_I2S_RCR4_MF(saiBaseAddr,order);
mbed_official 146:f64d43ff0c18 692 }
mbed_official 146:f64d43ff0c18 693
mbed_official 146:f64d43ff0c18 694 /*!
mbed_official 324:406fd2029f23 695 * @brief Tx Frame sync one bit early.
mbed_official 324:406fd2029f23 696 *
mbed_official 324:406fd2029f23 697 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 698 * @param enable True means the frame sync one bit early and false means no early.
mbed_official 324:406fd2029f23 699 */
mbed_official 324:406fd2029f23 700 static inline void SAI_HAL_TxSetFrameSyncEarlyCmd(uint32_t saiBaseAddr, bool enable)
mbed_official 324:406fd2029f23 701 {
mbed_official 324:406fd2029f23 702 BW_I2S_TCR4_FSE(saiBaseAddr,enable);
mbed_official 324:406fd2029f23 703 }
mbed_official 324:406fd2029f23 704
mbed_official 324:406fd2029f23 705 /*!
mbed_official 324:406fd2029f23 706 * @brief Rx Frame sync one bit early.
mbed_official 324:406fd2029f23 707 *
mbed_official 324:406fd2029f23 708 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 709 * @param enable True means the frame sync one bit early and false means no early.
mbed_official 324:406fd2029f23 710 */
mbed_official 324:406fd2029f23 711 static inline void SAI_HAL_RxSetFrameSyncEarlyCmd(uint32_t saiBaseAddr, bool enable)
mbed_official 324:406fd2029f23 712 {
mbed_official 324:406fd2029f23 713 BW_I2S_RCR4_FSE(saiBaseAddr,enable);
mbed_official 324:406fd2029f23 714 }
mbed_official 324:406fd2029f23 715
mbed_official 324:406fd2029f23 716 /*! @} */
mbed_official 324:406fd2029f23 717
mbed_official 324:406fd2029f23 718 /*!
mbed_official 324:406fd2029f23 719 * @name Word configurations
mbed_official 324:406fd2029f23 720 * @{
mbed_official 324:406fd2029f23 721 */
mbed_official 324:406fd2029f23 722
mbed_official 324:406fd2029f23 723 /*!
mbed_official 324:406fd2029f23 724 * @brief Sets the word size for Tx.
mbed_official 146:f64d43ff0c18 725 *
mbed_official 146:f64d43ff0c18 726 * The word size means the quantization level of audio file.
mbed_official 324:406fd2029f23 727 * SAI supports the 8 bit, 16 bit, 24 bit, and 32 bit formats.
mbed_official 324:406fd2029f23 728 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 729 * @param bits How many bits in a word.
mbed_official 146:f64d43ff0c18 730 */
mbed_official 324:406fd2029f23 731 static inline void SAI_HAL_TxSetWordSize(uint32_t saiBaseAddr,uint32_t bits)
mbed_official 146:f64d43ff0c18 732 {
mbed_official 324:406fd2029f23 733 BW_I2S_TCR5_WNW(saiBaseAddr,bits-1);
mbed_official 146:f64d43ff0c18 734 }
mbed_official 146:f64d43ff0c18 735
mbed_official 146:f64d43ff0c18 736 /*!
mbed_official 146:f64d43ff0c18 737 * @brief Sets the word size for Rx.
mbed_official 146:f64d43ff0c18 738 *
mbed_official 324:406fd2029f23 739 * The word size means the quantization level of audio file.
mbed_official 324:406fd2029f23 740 * SAI supports 8 bit, 16 bit, 24 bit, and 32 bit formats.
mbed_official 324:406fd2029f23 741 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 742 * @param bits How many bits in a word.
mbed_official 324:406fd2029f23 743 */
mbed_official 324:406fd2029f23 744 static inline void SAI_HAL_RxSetWordSize(uint32_t saiBaseAddr,uint32_t bits)
mbed_official 146:f64d43ff0c18 745 {
mbed_official 324:406fd2029f23 746 BW_I2S_RCR5_WNW(saiBaseAddr,bits-1);
mbed_official 324:406fd2029f23 747 }
mbed_official 324:406fd2029f23 748
mbed_official 324:406fd2029f23 749 /*!
mbed_official 324:406fd2029f23 750 * @brief Gets the Tx word size.
mbed_official 324:406fd2029f23 751 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 752 */
mbed_official 324:406fd2029f23 753 static inline uint32_t SAI_HAL_TxGetWordSize(uint32_t saiBaseAddr)
mbed_official 324:406fd2029f23 754 {
mbed_official 324:406fd2029f23 755 return BR_I2S_TCR5_WNW(saiBaseAddr);
mbed_official 146:f64d43ff0c18 756 }
mbed_official 146:f64d43ff0c18 757
mbed_official 146:f64d43ff0c18 758 /*!
mbed_official 324:406fd2029f23 759 * @brief Gets the Rx word size.
mbed_official 324:406fd2029f23 760 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 761 */
mbed_official 324:406fd2029f23 762 static inline uint32_t SAI_HAL_RxGetWordSize(uint32_t saiBaseAddr)
mbed_official 146:f64d43ff0c18 763 {
mbed_official 324:406fd2029f23 764 return BR_I2S_RCR5_WNW(saiBaseAddr);
mbed_official 146:f64d43ff0c18 765 }
mbed_official 146:f64d43ff0c18 766
mbed_official 146:f64d43ff0c18 767 /*!
mbed_official 324:406fd2029f23 768 * @brief Sets the size of the first word of the Tx frame .
mbed_official 146:f64d43ff0c18 769 *
mbed_official 146:f64d43ff0c18 770 * In I2S protocol, the size of the first word is the same as the size of other words. In some protocols,
mbed_official 324:406fd2029f23 771 * for example, AC'97, the first word is not the same size as others. This function
mbed_official 324:406fd2029f23 772 * sets the length of the first word which is, in most situations, the same as others.
mbed_official 324:406fd2029f23 773 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 774 * @param size The length of frame head word.
mbed_official 146:f64d43ff0c18 775 */
mbed_official 324:406fd2029f23 776 static inline void SAI_HAL_TxSetFirstWordSize(uint32_t saiBaseAddr, uint8_t size)
mbed_official 146:f64d43ff0c18 777 {
mbed_official 324:406fd2029f23 778 BW_I2S_TCR5_W0W(saiBaseAddr, size-1);
mbed_official 324:406fd2029f23 779 }
mbed_official 324:406fd2029f23 780
mbed_official 324:406fd2029f23 781 /*!
mbed_official 324:406fd2029f23 782 * @brief Sets the size of the first word of Rx frame .
mbed_official 324:406fd2029f23 783 *
mbed_official 324:406fd2029f23 784 * In I2S protocol, the size of the first word is the same as the size of other words. In some protocols,
mbed_official 324:406fd2029f23 785 * for example, AC'97, the first word is not the same size as others. This function
mbed_official 324:406fd2029f23 786 * sets the length of the first word which is, in most situations, the same as others.
mbed_official 324:406fd2029f23 787 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 788 * @param size The length of frame head word.
mbed_official 324:406fd2029f23 789 */
mbed_official 324:406fd2029f23 790 static inline void SAI_HAL_RxSetFirstWordSize(uint32_t saiBaseAddr, uint8_t size)
mbed_official 324:406fd2029f23 791 {
mbed_official 324:406fd2029f23 792 BW_I2S_RCR5_W0W(saiBaseAddr, size-1);
mbed_official 146:f64d43ff0c18 793 }
mbed_official 146:f64d43ff0c18 794
mbed_official 146:f64d43ff0c18 795 /*!
mbed_official 324:406fd2029f23 796 * @brief Sets the FIFO index for the first bit data.
mbed_official 146:f64d43ff0c18 797 *
mbed_official 324:406fd2029f23 798 * The FIFO is 32-bit in SAI. However, not all audio data is 32-bit, but is mostly 16-bit.
mbed_official 324:406fd2029f23 799 * In this situation, the codec needs to know which bit of the FIFO marks the valid audio data.
mbed_official 324:406fd2029f23 800 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 801 * @param index First bit shifted in FIFO.
mbed_official 146:f64d43ff0c18 802 */
mbed_official 324:406fd2029f23 803 static inline void SAI_HAL_TxSetFirstBitShifted(uint32_t saiBaseAddr, uint32_t index)
mbed_official 146:f64d43ff0c18 804 {
mbed_official 324:406fd2029f23 805 BW_I2S_TCR5_FBT(saiBaseAddr, index-1);
mbed_official 146:f64d43ff0c18 806 }
mbed_official 146:f64d43ff0c18 807
mbed_official 146:f64d43ff0c18 808 /*!
mbed_official 324:406fd2029f23 809 * @brief Sets the index in FIFO for the first bit data.
mbed_official 146:f64d43ff0c18 810 *
mbed_official 324:406fd2029f23 811 * The FIFO is 32-bit in SAI. However, not all audio data is 32-bit, but is mostly 16-bit.
mbed_official 324:406fd2029f23 812 * In this situation, the codec needs to know which bit of the FIFO marks the valid audio data.
mbed_official 324:406fd2029f23 813 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 814 * @param index First bit shifted in FIFO.
mbed_official 146:f64d43ff0c18 815 */
mbed_official 324:406fd2029f23 816 static inline void SAI_HAL_RxSetFirstBitShifted(uint32_t saiBaseAddr, uint32_t index)
mbed_official 146:f64d43ff0c18 817 {
mbed_official 324:406fd2029f23 818 BW_I2S_RCR5_FBT(saiBaseAddr, index-1);
mbed_official 324:406fd2029f23 819 }
mbed_official 324:406fd2029f23 820
mbed_official 324:406fd2029f23 821 /*!@}*/
mbed_official 324:406fd2029f23 822
mbed_official 324:406fd2029f23 823 /*!
mbed_official 324:406fd2029f23 824 * @name watermark settings
mbed_official 324:406fd2029f23 825 * @{
mbed_official 324:406fd2029f23 826 */
mbed_official 324:406fd2029f23 827
mbed_official 324:406fd2029f23 828 /*!
mbed_official 324:406fd2029f23 829 * @brief Sets the Tx watermark value.
mbed_official 324:406fd2029f23 830 *
mbed_official 324:406fd2029f23 831 * While the value in the FIFO is less or equal to the watermark , it generates an interrupt
mbed_official 324:406fd2029f23 832 * request or a DMA request. The watermark value cannot be greater than the depth of FIFO.
mbed_official 324:406fd2029f23 833 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 834 * @param watermark Watermark value of a FIFO.
mbed_official 324:406fd2029f23 835 */
mbed_official 324:406fd2029f23 836 static inline void SAI_HAL_TxSetWatermark(uint32_t saiBaseAddr, uint32_t watermark)
mbed_official 324:406fd2029f23 837 {
mbed_official 324:406fd2029f23 838 BW_I2S_TCR1_TFW(saiBaseAddr, watermark);
mbed_official 146:f64d43ff0c18 839 }
mbed_official 146:f64d43ff0c18 840
mbed_official 146:f64d43ff0c18 841 /*!
mbed_official 324:406fd2029f23 842 * @brief Sets the Tx watermark value.
mbed_official 146:f64d43ff0c18 843 *
mbed_official 324:406fd2029f23 844 * While the value in the FIFO is more or equal to the watermark , it generates an interrupt
mbed_official 146:f64d43ff0c18 845 * request or a DMA request. The watermark value cannot be greater than the depth of FIFO.
mbed_official 324:406fd2029f23 846 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 847 * @param watermark Watermark value of a FIFO.
mbed_official 146:f64d43ff0c18 848 */
mbed_official 324:406fd2029f23 849 static inline void SAI_HAL_RxSetWatermark(uint32_t saiBaseAddr, uint32_t watermark)
mbed_official 146:f64d43ff0c18 850 {
mbed_official 324:406fd2029f23 851 BW_I2S_RCR1_RFW(saiBaseAddr, watermark);
mbed_official 146:f64d43ff0c18 852 }
mbed_official 146:f64d43ff0c18 853
mbed_official 146:f64d43ff0c18 854 /*!
mbed_official 324:406fd2029f23 855 * @brief Gets the Tx watermark value.
mbed_official 146:f64d43ff0c18 856 *
mbed_official 324:406fd2029f23 857 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 858 */
mbed_official 324:406fd2029f23 859 static inline uint32_t SAI_HAL_TxGetWatermark(uint32_t saiBaseAddr)
mbed_official 146:f64d43ff0c18 860 {
mbed_official 324:406fd2029f23 861 return BR_I2S_TCR1_TFW(saiBaseAddr);
mbed_official 146:f64d43ff0c18 862 }
mbed_official 146:f64d43ff0c18 863
mbed_official 146:f64d43ff0c18 864 /*!
mbed_official 324:406fd2029f23 865 * @brief Gets the Rx watermark value.
mbed_official 146:f64d43ff0c18 866 *
mbed_official 324:406fd2029f23 867 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 868 */
mbed_official 324:406fd2029f23 869 static inline uint32_t SAI_HAL_RxGetWatermark(uint32_t saiBaseAddr)
mbed_official 324:406fd2029f23 870 {
mbed_official 324:406fd2029f23 871 return BR_I2S_RCR1_RFW(saiBaseAddr);
mbed_official 324:406fd2029f23 872 }
mbed_official 324:406fd2029f23 873
mbed_official 324:406fd2029f23 874 /*! @}*/
mbed_official 146:f64d43ff0c18 875
mbed_official 146:f64d43ff0c18 876 /*!
mbed_official 324:406fd2029f23 877 * @brief SAI Tx sync mode setting.
mbed_official 146:f64d43ff0c18 878 *
mbed_official 324:406fd2029f23 879 * The mode can be asynchronous mode, synchronous, or synchronous with another SAI device.
mbed_official 324:406fd2029f23 880 * When configured for a synchronous mode of operation, the receiver must be configured for the
mbed_official 324:406fd2029f23 881 * asynchronous operation.
mbed_official 324:406fd2029f23 882 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 883 * @param sync_mode Synchronous mode or Asynchronous mode.
mbed_official 146:f64d43ff0c18 884 */
mbed_official 324:406fd2029f23 885 void SAI_HAL_TxSetSyncMode(uint32_t saiBaseAddr, sai_sync_mode_t sync_mode);
mbed_official 146:f64d43ff0c18 886
mbed_official 146:f64d43ff0c18 887 /*!
mbed_official 324:406fd2029f23 888 * @brief SAI Rx sync mode setting.
mbed_official 146:f64d43ff0c18 889 *
mbed_official 146:f64d43ff0c18 890 * The mode can be asynchronous mode, synchronous, or synchronous with another SAI device.
mbed_official 324:406fd2029f23 891 * When configured for a synchronous mode of operation, the receiver must be configured for the
mbed_official 324:406fd2029f23 892 * asynchronous operation.
mbed_official 324:406fd2029f23 893 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 894 * @param sync_mode Synchronous mode or Asynchronous mode.
mbed_official 146:f64d43ff0c18 895 */
mbed_official 324:406fd2029f23 896 void SAI_HAL_RxSetSyncMode(uint32_t saiBaseAddr, sai_sync_mode_t sync_mode);
mbed_official 146:f64d43ff0c18 897
mbed_official 146:f64d43ff0c18 898 /*!
mbed_official 324:406fd2029f23 899 * @brief Gets the Tx FIFO read pointer.
mbed_official 146:f64d43ff0c18 900 *
mbed_official 324:406fd2029f23 901 * It is used to determine whether the FIFO is full or empty and know how much space there is for FIFO.
mbed_official 324:406fd2029f23 902 * If read_ptr == write_ptr, the FIFO is empty. While the bit of the read_ptr and the write_ptr are
mbed_official 324:406fd2029f23 903 * equal except for the MSB, the FIFO is full.
mbed_official 324:406fd2029f23 904 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 905 * @param fifo_channel FIFO channel selected.
mbed_official 324:406fd2029f23 906 * @return FIFO read pointer value.
mbed_official 146:f64d43ff0c18 907 */
mbed_official 324:406fd2029f23 908 static inline uint8_t SAI_HAL_TxGetFifoReadPointer(uint32_t saiBaseAddr, uint32_t fifo_channel)
mbed_official 324:406fd2029f23 909 {
mbed_official 324:406fd2029f23 910 return BR_I2S_TFRn_RFP(saiBaseAddr,fifo_channel);
mbed_official 324:406fd2029f23 911 }
mbed_official 146:f64d43ff0c18 912
mbed_official 146:f64d43ff0c18 913 /*!
mbed_official 324:406fd2029f23 914 * @brief Gets the Rx FIFO read pointer.
mbed_official 146:f64d43ff0c18 915 *
mbed_official 324:406fd2029f23 916 * It is used to determine whether the FIFO is full or empty and know how much space there is for FIFO.
mbed_official 146:f64d43ff0c18 917 * 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 918 * equal except for the MSB, the FIFO is full.
mbed_official 324:406fd2029f23 919 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 920 * @param fifo_channel FIFO channel selected.
mbed_official 324:406fd2029f23 921 * @return FIFO read pointer value.
mbed_official 324:406fd2029f23 922 */
mbed_official 324:406fd2029f23 923 static inline uint8_t SAI_HAL_RxGetFifoReadPointer(uint32_t saiBaseAddr, uint32_t fifo_channel)
mbed_official 324:406fd2029f23 924 {
mbed_official 324:406fd2029f23 925 return BR_I2S_RFRn_RFP(saiBaseAddr,fifo_channel);
mbed_official 324:406fd2029f23 926 }
mbed_official 324:406fd2029f23 927
mbed_official 324:406fd2029f23 928 /*!
mbed_official 324:406fd2029f23 929 * @brief Gets the Tx FIFO write pointer.
mbed_official 324:406fd2029f23 930 *
mbed_official 324:406fd2029f23 931 * It is used to determine whether the FIFO is full or empty and know how much space there is for FIFO.
mbed_official 324:406fd2029f23 932 * If read_ptr == write_ptr, the FIFO is empty. While the bit of the read_ptr and write_ptr are
mbed_official 324:406fd2029f23 933 * equal except for the MSB, the FIFO is full.
mbed_official 324:406fd2029f23 934 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 935 * @param fifo_channel FIFO channel selected.
mbed_official 146:f64d43ff0c18 936 * @return FIFO read pointer value.
mbed_official 146:f64d43ff0c18 937 */
mbed_official 324:406fd2029f23 938 static inline uint8_t SAI_HAL_TxGetFifoWritePointer(uint32_t saiBaseAddr,uint32_t fifo_channel)
mbed_official 324:406fd2029f23 939 {
mbed_official 324:406fd2029f23 940 return BR_I2S_TFRn_WFP(saiBaseAddr,fifo_channel);
mbed_official 324:406fd2029f23 941 }
mbed_official 146:f64d43ff0c18 942
mbed_official 146:f64d43ff0c18 943 /*!
mbed_official 324:406fd2029f23 944 * @brief Gets the Rx FIFO write pointer.
mbed_official 146:f64d43ff0c18 945 *
mbed_official 324:406fd2029f23 946 * It is used to determine whether the FIFO is full or empty and know how much space there is for FIFO.
mbed_official 324:406fd2029f23 947 * If read_ptr == write_ptr, the FIFO is empty. While the bit of the read_ptr and write_ptr are
mbed_official 146:f64d43ff0c18 948 * equal except for the MSB, the FIFO is full.
mbed_official 324:406fd2029f23 949 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 950 * @param fifo_channel FIFO channel selected.
mbed_official 324:406fd2029f23 951 * @return FIFO read pointer value.
mbed_official 146:f64d43ff0c18 952 */
mbed_official 324:406fd2029f23 953 static inline uint8_t SAI_HAL_RxGetFifoWritePointer(uint32_t saiBaseAddr,uint32_t fifo_channel)
mbed_official 324:406fd2029f23 954 {
mbed_official 324:406fd2029f23 955 return BR_I2S_RFRn_WFP(saiBaseAddr,fifo_channel);
mbed_official 324:406fd2029f23 956 }
mbed_official 146:f64d43ff0c18 957
mbed_official 146:f64d43ff0c18 958 /*!
mbed_official 324:406fd2029f23 959 * @brief Gets the TDR register address.
mbed_official 146:f64d43ff0c18 960 *
mbed_official 324:406fd2029f23 961 * This function determines the dest/src address of the DMA transfer.
mbed_official 324:406fd2029f23 962 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 963 * @param fifo_channel FIFO channel selected.
mbed_official 146:f64d43ff0c18 964 * @return TDR register or RDR register address
mbed_official 146:f64d43ff0c18 965 */
mbed_official 324:406fd2029f23 966 static inline uint32_t* SAI_HAL_TxGetFifoAddr(uint32_t saiBaseAddr, uint32_t fifo_channel)
mbed_official 146:f64d43ff0c18 967 {
mbed_official 324:406fd2029f23 968 return (uint32_t *)HW_I2S_TDRn_ADDR(saiBaseAddr, fifo_channel);
mbed_official 146:f64d43ff0c18 969 }
mbed_official 146:f64d43ff0c18 970
mbed_official 146:f64d43ff0c18 971 /*!
mbed_official 324:406fd2029f23 972 * @brief Gets the RDR register address.
mbed_official 146:f64d43ff0c18 973 *
mbed_official 324:406fd2029f23 974 * This function determines the dest/src address of the DMA transfer.
mbed_official 324:406fd2029f23 975 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 976 * @param fifo_channel FIFO channel selected.
mbed_official 324:406fd2029f23 977 * @return TDR register or RDR register address
mbed_official 146:f64d43ff0c18 978 */
mbed_official 324:406fd2029f23 979 static inline uint32_t* SAI_HAL_RxGetFifoAddr(uint32_t saiBaseAddr, uint32_t fifo_channel)
mbed_official 146:f64d43ff0c18 980 {
mbed_official 324:406fd2029f23 981 return (uint32_t *)HW_I2S_RDRn_ADDR(saiBaseAddr, fifo_channel);
mbed_official 324:406fd2029f23 982 }
mbed_official 324:406fd2029f23 983
mbed_official 324:406fd2029f23 984 /*!
mbed_official 324:406fd2029f23 985 * @brief Enables the SAI Tx module.
mbed_official 324:406fd2029f23 986 *
mbed_official 324:406fd2029f23 987 * Enables the Tx. This function enables both the bit clock and the transfer channel.
mbed_official 324:406fd2029f23 988 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 989 */
mbed_official 324:406fd2029f23 990 static inline void SAI_HAL_TxEnable(uint32_t saiBaseAddr)
mbed_official 324:406fd2029f23 991 {
mbed_official 324:406fd2029f23 992 BW_I2S_TCSR_BCE(saiBaseAddr,true);
mbed_official 324:406fd2029f23 993 BW_I2S_TCSR_TE(saiBaseAddr,true);
mbed_official 146:f64d43ff0c18 994 }
mbed_official 146:f64d43ff0c18 995
mbed_official 146:f64d43ff0c18 996 /*!
mbed_official 324:406fd2029f23 997 * @brief Enables the SAI Rx module.
mbed_official 146:f64d43ff0c18 998 *
mbed_official 324:406fd2029f23 999 * Enables the Rx. This function enables both the bit clock and the receive channel.
mbed_official 324:406fd2029f23 1000 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 1001 */
mbed_official 324:406fd2029f23 1002 static inline void SAI_HAL_RxEnable(uint32_t saiBaseAddr)
mbed_official 146:f64d43ff0c18 1003 {
mbed_official 324:406fd2029f23 1004 BW_I2S_RCSR_BCE(saiBaseAddr,true);
mbed_official 324:406fd2029f23 1005 BW_I2S_RCSR_RE(saiBaseAddr,true);
mbed_official 146:f64d43ff0c18 1006 }
mbed_official 146:f64d43ff0c18 1007
mbed_official 146:f64d43ff0c18 1008 /*!
mbed_official 324:406fd2029f23 1009 * @brief Disables the Tx module.
mbed_official 146:f64d43ff0c18 1010 *
mbed_official 324:406fd2029f23 1011 * Disables the Tx. This function disables both the bit clock and the transfer channel.
mbed_official 324:406fd2029f23 1012 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 1013 */
mbed_official 324:406fd2029f23 1014 static inline void SAI_HAL_TxDisable(uint32_t saiBaseAddr)
mbed_official 146:f64d43ff0c18 1015 {
mbed_official 324:406fd2029f23 1016 BW_I2S_TCSR_TE(saiBaseAddr,false);
mbed_official 324:406fd2029f23 1017 BW_I2S_TCSR_BCE(saiBaseAddr,false);
mbed_official 324:406fd2029f23 1018 }
mbed_official 324:406fd2029f23 1019
mbed_official 324:406fd2029f23 1020 /*!
mbed_official 324:406fd2029f23 1021 * @brief Disables the Rx module.
mbed_official 324:406fd2029f23 1022 *
mbed_official 324:406fd2029f23 1023 * Disables the Rx. This function disables both the bit clock and the receive channel.
mbed_official 324:406fd2029f23 1024 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 1025 */
mbed_official 324:406fd2029f23 1026 static inline void SAI_HAL_RxDisable(uint32_t saiBaseAddr)
mbed_official 324:406fd2029f23 1027 {
mbed_official 324:406fd2029f23 1028 BW_I2S_RCSR_RE(saiBaseAddr,false);
mbed_official 324:406fd2029f23 1029 BW_I2S_RCSR_BCE(saiBaseAddr,false);
mbed_official 146:f64d43ff0c18 1030 }
mbed_official 146:f64d43ff0c18 1031
mbed_official 146:f64d43ff0c18 1032 /*!
mbed_official 146:f64d43ff0c18 1033 * @brief Enables the Tx interrupt from different interrupt sources.
mbed_official 146:f64d43ff0c18 1034 *
mbed_official 146:f64d43ff0c18 1035 * The interrupt source can be : Word start flag, Sync error flag, FIFO error flag, FIFO warning flag, FIFO request flag.
mbed_official 324:406fd2029f23 1036 * This function sets which flag causes an interrupt request.
mbed_official 324:406fd2029f23 1037 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 1038 * @param source SAI interrupt request source.
mbed_official 324:406fd2029f23 1039 * @param enable Enable or disable.
mbed_official 146:f64d43ff0c18 1040 */
mbed_official 324:406fd2029f23 1041 void SAI_HAL_TxSetIntCmd(uint32_t saiBaseAddr,sai_interrupt_request_t source, bool enable);
mbed_official 146:f64d43ff0c18 1042
mbed_official 146:f64d43ff0c18 1043 /*!
mbed_official 324:406fd2029f23 1044 * @brief Enables the Rx interrupt from different interrupt sources.
mbed_official 146:f64d43ff0c18 1045 *
mbed_official 146:f64d43ff0c18 1046 * The interrupt source can be : Word start flag, Sync error flag, FIFO error flag, FIFO warning flag, FIFO request flag.
mbed_official 324:406fd2029f23 1047 * This function sets which flag causes an interrupt request.
mbed_official 324:406fd2029f23 1048 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 1049 * @param source SAI interrupt request source.
mbed_official 324:406fd2029f23 1050 * @param enable Enable or disable.
mbed_official 146:f64d43ff0c18 1051 */
mbed_official 324:406fd2029f23 1052 void SAI_HAL_RxSetIntCmd(uint32_t saiBaseAddr,sai_interrupt_request_t source, bool enable);
mbed_official 146:f64d43ff0c18 1053
mbed_official 146:f64d43ff0c18 1054 /*!
mbed_official 324:406fd2029f23 1055 * @brief Gets the status as to whether the Tx interrupt source is enabled.
mbed_official 146:f64d43ff0c18 1056 *
mbed_official 324:406fd2029f23 1057 * The interrupt source can be : Word start flag, Sync error flag, FIFO error flag, FIFO warning flag, FIFO request flag.
mbed_official 324:406fd2029f23 1058 * This function sets which flag causes an interrupt request.
mbed_official 324:406fd2029f23 1059 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 1060 * @param source SAI interrupt request source.
mbed_official 324:406fd2029f23 1061 * @return Enabled or disabled.
mbed_official 146:f64d43ff0c18 1062 */
mbed_official 324:406fd2029f23 1063 bool SAI_HAL_TxGetIntCmd(uint32_t saiBaseAddr,sai_interrupt_request_t source);
mbed_official 146:f64d43ff0c18 1064
mbed_official 146:f64d43ff0c18 1065 /*!
mbed_official 324:406fd2029f23 1066 * @brief Gets the status as to whether the Rx interrupt source is enabled.
mbed_official 146:f64d43ff0c18 1067 *
mbed_official 324:406fd2029f23 1068 * The interrupt source can be : Word start flag, Sync error flag, FIFO error flag, FIFO warning flag, FIFO request flag.
mbed_official 324:406fd2029f23 1069 * This function sets which flag causes an interrupt request.
mbed_official 324:406fd2029f23 1070 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 1071 * @param source SAI interrupt request source.
mbed_official 324:406fd2029f23 1072 * @return Enabled or disabled.
mbed_official 146:f64d43ff0c18 1073 */
mbed_official 324:406fd2029f23 1074 bool SAI_HAL_RxGetIntCmd(uint32_t saiBaseAddr,sai_interrupt_request_t source);
mbed_official 146:f64d43ff0c18 1075
mbed_official 146:f64d43ff0c18 1076 /*!
mbed_official 146:f64d43ff0c18 1077 * @brief Enables the Tx DMA request from different sources.
mbed_official 146:f64d43ff0c18 1078 *
mbed_official 324:406fd2029f23 1079 * The DMA sources can be: FIFO warning and FIFO request.
mbed_official 324:406fd2029f23 1080 * This function enables the DMA request from different DMA request sources.
mbed_official 324:406fd2029f23 1081 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 1082 * @param source SAI DMA request source.
mbed_official 324:406fd2029f23 1083 * @param enable Enable or disable.
mbed_official 146:f64d43ff0c18 1084 */
mbed_official 324:406fd2029f23 1085 void SAI_HAL_TxSetDmaCmd(uint32_t saiBaseAddr, sai_dma_request_t source, bool enable);
mbed_official 146:f64d43ff0c18 1086
mbed_official 146:f64d43ff0c18 1087 /*!
mbed_official 146:f64d43ff0c18 1088 * @brief Enables the Rx DMA request from different sources.
mbed_official 146:f64d43ff0c18 1089 *
mbed_official 146:f64d43ff0c18 1090 * The DMA sources can be: FIFO warning and FIFO request.
mbed_official 324:406fd2029f23 1091 * This function enables the DMA request from different DMA request sources.
mbed_official 324:406fd2029f23 1092 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 1093 * @param source SAI DMA request source.
mbed_official 324:406fd2029f23 1094 * @param enable Enable or disable.
mbed_official 146:f64d43ff0c18 1095 */
mbed_official 324:406fd2029f23 1096 void SAI_HAL_RxSetDmaCmd(uint32_t saiBaseAddr, sai_dma_request_t source, bool enable);
mbed_official 146:f64d43ff0c18 1097
mbed_official 146:f64d43ff0c18 1098 /*!
mbed_official 324:406fd2029f23 1099 * @brief Gets the status whether the Tx DMA source is enabled.
mbed_official 146:f64d43ff0c18 1100 *
mbed_official 324:406fd2029f23 1101 * The DMA sources can be: FIFO warning and FIFO request.
mbed_official 324:406fd2029f23 1102 * This function enables the DMA request from different DMA request sources.
mbed_official 324:406fd2029f23 1103 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 1104 * @param source SAI DMA request source.
mbed_official 324:406fd2029f23 1105 * @param Enable or disable.
mbed_official 146:f64d43ff0c18 1106 */
mbed_official 324:406fd2029f23 1107 bool SAI_HAL_TxGetDmaCmd(uint32_t saiBaseAddr, sai_dma_request_t source);
mbed_official 146:f64d43ff0c18 1108
mbed_official 146:f64d43ff0c18 1109 /*!
mbed_official 324:406fd2029f23 1110 * @brief Gets the status whether the Rx DMA source is enabled.
mbed_official 146:f64d43ff0c18 1111 *
mbed_official 324:406fd2029f23 1112 * The DMA sources can be: FIFO warning and FIFO request.
mbed_official 324:406fd2029f23 1113 * This function enables the DMA request from different DMA request sources.
mbed_official 324:406fd2029f23 1114 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 1115 * @param source SAI DMA request source.
mbed_official 324:406fd2029f23 1116 * @return Enable or disable.
mbed_official 146:f64d43ff0c18 1117 */
mbed_official 324:406fd2029f23 1118 bool SAI_HAL_RxGetDmaCmd(uint32_t saiBaseAddr, sai_dma_request_t source);
mbed_official 146:f64d43ff0c18 1119
mbed_official 146:f64d43ff0c18 1120 /*!
mbed_official 146:f64d43ff0c18 1121 * @brief Clears the Tx state flags.
mbed_official 146:f64d43ff0c18 1122 *
mbed_official 324:406fd2029f23 1123 * The function is used to clear the flags manually. It can clear word start, FIFO warning, FIFO error,
mbed_official 146:f64d43ff0c18 1124 * FIFO request flag.
mbed_official 324:406fd2029f23 1125 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 1126 * @param flag SAI state flag type. The flag can be word start, sync error, FIFO error/warning.
mbed_official 146:f64d43ff0c18 1127 */
mbed_official 324:406fd2029f23 1128 void SAI_HAL_TxClearStateFlag(uint32_t saiBaseAddr, sai_state_flag_t flag);
mbed_official 146:f64d43ff0c18 1129
mbed_official 146:f64d43ff0c18 1130 /*!
mbed_official 324:406fd2029f23 1131 * @brief Clears the Rx state flags.
mbed_official 146:f64d43ff0c18 1132 *
mbed_official 324:406fd2029f23 1133 * The function is used to clear the flags manually. It can clear word start, FIFO warning, FIFO error,
mbed_official 146:f64d43ff0c18 1134 * FIFO request flag.
mbed_official 324:406fd2029f23 1135 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 1136 * @param flag SAI state flag type. The flag can be word start, sync error, FIFO error/warning.
mbed_official 146:f64d43ff0c18 1137 */
mbed_official 324:406fd2029f23 1138 void SAI_HAL_RxClearStateFlag(uint32_t saiBaseAddr, sai_state_flag_t flag);
mbed_official 146:f64d43ff0c18 1139
mbed_official 146:f64d43ff0c18 1140 /*!
mbed_official 324:406fd2029f23 1141 * @brief Resets the Tx module.
mbed_official 146:f64d43ff0c18 1142 *
mbed_official 324:406fd2029f23 1143 * There are two kinds of resets: Software reset and FIFO reset.
mbed_official 324:406fd2029f23 1144 * Software reset: resets all transmitter internal logic, including the bit clock generation,
mbed_official 324:406fd2029f23 1145 * status flags and FIFO pointers. It does not reset the configuration registers.
mbed_official 324:406fd2029f23 1146 * FIFO reset: synchronizes the FIFO write pointer to the same value as the FIFO read pointer.
mbed_official 324:406fd2029f23 1147 * This empties the FIFO contents and is to be used after the Transmit FIFO Error Flag is set,
mbed_official 324:406fd2029f23 1148 * and before the FIFO is re-initialized and the Error Flag is cleared.
mbed_official 324:406fd2029f23 1149 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 1150 * @param type SAI reset type.
mbed_official 146:f64d43ff0c18 1151 */
mbed_official 324:406fd2029f23 1152 void SAI_HAL_TxSetReset(uint32_t saiBaseAddr, sai_reset_type_t type);
mbed_official 146:f64d43ff0c18 1153
mbed_official 146:f64d43ff0c18 1154 /*!
mbed_official 324:406fd2029f23 1155 * @brief Resets the Rx module.
mbed_official 324:406fd2029f23 1156 *
mbed_official 324:406fd2029f23 1157 * There are two kinds of resets: Software reset and FIFO reset.
mbed_official 324:406fd2029f23 1158 * Software reset: resets all transmitter internal logic, including the bit clock generation,
mbed_official 324:406fd2029f23 1159 * status flags and FIFO pointers. It does not reset the configuration registers.
mbed_official 324:406fd2029f23 1160 * FIFO reset: synchronizes the FIFO write pointer to the same value as the FIFO read pointer.
mbed_official 324:406fd2029f23 1161 * This empties the FIFO contents and is to be used after the Transmit FIFO Error Flag is set,
mbed_official 324:406fd2029f23 1162 * and before the FIFO is re-initialized and the Error Flag is cleared.
mbed_official 324:406fd2029f23 1163 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 1164 * @param type SAI reset type.
mbed_official 146:f64d43ff0c18 1165 */
mbed_official 324:406fd2029f23 1166 void SAI_HAL_RxSetReset(uint32_t saiBaseAddr, sai_reset_type_t type);
mbed_official 146:f64d43ff0c18 1167
mbed_official 146:f64d43ff0c18 1168 /*!
mbed_official 324:406fd2029f23 1169 * @brief Sets the Tx mask word of the frame.
mbed_official 146:f64d43ff0c18 1170 *
mbed_official 324:406fd2029f23 1171 * Each bit number represent the mask word index. For example, 0 represents mask the 0th word, 3
mbed_official 324:406fd2029f23 1172 * represents mask 0th and 1st word. The TMR register can be different from frame to frame. If the
mbed_official 324:406fd2029f23 1173 * user wants a mono audio, set the mask to 0/1.
mbed_official 324:406fd2029f23 1174 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 1175 * @param mask Which bits need to be masked in a frame.
mbed_official 146:f64d43ff0c18 1176 */
mbed_official 324:406fd2029f23 1177 static inline void SAI_HAL_TxSetWordMask(uint32_t saiBaseAddr, uint32_t mask)
mbed_official 146:f64d43ff0c18 1178 {
mbed_official 324:406fd2029f23 1179 BW_I2S_TMR_TWM(saiBaseAddr, mask);
mbed_official 146:f64d43ff0c18 1180 }
mbed_official 146:f64d43ff0c18 1181
mbed_official 146:f64d43ff0c18 1182 /*!
mbed_official 324:406fd2029f23 1183 * @brief Sets the Rx mask word of the frame.
mbed_official 324:406fd2029f23 1184 *
mbed_official 324:406fd2029f23 1185 * Each bit number represent the mask word index. For example, 0 represents mask the 0th word, 3
mbed_official 324:406fd2029f23 1186 * represents mask 0th and 1st word. The TMR register can be different from frame to frame. If the
mbed_official 324:406fd2029f23 1187 * user wants a mono audio, set the mask to 0/1.
mbed_official 324:406fd2029f23 1188 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 1189 * @param mask Which bits need to be masked in a frame.
mbed_official 146:f64d43ff0c18 1190 */
mbed_official 324:406fd2029f23 1191 static inline void SAI_HAL_RxSetWordMask(uint32_t saiBaseAddr, uint32_t mask)
mbed_official 146:f64d43ff0c18 1192 {
mbed_official 324:406fd2029f23 1193 BW_I2S_RMR_RWM(saiBaseAddr, mask);
mbed_official 146:f64d43ff0c18 1194 }
mbed_official 146:f64d43ff0c18 1195
mbed_official 146:f64d43ff0c18 1196 /*!
mbed_official 324:406fd2029f23 1197 * @brief Sets the Tx FIFO channel.
mbed_official 146:f64d43ff0c18 1198 *
mbed_official 324:406fd2029f23 1199 * A SAI saiBaseAddr includes a Tx and an Rx. Each has several channels according to
mbed_official 146:f64d43ff0c18 1200 * different platforms. A channel means a path for the audio data input/output.
mbed_official 324:406fd2029f23 1201 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 1202 * @param fifo_channel FIFO channel number.
mbed_official 146:f64d43ff0c18 1203 */
mbed_official 324:406fd2029f23 1204 static inline void SAI_HAL_TxSetDataChn(uint32_t saiBaseAddr, uint8_t fifo_channel)
mbed_official 146:f64d43ff0c18 1205 {
mbed_official 324:406fd2029f23 1206 BW_I2S_TCR3_TCE(saiBaseAddr, 1u << fifo_channel);
mbed_official 146:f64d43ff0c18 1207 }
mbed_official 146:f64d43ff0c18 1208
mbed_official 146:f64d43ff0c18 1209 /*!
mbed_official 146:f64d43ff0c18 1210 * @brief Sets the Rx FIFO channel.
mbed_official 324:406fd2029f23 1211 *
mbed_official 324:406fd2029f23 1212 * A SAI saiBaseAddr includes a Tx and a Rx. Each has several channels according to
mbed_official 324:406fd2029f23 1213 * different platforms. A channel means a path for the audio data input/output.
mbed_official 324:406fd2029f23 1214 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 1215 * @param fifo_channel FIFO channel number.
mbed_official 146:f64d43ff0c18 1216 */
mbed_official 324:406fd2029f23 1217 static inline void SAI_HAL_RxSetDataChn(uint32_t saiBaseAddr, uint8_t fifo_channel)
mbed_official 146:f64d43ff0c18 1218 {
mbed_official 324:406fd2029f23 1219 BW_I2S_RCR3_RCE(saiBaseAddr, 1u << fifo_channel);
mbed_official 146:f64d43ff0c18 1220 }
mbed_official 146:f64d43ff0c18 1221
mbed_official 146:f64d43ff0c18 1222 /*!
mbed_official 324:406fd2029f23 1223 * @brief Sets the running mode of the Tx. There is a debug mode, stop mode, and a normal mode.
mbed_official 146:f64d43ff0c18 1224 *
mbed_official 324:406fd2029f23 1225 * This function can set the working mode of the SAI saiBaseAddr. Stop mode is always
mbed_official 324:406fd2029f23 1226 * used in low power cases, and the debug mode disables the SAI after the current
mbed_official 324:406fd2029f23 1227 * transmit/receive is completed.
mbed_official 324:406fd2029f23 1228 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 1229 * @param run_mode SAI running mode.
mbed_official 324:406fd2029f23 1230 * @param enable Enable or disable a mode.
mbed_official 146:f64d43ff0c18 1231 */
mbed_official 324:406fd2029f23 1232 void SAI_HAL_TxSetRunModeCmd(uint32_t saiBaseAddr, sai_run_mode_t run_mode, bool enable);
mbed_official 146:f64d43ff0c18 1233
mbed_official 146:f64d43ff0c18 1234 /*!
mbed_official 324:406fd2029f23 1235 * @brief Sets the running mode of the Rx. There is a debug mode, stop mode, and a normal mode.
mbed_official 324:406fd2029f23 1236 *
mbed_official 324:406fd2029f23 1237 * This function can set the working mode of the SAI saiBaseAddr. Stop mode is always
mbed_official 324:406fd2029f23 1238 * used in low power cases, and the debug mode disables the SAI after the current
mbed_official 324:406fd2029f23 1239 * transmit/receive is completed.
mbed_official 324:406fd2029f23 1240 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 1241 * @param run_mode SAI running mode.
mbed_official 324:406fd2029f23 1242 * @param enable Enable or disable a mode.
mbed_official 146:f64d43ff0c18 1243 */
mbed_official 324:406fd2029f23 1244 void SAI_HAL_RxSetRunModeCmd(uint32_t saiBaseAddr, sai_run_mode_t run_mode, bool enable);
mbed_official 324:406fd2029f23 1245
mbed_official 324:406fd2029f23 1246 /*!
mbed_official 324:406fd2029f23 1247 * @brief Configures at which word the start of word flag is set in the Tx.
mbed_official 324:406fd2029f23 1248 *
mbed_official 324:406fd2029f23 1249 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 1250 * @param index Which word triggers word start flag.
mbed_official 324:406fd2029f23 1251 */
mbed_official 324:406fd2029f23 1252 static inline void SAI_HAL_TxSetWordStartIndex(uint32_t saiBaseAddr,uint32_t index)
mbed_official 146:f64d43ff0c18 1253 {
mbed_official 324:406fd2029f23 1254 assert(index <= FSL_FEATURE_SAI_MAX_WORDS_PER_FRAME);
mbed_official 324:406fd2029f23 1255 BW_I2S_TCR3_WDFL(saiBaseAddr, index -1);
mbed_official 146:f64d43ff0c18 1256 }
mbed_official 146:f64d43ff0c18 1257
mbed_official 146:f64d43ff0c18 1258 /*!
mbed_official 324:406fd2029f23 1259 * @brief Configures at which word the start of word flag is set in the Tx.
mbed_official 324:406fd2029f23 1260 *
mbed_official 324:406fd2029f23 1261 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 1262 * @param index Which word triggers word start flag.
mbed_official 146:f64d43ff0c18 1263 */
mbed_official 324:406fd2029f23 1264 static inline void SAI_HAL_RxSetWordStartIndex(uint32_t saiBaseAddr,uint32_t index)
mbed_official 324:406fd2029f23 1265 {
mbed_official 324:406fd2029f23 1266 assert(index <= FSL_FEATURE_SAI_MAX_WORDS_PER_FRAME);
mbed_official 324:406fd2029f23 1267 BW_I2S_RCR3_WDFL(saiBaseAddr, index -1);
mbed_official 324:406fd2029f23 1268 }
mbed_official 146:f64d43ff0c18 1269
mbed_official 146:f64d43ff0c18 1270 /*!
mbed_official 324:406fd2029f23 1271 * @brief Gets the state of the flags in the TCSR.
mbed_official 324:406fd2029f23 1272 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 1273 * @param flag State flag type, it can be FIFO error, FIFO warning and so on.
mbed_official 324:406fd2029f23 1274 * @return True if detect word start otherwise false.
mbed_official 146:f64d43ff0c18 1275 */
mbed_official 324:406fd2029f23 1276 bool SAI_HAL_TxGetStateFlag(uint32_t saiBaseAddr, sai_state_flag_t flag);
mbed_official 146:f64d43ff0c18 1277
mbed_official 146:f64d43ff0c18 1278 /*!
mbed_official 324:406fd2029f23 1279 * @brief Gets the state of the flags in the RCSR.
mbed_official 324:406fd2029f23 1280 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 1281 * @param flag State flag type, it can be FIFO error, FIFO warning and so on.
mbed_official 324:406fd2029f23 1282 * @return True if detect word start otherwise false.
mbed_official 146:f64d43ff0c18 1283 */
mbed_official 324:406fd2029f23 1284 bool SAI_HAL_RxGetStateFlag(uint32_t saiBaseAddr, sai_state_flag_t flag);
mbed_official 146:f64d43ff0c18 1285
mbed_official 146:f64d43ff0c18 1286 /*!
mbed_official 324:406fd2029f23 1287 * @brief Receives the data from the FIFO.
mbed_official 324:406fd2029f23 1288 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 1289 * @param rx_channel Rx FIFO channel.
mbed_official 146:f64d43ff0c18 1290 * @param data Pointer to the address to be written in.
mbed_official 146:f64d43ff0c18 1291 */
mbed_official 324:406fd2029f23 1292 static inline uint32_t SAI_HAL_ReceiveData(uint32_t saiBaseAddr, uint32_t rx_channel)
mbed_official 146:f64d43ff0c18 1293 {
mbed_official 324:406fd2029f23 1294 assert(rx_channel < FSL_FEATURE_SAI_CHANNEL_COUNT);
mbed_official 324:406fd2029f23 1295 return HW_I2S_RDRn_RD(saiBaseAddr, rx_channel);
mbed_official 146:f64d43ff0c18 1296 }
mbed_official 146:f64d43ff0c18 1297
mbed_official 146:f64d43ff0c18 1298 /*!
mbed_official 146:f64d43ff0c18 1299 * @brief Transmits data to the FIFO.
mbed_official 324:406fd2029f23 1300 * @param saiBaseAddr Register base address of SAI module.
mbed_official 146:f64d43ff0c18 1301 * @param tx_channel Tx FIFO channel.
mbed_official 146:f64d43ff0c18 1302 * @param data Data value which needs to be written into FIFO.
mbed_official 146:f64d43ff0c18 1303 */
mbed_official 324:406fd2029f23 1304 static inline void SAI_HAL_SendData(uint32_t saiBaseAddr, uint32_t tx_channel, uint32_t data)
mbed_official 324:406fd2029f23 1305 {
mbed_official 324:406fd2029f23 1306 assert(tx_channel < FSL_FEATURE_SAI_CHANNEL_COUNT);
mbed_official 324:406fd2029f23 1307 HW_I2S_TDRn_WR(saiBaseAddr,tx_channel,data);
mbed_official 324:406fd2029f23 1308 }
mbed_official 324:406fd2029f23 1309
mbed_official 324:406fd2029f23 1310 /*!
mbed_official 324:406fd2029f23 1311 * @brief Uses blocking to receive data.
mbed_official 324:406fd2029f23 1312 * @param saiBaseAddr The SAI saiBaseAddr.
mbed_official 324:406fd2029f23 1313 * @param rx_channel Rx FIFO channel.
mbed_official 324:406fd2029f23 1314 * @return Received data.
mbed_official 324:406fd2029f23 1315 */
mbed_official 324:406fd2029f23 1316 uint32_t SAI_HAL_ReceiveDataBlocking(uint32_t saiBaseAddr, uint32_t rx_channel);
mbed_official 324:406fd2029f23 1317
mbed_official 324:406fd2029f23 1318 /*!
mbed_official 324:406fd2029f23 1319 * @brief Uses blocking to send data.
mbed_official 324:406fd2029f23 1320 * @param saiBaseAddr The SAI saiBaseAddr.
mbed_official 324:406fd2029f23 1321 * @param tx_channel Tx FIFO channel.
mbed_official 324:406fd2029f23 1322 * @param data Data value which needs to be written into FIFO.
mbed_official 324:406fd2029f23 1323 */
mbed_official 324:406fd2029f23 1324 void SAI_HAL_SendDataBlocking(uint32_t saiBaseAddr, uint32_t tx_channel, uint32_t data);
mbed_official 324:406fd2029f23 1325
mbed_official 324:406fd2029f23 1326 #if FSL_FEATURE_SAI_HAS_ON_DEMAND_MODE
mbed_official 324:406fd2029f23 1327 /*!
mbed_official 324:406fd2029f23 1328 * @brief Tx on-demand mode setting.
mbed_official 324:406fd2029f23 1329 *
mbed_official 324:406fd2029f23 1330 * When set, the frame sync is generated internally. A frame sync is only generated when the
mbed_official 324:406fd2029f23 1331 * FIFO warning flag is clear.
mbed_official 324:406fd2029f23 1332 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 1333 * @param enable True means on demand mode enable, false means disable.
mbed_official 324:406fd2029f23 1334 */
mbed_official 324:406fd2029f23 1335 static inline void SAI_HAL_TxSetOndemandCmd(uint32_t saiBaseAddr, bool enable)
mbed_official 324:406fd2029f23 1336 {
mbed_official 324:406fd2029f23 1337 BW_I2S_TCR4_ONDEM(saiBaseAddr, enable);
mbed_official 324:406fd2029f23 1338 }
mbed_official 324:406fd2029f23 1339
mbed_official 324:406fd2029f23 1340 /*!
mbed_official 324:406fd2029f23 1341 * @brief Rx on-demand mode setting.
mbed_official 324:406fd2029f23 1342 *
mbed_official 324:406fd2029f23 1343 * When set, the frame sync is generated internally. A frame sync is only generated when the
mbed_official 324:406fd2029f23 1344 * FIFO warning flag is clear.
mbed_official 324:406fd2029f23 1345 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 1346 * @param enable True means on demand mode enable, false means disable.
mbed_official 324:406fd2029f23 1347 */
mbed_official 324:406fd2029f23 1348 static inline void SAI_HAL_RxSetOndemandCmd(uint32_t saiBaseAddr, bool enable)
mbed_official 146:f64d43ff0c18 1349 {
mbed_official 324:406fd2029f23 1350 BW_I2S_RCR4_ONDEM(saiBaseAddr, enable);
mbed_official 324:406fd2029f23 1351 }
mbed_official 324:406fd2029f23 1352 #endif
mbed_official 324:406fd2029f23 1353
mbed_official 324:406fd2029f23 1354 #if FSL_FEATURE_SAI_HAS_FIFO_FUNCTION_AFTER_ERROR
mbed_official 324:406fd2029f23 1355 /*!
mbed_official 324:406fd2029f23 1356 * @brief Tx FIFO continues on error.
mbed_official 324:406fd2029f23 1357 *
mbed_official 324:406fd2029f23 1358 * Configures when the SAI continues transmitting after a FIFO error has been detected.
mbed_official 324:406fd2029f23 1359 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 1360 * @param enable True means on demand mode enable, false means disable.
mbed_official 324:406fd2029f23 1361 */
mbed_official 324:406fd2029f23 1362 static inline void SAI_HAL_TxSetFIFOErrorContinueCmd(uint32_t saiBaseAddr, bool enable)
mbed_official 324:406fd2029f23 1363 {
mbed_official 324:406fd2029f23 1364 BW_I2S_TCR4_FCONT(saiBaseAddr, enable);
mbed_official 324:406fd2029f23 1365 }
mbed_official 324:406fd2029f23 1366
mbed_official 324:406fd2029f23 1367 /*!
mbed_official 324:406fd2029f23 1368 * @brief Rx FIFO continues on error.
mbed_official 324:406fd2029f23 1369 *
mbed_official 324:406fd2029f23 1370 * Configures when the SAI continues transmitting after a FIFO error has been detected.
mbed_official 324:406fd2029f23 1371 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 1372 * @param enable True means on demand mode enable, false means disable.
mbed_official 324:406fd2029f23 1373 */
mbed_official 324:406fd2029f23 1374 static inline void SAI_HAL_RxSetFIFOErrorContinueCmd(uint32_t saiBaseAddr, bool enable)
mbed_official 324:406fd2029f23 1375 {
mbed_official 324:406fd2029f23 1376 BW_I2S_RCR4_FCONT(saiBaseAddr, enable);
mbed_official 146:f64d43ff0c18 1377 }
mbed_official 324:406fd2029f23 1378 #endif
mbed_official 324:406fd2029f23 1379
mbed_official 324:406fd2029f23 1380 #if FSL_FEATURE_SAI_HAS_FIFO_PACKING
mbed_official 324:406fd2029f23 1381 /*!
mbed_official 324:406fd2029f23 1382 * @brief Tx FIFO packing mode setting.
mbed_official 324:406fd2029f23 1383 *
mbed_official 324:406fd2029f23 1384 * Enables packing 8-bit data or 16-bit data into each 32-bit FIFO word. If the word size is
mbed_official 324:406fd2029f23 1385 * greater than 8-bit or 16-bit, only the first 8-bit or 16-bits are loaded from the FIFO.
mbed_official 324:406fd2029f23 1386 * The first word in each frame always starts with a new 32-bit FIFO word and the first bit shifted
mbed_official 324:406fd2029f23 1387 * must be configured within the first packed word. When FIFO packing is enabled, the FIFO write
mbed_official 324:406fd2029f23 1388 * pointer only increments when the full 32-bit FIFO word has been written by software.
mbed_official 324:406fd2029f23 1389 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 1390 * @param mode FIFO packing mode.
mbed_official 324:406fd2029f23 1391 */
mbed_official 324:406fd2029f23 1392 static inline void SAI_HAL_TxSetFIFOPackingMode(uint32_t saiBaseAddr, sai_fifo_packing_t mode)
mbed_official 324:406fd2029f23 1393 {
mbed_official 324:406fd2029f23 1394 BW_I2S_TCR4_FPACK(saiBaseAddr,mode);
mbed_official 324:406fd2029f23 1395 }
mbed_official 324:406fd2029f23 1396
mbed_official 324:406fd2029f23 1397 /*!
mbed_official 324:406fd2029f23 1398 * @brief Rx FIFO packing mode setting.
mbed_official 324:406fd2029f23 1399 *
mbed_official 324:406fd2029f23 1400 * Enables packing 8-bit data or 16-bit data into each 32-bit FIFO word. If the word size is
mbed_official 324:406fd2029f23 1401 * greater than 8-bit or 16-bit, only the first 8-bit or 16-bits are loaded from the FIFO.
mbed_official 324:406fd2029f23 1402 * The first word in each frame always starts with a new 32-bit FIFO word and the first bit shifted
mbed_official 324:406fd2029f23 1403 * must be configured within the first packed word. When FIFO packing is enabled, the FIFO write
mbed_official 324:406fd2029f23 1404 * pointer only increments when the full 32-bit FIFO word has been written by software.
mbed_official 324:406fd2029f23 1405 * @param saiBaseAddr Register base address of SAI module.
mbed_official 324:406fd2029f23 1406 * @param mode FIFO packing mode.
mbed_official 324:406fd2029f23 1407 */
mbed_official 324:406fd2029f23 1408 static inline void SAI_HAL_RxSetFIFOPackingMode(uint32_t saiBaseAddr, sai_fifo_packing_t mode)
mbed_official 324:406fd2029f23 1409 {
mbed_official 324:406fd2029f23 1410 BW_I2S_RCR4_FPACK(saiBaseAddr,mode);
mbed_official 324:406fd2029f23 1411 }
mbed_official 324:406fd2029f23 1412 #endif
mbed_official 146:f64d43ff0c18 1413
mbed_official 146:f64d43ff0c18 1414 #if defined(__cplusplus)
mbed_official 146:f64d43ff0c18 1415 }
mbed_official 146:f64d43ff0c18 1416 #endif
mbed_official 146:f64d43ff0c18 1417
mbed_official 146:f64d43ff0c18 1418 /*! @} */
mbed_official 146:f64d43ff0c18 1419
mbed_official 146:f64d43ff0c18 1420 #endif /* __FSL_SAI_HAL_H__ */
mbed_official 146:f64d43ff0c18 1421 /*******************************************************************************
mbed_official 146:f64d43ff0c18 1422 * EOF
mbed_official 146:f64d43ff0c18 1423 *******************************************************************************/