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