The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
TARGET_KL43Z/TOOLCHAIN_IAR/fsl_sai.h@172:65be27845400, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 20:53:29 2019 +0000
- Revision:
- 172:65be27845400
- Parent:
- 171:3a7713b1edbc
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 171:3a7713b1edbc | 1 | /* |
AnnaBridge | 171:3a7713b1edbc | 2 | * Copyright (c) 2015, Freescale Semiconductor, Inc. |
AnnaBridge | 171:3a7713b1edbc | 3 | * All rights reserved. |
AnnaBridge | 171:3a7713b1edbc | 4 | * |
AnnaBridge | 171:3a7713b1edbc | 5 | * Redistribution and use in source and binary forms, with or without modification, |
AnnaBridge | 171:3a7713b1edbc | 6 | * are permitted provided that the following conditions are met: |
AnnaBridge | 171:3a7713b1edbc | 7 | * |
AnnaBridge | 171:3a7713b1edbc | 8 | * o Redistributions of source code must retain the above copyright notice, this list |
AnnaBridge | 171:3a7713b1edbc | 9 | * of conditions and the following disclaimer. |
AnnaBridge | 171:3a7713b1edbc | 10 | * |
AnnaBridge | 171:3a7713b1edbc | 11 | * o Redistributions in binary form must reproduce the above copyright notice, this |
AnnaBridge | 171:3a7713b1edbc | 12 | * list of conditions and the following disclaimer in the documentation and/or |
AnnaBridge | 171:3a7713b1edbc | 13 | * other materials provided with the distribution. |
AnnaBridge | 171:3a7713b1edbc | 14 | * |
AnnaBridge | 171:3a7713b1edbc | 15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its |
AnnaBridge | 171:3a7713b1edbc | 16 | * contributors may be used to endorse or promote products derived from this |
AnnaBridge | 171:3a7713b1edbc | 17 | * software without specific prior written permission. |
AnnaBridge | 171:3a7713b1edbc | 18 | * |
AnnaBridge | 171:3a7713b1edbc | 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
AnnaBridge | 171:3a7713b1edbc | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
AnnaBridge | 171:3a7713b1edbc | 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
AnnaBridge | 171:3a7713b1edbc | 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
AnnaBridge | 171:3a7713b1edbc | 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
AnnaBridge | 171:3a7713b1edbc | 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
AnnaBridge | 171:3a7713b1edbc | 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
AnnaBridge | 171:3a7713b1edbc | 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
AnnaBridge | 171:3a7713b1edbc | 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
AnnaBridge | 171:3a7713b1edbc | 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
AnnaBridge | 171:3a7713b1edbc | 29 | */ |
AnnaBridge | 171:3a7713b1edbc | 30 | |
AnnaBridge | 171:3a7713b1edbc | 31 | #ifndef _FSL_SAI_H_ |
AnnaBridge | 171:3a7713b1edbc | 32 | #define _FSL_SAI_H_ |
AnnaBridge | 171:3a7713b1edbc | 33 | |
AnnaBridge | 171:3a7713b1edbc | 34 | #include "fsl_common.h" |
AnnaBridge | 171:3a7713b1edbc | 35 | |
AnnaBridge | 171:3a7713b1edbc | 36 | /*! |
AnnaBridge | 171:3a7713b1edbc | 37 | * @addtogroup sai |
AnnaBridge | 171:3a7713b1edbc | 38 | * @{ |
AnnaBridge | 171:3a7713b1edbc | 39 | */ |
AnnaBridge | 171:3a7713b1edbc | 40 | |
AnnaBridge | 171:3a7713b1edbc | 41 | |
AnnaBridge | 171:3a7713b1edbc | 42 | /******************************************************************************* |
AnnaBridge | 171:3a7713b1edbc | 43 | * Definitions |
AnnaBridge | 171:3a7713b1edbc | 44 | ******************************************************************************/ |
AnnaBridge | 171:3a7713b1edbc | 45 | |
AnnaBridge | 171:3a7713b1edbc | 46 | /*! @name Driver version */ |
AnnaBridge | 171:3a7713b1edbc | 47 | /*@{*/ |
AnnaBridge | 171:3a7713b1edbc | 48 | #define FSL_SAI_DRIVER_VERSION (MAKE_VERSION(2, 1, 1)) /*!< Version 2.1.1 */ |
AnnaBridge | 171:3a7713b1edbc | 49 | /*@}*/ |
AnnaBridge | 171:3a7713b1edbc | 50 | |
AnnaBridge | 171:3a7713b1edbc | 51 | /*! @brief SAI return status*/ |
AnnaBridge | 171:3a7713b1edbc | 52 | enum _sai_status_t |
AnnaBridge | 171:3a7713b1edbc | 53 | { |
AnnaBridge | 171:3a7713b1edbc | 54 | kStatus_SAI_TxBusy = MAKE_STATUS(kStatusGroup_SAI, 0), /*!< SAI Tx is busy. */ |
AnnaBridge | 171:3a7713b1edbc | 55 | kStatus_SAI_RxBusy = MAKE_STATUS(kStatusGroup_SAI, 1), /*!< SAI Rx is busy. */ |
AnnaBridge | 171:3a7713b1edbc | 56 | kStatus_SAI_TxError = MAKE_STATUS(kStatusGroup_SAI, 2), /*!< SAI Tx FIFO error. */ |
AnnaBridge | 171:3a7713b1edbc | 57 | kStatus_SAI_RxError = MAKE_STATUS(kStatusGroup_SAI, 3), /*!< SAI Rx FIFO error. */ |
AnnaBridge | 171:3a7713b1edbc | 58 | kStatus_SAI_QueueFull = MAKE_STATUS(kStatusGroup_SAI, 4), /*!< SAI transfer queue is full. */ |
AnnaBridge | 171:3a7713b1edbc | 59 | kStatus_SAI_TxIdle = MAKE_STATUS(kStatusGroup_SAI, 5), /*!< SAI Tx is idle */ |
AnnaBridge | 171:3a7713b1edbc | 60 | kStatus_SAI_RxIdle = MAKE_STATUS(kStatusGroup_SAI, 6) /*!< SAI Rx is idle */ |
AnnaBridge | 171:3a7713b1edbc | 61 | }; |
AnnaBridge | 171:3a7713b1edbc | 62 | |
AnnaBridge | 171:3a7713b1edbc | 63 | /*! @brief Define the SAI bus type */ |
AnnaBridge | 171:3a7713b1edbc | 64 | typedef enum _sai_protocol |
AnnaBridge | 171:3a7713b1edbc | 65 | { |
AnnaBridge | 171:3a7713b1edbc | 66 | kSAI_BusLeftJustified = 0x0U, /*!< Uses left justified format.*/ |
AnnaBridge | 171:3a7713b1edbc | 67 | kSAI_BusRightJustified, /*!< Uses right justified format. */ |
AnnaBridge | 171:3a7713b1edbc | 68 | kSAI_BusI2S, /*!< Uses I2S format. */ |
AnnaBridge | 171:3a7713b1edbc | 69 | kSAI_BusPCMA, /*!< Uses I2S PCM A format.*/ |
AnnaBridge | 171:3a7713b1edbc | 70 | kSAI_BusPCMB /*!< Uses I2S PCM B format. */ |
AnnaBridge | 171:3a7713b1edbc | 71 | } sai_protocol_t; |
AnnaBridge | 171:3a7713b1edbc | 72 | |
AnnaBridge | 171:3a7713b1edbc | 73 | /*! @brief Master or slave mode */ |
AnnaBridge | 171:3a7713b1edbc | 74 | typedef enum _sai_master_slave |
AnnaBridge | 171:3a7713b1edbc | 75 | { |
AnnaBridge | 171:3a7713b1edbc | 76 | kSAI_Master = 0x0U, /*!< Master mode */ |
AnnaBridge | 171:3a7713b1edbc | 77 | kSAI_Slave = 0x1U /*!< Slave mode */ |
AnnaBridge | 171:3a7713b1edbc | 78 | } sai_master_slave_t; |
AnnaBridge | 171:3a7713b1edbc | 79 | |
AnnaBridge | 171:3a7713b1edbc | 80 | /*! @brief Mono or stereo audio format */ |
AnnaBridge | 171:3a7713b1edbc | 81 | typedef enum _sai_mono_stereo |
AnnaBridge | 171:3a7713b1edbc | 82 | { |
AnnaBridge | 171:3a7713b1edbc | 83 | kSAI_Stereo = 0x0U, /*!< Stereo sound. */ |
AnnaBridge | 171:3a7713b1edbc | 84 | kSAI_MonoLeft, /*!< Only left channel have sound. */ |
AnnaBridge | 171:3a7713b1edbc | 85 | kSAI_MonoRight /*!< Only Right channel have sound. */ |
AnnaBridge | 171:3a7713b1edbc | 86 | } sai_mono_stereo_t; |
AnnaBridge | 171:3a7713b1edbc | 87 | |
AnnaBridge | 171:3a7713b1edbc | 88 | /*! @brief Synchronous or asynchronous mode */ |
AnnaBridge | 171:3a7713b1edbc | 89 | typedef enum _sai_sync_mode |
AnnaBridge | 171:3a7713b1edbc | 90 | { |
AnnaBridge | 171:3a7713b1edbc | 91 | kSAI_ModeAsync = 0x0U, /*!< Asynchronous mode */ |
AnnaBridge | 171:3a7713b1edbc | 92 | kSAI_ModeSync, /*!< Synchronous mode (with receiver or transmit) */ |
AnnaBridge | 171:3a7713b1edbc | 93 | kSAI_ModeSyncWithOtherTx, /*!< Synchronous with another SAI transmit */ |
AnnaBridge | 171:3a7713b1edbc | 94 | kSAI_ModeSyncWithOtherRx /*!< Synchronous with another SAI receiver */ |
AnnaBridge | 171:3a7713b1edbc | 95 | } sai_sync_mode_t; |
AnnaBridge | 171:3a7713b1edbc | 96 | |
AnnaBridge | 171:3a7713b1edbc | 97 | /*! @brief Mater clock source */ |
AnnaBridge | 171:3a7713b1edbc | 98 | typedef enum _sai_mclk_source |
AnnaBridge | 171:3a7713b1edbc | 99 | { |
AnnaBridge | 171:3a7713b1edbc | 100 | kSAI_MclkSourceSysclk = 0x0U, /*!< Master clock from the system clock */ |
AnnaBridge | 171:3a7713b1edbc | 101 | kSAI_MclkSourceSelect1, /*!< Master clock from source 1 */ |
AnnaBridge | 171:3a7713b1edbc | 102 | kSAI_MclkSourceSelect2, /*!< Master clock from source 2 */ |
AnnaBridge | 171:3a7713b1edbc | 103 | kSAI_MclkSourceSelect3 /*!< Master clock from source 3 */ |
AnnaBridge | 171:3a7713b1edbc | 104 | } sai_mclk_source_t; |
AnnaBridge | 171:3a7713b1edbc | 105 | |
AnnaBridge | 171:3a7713b1edbc | 106 | /*! @brief Bit clock source */ |
AnnaBridge | 171:3a7713b1edbc | 107 | typedef enum _sai_bclk_source |
AnnaBridge | 171:3a7713b1edbc | 108 | { |
AnnaBridge | 171:3a7713b1edbc | 109 | kSAI_BclkSourceBusclk = 0x0U, /*!< Bit clock using bus clock */ |
AnnaBridge | 171:3a7713b1edbc | 110 | kSAI_BclkSourceMclkDiv, /*!< Bit clock using master clock divider */ |
AnnaBridge | 171:3a7713b1edbc | 111 | kSAI_BclkSourceOtherSai0, /*!< Bit clock from other SAI device */ |
AnnaBridge | 171:3a7713b1edbc | 112 | kSAI_BclkSourceOtherSai1 /*!< Bit clock from other SAI device */ |
AnnaBridge | 171:3a7713b1edbc | 113 | } sai_bclk_source_t; |
AnnaBridge | 171:3a7713b1edbc | 114 | |
AnnaBridge | 171:3a7713b1edbc | 115 | /*! @brief The SAI interrupt enable flag */ |
AnnaBridge | 171:3a7713b1edbc | 116 | enum _sai_interrupt_enable_t |
AnnaBridge | 171:3a7713b1edbc | 117 | { |
AnnaBridge | 171:3a7713b1edbc | 118 | kSAI_WordStartInterruptEnable = |
AnnaBridge | 171:3a7713b1edbc | 119 | I2S_TCSR_WSIE_MASK, /*!< Word start flag, means the first word in a frame detected */ |
AnnaBridge | 171:3a7713b1edbc | 120 | kSAI_SyncErrorInterruptEnable = I2S_TCSR_SEIE_MASK, /*!< Sync error flag, means the sync error is detected */ |
AnnaBridge | 171:3a7713b1edbc | 121 | kSAI_FIFOWarningInterruptEnable = I2S_TCSR_FWIE_MASK, /*!< FIFO warning flag, means the FIFO is empty */ |
AnnaBridge | 171:3a7713b1edbc | 122 | kSAI_FIFOErrorInterruptEnable = I2S_TCSR_FEIE_MASK, /*!< FIFO error flag */ |
AnnaBridge | 171:3a7713b1edbc | 123 | #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1) |
AnnaBridge | 171:3a7713b1edbc | 124 | kSAI_FIFORequestInterruptEnable = I2S_TCSR_FRIE_MASK, /*!< FIFO request, means reached watermark */ |
AnnaBridge | 171:3a7713b1edbc | 125 | #endif /* FSL_FEATURE_SAI_FIFO_COUNT */ |
AnnaBridge | 171:3a7713b1edbc | 126 | }; |
AnnaBridge | 171:3a7713b1edbc | 127 | |
AnnaBridge | 171:3a7713b1edbc | 128 | /*! @brief The DMA request sources */ |
AnnaBridge | 171:3a7713b1edbc | 129 | enum _sai_dma_enable_t |
AnnaBridge | 171:3a7713b1edbc | 130 | { |
AnnaBridge | 171:3a7713b1edbc | 131 | kSAI_FIFOWarningDMAEnable = I2S_TCSR_FWDE_MASK, /*!< FIFO warning caused by the DMA request */ |
AnnaBridge | 171:3a7713b1edbc | 132 | #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1) |
AnnaBridge | 171:3a7713b1edbc | 133 | kSAI_FIFORequestDMAEnable = I2S_TCSR_FRDE_MASK, /*!< FIFO request caused by the DMA request */ |
AnnaBridge | 171:3a7713b1edbc | 134 | #endif /* FSL_FEATURE_SAI_FIFO_COUNT */ |
AnnaBridge | 171:3a7713b1edbc | 135 | }; |
AnnaBridge | 171:3a7713b1edbc | 136 | |
AnnaBridge | 171:3a7713b1edbc | 137 | /*! @brief The SAI status flag */ |
AnnaBridge | 171:3a7713b1edbc | 138 | enum _sai_flags |
AnnaBridge | 171:3a7713b1edbc | 139 | { |
AnnaBridge | 171:3a7713b1edbc | 140 | kSAI_WordStartFlag = I2S_TCSR_WSF_MASK, /*!< Word start flag, means the first word in a frame detected */ |
AnnaBridge | 171:3a7713b1edbc | 141 | kSAI_SyncErrorFlag = I2S_TCSR_SEF_MASK, /*!< Sync error flag, means the sync error is detected */ |
AnnaBridge | 171:3a7713b1edbc | 142 | kSAI_FIFOErrorFlag = I2S_TCSR_FEF_MASK, /*!< FIFO error flag */ |
AnnaBridge | 171:3a7713b1edbc | 143 | #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1) |
AnnaBridge | 171:3a7713b1edbc | 144 | kSAI_FIFORequestFlag = I2S_TCSR_FRF_MASK, /*!< FIFO request flag. */ |
AnnaBridge | 171:3a7713b1edbc | 145 | #endif /* FSL_FEATURE_SAI_FIFO_COUNT */ |
AnnaBridge | 171:3a7713b1edbc | 146 | kSAI_FIFOWarningFlag = I2S_TCSR_FWF_MASK, /*!< FIFO warning flag */ |
AnnaBridge | 171:3a7713b1edbc | 147 | }; |
AnnaBridge | 171:3a7713b1edbc | 148 | |
AnnaBridge | 171:3a7713b1edbc | 149 | /*! @brief The reset type */ |
AnnaBridge | 171:3a7713b1edbc | 150 | typedef enum _sai_reset_type |
AnnaBridge | 171:3a7713b1edbc | 151 | { |
AnnaBridge | 171:3a7713b1edbc | 152 | kSAI_ResetTypeSoftware = I2S_TCSR_SR_MASK, /*!< Software reset, reset the logic state */ |
AnnaBridge | 171:3a7713b1edbc | 153 | kSAI_ResetTypeFIFO = I2S_TCSR_FR_MASK, /*!< FIFO reset, reset the FIFO read and write pointer */ |
AnnaBridge | 171:3a7713b1edbc | 154 | kSAI_ResetAll = I2S_TCSR_SR_MASK | I2S_TCSR_FR_MASK /*!< All reset. */ |
AnnaBridge | 171:3a7713b1edbc | 155 | } sai_reset_type_t; |
AnnaBridge | 171:3a7713b1edbc | 156 | |
AnnaBridge | 171:3a7713b1edbc | 157 | #if defined(FSL_FEATURE_SAI_HAS_FIFO_PACKING) && FSL_FEATURE_SAI_HAS_FIFO_PACKING |
AnnaBridge | 171:3a7713b1edbc | 158 | /*! |
AnnaBridge | 171:3a7713b1edbc | 159 | * @brief The SAI packing mode |
AnnaBridge | 171:3a7713b1edbc | 160 | * The mode includes 8 bit and 16 bit packing. |
AnnaBridge | 171:3a7713b1edbc | 161 | */ |
AnnaBridge | 171:3a7713b1edbc | 162 | typedef enum _sai_fifo_packing |
AnnaBridge | 171:3a7713b1edbc | 163 | { |
AnnaBridge | 171:3a7713b1edbc | 164 | kSAI_FifoPackingDisabled = 0x0U, /*!< Packing disabled */ |
AnnaBridge | 171:3a7713b1edbc | 165 | kSAI_FifoPacking8bit = 0x2U, /*!< 8 bit packing enabled */ |
AnnaBridge | 171:3a7713b1edbc | 166 | kSAI_FifoPacking16bit = 0x3U /*!< 16bit packing enabled */ |
AnnaBridge | 171:3a7713b1edbc | 167 | } sai_fifo_packing_t; |
AnnaBridge | 171:3a7713b1edbc | 168 | #endif /* FSL_FEATURE_SAI_HAS_FIFO_PACKING */ |
AnnaBridge | 171:3a7713b1edbc | 169 | |
AnnaBridge | 171:3a7713b1edbc | 170 | /*! @brief SAI user configuration structure */ |
AnnaBridge | 171:3a7713b1edbc | 171 | typedef struct _sai_config |
AnnaBridge | 171:3a7713b1edbc | 172 | { |
AnnaBridge | 171:3a7713b1edbc | 173 | sai_protocol_t protocol; /*!< Audio bus protocol in SAI */ |
AnnaBridge | 171:3a7713b1edbc | 174 | sai_sync_mode_t syncMode; /*!< SAI sync mode, control Tx/Rx clock sync */ |
AnnaBridge | 171:3a7713b1edbc | 175 | #if defined(FSL_FEATURE_SAI_HAS_MCR) && (FSL_FEATURE_SAI_HAS_MCR) |
AnnaBridge | 171:3a7713b1edbc | 176 | bool mclkOutputEnable; /*!< Master clock output enable, true means master clock divider enabled */ |
AnnaBridge | 171:3a7713b1edbc | 177 | #endif /* FSL_FEATURE_SAI_HAS_MCR */ |
AnnaBridge | 171:3a7713b1edbc | 178 | sai_mclk_source_t mclkSource; /*!< Master Clock source */ |
AnnaBridge | 171:3a7713b1edbc | 179 | sai_bclk_source_t bclkSource; /*!< Bit Clock source */ |
AnnaBridge | 171:3a7713b1edbc | 180 | sai_master_slave_t masterSlave; /*!< Master or slave */ |
AnnaBridge | 171:3a7713b1edbc | 181 | } sai_config_t; |
AnnaBridge | 171:3a7713b1edbc | 182 | |
AnnaBridge | 171:3a7713b1edbc | 183 | /*!@brief SAI transfer queue size, user can refine it according to use case. */ |
AnnaBridge | 171:3a7713b1edbc | 184 | #define SAI_XFER_QUEUE_SIZE (4) |
AnnaBridge | 171:3a7713b1edbc | 185 | |
AnnaBridge | 171:3a7713b1edbc | 186 | /*! @brief Audio sample rate */ |
AnnaBridge | 171:3a7713b1edbc | 187 | typedef enum _sai_sample_rate |
AnnaBridge | 171:3a7713b1edbc | 188 | { |
AnnaBridge | 171:3a7713b1edbc | 189 | kSAI_SampleRate8KHz = 8000U, /*!< Sample rate 8000Hz */ |
AnnaBridge | 171:3a7713b1edbc | 190 | kSAI_SampleRate11025Hz = 11025U, /*!< Sample rate 11025Hz */ |
AnnaBridge | 171:3a7713b1edbc | 191 | kSAI_SampleRate12KHz = 12000U, /*!< Sample rate 12000Hz */ |
AnnaBridge | 171:3a7713b1edbc | 192 | kSAI_SampleRate16KHz = 16000U, /*!< Sample rate 16000Hz */ |
AnnaBridge | 171:3a7713b1edbc | 193 | kSAI_SampleRate22050Hz = 22050U, /*!< Sample rate 22050Hz */ |
AnnaBridge | 171:3a7713b1edbc | 194 | kSAI_SampleRate24KHz = 24000U, /*!< Sample rate 24000Hz */ |
AnnaBridge | 171:3a7713b1edbc | 195 | kSAI_SampleRate32KHz = 32000U, /*!< Sample rate 32000Hz */ |
AnnaBridge | 171:3a7713b1edbc | 196 | kSAI_SampleRate44100Hz = 44100U, /*!< Sample rate 44100Hz */ |
AnnaBridge | 171:3a7713b1edbc | 197 | kSAI_SampleRate48KHz = 48000U, /*!< Sample rate 48000Hz */ |
AnnaBridge | 171:3a7713b1edbc | 198 | kSAI_SampleRate96KHz = 96000U /*!< Sample rate 96000Hz */ |
AnnaBridge | 171:3a7713b1edbc | 199 | } sai_sample_rate_t; |
AnnaBridge | 171:3a7713b1edbc | 200 | |
AnnaBridge | 171:3a7713b1edbc | 201 | /*! @brief Audio word width */ |
AnnaBridge | 171:3a7713b1edbc | 202 | typedef enum _sai_word_width |
AnnaBridge | 171:3a7713b1edbc | 203 | { |
AnnaBridge | 171:3a7713b1edbc | 204 | kSAI_WordWidth8bits = 8U, /*!< Audio data width 8 bits */ |
AnnaBridge | 171:3a7713b1edbc | 205 | kSAI_WordWidth16bits = 16U, /*!< Audio data width 16 bits */ |
AnnaBridge | 171:3a7713b1edbc | 206 | kSAI_WordWidth24bits = 24U, /*!< Audio data width 24 bits */ |
AnnaBridge | 171:3a7713b1edbc | 207 | kSAI_WordWidth32bits = 32U /*!< Audio data width 32 bits */ |
AnnaBridge | 171:3a7713b1edbc | 208 | } sai_word_width_t; |
AnnaBridge | 171:3a7713b1edbc | 209 | |
AnnaBridge | 171:3a7713b1edbc | 210 | /*! @brief sai transfer format */ |
AnnaBridge | 171:3a7713b1edbc | 211 | typedef struct _sai_transfer_format |
AnnaBridge | 171:3a7713b1edbc | 212 | { |
AnnaBridge | 171:3a7713b1edbc | 213 | uint32_t sampleRate_Hz; /*!< Sample rate of audio data */ |
AnnaBridge | 171:3a7713b1edbc | 214 | uint32_t bitWidth; /*!< Data length of audio data, usually 8/16/24/32bits */ |
AnnaBridge | 171:3a7713b1edbc | 215 | sai_mono_stereo_t stereo; /*!< Mono or stereo */ |
AnnaBridge | 171:3a7713b1edbc | 216 | uint32_t masterClockHz; /*!< Master clock frequency in Hz */ |
AnnaBridge | 171:3a7713b1edbc | 217 | #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1) |
AnnaBridge | 171:3a7713b1edbc | 218 | uint8_t watermark; /*!< Watermark value */ |
AnnaBridge | 171:3a7713b1edbc | 219 | #endif /* FSL_FEATURE_SAI_FIFO_COUNT */ |
AnnaBridge | 171:3a7713b1edbc | 220 | uint8_t channel; /*!< Data channel used in transfer.*/ |
AnnaBridge | 171:3a7713b1edbc | 221 | sai_protocol_t protocol; /*!< Which audio protocol used */ |
AnnaBridge | 171:3a7713b1edbc | 222 | } sai_transfer_format_t; |
AnnaBridge | 171:3a7713b1edbc | 223 | |
AnnaBridge | 171:3a7713b1edbc | 224 | /*! @brief SAI transfer structure */ |
AnnaBridge | 171:3a7713b1edbc | 225 | typedef struct _sai_transfer |
AnnaBridge | 171:3a7713b1edbc | 226 | { |
AnnaBridge | 171:3a7713b1edbc | 227 | uint8_t *data; /*!< Data start address to transfer. */ |
AnnaBridge | 171:3a7713b1edbc | 228 | size_t dataSize; /*!< Transfer size. */ |
AnnaBridge | 171:3a7713b1edbc | 229 | } sai_transfer_t; |
AnnaBridge | 171:3a7713b1edbc | 230 | |
AnnaBridge | 171:3a7713b1edbc | 231 | typedef struct _sai_handle sai_handle_t; |
AnnaBridge | 171:3a7713b1edbc | 232 | |
AnnaBridge | 171:3a7713b1edbc | 233 | /*! @brief SAI transfer callback prototype */ |
AnnaBridge | 171:3a7713b1edbc | 234 | typedef void (*sai_transfer_callback_t)(I2S_Type *base, sai_handle_t *handle, status_t status, void *userData); |
AnnaBridge | 171:3a7713b1edbc | 235 | |
AnnaBridge | 171:3a7713b1edbc | 236 | /*! @brief SAI handle structure */ |
AnnaBridge | 171:3a7713b1edbc | 237 | struct _sai_handle |
AnnaBridge | 171:3a7713b1edbc | 238 | { |
AnnaBridge | 171:3a7713b1edbc | 239 | uint32_t state; /*!< Transfer status */ |
AnnaBridge | 171:3a7713b1edbc | 240 | sai_transfer_callback_t callback; /*!< Callback function called at transfer event*/ |
AnnaBridge | 171:3a7713b1edbc | 241 | void *userData; /*!< Callback parameter passed to callback function*/ |
AnnaBridge | 171:3a7713b1edbc | 242 | uint8_t bitWidth; /*!< Bit width for transfer, 8/16/24/32bits */ |
AnnaBridge | 171:3a7713b1edbc | 243 | uint8_t channel; /*!< Transfer channel */ |
AnnaBridge | 171:3a7713b1edbc | 244 | sai_transfer_t saiQueue[SAI_XFER_QUEUE_SIZE]; /*!< Transfer queue storing queued transfer */ |
AnnaBridge | 171:3a7713b1edbc | 245 | size_t transferSize[SAI_XFER_QUEUE_SIZE]; /*!< Data bytes need to transfer */ |
AnnaBridge | 171:3a7713b1edbc | 246 | volatile uint8_t queueUser; /*!< Index for user to queue transfer */ |
AnnaBridge | 171:3a7713b1edbc | 247 | volatile uint8_t queueDriver; /*!< Index for driver to get the transfer data and size */ |
AnnaBridge | 171:3a7713b1edbc | 248 | #if defined(FSL_FEATURE_SAI_FIFO_COUNT) && (FSL_FEATURE_SAI_FIFO_COUNT > 1) |
AnnaBridge | 171:3a7713b1edbc | 249 | uint8_t watermark; /*!< Watermark value */ |
AnnaBridge | 171:3a7713b1edbc | 250 | #endif |
AnnaBridge | 171:3a7713b1edbc | 251 | }; |
AnnaBridge | 171:3a7713b1edbc | 252 | |
AnnaBridge | 171:3a7713b1edbc | 253 | /******************************************************************************* |
AnnaBridge | 171:3a7713b1edbc | 254 | * API |
AnnaBridge | 171:3a7713b1edbc | 255 | ******************************************************************************/ |
AnnaBridge | 171:3a7713b1edbc | 256 | |
AnnaBridge | 171:3a7713b1edbc | 257 | #if defined(__cplusplus) |
AnnaBridge | 171:3a7713b1edbc | 258 | extern "C" { |
AnnaBridge | 171:3a7713b1edbc | 259 | #endif /*_cplusplus*/ |
AnnaBridge | 171:3a7713b1edbc | 260 | |
AnnaBridge | 171:3a7713b1edbc | 261 | /*! |
AnnaBridge | 171:3a7713b1edbc | 262 | * @name Initialization and deinitialization |
AnnaBridge | 171:3a7713b1edbc | 263 | * @{ |
AnnaBridge | 171:3a7713b1edbc | 264 | */ |
AnnaBridge | 171:3a7713b1edbc | 265 | |
AnnaBridge | 171:3a7713b1edbc | 266 | /*! |
AnnaBridge | 171:3a7713b1edbc | 267 | * @brief Initializes the SAI Tx peripheral. |
AnnaBridge | 171:3a7713b1edbc | 268 | * |
AnnaBridge | 171:3a7713b1edbc | 269 | * Ungates the SAI clock, resets the module, and configures SAI Tx with a configuration structure. |
AnnaBridge | 171:3a7713b1edbc | 270 | * The configuration structure can be custom filled or set with default values by |
AnnaBridge | 171:3a7713b1edbc | 271 | * SAI_TxGetDefaultConfig(). |
AnnaBridge | 171:3a7713b1edbc | 272 | * |
AnnaBridge | 171:3a7713b1edbc | 273 | * @note This API should be called at the beginning of the application to use |
AnnaBridge | 171:3a7713b1edbc | 274 | * the SAI driver. Otherwise, accessing the SAIM module can cause a hard fault |
AnnaBridge | 171:3a7713b1edbc | 275 | * because the clock is not enabled. |
AnnaBridge | 171:3a7713b1edbc | 276 | * |
AnnaBridge | 171:3a7713b1edbc | 277 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 278 | * @param config SAI configuration structure. |
AnnaBridge | 171:3a7713b1edbc | 279 | */ |
AnnaBridge | 171:3a7713b1edbc | 280 | void SAI_TxInit(I2S_Type *base, const sai_config_t *config); |
AnnaBridge | 171:3a7713b1edbc | 281 | |
AnnaBridge | 171:3a7713b1edbc | 282 | /*! |
AnnaBridge | 171:3a7713b1edbc | 283 | * @brief Initializes the the SAI Rx peripheral. |
AnnaBridge | 171:3a7713b1edbc | 284 | * |
AnnaBridge | 171:3a7713b1edbc | 285 | * Ungates the SAI clock, resets the module, and configures the SAI Rx with a configuration structure. |
AnnaBridge | 171:3a7713b1edbc | 286 | * The configuration structure can be custom filled or set with default values by |
AnnaBridge | 171:3a7713b1edbc | 287 | * SAI_RxGetDefaultConfig(). |
AnnaBridge | 171:3a7713b1edbc | 288 | * |
AnnaBridge | 171:3a7713b1edbc | 289 | * @note This API should be called at the beginning of the application to use |
AnnaBridge | 171:3a7713b1edbc | 290 | * the SAI driver. Otherwise, accessing the SAI module can cause a hard fault |
AnnaBridge | 171:3a7713b1edbc | 291 | * because the clock is not enabled. |
AnnaBridge | 171:3a7713b1edbc | 292 | * |
AnnaBridge | 171:3a7713b1edbc | 293 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 294 | * @param config SAI configuration structure. |
AnnaBridge | 171:3a7713b1edbc | 295 | */ |
AnnaBridge | 171:3a7713b1edbc | 296 | void SAI_RxInit(I2S_Type *base, const sai_config_t *config); |
AnnaBridge | 171:3a7713b1edbc | 297 | |
AnnaBridge | 171:3a7713b1edbc | 298 | /*! |
AnnaBridge | 171:3a7713b1edbc | 299 | * @brief Sets the SAI Tx configuration structure to default values. |
AnnaBridge | 171:3a7713b1edbc | 300 | * |
AnnaBridge | 171:3a7713b1edbc | 301 | * This API initializes the configuration structure for use in SAI_TxConfig(). |
AnnaBridge | 171:3a7713b1edbc | 302 | * The initialized structure can remain unchanged in SAI_TxConfig(), or it can be modified |
AnnaBridge | 171:3a7713b1edbc | 303 | * before calling SAI_TxConfig(). |
AnnaBridge | 171:3a7713b1edbc | 304 | * Example: |
AnnaBridge | 171:3a7713b1edbc | 305 | @code |
AnnaBridge | 171:3a7713b1edbc | 306 | sai_config_t config; |
AnnaBridge | 171:3a7713b1edbc | 307 | SAI_TxGetDefaultConfig(&config); |
AnnaBridge | 171:3a7713b1edbc | 308 | @endcode |
AnnaBridge | 171:3a7713b1edbc | 309 | * |
AnnaBridge | 171:3a7713b1edbc | 310 | * @param config pointer to master configuration structure |
AnnaBridge | 171:3a7713b1edbc | 311 | */ |
AnnaBridge | 171:3a7713b1edbc | 312 | void SAI_TxGetDefaultConfig(sai_config_t *config); |
AnnaBridge | 171:3a7713b1edbc | 313 | |
AnnaBridge | 171:3a7713b1edbc | 314 | /*! |
AnnaBridge | 171:3a7713b1edbc | 315 | * @brief Sets the SAI Rx configuration structure to default values. |
AnnaBridge | 171:3a7713b1edbc | 316 | * |
AnnaBridge | 171:3a7713b1edbc | 317 | * This API initializes the configuration structure for use in SAI_RxConfig(). |
AnnaBridge | 171:3a7713b1edbc | 318 | * The initialized structure can remain unchanged in SAI_RxConfig() or it can be modified |
AnnaBridge | 171:3a7713b1edbc | 319 | * before calling SAI_RxConfig(). |
AnnaBridge | 171:3a7713b1edbc | 320 | * Example: |
AnnaBridge | 171:3a7713b1edbc | 321 | @code |
AnnaBridge | 171:3a7713b1edbc | 322 | sai_config_t config; |
AnnaBridge | 171:3a7713b1edbc | 323 | SAI_RxGetDefaultConfig(&config); |
AnnaBridge | 171:3a7713b1edbc | 324 | @endcode |
AnnaBridge | 171:3a7713b1edbc | 325 | * |
AnnaBridge | 171:3a7713b1edbc | 326 | * @param config pointer to master configuration structure |
AnnaBridge | 171:3a7713b1edbc | 327 | */ |
AnnaBridge | 171:3a7713b1edbc | 328 | void SAI_RxGetDefaultConfig(sai_config_t *config); |
AnnaBridge | 171:3a7713b1edbc | 329 | |
AnnaBridge | 171:3a7713b1edbc | 330 | /*! |
AnnaBridge | 171:3a7713b1edbc | 331 | * @brief De-initializes the SAI peripheral. |
AnnaBridge | 171:3a7713b1edbc | 332 | * |
AnnaBridge | 171:3a7713b1edbc | 333 | * This API gates the SAI clock. The SAI module can't operate unless SAI_TxInit |
AnnaBridge | 171:3a7713b1edbc | 334 | * or SAI_RxInit is called to enable the clock. |
AnnaBridge | 171:3a7713b1edbc | 335 | * |
AnnaBridge | 171:3a7713b1edbc | 336 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 337 | */ |
AnnaBridge | 171:3a7713b1edbc | 338 | void SAI_Deinit(I2S_Type *base); |
AnnaBridge | 171:3a7713b1edbc | 339 | |
AnnaBridge | 171:3a7713b1edbc | 340 | /*! |
AnnaBridge | 171:3a7713b1edbc | 341 | * @brief Resets the SAI Tx. |
AnnaBridge | 171:3a7713b1edbc | 342 | * |
AnnaBridge | 171:3a7713b1edbc | 343 | * This function enables the software reset and FIFO reset of SAI Tx. After reset, clear the reset bit. |
AnnaBridge | 171:3a7713b1edbc | 344 | * |
AnnaBridge | 171:3a7713b1edbc | 345 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 346 | */ |
AnnaBridge | 171:3a7713b1edbc | 347 | void SAI_TxReset(I2S_Type *base); |
AnnaBridge | 171:3a7713b1edbc | 348 | |
AnnaBridge | 171:3a7713b1edbc | 349 | /*! |
AnnaBridge | 171:3a7713b1edbc | 350 | * @brief Resets the SAI Rx. |
AnnaBridge | 171:3a7713b1edbc | 351 | * |
AnnaBridge | 171:3a7713b1edbc | 352 | * This function enables the software reset and FIFO reset of SAI Rx. After reset, clear the reset bit. |
AnnaBridge | 171:3a7713b1edbc | 353 | * |
AnnaBridge | 171:3a7713b1edbc | 354 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 355 | */ |
AnnaBridge | 171:3a7713b1edbc | 356 | void SAI_RxReset(I2S_Type *base); |
AnnaBridge | 171:3a7713b1edbc | 357 | |
AnnaBridge | 171:3a7713b1edbc | 358 | /*! |
AnnaBridge | 171:3a7713b1edbc | 359 | * @brief Enables/disables SAI Tx. |
AnnaBridge | 171:3a7713b1edbc | 360 | * |
AnnaBridge | 171:3a7713b1edbc | 361 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 362 | * @param enable True means enable SAI Tx, false means disable. |
AnnaBridge | 171:3a7713b1edbc | 363 | */ |
AnnaBridge | 171:3a7713b1edbc | 364 | void SAI_TxEnable(I2S_Type *base, bool enable); |
AnnaBridge | 171:3a7713b1edbc | 365 | |
AnnaBridge | 171:3a7713b1edbc | 366 | /*! |
AnnaBridge | 171:3a7713b1edbc | 367 | * @brief Enables/disables SAI Rx. |
AnnaBridge | 171:3a7713b1edbc | 368 | * |
AnnaBridge | 171:3a7713b1edbc | 369 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 370 | * @param enable True means enable SAI Rx, false means disable. |
AnnaBridge | 171:3a7713b1edbc | 371 | */ |
AnnaBridge | 171:3a7713b1edbc | 372 | void SAI_RxEnable(I2S_Type *base, bool enable); |
AnnaBridge | 171:3a7713b1edbc | 373 | |
AnnaBridge | 171:3a7713b1edbc | 374 | /*! @} */ |
AnnaBridge | 171:3a7713b1edbc | 375 | |
AnnaBridge | 171:3a7713b1edbc | 376 | /*! |
AnnaBridge | 171:3a7713b1edbc | 377 | * @name Status |
AnnaBridge | 171:3a7713b1edbc | 378 | * @{ |
AnnaBridge | 171:3a7713b1edbc | 379 | */ |
AnnaBridge | 171:3a7713b1edbc | 380 | |
AnnaBridge | 171:3a7713b1edbc | 381 | /*! |
AnnaBridge | 171:3a7713b1edbc | 382 | * @brief Gets the SAI Tx status flag state. |
AnnaBridge | 171:3a7713b1edbc | 383 | * |
AnnaBridge | 171:3a7713b1edbc | 384 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 385 | * @return SAI Tx status flag value. Use the Status Mask to get the status value needed. |
AnnaBridge | 171:3a7713b1edbc | 386 | */ |
AnnaBridge | 171:3a7713b1edbc | 387 | static inline uint32_t SAI_TxGetStatusFlag(I2S_Type *base) |
AnnaBridge | 171:3a7713b1edbc | 388 | { |
AnnaBridge | 171:3a7713b1edbc | 389 | return base->TCSR; |
AnnaBridge | 171:3a7713b1edbc | 390 | } |
AnnaBridge | 171:3a7713b1edbc | 391 | |
AnnaBridge | 171:3a7713b1edbc | 392 | /*! |
AnnaBridge | 171:3a7713b1edbc | 393 | * @brief Clears the SAI Tx status flag state. |
AnnaBridge | 171:3a7713b1edbc | 394 | * |
AnnaBridge | 171:3a7713b1edbc | 395 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 396 | * @param mask State mask. It can be a combination of the following source if defined: |
AnnaBridge | 171:3a7713b1edbc | 397 | * @arg kSAI_WordStartFlag |
AnnaBridge | 171:3a7713b1edbc | 398 | * @arg kSAI_SyncErrorFlag |
AnnaBridge | 171:3a7713b1edbc | 399 | * @arg kSAI_FIFOErrorFlag |
AnnaBridge | 171:3a7713b1edbc | 400 | */ |
AnnaBridge | 171:3a7713b1edbc | 401 | static inline void SAI_TxClearStatusFlags(I2S_Type *base, uint32_t mask) |
AnnaBridge | 171:3a7713b1edbc | 402 | { |
AnnaBridge | 171:3a7713b1edbc | 403 | base->TCSR = ((base->TCSR & 0xFFE3FFFFU) | mask); |
AnnaBridge | 171:3a7713b1edbc | 404 | } |
AnnaBridge | 171:3a7713b1edbc | 405 | |
AnnaBridge | 171:3a7713b1edbc | 406 | /*! |
AnnaBridge | 171:3a7713b1edbc | 407 | * @brief Gets the SAI Tx status flag state. |
AnnaBridge | 171:3a7713b1edbc | 408 | * |
AnnaBridge | 171:3a7713b1edbc | 409 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 410 | * @return SAI Rx status flag value. Use the Status Mask to get the status value needed. |
AnnaBridge | 171:3a7713b1edbc | 411 | */ |
AnnaBridge | 171:3a7713b1edbc | 412 | static inline uint32_t SAI_RxGetStatusFlag(I2S_Type *base) |
AnnaBridge | 171:3a7713b1edbc | 413 | { |
AnnaBridge | 171:3a7713b1edbc | 414 | return base->RCSR; |
AnnaBridge | 171:3a7713b1edbc | 415 | } |
AnnaBridge | 171:3a7713b1edbc | 416 | |
AnnaBridge | 171:3a7713b1edbc | 417 | /*! |
AnnaBridge | 171:3a7713b1edbc | 418 | * @brief Clears the SAI Rx status flag state. |
AnnaBridge | 171:3a7713b1edbc | 419 | * |
AnnaBridge | 171:3a7713b1edbc | 420 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 421 | * @param mask State mask. It can be a combination of the following source if defined: |
AnnaBridge | 171:3a7713b1edbc | 422 | * @arg kSAI_WordStartFlag |
AnnaBridge | 171:3a7713b1edbc | 423 | * @arg kSAI_SyncErrorFlag |
AnnaBridge | 171:3a7713b1edbc | 424 | * @arg kSAI_FIFOErrorFlag |
AnnaBridge | 171:3a7713b1edbc | 425 | */ |
AnnaBridge | 171:3a7713b1edbc | 426 | static inline void SAI_RxClearStatusFlags(I2S_Type *base, uint32_t mask) |
AnnaBridge | 171:3a7713b1edbc | 427 | { |
AnnaBridge | 171:3a7713b1edbc | 428 | base->RCSR = ((base->RCSR & 0xFFE3FFFFU) | mask); |
AnnaBridge | 171:3a7713b1edbc | 429 | } |
AnnaBridge | 171:3a7713b1edbc | 430 | |
AnnaBridge | 171:3a7713b1edbc | 431 | /*! @} */ |
AnnaBridge | 171:3a7713b1edbc | 432 | |
AnnaBridge | 171:3a7713b1edbc | 433 | /*! |
AnnaBridge | 171:3a7713b1edbc | 434 | * @name Interrupts |
AnnaBridge | 171:3a7713b1edbc | 435 | * @{ |
AnnaBridge | 171:3a7713b1edbc | 436 | */ |
AnnaBridge | 171:3a7713b1edbc | 437 | |
AnnaBridge | 171:3a7713b1edbc | 438 | /*! |
AnnaBridge | 171:3a7713b1edbc | 439 | * @brief Enables SAI Tx interrupt requests. |
AnnaBridge | 171:3a7713b1edbc | 440 | * |
AnnaBridge | 171:3a7713b1edbc | 441 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 442 | * @param mask interrupt source |
AnnaBridge | 171:3a7713b1edbc | 443 | * The parameter can be a combination of the following source if defined: |
AnnaBridge | 171:3a7713b1edbc | 444 | * @arg kSAI_WordStartInterruptEnable |
AnnaBridge | 171:3a7713b1edbc | 445 | * @arg kSAI_SyncErrorInterruptEnable |
AnnaBridge | 171:3a7713b1edbc | 446 | * @arg kSAI_FIFOWarningInterruptEnable |
AnnaBridge | 171:3a7713b1edbc | 447 | * @arg kSAI_FIFORequestInterruptEnable |
AnnaBridge | 171:3a7713b1edbc | 448 | * @arg kSAI_FIFOErrorInterruptEnable |
AnnaBridge | 171:3a7713b1edbc | 449 | */ |
AnnaBridge | 171:3a7713b1edbc | 450 | static inline void SAI_TxEnableInterrupts(I2S_Type *base, uint32_t mask) |
AnnaBridge | 171:3a7713b1edbc | 451 | { |
AnnaBridge | 171:3a7713b1edbc | 452 | base->TCSR = ((base->TCSR & 0xFFE3FFFFU) | mask); |
AnnaBridge | 171:3a7713b1edbc | 453 | } |
AnnaBridge | 171:3a7713b1edbc | 454 | |
AnnaBridge | 171:3a7713b1edbc | 455 | /*! |
AnnaBridge | 171:3a7713b1edbc | 456 | * @brief Enables SAI Rx interrupt requests. |
AnnaBridge | 171:3a7713b1edbc | 457 | * |
AnnaBridge | 171:3a7713b1edbc | 458 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 459 | * @param mask interrupt source |
AnnaBridge | 171:3a7713b1edbc | 460 | * The parameter can be a combination of the following source if defined: |
AnnaBridge | 171:3a7713b1edbc | 461 | * @arg kSAI_WordStartInterruptEnable |
AnnaBridge | 171:3a7713b1edbc | 462 | * @arg kSAI_SyncErrorInterruptEnable |
AnnaBridge | 171:3a7713b1edbc | 463 | * @arg kSAI_FIFOWarningInterruptEnable |
AnnaBridge | 171:3a7713b1edbc | 464 | * @arg kSAI_FIFORequestInterruptEnable |
AnnaBridge | 171:3a7713b1edbc | 465 | * @arg kSAI_FIFOErrorInterruptEnable |
AnnaBridge | 171:3a7713b1edbc | 466 | */ |
AnnaBridge | 171:3a7713b1edbc | 467 | static inline void SAI_RxEnableInterrupts(I2S_Type *base, uint32_t mask) |
AnnaBridge | 171:3a7713b1edbc | 468 | { |
AnnaBridge | 171:3a7713b1edbc | 469 | base->RCSR = ((base->RCSR & 0xFFE3FFFFU) | mask); |
AnnaBridge | 171:3a7713b1edbc | 470 | } |
AnnaBridge | 171:3a7713b1edbc | 471 | |
AnnaBridge | 171:3a7713b1edbc | 472 | /*! |
AnnaBridge | 171:3a7713b1edbc | 473 | * @brief Disables SAI Tx interrupt requests. |
AnnaBridge | 171:3a7713b1edbc | 474 | * |
AnnaBridge | 171:3a7713b1edbc | 475 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 476 | * @param mask interrupt source |
AnnaBridge | 171:3a7713b1edbc | 477 | * The parameter can be a combination of the following source if defined: |
AnnaBridge | 171:3a7713b1edbc | 478 | * @arg kSAI_WordStartInterruptEnable |
AnnaBridge | 171:3a7713b1edbc | 479 | * @arg kSAI_SyncErrorInterruptEnable |
AnnaBridge | 171:3a7713b1edbc | 480 | * @arg kSAI_FIFOWarningInterruptEnable |
AnnaBridge | 171:3a7713b1edbc | 481 | * @arg kSAI_FIFORequestInterruptEnable |
AnnaBridge | 171:3a7713b1edbc | 482 | * @arg kSAI_FIFOErrorInterruptEnable |
AnnaBridge | 171:3a7713b1edbc | 483 | */ |
AnnaBridge | 171:3a7713b1edbc | 484 | static inline void SAI_TxDisableInterrupts(I2S_Type *base, uint32_t mask) |
AnnaBridge | 171:3a7713b1edbc | 485 | { |
AnnaBridge | 171:3a7713b1edbc | 486 | base->TCSR = ((base->TCSR & 0xFFE3FFFFU) & (~mask)); |
AnnaBridge | 171:3a7713b1edbc | 487 | } |
AnnaBridge | 171:3a7713b1edbc | 488 | |
AnnaBridge | 171:3a7713b1edbc | 489 | /*! |
AnnaBridge | 171:3a7713b1edbc | 490 | * @brief Disables SAI Rx interrupt requests. |
AnnaBridge | 171:3a7713b1edbc | 491 | * |
AnnaBridge | 171:3a7713b1edbc | 492 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 493 | * @param mask interrupt source |
AnnaBridge | 171:3a7713b1edbc | 494 | * The parameter can be a combination of the following source if defined: |
AnnaBridge | 171:3a7713b1edbc | 495 | * @arg kSAI_WordStartInterruptEnable |
AnnaBridge | 171:3a7713b1edbc | 496 | * @arg kSAI_SyncErrorInterruptEnable |
AnnaBridge | 171:3a7713b1edbc | 497 | * @arg kSAI_FIFOWarningInterruptEnable |
AnnaBridge | 171:3a7713b1edbc | 498 | * @arg kSAI_FIFORequestInterruptEnable |
AnnaBridge | 171:3a7713b1edbc | 499 | * @arg kSAI_FIFOErrorInterruptEnable |
AnnaBridge | 171:3a7713b1edbc | 500 | */ |
AnnaBridge | 171:3a7713b1edbc | 501 | static inline void SAI_RxDisableInterrupts(I2S_Type *base, uint32_t mask) |
AnnaBridge | 171:3a7713b1edbc | 502 | { |
AnnaBridge | 171:3a7713b1edbc | 503 | base->RCSR = ((base->RCSR & 0xFFE3FFFFU) & (~mask)); |
AnnaBridge | 171:3a7713b1edbc | 504 | } |
AnnaBridge | 171:3a7713b1edbc | 505 | |
AnnaBridge | 171:3a7713b1edbc | 506 | /*! @} */ |
AnnaBridge | 171:3a7713b1edbc | 507 | |
AnnaBridge | 171:3a7713b1edbc | 508 | /*! |
AnnaBridge | 171:3a7713b1edbc | 509 | * @name DMA Control |
AnnaBridge | 171:3a7713b1edbc | 510 | * @{ |
AnnaBridge | 171:3a7713b1edbc | 511 | */ |
AnnaBridge | 171:3a7713b1edbc | 512 | |
AnnaBridge | 171:3a7713b1edbc | 513 | /*! |
AnnaBridge | 171:3a7713b1edbc | 514 | * @brief Enables/disables SAI Tx DMA requests. |
AnnaBridge | 171:3a7713b1edbc | 515 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 516 | * @param mask DMA source |
AnnaBridge | 171:3a7713b1edbc | 517 | * The parameter can be combination of the following source if defined: |
AnnaBridge | 171:3a7713b1edbc | 518 | * @arg kSAI_FIFOWarningDMAEnable |
AnnaBridge | 171:3a7713b1edbc | 519 | * @arg kSAI_FIFORequestDMAEnable |
AnnaBridge | 171:3a7713b1edbc | 520 | * @param enable True means enable DMA, false means disable DMA. |
AnnaBridge | 171:3a7713b1edbc | 521 | */ |
AnnaBridge | 171:3a7713b1edbc | 522 | static inline void SAI_TxEnableDMA(I2S_Type *base, uint32_t mask, bool enable) |
AnnaBridge | 171:3a7713b1edbc | 523 | { |
AnnaBridge | 171:3a7713b1edbc | 524 | if (enable) |
AnnaBridge | 171:3a7713b1edbc | 525 | { |
AnnaBridge | 171:3a7713b1edbc | 526 | base->TCSR = ((base->TCSR & 0xFFE3FFFFU) | mask); |
AnnaBridge | 171:3a7713b1edbc | 527 | } |
AnnaBridge | 171:3a7713b1edbc | 528 | else |
AnnaBridge | 171:3a7713b1edbc | 529 | { |
AnnaBridge | 171:3a7713b1edbc | 530 | base->TCSR = ((base->TCSR & 0xFFE3FFFFU) & (~mask)); |
AnnaBridge | 171:3a7713b1edbc | 531 | } |
AnnaBridge | 171:3a7713b1edbc | 532 | } |
AnnaBridge | 171:3a7713b1edbc | 533 | |
AnnaBridge | 171:3a7713b1edbc | 534 | /*! |
AnnaBridge | 171:3a7713b1edbc | 535 | * @brief Enables/disables SAI Rx DMA requests. |
AnnaBridge | 171:3a7713b1edbc | 536 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 537 | * @param mask DMA source |
AnnaBridge | 171:3a7713b1edbc | 538 | * The parameter can be a combination of the following source if defined: |
AnnaBridge | 171:3a7713b1edbc | 539 | * @arg kSAI_FIFOWarningDMAEnable |
AnnaBridge | 171:3a7713b1edbc | 540 | * @arg kSAI_FIFORequestDMAEnable |
AnnaBridge | 171:3a7713b1edbc | 541 | * @param enable True means enable DMA, false means disable DMA. |
AnnaBridge | 171:3a7713b1edbc | 542 | */ |
AnnaBridge | 171:3a7713b1edbc | 543 | static inline void SAI_RxEnableDMA(I2S_Type *base, uint32_t mask, bool enable) |
AnnaBridge | 171:3a7713b1edbc | 544 | { |
AnnaBridge | 171:3a7713b1edbc | 545 | if (enable) |
AnnaBridge | 171:3a7713b1edbc | 546 | { |
AnnaBridge | 171:3a7713b1edbc | 547 | base->RCSR = ((base->RCSR & 0xFFE3FFFFU) | mask); |
AnnaBridge | 171:3a7713b1edbc | 548 | } |
AnnaBridge | 171:3a7713b1edbc | 549 | else |
AnnaBridge | 171:3a7713b1edbc | 550 | { |
AnnaBridge | 171:3a7713b1edbc | 551 | base->RCSR = ((base->RCSR & 0xFFE3FFFFU) & (~mask)); |
AnnaBridge | 171:3a7713b1edbc | 552 | } |
AnnaBridge | 171:3a7713b1edbc | 553 | } |
AnnaBridge | 171:3a7713b1edbc | 554 | |
AnnaBridge | 171:3a7713b1edbc | 555 | /*! |
AnnaBridge | 171:3a7713b1edbc | 556 | * @brief Gets the SAI Tx data register address. |
AnnaBridge | 171:3a7713b1edbc | 557 | * |
AnnaBridge | 171:3a7713b1edbc | 558 | * This API is used to provide a transfer address for SAI DMA transfer configuration. |
AnnaBridge | 171:3a7713b1edbc | 559 | * |
AnnaBridge | 171:3a7713b1edbc | 560 | * @param base SAI base pointer. |
AnnaBridge | 171:3a7713b1edbc | 561 | * @param channel Which data channel used. |
AnnaBridge | 171:3a7713b1edbc | 562 | * @return data register address. |
AnnaBridge | 171:3a7713b1edbc | 563 | */ |
AnnaBridge | 171:3a7713b1edbc | 564 | static inline uint32_t SAI_TxGetDataRegisterAddress(I2S_Type *base, uint32_t channel) |
AnnaBridge | 171:3a7713b1edbc | 565 | { |
AnnaBridge | 171:3a7713b1edbc | 566 | return (uint32_t)(&(base->TDR)[channel]); |
AnnaBridge | 171:3a7713b1edbc | 567 | } |
AnnaBridge | 171:3a7713b1edbc | 568 | |
AnnaBridge | 171:3a7713b1edbc | 569 | /*! |
AnnaBridge | 171:3a7713b1edbc | 570 | * @brief Gets the SAI Rx data register address. |
AnnaBridge | 171:3a7713b1edbc | 571 | * |
AnnaBridge | 171:3a7713b1edbc | 572 | * This API is used to provide a transfer address for SAI DMA transfer configuration. |
AnnaBridge | 171:3a7713b1edbc | 573 | * |
AnnaBridge | 171:3a7713b1edbc | 574 | * @param base SAI base pointer. |
AnnaBridge | 171:3a7713b1edbc | 575 | * @param channel Which data channel used. |
AnnaBridge | 171:3a7713b1edbc | 576 | * @return data register address. |
AnnaBridge | 171:3a7713b1edbc | 577 | */ |
AnnaBridge | 171:3a7713b1edbc | 578 | static inline uint32_t SAI_RxGetDataRegisterAddress(I2S_Type *base, uint32_t channel) |
AnnaBridge | 171:3a7713b1edbc | 579 | { |
AnnaBridge | 171:3a7713b1edbc | 580 | return (uint32_t)(&(base->RDR)[channel]); |
AnnaBridge | 171:3a7713b1edbc | 581 | } |
AnnaBridge | 171:3a7713b1edbc | 582 | |
AnnaBridge | 171:3a7713b1edbc | 583 | /*! @} */ |
AnnaBridge | 171:3a7713b1edbc | 584 | |
AnnaBridge | 171:3a7713b1edbc | 585 | /*! |
AnnaBridge | 171:3a7713b1edbc | 586 | * @name Bus Operations |
AnnaBridge | 171:3a7713b1edbc | 587 | * @{ |
AnnaBridge | 171:3a7713b1edbc | 588 | */ |
AnnaBridge | 171:3a7713b1edbc | 589 | |
AnnaBridge | 171:3a7713b1edbc | 590 | /*! |
AnnaBridge | 171:3a7713b1edbc | 591 | * @brief Configures the SAI Tx audio format. |
AnnaBridge | 171:3a7713b1edbc | 592 | * |
AnnaBridge | 171:3a7713b1edbc | 593 | * The audio format can be changed at run-time. This function configures the sample rate and audio data |
AnnaBridge | 171:3a7713b1edbc | 594 | * format to be transferred. |
AnnaBridge | 171:3a7713b1edbc | 595 | * |
AnnaBridge | 171:3a7713b1edbc | 596 | * @param base SAI base pointer. |
AnnaBridge | 171:3a7713b1edbc | 597 | * @param format Pointer to SAI audio data format structure. |
AnnaBridge | 171:3a7713b1edbc | 598 | * @param mclkSourceClockHz SAI master clock source frequency in Hz. |
AnnaBridge | 171:3a7713b1edbc | 599 | * @param bclkSourceClockHz SAI bit clock source frequency in Hz. If bit clock source is master |
AnnaBridge | 171:3a7713b1edbc | 600 | * clock, this value should equals to masterClockHz in format. |
AnnaBridge | 171:3a7713b1edbc | 601 | */ |
AnnaBridge | 171:3a7713b1edbc | 602 | void SAI_TxSetFormat(I2S_Type *base, |
AnnaBridge | 171:3a7713b1edbc | 603 | sai_transfer_format_t *format, |
AnnaBridge | 171:3a7713b1edbc | 604 | uint32_t mclkSourceClockHz, |
AnnaBridge | 171:3a7713b1edbc | 605 | uint32_t bclkSourceClockHz); |
AnnaBridge | 171:3a7713b1edbc | 606 | |
AnnaBridge | 171:3a7713b1edbc | 607 | /*! |
AnnaBridge | 171:3a7713b1edbc | 608 | * @brief Configures the SAI Rx audio format. |
AnnaBridge | 171:3a7713b1edbc | 609 | * |
AnnaBridge | 171:3a7713b1edbc | 610 | * The audio format can be changed at run-time. This function configures the sample rate and audio data |
AnnaBridge | 171:3a7713b1edbc | 611 | * format to be transferred. |
AnnaBridge | 171:3a7713b1edbc | 612 | * |
AnnaBridge | 171:3a7713b1edbc | 613 | * @param base SAI base pointer. |
AnnaBridge | 171:3a7713b1edbc | 614 | * @param format Pointer to SAI audio data format structure. |
AnnaBridge | 171:3a7713b1edbc | 615 | * @param mclkSourceClockHz SAI master clock source frequency in Hz. |
AnnaBridge | 171:3a7713b1edbc | 616 | * @param bclkSourceClockHz SAI bit clock source frequency in Hz. If bit clock source is master |
AnnaBridge | 171:3a7713b1edbc | 617 | * clock, this value should equals to masterClockHz in format. |
AnnaBridge | 171:3a7713b1edbc | 618 | */ |
AnnaBridge | 171:3a7713b1edbc | 619 | void SAI_RxSetFormat(I2S_Type *base, |
AnnaBridge | 171:3a7713b1edbc | 620 | sai_transfer_format_t *format, |
AnnaBridge | 171:3a7713b1edbc | 621 | uint32_t mclkSourceClockHz, |
AnnaBridge | 171:3a7713b1edbc | 622 | uint32_t bclkSourceClockHz); |
AnnaBridge | 171:3a7713b1edbc | 623 | |
AnnaBridge | 171:3a7713b1edbc | 624 | /*! |
AnnaBridge | 171:3a7713b1edbc | 625 | * @brief Sends data using a blocking method. |
AnnaBridge | 171:3a7713b1edbc | 626 | * |
AnnaBridge | 171:3a7713b1edbc | 627 | * @note This function blocks by polling until data is ready to be sent. |
AnnaBridge | 171:3a7713b1edbc | 628 | * |
AnnaBridge | 171:3a7713b1edbc | 629 | * @param base SAI base pointer. |
AnnaBridge | 171:3a7713b1edbc | 630 | * @param channel Data channel used. |
AnnaBridge | 171:3a7713b1edbc | 631 | * @param bitWidth How many bits in a audio word, usually 8/16/24/32 bits. |
AnnaBridge | 171:3a7713b1edbc | 632 | * @param buffer Pointer to the data to be written. |
AnnaBridge | 171:3a7713b1edbc | 633 | * @param size Bytes to be written. |
AnnaBridge | 171:3a7713b1edbc | 634 | */ |
AnnaBridge | 171:3a7713b1edbc | 635 | void SAI_WriteBlocking(I2S_Type *base, uint32_t channel, uint32_t bitWidth, uint8_t *buffer, uint32_t size); |
AnnaBridge | 171:3a7713b1edbc | 636 | |
AnnaBridge | 171:3a7713b1edbc | 637 | /*! |
AnnaBridge | 171:3a7713b1edbc | 638 | * @brief Writes data into SAI FIFO. |
AnnaBridge | 171:3a7713b1edbc | 639 | * |
AnnaBridge | 171:3a7713b1edbc | 640 | * @param base SAI base pointer. |
AnnaBridge | 171:3a7713b1edbc | 641 | * @param channel Data channel used. |
AnnaBridge | 171:3a7713b1edbc | 642 | * @param data Data needs to be written. |
AnnaBridge | 171:3a7713b1edbc | 643 | */ |
AnnaBridge | 171:3a7713b1edbc | 644 | static inline void SAI_WriteData(I2S_Type *base, uint32_t channel, uint32_t data) |
AnnaBridge | 171:3a7713b1edbc | 645 | { |
AnnaBridge | 171:3a7713b1edbc | 646 | base->TDR[channel] = data; |
AnnaBridge | 171:3a7713b1edbc | 647 | } |
AnnaBridge | 171:3a7713b1edbc | 648 | |
AnnaBridge | 171:3a7713b1edbc | 649 | /*! |
AnnaBridge | 171:3a7713b1edbc | 650 | * @brief Receives data using a blocking method. |
AnnaBridge | 171:3a7713b1edbc | 651 | * |
AnnaBridge | 171:3a7713b1edbc | 652 | * @note This function blocks by polling until data is ready to be sent. |
AnnaBridge | 171:3a7713b1edbc | 653 | * |
AnnaBridge | 171:3a7713b1edbc | 654 | * @param base SAI base pointer. |
AnnaBridge | 171:3a7713b1edbc | 655 | * @param channel Data channel used. |
AnnaBridge | 171:3a7713b1edbc | 656 | * @param bitWidth How many bits in a audio word, usually 8/16/24/32 bits. |
AnnaBridge | 171:3a7713b1edbc | 657 | * @param buffer Pointer to the data to be read. |
AnnaBridge | 171:3a7713b1edbc | 658 | * @param size Bytes to be read. |
AnnaBridge | 171:3a7713b1edbc | 659 | */ |
AnnaBridge | 171:3a7713b1edbc | 660 | void SAI_ReadBlocking(I2S_Type *base, uint32_t channel, uint32_t bitWidth, uint8_t *buffer, uint32_t size); |
AnnaBridge | 171:3a7713b1edbc | 661 | |
AnnaBridge | 171:3a7713b1edbc | 662 | /*! |
AnnaBridge | 171:3a7713b1edbc | 663 | * @brief Reads data from SAI FIFO. |
AnnaBridge | 171:3a7713b1edbc | 664 | * |
AnnaBridge | 171:3a7713b1edbc | 665 | * @param base SAI base pointer. |
AnnaBridge | 171:3a7713b1edbc | 666 | * @param channel Data channel used. |
AnnaBridge | 171:3a7713b1edbc | 667 | * @return Data in SAI FIFO. |
AnnaBridge | 171:3a7713b1edbc | 668 | */ |
AnnaBridge | 171:3a7713b1edbc | 669 | static inline uint32_t SAI_ReadData(I2S_Type *base, uint32_t channel) |
AnnaBridge | 171:3a7713b1edbc | 670 | { |
AnnaBridge | 171:3a7713b1edbc | 671 | return base->RDR[channel]; |
AnnaBridge | 171:3a7713b1edbc | 672 | } |
AnnaBridge | 171:3a7713b1edbc | 673 | |
AnnaBridge | 171:3a7713b1edbc | 674 | /*! @} */ |
AnnaBridge | 171:3a7713b1edbc | 675 | |
AnnaBridge | 171:3a7713b1edbc | 676 | /*! |
AnnaBridge | 171:3a7713b1edbc | 677 | * @name Transactional |
AnnaBridge | 171:3a7713b1edbc | 678 | * @{ |
AnnaBridge | 171:3a7713b1edbc | 679 | */ |
AnnaBridge | 171:3a7713b1edbc | 680 | |
AnnaBridge | 171:3a7713b1edbc | 681 | /*! |
AnnaBridge | 171:3a7713b1edbc | 682 | * @brief Initializes the SAI Tx handle. |
AnnaBridge | 171:3a7713b1edbc | 683 | * |
AnnaBridge | 171:3a7713b1edbc | 684 | * This function initializes the Tx handle for SAI Tx transactional APIs. Call |
AnnaBridge | 171:3a7713b1edbc | 685 | * this function one time to get the handle initialized. |
AnnaBridge | 171:3a7713b1edbc | 686 | * |
AnnaBridge | 171:3a7713b1edbc | 687 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 688 | * @param handle SAI handle pointer. |
AnnaBridge | 171:3a7713b1edbc | 689 | * @param callback pointer to user callback function |
AnnaBridge | 171:3a7713b1edbc | 690 | * @param userData user parameter passed to the callback function |
AnnaBridge | 171:3a7713b1edbc | 691 | */ |
AnnaBridge | 171:3a7713b1edbc | 692 | void SAI_TransferTxCreateHandle(I2S_Type *base, sai_handle_t *handle, sai_transfer_callback_t callback, void *userData); |
AnnaBridge | 171:3a7713b1edbc | 693 | |
AnnaBridge | 171:3a7713b1edbc | 694 | /*! |
AnnaBridge | 171:3a7713b1edbc | 695 | * @brief Initializes the SAI Rx handle. |
AnnaBridge | 171:3a7713b1edbc | 696 | * |
AnnaBridge | 171:3a7713b1edbc | 697 | * This function initializes the Rx handle for SAI Rx transactional APIs. Call |
AnnaBridge | 171:3a7713b1edbc | 698 | * this function one time to get the handle initialized. |
AnnaBridge | 171:3a7713b1edbc | 699 | * |
AnnaBridge | 171:3a7713b1edbc | 700 | * @param base SAI base pointer. |
AnnaBridge | 171:3a7713b1edbc | 701 | * @param handle SAI handle pointer. |
AnnaBridge | 171:3a7713b1edbc | 702 | * @param callback pointer to user callback function |
AnnaBridge | 171:3a7713b1edbc | 703 | * @param userData user parameter passed to the callback function |
AnnaBridge | 171:3a7713b1edbc | 704 | */ |
AnnaBridge | 171:3a7713b1edbc | 705 | void SAI_TransferRxCreateHandle(I2S_Type *base, sai_handle_t *handle, sai_transfer_callback_t callback, void *userData); |
AnnaBridge | 171:3a7713b1edbc | 706 | |
AnnaBridge | 171:3a7713b1edbc | 707 | /*! |
AnnaBridge | 171:3a7713b1edbc | 708 | * @brief Configures the SAI Tx audio format. |
AnnaBridge | 171:3a7713b1edbc | 709 | * |
AnnaBridge | 171:3a7713b1edbc | 710 | * The audio format can be changed at run-time. This function configures the sample rate and audio data |
AnnaBridge | 171:3a7713b1edbc | 711 | * format to be transferred. |
AnnaBridge | 171:3a7713b1edbc | 712 | * |
AnnaBridge | 171:3a7713b1edbc | 713 | * @param base SAI base pointer. |
AnnaBridge | 171:3a7713b1edbc | 714 | * @param handle SAI handle pointer. |
AnnaBridge | 171:3a7713b1edbc | 715 | * @param format Pointer to SAI audio data format structure. |
AnnaBridge | 171:3a7713b1edbc | 716 | * @param mclkSourceClockHz SAI master clock source frequency in Hz. |
AnnaBridge | 171:3a7713b1edbc | 717 | * @param bclkSourceClockHz SAI bit clock source frequency in Hz. If a bit clock source is a master |
AnnaBridge | 171:3a7713b1edbc | 718 | * clock, this value should equal to masterClockHz in format. |
AnnaBridge | 171:3a7713b1edbc | 719 | * @return Status of this function. Return value is one of status_t. |
AnnaBridge | 171:3a7713b1edbc | 720 | */ |
AnnaBridge | 171:3a7713b1edbc | 721 | status_t SAI_TransferTxSetFormat(I2S_Type *base, |
AnnaBridge | 171:3a7713b1edbc | 722 | sai_handle_t *handle, |
AnnaBridge | 171:3a7713b1edbc | 723 | sai_transfer_format_t *format, |
AnnaBridge | 171:3a7713b1edbc | 724 | uint32_t mclkSourceClockHz, |
AnnaBridge | 171:3a7713b1edbc | 725 | uint32_t bclkSourceClockHz); |
AnnaBridge | 171:3a7713b1edbc | 726 | |
AnnaBridge | 171:3a7713b1edbc | 727 | /*! |
AnnaBridge | 171:3a7713b1edbc | 728 | * @brief Configures the SAI Rx audio format. |
AnnaBridge | 171:3a7713b1edbc | 729 | * |
AnnaBridge | 171:3a7713b1edbc | 730 | * The audio format can be changed at run-time. This function configures the sample rate and audio data |
AnnaBridge | 171:3a7713b1edbc | 731 | * format to be transferred. |
AnnaBridge | 171:3a7713b1edbc | 732 | * |
AnnaBridge | 171:3a7713b1edbc | 733 | * @param base SAI base pointer. |
AnnaBridge | 171:3a7713b1edbc | 734 | * @param handle SAI handle pointer. |
AnnaBridge | 171:3a7713b1edbc | 735 | * @param format Pointer to SAI audio data format structure. |
AnnaBridge | 171:3a7713b1edbc | 736 | * @param mclkSourceClockHz SAI master clock source frequency in Hz. |
AnnaBridge | 171:3a7713b1edbc | 737 | * @param bclkSourceClockHz SAI bit clock source frequency in Hz. If bit clock source is master |
AnnaBridge | 171:3a7713b1edbc | 738 | * clock, this value should equals to masterClockHz in format. |
AnnaBridge | 171:3a7713b1edbc | 739 | * @return Status of this function. Return value is one of status_t. |
AnnaBridge | 171:3a7713b1edbc | 740 | */ |
AnnaBridge | 171:3a7713b1edbc | 741 | status_t SAI_TransferRxSetFormat(I2S_Type *base, |
AnnaBridge | 171:3a7713b1edbc | 742 | sai_handle_t *handle, |
AnnaBridge | 171:3a7713b1edbc | 743 | sai_transfer_format_t *format, |
AnnaBridge | 171:3a7713b1edbc | 744 | uint32_t mclkSourceClockHz, |
AnnaBridge | 171:3a7713b1edbc | 745 | uint32_t bclkSourceClockHz); |
AnnaBridge | 171:3a7713b1edbc | 746 | |
AnnaBridge | 171:3a7713b1edbc | 747 | /*! |
AnnaBridge | 171:3a7713b1edbc | 748 | * @brief Performs an interrupt non-blocking send transfer on SAI. |
AnnaBridge | 171:3a7713b1edbc | 749 | * |
AnnaBridge | 171:3a7713b1edbc | 750 | * @note This API returns immediately after the transfer initiates. |
AnnaBridge | 171:3a7713b1edbc | 751 | * Call the SAI_TxGetTransferStatusIRQ to poll the transfer status and check whether |
AnnaBridge | 171:3a7713b1edbc | 752 | * the transfer is finished. If the return status is not kStatus_SAI_Busy, the transfer |
AnnaBridge | 171:3a7713b1edbc | 753 | * is finished. |
AnnaBridge | 171:3a7713b1edbc | 754 | * |
AnnaBridge | 171:3a7713b1edbc | 755 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 756 | * @param handle pointer to sai_handle_t structure which stores the transfer state |
AnnaBridge | 171:3a7713b1edbc | 757 | * @param xfer pointer to sai_transfer_t structure |
AnnaBridge | 171:3a7713b1edbc | 758 | * @retval kStatus_Success Successfully started the data receive. |
AnnaBridge | 171:3a7713b1edbc | 759 | * @retval kStatus_SAI_TxBusy Previous receive still not finished. |
AnnaBridge | 171:3a7713b1edbc | 760 | * @retval kStatus_InvalidArgument The input parameter is invalid. |
AnnaBridge | 171:3a7713b1edbc | 761 | */ |
AnnaBridge | 171:3a7713b1edbc | 762 | status_t SAI_TransferSendNonBlocking(I2S_Type *base, sai_handle_t *handle, sai_transfer_t *xfer); |
AnnaBridge | 171:3a7713b1edbc | 763 | |
AnnaBridge | 171:3a7713b1edbc | 764 | /*! |
AnnaBridge | 171:3a7713b1edbc | 765 | * @brief Performs an interrupt non-blocking receive transfer on SAI. |
AnnaBridge | 171:3a7713b1edbc | 766 | * |
AnnaBridge | 171:3a7713b1edbc | 767 | * @note This API returns immediately after the transfer initiates. |
AnnaBridge | 171:3a7713b1edbc | 768 | * Call the SAI_RxGetTransferStatusIRQ to poll the transfer status and check whether |
AnnaBridge | 171:3a7713b1edbc | 769 | * the transfer is finished. If the return status is not kStatus_SAI_Busy, the transfer |
AnnaBridge | 171:3a7713b1edbc | 770 | * is finished. |
AnnaBridge | 171:3a7713b1edbc | 771 | * |
AnnaBridge | 171:3a7713b1edbc | 772 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 773 | * @param handle pointer to sai_handle_t structure which stores the transfer state |
AnnaBridge | 171:3a7713b1edbc | 774 | * @param xfer pointer to sai_transfer_t structure |
AnnaBridge | 171:3a7713b1edbc | 775 | * @retval kStatus_Success Successfully started the data receive. |
AnnaBridge | 171:3a7713b1edbc | 776 | * @retval kStatus_SAI_RxBusy Previous receive still not finished. |
AnnaBridge | 171:3a7713b1edbc | 777 | * @retval kStatus_InvalidArgument The input parameter is invalid. |
AnnaBridge | 171:3a7713b1edbc | 778 | */ |
AnnaBridge | 171:3a7713b1edbc | 779 | status_t SAI_TransferReceiveNonBlocking(I2S_Type *base, sai_handle_t *handle, sai_transfer_t *xfer); |
AnnaBridge | 171:3a7713b1edbc | 780 | |
AnnaBridge | 171:3a7713b1edbc | 781 | /*! |
AnnaBridge | 171:3a7713b1edbc | 782 | * @brief Gets a set byte count. |
AnnaBridge | 171:3a7713b1edbc | 783 | * |
AnnaBridge | 171:3a7713b1edbc | 784 | * @param base SAI base pointer. |
AnnaBridge | 171:3a7713b1edbc | 785 | * @param handle pointer to sai_handle_t structure which stores the transfer state. |
AnnaBridge | 171:3a7713b1edbc | 786 | * @param count Bytes count sent. |
AnnaBridge | 171:3a7713b1edbc | 787 | * @retval kStatus_Success Succeed get the transfer count. |
AnnaBridge | 171:3a7713b1edbc | 788 | * @retval kStatus_NoTransferInProgress There is not a non-blocking transaction currently in progress. |
AnnaBridge | 171:3a7713b1edbc | 789 | */ |
AnnaBridge | 171:3a7713b1edbc | 790 | status_t SAI_TransferGetSendCount(I2S_Type *base, sai_handle_t *handle, size_t *count); |
AnnaBridge | 171:3a7713b1edbc | 791 | |
AnnaBridge | 171:3a7713b1edbc | 792 | /*! |
AnnaBridge | 171:3a7713b1edbc | 793 | * @brief Gets a received byte count. |
AnnaBridge | 171:3a7713b1edbc | 794 | * |
AnnaBridge | 171:3a7713b1edbc | 795 | * @param base SAI base pointer. |
AnnaBridge | 171:3a7713b1edbc | 796 | * @param handle pointer to sai_handle_t structure which stores the transfer state. |
AnnaBridge | 171:3a7713b1edbc | 797 | * @param count Bytes count received. |
AnnaBridge | 171:3a7713b1edbc | 798 | * @retval kStatus_Success Succeed get the transfer count. |
AnnaBridge | 171:3a7713b1edbc | 799 | * @retval kStatus_NoTransferInProgress There is not a non-blocking transaction currently in progress. |
AnnaBridge | 171:3a7713b1edbc | 800 | */ |
AnnaBridge | 171:3a7713b1edbc | 801 | status_t SAI_TransferGetReceiveCount(I2S_Type *base, sai_handle_t *handle, size_t *count); |
AnnaBridge | 171:3a7713b1edbc | 802 | |
AnnaBridge | 171:3a7713b1edbc | 803 | /*! |
AnnaBridge | 171:3a7713b1edbc | 804 | * @brief Aborts the current send. |
AnnaBridge | 171:3a7713b1edbc | 805 | * |
AnnaBridge | 171:3a7713b1edbc | 806 | * @note This API can be called any time when an interrupt non-blocking transfer initiates |
AnnaBridge | 171:3a7713b1edbc | 807 | * to abort the transfer early. |
AnnaBridge | 171:3a7713b1edbc | 808 | * |
AnnaBridge | 171:3a7713b1edbc | 809 | * @param base SAI base pointer. |
AnnaBridge | 171:3a7713b1edbc | 810 | * @param handle pointer to sai_handle_t structure which stores the transfer state. |
AnnaBridge | 171:3a7713b1edbc | 811 | */ |
AnnaBridge | 171:3a7713b1edbc | 812 | void SAI_TransferAbortSend(I2S_Type *base, sai_handle_t *handle); |
AnnaBridge | 171:3a7713b1edbc | 813 | |
AnnaBridge | 171:3a7713b1edbc | 814 | /*! |
AnnaBridge | 171:3a7713b1edbc | 815 | * @brief Aborts the the current IRQ receive. |
AnnaBridge | 171:3a7713b1edbc | 816 | * |
AnnaBridge | 171:3a7713b1edbc | 817 | * @note This API can be called any time when an interrupt non-blocking transfer initiates |
AnnaBridge | 171:3a7713b1edbc | 818 | * to abort the transfer early. |
AnnaBridge | 171:3a7713b1edbc | 819 | * |
AnnaBridge | 171:3a7713b1edbc | 820 | * @param base SAI base pointer |
AnnaBridge | 171:3a7713b1edbc | 821 | * @param handle pointer to sai_handle_t structure which stores the transfer state. |
AnnaBridge | 171:3a7713b1edbc | 822 | */ |
AnnaBridge | 171:3a7713b1edbc | 823 | void SAI_TransferAbortReceive(I2S_Type *base, sai_handle_t *handle); |
AnnaBridge | 171:3a7713b1edbc | 824 | |
AnnaBridge | 171:3a7713b1edbc | 825 | /*! |
AnnaBridge | 171:3a7713b1edbc | 826 | * @brief Tx interrupt handler. |
AnnaBridge | 171:3a7713b1edbc | 827 | * |
AnnaBridge | 171:3a7713b1edbc | 828 | * @param base SAI base pointer. |
AnnaBridge | 171:3a7713b1edbc | 829 | * @param handle pointer to sai_handle_t structure. |
AnnaBridge | 171:3a7713b1edbc | 830 | */ |
AnnaBridge | 171:3a7713b1edbc | 831 | void SAI_TransferTxHandleIRQ(I2S_Type *base, sai_handle_t *handle); |
AnnaBridge | 171:3a7713b1edbc | 832 | |
AnnaBridge | 171:3a7713b1edbc | 833 | /*! |
AnnaBridge | 171:3a7713b1edbc | 834 | * @brief Tx interrupt handler. |
AnnaBridge | 171:3a7713b1edbc | 835 | * |
AnnaBridge | 171:3a7713b1edbc | 836 | * @param base SAI base pointer. |
AnnaBridge | 171:3a7713b1edbc | 837 | * @param handle pointer to sai_handle_t structure. |
AnnaBridge | 171:3a7713b1edbc | 838 | */ |
AnnaBridge | 171:3a7713b1edbc | 839 | void SAI_TransferRxHandleIRQ(I2S_Type *base, sai_handle_t *handle); |
AnnaBridge | 171:3a7713b1edbc | 840 | |
AnnaBridge | 171:3a7713b1edbc | 841 | /*! @} */ |
AnnaBridge | 171:3a7713b1edbc | 842 | |
AnnaBridge | 171:3a7713b1edbc | 843 | #if defined(__cplusplus) |
AnnaBridge | 171:3a7713b1edbc | 844 | } |
AnnaBridge | 171:3a7713b1edbc | 845 | #endif /*_cplusplus*/ |
AnnaBridge | 171:3a7713b1edbc | 846 | |
AnnaBridge | 171:3a7713b1edbc | 847 | /*! @} */ |
AnnaBridge | 171:3a7713b1edbc | 848 | |
AnnaBridge | 171:3a7713b1edbc | 849 | #endif /* _FSL_SAI_H_ */ |