mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_STM32F7/stm32f7xx_hal_sai.c@637:ed69428d4850, 2015-12-22 (annotated)
- Committer:
- jaerts
- Date:
- Tue Dec 22 13:22:16 2015 +0000
- Revision:
- 637:ed69428d4850
- Parent:
- 610:813dcc80987e
Add very shady LPC1768 CAN Filter implementation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 573:ad23fe03a082 | 1 | /** |
mbed_official | 573:ad23fe03a082 | 2 | ****************************************************************************** |
mbed_official | 573:ad23fe03a082 | 3 | * @file stm32f7xx_hal_sai.c |
mbed_official | 573:ad23fe03a082 | 4 | * @author MCD Application Team |
mbed_official | 610:813dcc80987e | 5 | * @version V1.0.1 |
mbed_official | 610:813dcc80987e | 6 | * @date 25-June-2015 |
mbed_official | 573:ad23fe03a082 | 7 | * @brief SAI HAL module driver. |
mbed_official | 573:ad23fe03a082 | 8 | * This file provides firmware functions to manage the following |
mbed_official | 573:ad23fe03a082 | 9 | * functionalities of the Serial Audio Interface (SAI) peripheral: |
mbed_official | 573:ad23fe03a082 | 10 | * + Initialization/de-initialization functions |
mbed_official | 573:ad23fe03a082 | 11 | * + I/O operation functions |
mbed_official | 573:ad23fe03a082 | 12 | * + Peripheral Control functions |
mbed_official | 573:ad23fe03a082 | 13 | * + Peripheral State functions |
mbed_official | 573:ad23fe03a082 | 14 | * |
mbed_official | 573:ad23fe03a082 | 15 | @verbatim |
mbed_official | 573:ad23fe03a082 | 16 | ============================================================================== |
mbed_official | 573:ad23fe03a082 | 17 | ##### How to use this driver ##### |
mbed_official | 573:ad23fe03a082 | 18 | ============================================================================== |
mbed_official | 573:ad23fe03a082 | 19 | |
mbed_official | 573:ad23fe03a082 | 20 | [..] |
mbed_official | 573:ad23fe03a082 | 21 | The SAI HAL driver can be used as follows: |
mbed_official | 573:ad23fe03a082 | 22 | |
mbed_official | 573:ad23fe03a082 | 23 | (#) Declare a SAI_HandleTypeDef handle structure. |
mbed_official | 573:ad23fe03a082 | 24 | (#) Initialize the SAI low level resources by implementing the HAL_SAI_MspInit() API: |
mbed_official | 573:ad23fe03a082 | 25 | (##) Enable the SAI interface clock. |
mbed_official | 573:ad23fe03a082 | 26 | (##) SAI pins configuration: |
mbed_official | 573:ad23fe03a082 | 27 | (+++) Enable the clock for the SAI GPIOs. |
mbed_official | 573:ad23fe03a082 | 28 | (+++) Configure these SAI pins as alternate function pull-up. |
mbed_official | 573:ad23fe03a082 | 29 | (##) NVIC configuration if you need to use interrupt process (HAL_SAI_Transmit_IT() |
mbed_official | 573:ad23fe03a082 | 30 | and HAL_SAI_Receive_IT() APIs): |
mbed_official | 573:ad23fe03a082 | 31 | (+++) Configure the SAI interrupt priority. |
mbed_official | 573:ad23fe03a082 | 32 | (+++) Enable the NVIC SAI IRQ handle. |
mbed_official | 573:ad23fe03a082 | 33 | |
mbed_official | 573:ad23fe03a082 | 34 | (##) DMA Configuration if you need to use DMA process (HAL_SAI_Transmit_DMA() |
mbed_official | 573:ad23fe03a082 | 35 | and HAL_SAI_Receive_DMA() APIs): |
mbed_official | 573:ad23fe03a082 | 36 | (+++) Declare a DMA handle structure for the Tx/Rx stream. |
mbed_official | 573:ad23fe03a082 | 37 | (+++) Enable the DMAx interface clock. |
mbed_official | 573:ad23fe03a082 | 38 | (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters. |
mbed_official | 573:ad23fe03a082 | 39 | (+++) Configure the DMA Tx/Rx Stream. |
mbed_official | 573:ad23fe03a082 | 40 | (+++) Associate the initialized DMA handle to the SAI DMA Tx/Rx handle. |
mbed_official | 573:ad23fe03a082 | 41 | (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the |
mbed_official | 573:ad23fe03a082 | 42 | DMA Tx/Rx Stream. |
mbed_official | 573:ad23fe03a082 | 43 | |
mbed_official | 573:ad23fe03a082 | 44 | (#) Program the SAI Mode, Standard, Data Format, MCLK Output, Audio frequency and Polarity |
mbed_official | 573:ad23fe03a082 | 45 | using HAL_SAI_Init() function. |
mbed_official | 573:ad23fe03a082 | 46 | |
mbed_official | 573:ad23fe03a082 | 47 | -@- The specific SAI interrupts (FIFO request and Overrun underrun interrupt) |
mbed_official | 573:ad23fe03a082 | 48 | will be managed using the macros __SAI_ENABLE_IT() and __SAI_DISABLE_IT() |
mbed_official | 573:ad23fe03a082 | 49 | inside the transmit and receive process. |
mbed_official | 573:ad23fe03a082 | 50 | |
mbed_official | 573:ad23fe03a082 | 51 | [..] |
mbed_official | 573:ad23fe03a082 | 52 | (@) SAI Clock Source, the configuration is managed through RCCEx_PeriphCLKConfig() |
mbed_official | 573:ad23fe03a082 | 53 | function in the HAL RCC drivers |
mbed_official | 573:ad23fe03a082 | 54 | [..] |
mbed_official | 573:ad23fe03a082 | 55 | (@) Make sure that either: |
mbed_official | 573:ad23fe03a082 | 56 | (+@) I2S PLL is configured or |
mbed_official | 573:ad23fe03a082 | 57 | (+@) SAI PLL is configured or |
mbed_official | 573:ad23fe03a082 | 58 | (+@) External clock source is configured after setting correctly |
mbed_official | 573:ad23fe03a082 | 59 | the define constant EXTERNAL_CLOCK_VALUE in the stm32f7xx_hal_conf.h file. |
mbed_official | 573:ad23fe03a082 | 60 | |
mbed_official | 573:ad23fe03a082 | 61 | [..] |
mbed_official | 573:ad23fe03a082 | 62 | (@) In master Tx mode: enabling the audio block immediately generates the bit clock |
mbed_official | 573:ad23fe03a082 | 63 | for the external slaves even if there is no data in the FIFO, However FS signal |
mbed_official | 573:ad23fe03a082 | 64 | generation is conditioned by the presence of data in the FIFO. |
mbed_official | 573:ad23fe03a082 | 65 | |
mbed_official | 573:ad23fe03a082 | 66 | [..] |
mbed_official | 573:ad23fe03a082 | 67 | (@) In master Rx mode: enabling the audio block immediately generates the bit clock |
mbed_official | 573:ad23fe03a082 | 68 | and FS signal for the external slaves. |
mbed_official | 573:ad23fe03a082 | 69 | |
mbed_official | 573:ad23fe03a082 | 70 | [..] |
mbed_official | 573:ad23fe03a082 | 71 | (@) It is mandatory to respect the following conditions in order to avoid bad SAI behavior: |
mbed_official | 573:ad23fe03a082 | 72 | (+@) First bit Offset <= (SLOT size - Data size) |
mbed_official | 573:ad23fe03a082 | 73 | (+@) Data size <= SLOT size |
mbed_official | 573:ad23fe03a082 | 74 | (+@) Number of SLOT x SLOT size = Frame length |
mbed_official | 573:ad23fe03a082 | 75 | (+@) The number of slots should be even when SAI_FS_CHANNEL_IDENTIFICATION is selected. |
mbed_official | 573:ad23fe03a082 | 76 | |
mbed_official | 573:ad23fe03a082 | 77 | [..] |
mbed_official | 573:ad23fe03a082 | 78 | Three operation modes are available within this driver : |
mbed_official | 573:ad23fe03a082 | 79 | |
mbed_official | 573:ad23fe03a082 | 80 | *** Polling mode IO operation *** |
mbed_official | 573:ad23fe03a082 | 81 | ================================= |
mbed_official | 573:ad23fe03a082 | 82 | [..] |
mbed_official | 573:ad23fe03a082 | 83 | (+) Send an amount of data in blocking mode using HAL_SAI_Transmit() |
mbed_official | 573:ad23fe03a082 | 84 | (+) Receive an amount of data in blocking mode using HAL_SAI_Receive() |
mbed_official | 573:ad23fe03a082 | 85 | |
mbed_official | 573:ad23fe03a082 | 86 | *** Interrupt mode IO operation *** |
mbed_official | 573:ad23fe03a082 | 87 | =================================== |
mbed_official | 573:ad23fe03a082 | 88 | [..] |
mbed_official | 573:ad23fe03a082 | 89 | (+) Send an amount of data in non blocking mode using HAL_SAI_Transmit_IT() |
mbed_official | 573:ad23fe03a082 | 90 | (+) At transmission end of transfer HAL_SAI_TxCpltCallback is executed and user can |
mbed_official | 573:ad23fe03a082 | 91 | add his own code by customization of function pointer HAL_SAI_TxCpltCallback |
mbed_official | 573:ad23fe03a082 | 92 | (+) Receive an amount of data in non blocking mode using HAL_SAI_Receive_IT() |
mbed_official | 573:ad23fe03a082 | 93 | (+) At reception end of transfer HAL_SAI_RxCpltCallback is executed and user can |
mbed_official | 573:ad23fe03a082 | 94 | add his own code by customization of function pointer HAL_SAI_RxCpltCallback |
mbed_official | 573:ad23fe03a082 | 95 | (+) In case of transfer Error, HAL_SAI_ErrorCallback() function is executed and user can |
mbed_official | 573:ad23fe03a082 | 96 | add his own code by customization of function pointer HAL_SAI_ErrorCallback |
mbed_official | 573:ad23fe03a082 | 97 | |
mbed_official | 573:ad23fe03a082 | 98 | *** DMA mode IO operation *** |
mbed_official | 573:ad23fe03a082 | 99 | ============================== |
mbed_official | 573:ad23fe03a082 | 100 | [..] |
mbed_official | 573:ad23fe03a082 | 101 | (+) Send an amount of data in non blocking mode (DMA) using HAL_SAI_Transmit_DMA() |
mbed_official | 573:ad23fe03a082 | 102 | (+) At transmission end of transfer HAL_SAI_TxCpltCallback is executed and user can |
mbed_official | 573:ad23fe03a082 | 103 | add his own code by customization of function pointer HAL_SAI_TxCpltCallback |
mbed_official | 573:ad23fe03a082 | 104 | (+) Receive an amount of data in non blocking mode (DMA) using HAL_SAI_Receive_DMA() |
mbed_official | 573:ad23fe03a082 | 105 | (+) At reception end of transfer HAL_SAI_RxCpltCallback is executed and user can |
mbed_official | 573:ad23fe03a082 | 106 | add his own code by customization of function pointer HAL_SAI_RxCpltCallback |
mbed_official | 573:ad23fe03a082 | 107 | (+) In case of transfer Error, HAL_SAI_ErrorCallback() function is executed and user can |
mbed_official | 573:ad23fe03a082 | 108 | add his own code by customization of function pointer HAL_SAI_ErrorCallback |
mbed_official | 573:ad23fe03a082 | 109 | (+) Pause the DMA Transfer using HAL_SAI_DMAPause() |
mbed_official | 573:ad23fe03a082 | 110 | (+) Resume the DMA Transfer using HAL_SAI_DMAResume() |
mbed_official | 573:ad23fe03a082 | 111 | (+) Stop the DMA Transfer using HAL_SAI_DMAStop() |
mbed_official | 573:ad23fe03a082 | 112 | |
mbed_official | 573:ad23fe03a082 | 113 | *** SAI HAL driver macros list *** |
mbed_official | 573:ad23fe03a082 | 114 | ============================================= |
mbed_official | 573:ad23fe03a082 | 115 | [..] |
mbed_official | 573:ad23fe03a082 | 116 | Below the list of most used macros in USART HAL driver : |
mbed_official | 573:ad23fe03a082 | 117 | |
mbed_official | 573:ad23fe03a082 | 118 | (+) __HAL_SAI_ENABLE: Enable the SAI peripheral |
mbed_official | 573:ad23fe03a082 | 119 | (+) __HAL_SAI_DISABLE: Disable the SAI peripheral |
mbed_official | 573:ad23fe03a082 | 120 | (+) __HAL_SAI_ENABLE_IT : Enable the specified SAI interrupts |
mbed_official | 573:ad23fe03a082 | 121 | (+) __HAL_SAI_DISABLE_IT : Disable the specified SAI interrupts |
mbed_official | 573:ad23fe03a082 | 122 | (+) __HAL_SAI_GET_IT_SOURCE: Check if the specified SAI interrupt source is |
mbed_official | 573:ad23fe03a082 | 123 | enabled or disabled |
mbed_official | 573:ad23fe03a082 | 124 | (+) __HAL_SAI_GET_FLAG: Check whether the specified SAI flag is set or not |
mbed_official | 573:ad23fe03a082 | 125 | |
mbed_official | 573:ad23fe03a082 | 126 | @endverbatim |
mbed_official | 573:ad23fe03a082 | 127 | ****************************************************************************** |
mbed_official | 573:ad23fe03a082 | 128 | * @attention |
mbed_official | 573:ad23fe03a082 | 129 | * |
mbed_official | 573:ad23fe03a082 | 130 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
mbed_official | 573:ad23fe03a082 | 131 | * |
mbed_official | 573:ad23fe03a082 | 132 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 573:ad23fe03a082 | 133 | * are permitted provided that the following conditions are met: |
mbed_official | 573:ad23fe03a082 | 134 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 573:ad23fe03a082 | 135 | * this list of conditions and the following disclaimer. |
mbed_official | 573:ad23fe03a082 | 136 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 573:ad23fe03a082 | 137 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 573:ad23fe03a082 | 138 | * and/or other materials provided with the distribution. |
mbed_official | 573:ad23fe03a082 | 139 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 573:ad23fe03a082 | 140 | * may be used to endorse or promote products derived from this software |
mbed_official | 573:ad23fe03a082 | 141 | * without specific prior written permission. |
mbed_official | 573:ad23fe03a082 | 142 | * |
mbed_official | 573:ad23fe03a082 | 143 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 573:ad23fe03a082 | 144 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 573:ad23fe03a082 | 145 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 573:ad23fe03a082 | 146 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 573:ad23fe03a082 | 147 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 573:ad23fe03a082 | 148 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 573:ad23fe03a082 | 149 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 573:ad23fe03a082 | 150 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 573:ad23fe03a082 | 151 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 573:ad23fe03a082 | 152 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 573:ad23fe03a082 | 153 | * |
mbed_official | 573:ad23fe03a082 | 154 | ****************************************************************************** |
mbed_official | 573:ad23fe03a082 | 155 | */ |
mbed_official | 573:ad23fe03a082 | 156 | |
mbed_official | 573:ad23fe03a082 | 157 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 158 | #include "stm32f7xx_hal.h" |
mbed_official | 573:ad23fe03a082 | 159 | |
mbed_official | 573:ad23fe03a082 | 160 | /** @addtogroup STM32F7xx_HAL_Driver |
mbed_official | 573:ad23fe03a082 | 161 | * @{ |
mbed_official | 573:ad23fe03a082 | 162 | */ |
mbed_official | 573:ad23fe03a082 | 163 | |
mbed_official | 573:ad23fe03a082 | 164 | /** @defgroup SAI SAI |
mbed_official | 573:ad23fe03a082 | 165 | * @brief SAI HAL module driver |
mbed_official | 573:ad23fe03a082 | 166 | * @{ |
mbed_official | 573:ad23fe03a082 | 167 | */ |
mbed_official | 573:ad23fe03a082 | 168 | |
mbed_official | 573:ad23fe03a082 | 169 | #ifdef HAL_SAI_MODULE_ENABLED |
mbed_official | 573:ad23fe03a082 | 170 | |
mbed_official | 573:ad23fe03a082 | 171 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 172 | /** @defgroup SAI_Private_Typedefs SAI Private Typedefs |
mbed_official | 573:ad23fe03a082 | 173 | * @{ |
mbed_official | 573:ad23fe03a082 | 174 | */ |
mbed_official | 573:ad23fe03a082 | 175 | typedef enum { |
mbed_official | 573:ad23fe03a082 | 176 | SAI_MODE_DMA, |
mbed_official | 573:ad23fe03a082 | 177 | SAI_MODE_IT |
mbed_official | 573:ad23fe03a082 | 178 | }SAI_ModeTypedef; |
mbed_official | 573:ad23fe03a082 | 179 | /** |
mbed_official | 573:ad23fe03a082 | 180 | * @} |
mbed_official | 573:ad23fe03a082 | 181 | */ |
mbed_official | 573:ad23fe03a082 | 182 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 183 | /** @defgroup SAI_Private_Constants SAI Private Constants |
mbed_official | 573:ad23fe03a082 | 184 | * @{ |
mbed_official | 573:ad23fe03a082 | 185 | */ |
mbed_official | 573:ad23fe03a082 | 186 | #define SAI_FIFO_SIZE 8 |
mbed_official | 573:ad23fe03a082 | 187 | #define SAI_DEFAULT_TIMEOUT 4 |
mbed_official | 573:ad23fe03a082 | 188 | /** |
mbed_official | 573:ad23fe03a082 | 189 | * @} |
mbed_official | 573:ad23fe03a082 | 190 | */ |
mbed_official | 573:ad23fe03a082 | 191 | |
mbed_official | 573:ad23fe03a082 | 192 | /* SAI registers Masks */ |
mbed_official | 573:ad23fe03a082 | 193 | #define CR1_CLEAR_MASK ((uint32_t)0xFF04C010) |
mbed_official | 573:ad23fe03a082 | 194 | #define FRCR_CLEAR_MASK ((uint32_t)0xFFF88000) |
mbed_official | 573:ad23fe03a082 | 195 | #define SLOTR_CLEAR_MASK ((uint32_t)0x0000F020) |
mbed_official | 573:ad23fe03a082 | 196 | |
mbed_official | 573:ad23fe03a082 | 197 | #define SAI_TIMEOUT_VALUE 10 |
mbed_official | 573:ad23fe03a082 | 198 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 199 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 200 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 201 | static void SAI_FillFifo(SAI_HandleTypeDef *hsai); |
mbed_official | 573:ad23fe03a082 | 202 | static uint32_t SAI_InterruptFlag(SAI_HandleTypeDef *hsai, uint32_t mode); |
mbed_official | 573:ad23fe03a082 | 203 | static HAL_StatusTypeDef SAI_InitI2S(SAI_HandleTypeDef *hsai, uint32_t protocol, uint32_t datasize, uint32_t nbslot); |
mbed_official | 573:ad23fe03a082 | 204 | static HAL_StatusTypeDef SAI_InitPCM(SAI_HandleTypeDef *hsai, uint32_t protocol, uint32_t datasize, uint32_t nbslot); |
mbed_official | 573:ad23fe03a082 | 205 | |
mbed_official | 573:ad23fe03a082 | 206 | static HAL_StatusTypeDef SAI_Disable(SAI_HandleTypeDef *hsai); |
mbed_official | 573:ad23fe03a082 | 207 | static void SAI_Transmit_IT8Bit(SAI_HandleTypeDef *hsai); |
mbed_official | 573:ad23fe03a082 | 208 | static void SAI_Transmit_IT16Bit(SAI_HandleTypeDef *hsai); |
mbed_official | 573:ad23fe03a082 | 209 | static void SAI_Transmit_IT32Bit(SAI_HandleTypeDef *hsai); |
mbed_official | 573:ad23fe03a082 | 210 | static void SAI_Receive_IT8Bit(SAI_HandleTypeDef *hsai); |
mbed_official | 573:ad23fe03a082 | 211 | static void SAI_Receive_IT16Bit(SAI_HandleTypeDef *hsai); |
mbed_official | 573:ad23fe03a082 | 212 | static void SAI_Receive_IT32Bit(SAI_HandleTypeDef *hsai); |
mbed_official | 573:ad23fe03a082 | 213 | |
mbed_official | 573:ad23fe03a082 | 214 | static void SAI_DMATxCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 573:ad23fe03a082 | 215 | static void SAI_DMATxHalfCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 573:ad23fe03a082 | 216 | static void SAI_DMARxCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 573:ad23fe03a082 | 217 | static void SAI_DMARxHalfCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 573:ad23fe03a082 | 218 | static void SAI_DMAError(DMA_HandleTypeDef *hdma); |
mbed_official | 573:ad23fe03a082 | 219 | |
mbed_official | 573:ad23fe03a082 | 220 | /* Exported functions ---------------------------------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 221 | |
mbed_official | 573:ad23fe03a082 | 222 | /** @defgroup SAI_Exported_Functions SAI Exported Functions |
mbed_official | 573:ad23fe03a082 | 223 | * @{ |
mbed_official | 573:ad23fe03a082 | 224 | */ |
mbed_official | 573:ad23fe03a082 | 225 | |
mbed_official | 573:ad23fe03a082 | 226 | /** @defgroup SAI_Exported_Functions_Group1 Initialization and de-initialization functions |
mbed_official | 573:ad23fe03a082 | 227 | * @brief Initialization and Configuration functions |
mbed_official | 573:ad23fe03a082 | 228 | * |
mbed_official | 573:ad23fe03a082 | 229 | @verbatim |
mbed_official | 573:ad23fe03a082 | 230 | =============================================================================== |
mbed_official | 573:ad23fe03a082 | 231 | ##### Initialization and de-initialization functions ##### |
mbed_official | 573:ad23fe03a082 | 232 | =============================================================================== |
mbed_official | 573:ad23fe03a082 | 233 | [..] This subsection provides a set of functions allowing to initialize and |
mbed_official | 573:ad23fe03a082 | 234 | de-initialize the SAIx peripheral: |
mbed_official | 573:ad23fe03a082 | 235 | |
mbed_official | 573:ad23fe03a082 | 236 | (+) User must implement HAL_SAI_MspInit() function in which he configures |
mbed_official | 573:ad23fe03a082 | 237 | all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ). |
mbed_official | 573:ad23fe03a082 | 238 | |
mbed_official | 573:ad23fe03a082 | 239 | (+) Call the function HAL_SAI_Init() to configure the selected device with |
mbed_official | 573:ad23fe03a082 | 240 | the selected configuration: |
mbed_official | 573:ad23fe03a082 | 241 | (++) Mode (Master/slave TX/RX) |
mbed_official | 573:ad23fe03a082 | 242 | (++) Protocol |
mbed_official | 573:ad23fe03a082 | 243 | (++) Data Size |
mbed_official | 573:ad23fe03a082 | 244 | (++) MCLK Output |
mbed_official | 573:ad23fe03a082 | 245 | (++) Audio frequency |
mbed_official | 573:ad23fe03a082 | 246 | (++) FIFO Threshold |
mbed_official | 573:ad23fe03a082 | 247 | (++) Frame Config |
mbed_official | 573:ad23fe03a082 | 248 | (++) Slot Config |
mbed_official | 573:ad23fe03a082 | 249 | |
mbed_official | 573:ad23fe03a082 | 250 | (+) Call the function HAL_SAI_DeInit() to restore the default configuration |
mbed_official | 573:ad23fe03a082 | 251 | of the selected SAI peripheral. |
mbed_official | 573:ad23fe03a082 | 252 | |
mbed_official | 573:ad23fe03a082 | 253 | @endverbatim |
mbed_official | 573:ad23fe03a082 | 254 | * @{ |
mbed_official | 573:ad23fe03a082 | 255 | */ |
mbed_official | 573:ad23fe03a082 | 256 | |
mbed_official | 573:ad23fe03a082 | 257 | /** |
mbed_official | 573:ad23fe03a082 | 258 | * @brief Initializes the structure FrameInit, SlotInit and the low part of |
mbed_official | 573:ad23fe03a082 | 259 | * Init according to the specified parameters and call the function |
mbed_official | 573:ad23fe03a082 | 260 | * HAL_SAI_Init to initialize the SAI block. |
mbed_official | 573:ad23fe03a082 | 261 | * @param hsai : pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 262 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 263 | * @param protocol : one of the supported protocol @ref SAI_Protocol |
mbed_official | 573:ad23fe03a082 | 264 | * @param datasize : one of the supported datasize @ref SAI_Protocol_DataSize |
mbed_official | 573:ad23fe03a082 | 265 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 266 | * @param nbslot : Number of slot. |
mbed_official | 573:ad23fe03a082 | 267 | * @retval HAL status |
mbed_official | 573:ad23fe03a082 | 268 | */ |
mbed_official | 573:ad23fe03a082 | 269 | HAL_StatusTypeDef HAL_SAI_InitProtocol(SAI_HandleTypeDef *hsai, uint32_t protocol, uint32_t datasize, uint32_t nbslot) |
mbed_official | 573:ad23fe03a082 | 270 | { |
mbed_official | 573:ad23fe03a082 | 271 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 573:ad23fe03a082 | 272 | |
mbed_official | 573:ad23fe03a082 | 273 | /* Check the parameters */ |
mbed_official | 573:ad23fe03a082 | 274 | assert_param(IS_SAI_SUPPORTED_PROTOCOL(protocol)); |
mbed_official | 573:ad23fe03a082 | 275 | assert_param(IS_SAI_PROTOCOL_DATASIZE(datasize)); |
mbed_official | 573:ad23fe03a082 | 276 | |
mbed_official | 573:ad23fe03a082 | 277 | switch(protocol) |
mbed_official | 573:ad23fe03a082 | 278 | { |
mbed_official | 573:ad23fe03a082 | 279 | case SAI_I2S_STANDARD : |
mbed_official | 573:ad23fe03a082 | 280 | case SAI_I2S_MSBJUSTIFIED : |
mbed_official | 573:ad23fe03a082 | 281 | case SAI_I2S_LSBJUSTIFIED : |
mbed_official | 573:ad23fe03a082 | 282 | status = SAI_InitI2S(hsai, protocol, datasize, nbslot); |
mbed_official | 573:ad23fe03a082 | 283 | break; |
mbed_official | 573:ad23fe03a082 | 284 | case SAI_PCM_LONG : |
mbed_official | 573:ad23fe03a082 | 285 | case SAI_PCM_SHORT : |
mbed_official | 573:ad23fe03a082 | 286 | status = SAI_InitPCM(hsai, protocol, datasize, nbslot); |
mbed_official | 573:ad23fe03a082 | 287 | break; |
mbed_official | 573:ad23fe03a082 | 288 | default : |
mbed_official | 573:ad23fe03a082 | 289 | status = HAL_ERROR; |
mbed_official | 573:ad23fe03a082 | 290 | break; |
mbed_official | 573:ad23fe03a082 | 291 | } |
mbed_official | 573:ad23fe03a082 | 292 | |
mbed_official | 573:ad23fe03a082 | 293 | if(status == HAL_OK) |
mbed_official | 573:ad23fe03a082 | 294 | { |
mbed_official | 573:ad23fe03a082 | 295 | status = HAL_SAI_Init(hsai); |
mbed_official | 573:ad23fe03a082 | 296 | } |
mbed_official | 573:ad23fe03a082 | 297 | |
mbed_official | 573:ad23fe03a082 | 298 | return status; |
mbed_official | 573:ad23fe03a082 | 299 | } |
mbed_official | 573:ad23fe03a082 | 300 | |
mbed_official | 573:ad23fe03a082 | 301 | /** |
mbed_official | 573:ad23fe03a082 | 302 | * @brief Initializes the SAI according to the specified parameters |
mbed_official | 573:ad23fe03a082 | 303 | * in the SAI_InitTypeDef and create the associated handle. |
mbed_official | 573:ad23fe03a082 | 304 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 305 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 306 | * @retval HAL status |
mbed_official | 573:ad23fe03a082 | 307 | */ |
mbed_official | 573:ad23fe03a082 | 308 | HAL_StatusTypeDef HAL_SAI_Init(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 309 | { |
mbed_official | 573:ad23fe03a082 | 310 | uint32_t tmpclock = 0; |
mbed_official | 573:ad23fe03a082 | 311 | |
mbed_official | 573:ad23fe03a082 | 312 | /* This variable used to store the SAI_CK_x (value in Hz) */ |
mbed_official | 573:ad23fe03a082 | 313 | uint32_t freq = 0; |
mbed_official | 573:ad23fe03a082 | 314 | |
mbed_official | 573:ad23fe03a082 | 315 | /* Check the SAI handle allocation */ |
mbed_official | 573:ad23fe03a082 | 316 | if(hsai == NULL) |
mbed_official | 573:ad23fe03a082 | 317 | { |
mbed_official | 573:ad23fe03a082 | 318 | return HAL_ERROR; |
mbed_official | 573:ad23fe03a082 | 319 | } |
mbed_official | 573:ad23fe03a082 | 320 | |
mbed_official | 573:ad23fe03a082 | 321 | /* Check the SAI Block parameters */ |
mbed_official | 573:ad23fe03a082 | 322 | assert_param(IS_SAI_AUDIO_FREQUENCY(hsai->Init.AudioFrequency)); |
mbed_official | 573:ad23fe03a082 | 323 | assert_param(IS_SAI_BLOCK_PROTOCOL(hsai->Init.Protocol)); |
mbed_official | 573:ad23fe03a082 | 324 | assert_param(IS_SAI_BLOCK_MODE(hsai->Init.AudioMode)); |
mbed_official | 573:ad23fe03a082 | 325 | assert_param(IS_SAI_BLOCK_SYNCEXT(hsai->Init.SynchroExt)); |
mbed_official | 573:ad23fe03a082 | 326 | assert_param(IS_SAI_BLOCK_DATASIZE(hsai->Init.DataSize)); |
mbed_official | 573:ad23fe03a082 | 327 | assert_param(IS_SAI_BLOCK_FIRST_BIT(hsai->Init.FirstBit)); |
mbed_official | 573:ad23fe03a082 | 328 | assert_param(IS_SAI_BLOCK_CLOCK_STROBING(hsai->Init.ClockStrobing)); |
mbed_official | 573:ad23fe03a082 | 329 | assert_param(IS_SAI_BLOCK_SYNCHRO(hsai->Init.Synchro)); |
mbed_official | 573:ad23fe03a082 | 330 | assert_param(IS_SAI_BLOCK_OUTPUT_DRIVE(hsai->Init.OutputDrive)); |
mbed_official | 573:ad23fe03a082 | 331 | assert_param(IS_SAI_BLOCK_NODIVIDER(hsai->Init.NoDivider)); |
mbed_official | 573:ad23fe03a082 | 332 | assert_param(IS_SAI_BLOCK_FIFO_THRESHOLD(hsai->Init.FIFOThreshold)); |
mbed_official | 573:ad23fe03a082 | 333 | assert_param(IS_SAI_MONO_STEREO_MODE(hsai->Init.MonoStereoMode)); |
mbed_official | 573:ad23fe03a082 | 334 | assert_param(IS_SAI_BLOCK_COMPANDING_MODE(hsai->Init.CompandingMode)); |
mbed_official | 573:ad23fe03a082 | 335 | assert_param(IS_SAI_BLOCK_TRISTATE_MANAGEMENT(hsai->Init.TriState)); |
mbed_official | 573:ad23fe03a082 | 336 | |
mbed_official | 573:ad23fe03a082 | 337 | /* Check the SAI Block Frame parameters */ |
mbed_official | 573:ad23fe03a082 | 338 | assert_param(IS_SAI_BLOCK_FRAME_LENGTH(hsai->FrameInit.FrameLength)); |
mbed_official | 573:ad23fe03a082 | 339 | assert_param(IS_SAI_BLOCK_ACTIVE_FRAME(hsai->FrameInit.ActiveFrameLength)); |
mbed_official | 573:ad23fe03a082 | 340 | assert_param(IS_SAI_BLOCK_FS_DEFINITION(hsai->FrameInit.FSDefinition)); |
mbed_official | 573:ad23fe03a082 | 341 | assert_param(IS_SAI_BLOCK_FS_POLARITY(hsai->FrameInit.FSPolarity)); |
mbed_official | 573:ad23fe03a082 | 342 | assert_param(IS_SAI_BLOCK_FS_OFFSET(hsai->FrameInit.FSOffset)); |
mbed_official | 573:ad23fe03a082 | 343 | |
mbed_official | 573:ad23fe03a082 | 344 | /* Check the SAI Block Slot parameters */ |
mbed_official | 573:ad23fe03a082 | 345 | assert_param(IS_SAI_BLOCK_FIRSTBIT_OFFSET(hsai->SlotInit.FirstBitOffset)); |
mbed_official | 573:ad23fe03a082 | 346 | assert_param(IS_SAI_BLOCK_SLOT_SIZE(hsai->SlotInit.SlotSize)); |
mbed_official | 573:ad23fe03a082 | 347 | assert_param(IS_SAI_BLOCK_SLOT_NUMBER(hsai->SlotInit.SlotNumber)); |
mbed_official | 573:ad23fe03a082 | 348 | assert_param(IS_SAI_SLOT_ACTIVE(hsai->SlotInit.SlotActive)); |
mbed_official | 573:ad23fe03a082 | 349 | |
mbed_official | 573:ad23fe03a082 | 350 | if(hsai->State == HAL_SAI_STATE_RESET) |
mbed_official | 573:ad23fe03a082 | 351 | { |
mbed_official | 573:ad23fe03a082 | 352 | /* Allocate lock resource and initialize it */ |
mbed_official | 573:ad23fe03a082 | 353 | hsai->Lock = HAL_UNLOCKED; |
mbed_official | 573:ad23fe03a082 | 354 | |
mbed_official | 573:ad23fe03a082 | 355 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
mbed_official | 573:ad23fe03a082 | 356 | HAL_SAI_MspInit(hsai); |
mbed_official | 573:ad23fe03a082 | 357 | } |
mbed_official | 573:ad23fe03a082 | 358 | |
mbed_official | 573:ad23fe03a082 | 359 | hsai->State = HAL_SAI_STATE_BUSY; |
mbed_official | 573:ad23fe03a082 | 360 | |
mbed_official | 573:ad23fe03a082 | 361 | /* Disable the selected SAI peripheral */ |
mbed_official | 573:ad23fe03a082 | 362 | SAI_Disable(hsai); |
mbed_official | 573:ad23fe03a082 | 363 | |
mbed_official | 573:ad23fe03a082 | 364 | /* SAI Block Synchro Configuration -----------------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 365 | SAI_BlockSynchroConfig(hsai); |
mbed_official | 573:ad23fe03a082 | 366 | |
mbed_official | 573:ad23fe03a082 | 367 | /* Configure Master Clock using the following formula : |
mbed_official | 573:ad23fe03a082 | 368 | MCLK_x = SAI_CK_x / (MCKDIV[3:0] * 2) with MCLK_x = 256 * FS |
mbed_official | 573:ad23fe03a082 | 369 | FS = SAI_CK_x / (MCKDIV[3:0] * 2) * 256 |
mbed_official | 573:ad23fe03a082 | 370 | MCKDIV[3:0] = SAI_CK_x / FS * 512 */ |
mbed_official | 573:ad23fe03a082 | 371 | if(hsai->Init.AudioFrequency != SAI_AUDIO_FREQUENCY_MCKDIV) |
mbed_official | 573:ad23fe03a082 | 372 | { |
mbed_official | 573:ad23fe03a082 | 373 | /* Get SAI clock source based on Source clock selection from RCC */ |
mbed_official | 573:ad23fe03a082 | 374 | freq = SAI_GetInputClock(hsai); |
mbed_official | 573:ad23fe03a082 | 375 | |
mbed_official | 573:ad23fe03a082 | 376 | /* (saiclocksource x 10) to keep Significant digits */ |
mbed_official | 573:ad23fe03a082 | 377 | tmpclock = (((freq * 10) / ((hsai->Init.AudioFrequency) * 512))); |
mbed_official | 573:ad23fe03a082 | 378 | |
mbed_official | 573:ad23fe03a082 | 379 | hsai->Init.Mckdiv = tmpclock / 10; |
mbed_official | 573:ad23fe03a082 | 380 | |
mbed_official | 573:ad23fe03a082 | 381 | /* Round result to the nearest integer */ |
mbed_official | 573:ad23fe03a082 | 382 | if((tmpclock % 10) > 8) |
mbed_official | 573:ad23fe03a082 | 383 | { |
mbed_official | 573:ad23fe03a082 | 384 | hsai->Init.Mckdiv+= 1; |
mbed_official | 573:ad23fe03a082 | 385 | } |
mbed_official | 573:ad23fe03a082 | 386 | } |
mbed_official | 573:ad23fe03a082 | 387 | |
mbed_official | 573:ad23fe03a082 | 388 | /* SAI Block Configuration ------------------------------------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 389 | /* SAI CR1 Configuration */ |
mbed_official | 573:ad23fe03a082 | 390 | hsai->Instance->CR1&=~(SAI_xCR1_MODE | SAI_xCR1_PRTCFG | SAI_xCR1_DS | \ |
mbed_official | 573:ad23fe03a082 | 391 | SAI_xCR1_LSBFIRST | SAI_xCR1_CKSTR | SAI_xCR1_SYNCEN |\ |
mbed_official | 573:ad23fe03a082 | 392 | SAI_xCR1_MONO | SAI_xCR1_OUTDRIV | SAI_xCR1_DMAEN | \ |
mbed_official | 573:ad23fe03a082 | 393 | SAI_xCR1_NODIV | SAI_xCR1_MCKDIV); |
mbed_official | 573:ad23fe03a082 | 394 | |
mbed_official | 573:ad23fe03a082 | 395 | hsai->Instance->CR1|= (hsai->Init.AudioMode | hsai->Init.Protocol | \ |
mbed_official | 573:ad23fe03a082 | 396 | hsai->Init.DataSize | hsai->Init.FirstBit | \ |
mbed_official | 573:ad23fe03a082 | 397 | hsai->Init.ClockStrobing | hsai->Init.Synchro | \ |
mbed_official | 573:ad23fe03a082 | 398 | hsai->Init.MonoStereoMode | hsai->Init.OutputDrive | \ |
mbed_official | 573:ad23fe03a082 | 399 | hsai->Init.NoDivider | (hsai->Init.Mckdiv << 20) | hsai->Init.CompandingMode); |
mbed_official | 573:ad23fe03a082 | 400 | |
mbed_official | 573:ad23fe03a082 | 401 | /* SAI CR2 Configuration */ |
mbed_official | 573:ad23fe03a082 | 402 | hsai->Instance->CR2&= ~(SAI_xCR2_FTH | SAI_xCR2_FFLUSH | SAI_xCR2_COMP); |
mbed_official | 573:ad23fe03a082 | 403 | hsai->Instance->CR2|= (hsai->Init.FIFOThreshold | hsai->Init.CompandingMode | hsai->Init.TriState); |
mbed_official | 573:ad23fe03a082 | 404 | |
mbed_official | 573:ad23fe03a082 | 405 | |
mbed_official | 573:ad23fe03a082 | 406 | /* SAI Frame Configuration -----------------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 407 | hsai->Instance->FRCR&=(~(SAI_xFRCR_FRL | SAI_xFRCR_FSALL | SAI_xFRCR_FSDEF | \ |
mbed_official | 573:ad23fe03a082 | 408 | SAI_xFRCR_FSPO | SAI_xFRCR_FSOFF)); |
mbed_official | 573:ad23fe03a082 | 409 | hsai->Instance->FRCR|=((hsai->FrameInit.FrameLength - 1) | |
mbed_official | 573:ad23fe03a082 | 410 | hsai->FrameInit.FSOffset | |
mbed_official | 573:ad23fe03a082 | 411 | hsai->FrameInit.FSDefinition | |
mbed_official | 573:ad23fe03a082 | 412 | hsai->FrameInit.FSPolarity | |
mbed_official | 573:ad23fe03a082 | 413 | ((hsai->FrameInit.ActiveFrameLength - 1) << 8)); |
mbed_official | 573:ad23fe03a082 | 414 | |
mbed_official | 573:ad23fe03a082 | 415 | /* SAI Block_x SLOT Configuration ------------------------------------------*/ |
mbed_official | 610:813dcc80987e | 416 | /* This register has no meaning in AC 97 and SPDIF audio protocol */ |
mbed_official | 573:ad23fe03a082 | 417 | hsai->Instance->SLOTR&= (~(SAI_xSLOTR_FBOFF | SAI_xSLOTR_SLOTSZ | \ |
mbed_official | 573:ad23fe03a082 | 418 | SAI_xSLOTR_NBSLOT | SAI_xSLOTR_SLOTEN )); |
mbed_official | 573:ad23fe03a082 | 419 | |
mbed_official | 573:ad23fe03a082 | 420 | hsai->Instance->SLOTR|= hsai->SlotInit.FirstBitOffset | hsai->SlotInit.SlotSize |
mbed_official | 573:ad23fe03a082 | 421 | | hsai->SlotInit.SlotActive | ((hsai->SlotInit.SlotNumber - 1) << 8); |
mbed_official | 573:ad23fe03a082 | 422 | |
mbed_official | 573:ad23fe03a082 | 423 | /* Initialise the error code */ |
mbed_official | 573:ad23fe03a082 | 424 | hsai->ErrorCode = HAL_SAI_ERROR_NONE; |
mbed_official | 573:ad23fe03a082 | 425 | |
mbed_official | 573:ad23fe03a082 | 426 | /* Initialize the SAI state */ |
mbed_official | 573:ad23fe03a082 | 427 | hsai->State= HAL_SAI_STATE_READY; |
mbed_official | 573:ad23fe03a082 | 428 | |
mbed_official | 573:ad23fe03a082 | 429 | /* Release Lock */ |
mbed_official | 573:ad23fe03a082 | 430 | __HAL_UNLOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 431 | |
mbed_official | 573:ad23fe03a082 | 432 | return HAL_OK; |
mbed_official | 573:ad23fe03a082 | 433 | } |
mbed_official | 573:ad23fe03a082 | 434 | |
mbed_official | 573:ad23fe03a082 | 435 | /** |
mbed_official | 573:ad23fe03a082 | 436 | * @brief DeInitializes the SAI peripheral. |
mbed_official | 573:ad23fe03a082 | 437 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 438 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 439 | * @retval HAL status |
mbed_official | 573:ad23fe03a082 | 440 | */ |
mbed_official | 573:ad23fe03a082 | 441 | HAL_StatusTypeDef HAL_SAI_DeInit(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 442 | { |
mbed_official | 573:ad23fe03a082 | 443 | /* Check the SAI handle allocation */ |
mbed_official | 573:ad23fe03a082 | 444 | if(hsai == NULL) |
mbed_official | 573:ad23fe03a082 | 445 | { |
mbed_official | 573:ad23fe03a082 | 446 | return HAL_ERROR; |
mbed_official | 573:ad23fe03a082 | 447 | } |
mbed_official | 573:ad23fe03a082 | 448 | |
mbed_official | 573:ad23fe03a082 | 449 | hsai->State = HAL_SAI_STATE_BUSY; |
mbed_official | 573:ad23fe03a082 | 450 | |
mbed_official | 573:ad23fe03a082 | 451 | /* Disabled All interrupt and clear all the flag */ |
mbed_official | 573:ad23fe03a082 | 452 | hsai->Instance->IMR = 0; |
mbed_official | 573:ad23fe03a082 | 453 | hsai->Instance->CLRFR = 0xFFFFFFFF; |
mbed_official | 573:ad23fe03a082 | 454 | |
mbed_official | 573:ad23fe03a082 | 455 | /* Disable the SAI */ |
mbed_official | 573:ad23fe03a082 | 456 | SAI_Disable(hsai); |
mbed_official | 573:ad23fe03a082 | 457 | |
mbed_official | 573:ad23fe03a082 | 458 | /* Flush the fifo */ |
mbed_official | 573:ad23fe03a082 | 459 | SET_BIT(hsai->Instance->CR2, SAI_xCR2_FFLUSH); |
mbed_official | 573:ad23fe03a082 | 460 | |
mbed_official | 573:ad23fe03a082 | 461 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */ |
mbed_official | 573:ad23fe03a082 | 462 | HAL_SAI_MspDeInit(hsai); |
mbed_official | 573:ad23fe03a082 | 463 | |
mbed_official | 573:ad23fe03a082 | 464 | /* Initialize the error code */ |
mbed_official | 573:ad23fe03a082 | 465 | hsai->ErrorCode = HAL_SAI_ERROR_NONE; |
mbed_official | 573:ad23fe03a082 | 466 | |
mbed_official | 573:ad23fe03a082 | 467 | /* Initialize the SAI state */ |
mbed_official | 573:ad23fe03a082 | 468 | hsai->State = HAL_SAI_STATE_RESET; |
mbed_official | 573:ad23fe03a082 | 469 | |
mbed_official | 573:ad23fe03a082 | 470 | /* Release Lock */ |
mbed_official | 573:ad23fe03a082 | 471 | __HAL_UNLOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 472 | |
mbed_official | 573:ad23fe03a082 | 473 | return HAL_OK; |
mbed_official | 573:ad23fe03a082 | 474 | } |
mbed_official | 573:ad23fe03a082 | 475 | |
mbed_official | 573:ad23fe03a082 | 476 | /** |
mbed_official | 573:ad23fe03a082 | 477 | * @brief SAI MSP Init. |
mbed_official | 573:ad23fe03a082 | 478 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 479 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 480 | * @retval None |
mbed_official | 573:ad23fe03a082 | 481 | */ |
mbed_official | 573:ad23fe03a082 | 482 | __weak void HAL_SAI_MspInit(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 483 | { |
mbed_official | 573:ad23fe03a082 | 484 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 573:ad23fe03a082 | 485 | the HAL_SAI_MspInit could be implemented in the user file |
mbed_official | 573:ad23fe03a082 | 486 | */ |
mbed_official | 573:ad23fe03a082 | 487 | } |
mbed_official | 573:ad23fe03a082 | 488 | |
mbed_official | 573:ad23fe03a082 | 489 | /** |
mbed_official | 573:ad23fe03a082 | 490 | * @brief SAI MSP DeInit. |
mbed_official | 573:ad23fe03a082 | 491 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 492 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 493 | * @retval None |
mbed_official | 573:ad23fe03a082 | 494 | */ |
mbed_official | 573:ad23fe03a082 | 495 | __weak void HAL_SAI_MspDeInit(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 496 | { |
mbed_official | 573:ad23fe03a082 | 497 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 573:ad23fe03a082 | 498 | the HAL_SAI_MspDeInit could be implemented in the user file |
mbed_official | 573:ad23fe03a082 | 499 | */ |
mbed_official | 573:ad23fe03a082 | 500 | } |
mbed_official | 573:ad23fe03a082 | 501 | |
mbed_official | 573:ad23fe03a082 | 502 | /** |
mbed_official | 573:ad23fe03a082 | 503 | * @} |
mbed_official | 573:ad23fe03a082 | 504 | */ |
mbed_official | 573:ad23fe03a082 | 505 | |
mbed_official | 573:ad23fe03a082 | 506 | /** @defgroup SAI_Exported_Functions_Group2 IO operation functions |
mbed_official | 573:ad23fe03a082 | 507 | * @brief Data transfers functions |
mbed_official | 573:ad23fe03a082 | 508 | * |
mbed_official | 573:ad23fe03a082 | 509 | @verbatim |
mbed_official | 573:ad23fe03a082 | 510 | =============================================================================== |
mbed_official | 573:ad23fe03a082 | 511 | ##### IO operation functions ##### |
mbed_official | 573:ad23fe03a082 | 512 | =============================================================================== |
mbed_official | 573:ad23fe03a082 | 513 | [..] |
mbed_official | 573:ad23fe03a082 | 514 | This subsection provides a set of functions allowing to manage the SAI data |
mbed_official | 573:ad23fe03a082 | 515 | transfers. |
mbed_official | 573:ad23fe03a082 | 516 | |
mbed_official | 573:ad23fe03a082 | 517 | (+) There are two modes of transfer: |
mbed_official | 573:ad23fe03a082 | 518 | (++) Blocking mode : The communication is performed in the polling mode. |
mbed_official | 573:ad23fe03a082 | 519 | The status of all data processing is returned by the same function |
mbed_official | 573:ad23fe03a082 | 520 | after finishing transfer. |
mbed_official | 573:ad23fe03a082 | 521 | (++) No-Blocking mode : The communication is performed using Interrupts |
mbed_official | 573:ad23fe03a082 | 522 | or DMA. These functions return the status of the transfer startup. |
mbed_official | 573:ad23fe03a082 | 523 | The end of the data processing will be indicated through the |
mbed_official | 573:ad23fe03a082 | 524 | dedicated SAI IRQ when using Interrupt mode or the DMA IRQ when |
mbed_official | 573:ad23fe03a082 | 525 | using DMA mode. |
mbed_official | 573:ad23fe03a082 | 526 | |
mbed_official | 573:ad23fe03a082 | 527 | (+) Blocking mode functions are : |
mbed_official | 573:ad23fe03a082 | 528 | (++) HAL_SAI_Transmit() |
mbed_official | 573:ad23fe03a082 | 529 | (++) HAL_SAI_Receive() |
mbed_official | 573:ad23fe03a082 | 530 | (++) HAL_SAI_TransmitReceive() |
mbed_official | 573:ad23fe03a082 | 531 | |
mbed_official | 573:ad23fe03a082 | 532 | (+) Non Blocking mode functions with Interrupt are : |
mbed_official | 573:ad23fe03a082 | 533 | (++) HAL_SAI_Transmit_IT() |
mbed_official | 573:ad23fe03a082 | 534 | (++) HAL_SAI_Receive_IT() |
mbed_official | 573:ad23fe03a082 | 535 | (++) HAL_SAI_TransmitReceive_IT() |
mbed_official | 573:ad23fe03a082 | 536 | |
mbed_official | 573:ad23fe03a082 | 537 | (+) Non Blocking mode functions with DMA are : |
mbed_official | 573:ad23fe03a082 | 538 | (++) HAL_SAI_Transmit_DMA() |
mbed_official | 573:ad23fe03a082 | 539 | (++) HAL_SAI_Receive_DMA() |
mbed_official | 573:ad23fe03a082 | 540 | (++) HAL_SAI_TransmitReceive_DMA() |
mbed_official | 573:ad23fe03a082 | 541 | |
mbed_official | 573:ad23fe03a082 | 542 | (+) A set of Transfer Complete Callbacks are provided in non Blocking mode: |
mbed_official | 573:ad23fe03a082 | 543 | (++) HAL_SAI_TxCpltCallback() |
mbed_official | 573:ad23fe03a082 | 544 | (++) HAL_SAI_RxCpltCallback() |
mbed_official | 573:ad23fe03a082 | 545 | (++) HAL_SAI_ErrorCallback() |
mbed_official | 573:ad23fe03a082 | 546 | |
mbed_official | 573:ad23fe03a082 | 547 | @endverbatim |
mbed_official | 573:ad23fe03a082 | 548 | * @{ |
mbed_official | 573:ad23fe03a082 | 549 | */ |
mbed_official | 573:ad23fe03a082 | 550 | |
mbed_official | 573:ad23fe03a082 | 551 | /** |
mbed_official | 573:ad23fe03a082 | 552 | * @brief Transmits an amount of data in blocking mode. |
mbed_official | 573:ad23fe03a082 | 553 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 554 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 555 | * @param pData: Pointer to data buffer |
mbed_official | 573:ad23fe03a082 | 556 | * @param Size: Amount of data to be sent |
mbed_official | 573:ad23fe03a082 | 557 | * @param Timeout: Timeout duration |
mbed_official | 573:ad23fe03a082 | 558 | * @retval HAL status |
mbed_official | 573:ad23fe03a082 | 559 | */ |
mbed_official | 573:ad23fe03a082 | 560 | HAL_StatusTypeDef HAL_SAI_Transmit(SAI_HandleTypeDef *hsai, uint8_t* pData, uint16_t Size, uint32_t Timeout) |
mbed_official | 573:ad23fe03a082 | 561 | { |
mbed_official | 573:ad23fe03a082 | 562 | uint32_t tickstart = 0; |
mbed_official | 573:ad23fe03a082 | 563 | |
mbed_official | 573:ad23fe03a082 | 564 | if((pData == NULL ) || (Size == 0)) |
mbed_official | 573:ad23fe03a082 | 565 | { |
mbed_official | 573:ad23fe03a082 | 566 | return HAL_ERROR; |
mbed_official | 573:ad23fe03a082 | 567 | } |
mbed_official | 573:ad23fe03a082 | 568 | |
mbed_official | 573:ad23fe03a082 | 569 | if(hsai->State == HAL_SAI_STATE_READY) |
mbed_official | 573:ad23fe03a082 | 570 | { |
mbed_official | 573:ad23fe03a082 | 571 | /* Process Locked */ |
mbed_official | 573:ad23fe03a082 | 572 | __HAL_LOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 573 | |
mbed_official | 573:ad23fe03a082 | 574 | hsai->State = HAL_SAI_STATE_BUSY_TX; |
mbed_official | 573:ad23fe03a082 | 575 | hsai->ErrorCode = HAL_SAI_ERROR_NONE; |
mbed_official | 573:ad23fe03a082 | 576 | hsai->XferSize = Size; |
mbed_official | 573:ad23fe03a082 | 577 | hsai->XferCount = Size; |
mbed_official | 573:ad23fe03a082 | 578 | hsai->pBuffPtr = pData; |
mbed_official | 573:ad23fe03a082 | 579 | |
mbed_official | 573:ad23fe03a082 | 580 | /* Check if the SAI is already enabled */ |
mbed_official | 573:ad23fe03a082 | 581 | if((hsai->Instance->CR1 & SAI_xCR1_SAIEN) != SAI_xCR1_SAIEN) |
mbed_official | 573:ad23fe03a082 | 582 | { |
mbed_official | 573:ad23fe03a082 | 583 | /* fill the fifo with data before to enabled the SAI */ |
mbed_official | 573:ad23fe03a082 | 584 | SAI_FillFifo(hsai); |
mbed_official | 573:ad23fe03a082 | 585 | /* Enable SAI peripheral */ |
mbed_official | 573:ad23fe03a082 | 586 | __HAL_SAI_ENABLE(hsai); |
mbed_official | 573:ad23fe03a082 | 587 | } |
mbed_official | 573:ad23fe03a082 | 588 | |
mbed_official | 573:ad23fe03a082 | 589 | while(hsai->XferCount > 0) |
mbed_official | 573:ad23fe03a082 | 590 | { |
mbed_official | 573:ad23fe03a082 | 591 | /* Write data if the FIFO is not full */ |
mbed_official | 573:ad23fe03a082 | 592 | if((hsai->Instance->SR & SAI_xSR_FLVL) != SAI_FIFOSTATUS_FULL) |
mbed_official | 573:ad23fe03a082 | 593 | { |
mbed_official | 573:ad23fe03a082 | 594 | if((hsai->Init.DataSize == SAI_DATASIZE_8) && (hsai->Init.CompandingMode == SAI_NOCOMPANDING)) |
mbed_official | 573:ad23fe03a082 | 595 | { |
mbed_official | 573:ad23fe03a082 | 596 | hsai->Instance->DR = (*hsai->pBuffPtr++); |
mbed_official | 573:ad23fe03a082 | 597 | } |
mbed_official | 573:ad23fe03a082 | 598 | else if(hsai->Init.DataSize <= SAI_DATASIZE_16) |
mbed_official | 573:ad23fe03a082 | 599 | { |
mbed_official | 573:ad23fe03a082 | 600 | hsai->Instance->DR = *((uint16_t *)hsai->pBuffPtr); |
mbed_official | 573:ad23fe03a082 | 601 | hsai->pBuffPtr+= 2; |
mbed_official | 573:ad23fe03a082 | 602 | } |
mbed_official | 573:ad23fe03a082 | 603 | else |
mbed_official | 573:ad23fe03a082 | 604 | { |
mbed_official | 573:ad23fe03a082 | 605 | hsai->Instance->DR = *((uint32_t *)hsai->pBuffPtr); |
mbed_official | 573:ad23fe03a082 | 606 | hsai->pBuffPtr+= 4; |
mbed_official | 573:ad23fe03a082 | 607 | } |
mbed_official | 573:ad23fe03a082 | 608 | hsai->XferCount--; |
mbed_official | 573:ad23fe03a082 | 609 | } |
mbed_official | 573:ad23fe03a082 | 610 | else |
mbed_official | 573:ad23fe03a082 | 611 | { |
mbed_official | 573:ad23fe03a082 | 612 | /* Get tick */ |
mbed_official | 573:ad23fe03a082 | 613 | tickstart = HAL_GetTick(); |
mbed_official | 573:ad23fe03a082 | 614 | /* Check for the Timeout */ |
mbed_official | 573:ad23fe03a082 | 615 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 573:ad23fe03a082 | 616 | { |
mbed_official | 573:ad23fe03a082 | 617 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
mbed_official | 573:ad23fe03a082 | 618 | { |
mbed_official | 573:ad23fe03a082 | 619 | /* Update error code */ |
mbed_official | 573:ad23fe03a082 | 620 | hsai->ErrorCode |= HAL_SAI_ERROR_TIMEOUT; |
mbed_official | 573:ad23fe03a082 | 621 | |
mbed_official | 573:ad23fe03a082 | 622 | /* Process Unlocked */ |
mbed_official | 573:ad23fe03a082 | 623 | __HAL_UNLOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 624 | |
mbed_official | 573:ad23fe03a082 | 625 | /* Change the SAI state */ |
mbed_official | 573:ad23fe03a082 | 626 | hsai->State = HAL_SAI_STATE_TIMEOUT; |
mbed_official | 573:ad23fe03a082 | 627 | |
mbed_official | 573:ad23fe03a082 | 628 | return HAL_TIMEOUT; |
mbed_official | 573:ad23fe03a082 | 629 | } |
mbed_official | 573:ad23fe03a082 | 630 | } |
mbed_official | 573:ad23fe03a082 | 631 | } |
mbed_official | 573:ad23fe03a082 | 632 | } |
mbed_official | 573:ad23fe03a082 | 633 | |
mbed_official | 573:ad23fe03a082 | 634 | hsai->State = HAL_SAI_STATE_READY; |
mbed_official | 573:ad23fe03a082 | 635 | |
mbed_official | 573:ad23fe03a082 | 636 | /* Process Unlocked */ |
mbed_official | 573:ad23fe03a082 | 637 | __HAL_UNLOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 638 | |
mbed_official | 573:ad23fe03a082 | 639 | return HAL_OK; |
mbed_official | 573:ad23fe03a082 | 640 | } |
mbed_official | 573:ad23fe03a082 | 641 | else |
mbed_official | 573:ad23fe03a082 | 642 | { |
mbed_official | 573:ad23fe03a082 | 643 | return HAL_BUSY; |
mbed_official | 573:ad23fe03a082 | 644 | } |
mbed_official | 573:ad23fe03a082 | 645 | } |
mbed_official | 573:ad23fe03a082 | 646 | |
mbed_official | 573:ad23fe03a082 | 647 | /** |
mbed_official | 573:ad23fe03a082 | 648 | * @brief Receives an amount of data in blocking mode. |
mbed_official | 573:ad23fe03a082 | 649 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 650 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 651 | * @param pData: Pointer to data buffer |
mbed_official | 573:ad23fe03a082 | 652 | * @param Size: Amount of data to be received |
mbed_official | 573:ad23fe03a082 | 653 | * @param Timeout: Timeout duration |
mbed_official | 573:ad23fe03a082 | 654 | * @retval HAL status |
mbed_official | 573:ad23fe03a082 | 655 | */ |
mbed_official | 573:ad23fe03a082 | 656 | HAL_StatusTypeDef HAL_SAI_Receive(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
mbed_official | 573:ad23fe03a082 | 657 | { |
mbed_official | 573:ad23fe03a082 | 658 | uint32_t tickstart = 0; |
mbed_official | 573:ad23fe03a082 | 659 | |
mbed_official | 573:ad23fe03a082 | 660 | if((pData == NULL ) || (Size == 0)) |
mbed_official | 573:ad23fe03a082 | 661 | { |
mbed_official | 573:ad23fe03a082 | 662 | return HAL_ERROR; |
mbed_official | 573:ad23fe03a082 | 663 | } |
mbed_official | 573:ad23fe03a082 | 664 | |
mbed_official | 573:ad23fe03a082 | 665 | if(hsai->State == HAL_SAI_STATE_READY) |
mbed_official | 573:ad23fe03a082 | 666 | { |
mbed_official | 573:ad23fe03a082 | 667 | /* Process Locked */ |
mbed_official | 573:ad23fe03a082 | 668 | __HAL_LOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 669 | |
mbed_official | 573:ad23fe03a082 | 670 | hsai->State = HAL_SAI_STATE_BUSY_RX; |
mbed_official | 573:ad23fe03a082 | 671 | hsai->ErrorCode = HAL_SAI_ERROR_NONE; |
mbed_official | 573:ad23fe03a082 | 672 | hsai->pBuffPtr = pData; |
mbed_official | 573:ad23fe03a082 | 673 | hsai->XferSize = Size; |
mbed_official | 573:ad23fe03a082 | 674 | hsai->XferCount = Size; |
mbed_official | 573:ad23fe03a082 | 675 | |
mbed_official | 573:ad23fe03a082 | 676 | /* Check if the SAI is already enabled */ |
mbed_official | 573:ad23fe03a082 | 677 | if((hsai->Instance->CR1 & SAI_xCR1_SAIEN) != SAI_xCR1_SAIEN) |
mbed_official | 573:ad23fe03a082 | 678 | { |
mbed_official | 573:ad23fe03a082 | 679 | /* Enable SAI peripheral */ |
mbed_official | 573:ad23fe03a082 | 680 | __HAL_SAI_ENABLE(hsai); |
mbed_official | 573:ad23fe03a082 | 681 | } |
mbed_official | 573:ad23fe03a082 | 682 | |
mbed_official | 573:ad23fe03a082 | 683 | /* Receive data */ |
mbed_official | 573:ad23fe03a082 | 684 | while(hsai->XferCount > 0) |
mbed_official | 573:ad23fe03a082 | 685 | { |
mbed_official | 573:ad23fe03a082 | 686 | |
mbed_official | 573:ad23fe03a082 | 687 | if((hsai->Instance->SR & SAI_xSR_FLVL) != SAI_FIFOSTATUS_EMPTY) |
mbed_official | 573:ad23fe03a082 | 688 | { |
mbed_official | 573:ad23fe03a082 | 689 | if((hsai->Init.DataSize == SAI_DATASIZE_8) && (hsai->Init.CompandingMode == SAI_NOCOMPANDING)) |
mbed_official | 573:ad23fe03a082 | 690 | { |
mbed_official | 573:ad23fe03a082 | 691 | (*hsai->pBuffPtr++) = hsai->Instance->DR; |
mbed_official | 573:ad23fe03a082 | 692 | } |
mbed_official | 573:ad23fe03a082 | 693 | else if(hsai->Init.DataSize <= SAI_DATASIZE_16) |
mbed_official | 573:ad23fe03a082 | 694 | { |
mbed_official | 573:ad23fe03a082 | 695 | *((uint16_t*)hsai->pBuffPtr) = hsai->Instance->DR; |
mbed_official | 573:ad23fe03a082 | 696 | hsai->pBuffPtr+= 2; |
mbed_official | 573:ad23fe03a082 | 697 | } |
mbed_official | 573:ad23fe03a082 | 698 | else |
mbed_official | 573:ad23fe03a082 | 699 | { |
mbed_official | 573:ad23fe03a082 | 700 | *((uint32_t*)hsai->pBuffPtr) = hsai->Instance->DR; |
mbed_official | 573:ad23fe03a082 | 701 | hsai->pBuffPtr+= 4; |
mbed_official | 573:ad23fe03a082 | 702 | } |
mbed_official | 573:ad23fe03a082 | 703 | hsai->XferCount--; |
mbed_official | 573:ad23fe03a082 | 704 | } |
mbed_official | 573:ad23fe03a082 | 705 | else |
mbed_official | 573:ad23fe03a082 | 706 | { |
mbed_official | 573:ad23fe03a082 | 707 | /* Get tick */ |
mbed_official | 573:ad23fe03a082 | 708 | tickstart = HAL_GetTick(); |
mbed_official | 573:ad23fe03a082 | 709 | /* Check for the Timeout */ |
mbed_official | 573:ad23fe03a082 | 710 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 573:ad23fe03a082 | 711 | { |
mbed_official | 573:ad23fe03a082 | 712 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
mbed_official | 573:ad23fe03a082 | 713 | { |
mbed_official | 573:ad23fe03a082 | 714 | /* Update error code */ |
mbed_official | 573:ad23fe03a082 | 715 | hsai->ErrorCode |= HAL_SAI_ERROR_TIMEOUT; |
mbed_official | 573:ad23fe03a082 | 716 | |
mbed_official | 573:ad23fe03a082 | 717 | /* Process Unlocked */ |
mbed_official | 573:ad23fe03a082 | 718 | __HAL_UNLOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 719 | |
mbed_official | 573:ad23fe03a082 | 720 | /* Change the SAI state */ |
mbed_official | 573:ad23fe03a082 | 721 | hsai->State = HAL_SAI_STATE_TIMEOUT; |
mbed_official | 573:ad23fe03a082 | 722 | |
mbed_official | 573:ad23fe03a082 | 723 | return HAL_TIMEOUT; |
mbed_official | 573:ad23fe03a082 | 724 | } |
mbed_official | 573:ad23fe03a082 | 725 | } |
mbed_official | 573:ad23fe03a082 | 726 | } |
mbed_official | 573:ad23fe03a082 | 727 | } |
mbed_official | 573:ad23fe03a082 | 728 | |
mbed_official | 573:ad23fe03a082 | 729 | hsai->State = HAL_SAI_STATE_READY; |
mbed_official | 573:ad23fe03a082 | 730 | |
mbed_official | 573:ad23fe03a082 | 731 | /* Process Unlocked */ |
mbed_official | 573:ad23fe03a082 | 732 | __HAL_UNLOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 733 | |
mbed_official | 573:ad23fe03a082 | 734 | return HAL_OK; |
mbed_official | 573:ad23fe03a082 | 735 | } |
mbed_official | 573:ad23fe03a082 | 736 | else |
mbed_official | 573:ad23fe03a082 | 737 | { |
mbed_official | 573:ad23fe03a082 | 738 | return HAL_BUSY; |
mbed_official | 573:ad23fe03a082 | 739 | } |
mbed_official | 573:ad23fe03a082 | 740 | } |
mbed_official | 573:ad23fe03a082 | 741 | |
mbed_official | 573:ad23fe03a082 | 742 | /** |
mbed_official | 573:ad23fe03a082 | 743 | * @brief Transmits an amount of data in no-blocking mode with Interrupt. |
mbed_official | 573:ad23fe03a082 | 744 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 745 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 746 | * @param pData: Pointer to data buffer |
mbed_official | 573:ad23fe03a082 | 747 | * @param Size: Amount of data to be sent |
mbed_official | 573:ad23fe03a082 | 748 | * @retval HAL status |
mbed_official | 573:ad23fe03a082 | 749 | */ |
mbed_official | 573:ad23fe03a082 | 750 | HAL_StatusTypeDef HAL_SAI_Transmit_IT(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size) |
mbed_official | 573:ad23fe03a082 | 751 | { |
mbed_official | 573:ad23fe03a082 | 752 | if(hsai->State == HAL_SAI_STATE_READY) |
mbed_official | 573:ad23fe03a082 | 753 | { |
mbed_official | 573:ad23fe03a082 | 754 | if((pData == NULL) || (Size == 0)) |
mbed_official | 573:ad23fe03a082 | 755 | { |
mbed_official | 573:ad23fe03a082 | 756 | return HAL_ERROR; |
mbed_official | 573:ad23fe03a082 | 757 | } |
mbed_official | 573:ad23fe03a082 | 758 | |
mbed_official | 573:ad23fe03a082 | 759 | hsai->pBuffPtr = pData; |
mbed_official | 573:ad23fe03a082 | 760 | hsai->XferSize = Size; |
mbed_official | 573:ad23fe03a082 | 761 | hsai->XferCount = Size; |
mbed_official | 573:ad23fe03a082 | 762 | |
mbed_official | 573:ad23fe03a082 | 763 | /* Process Locked */ |
mbed_official | 573:ad23fe03a082 | 764 | __HAL_LOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 765 | |
mbed_official | 573:ad23fe03a082 | 766 | hsai->State = HAL_SAI_STATE_BUSY_TX; |
mbed_official | 573:ad23fe03a082 | 767 | |
mbed_official | 573:ad23fe03a082 | 768 | if((hsai->Init.DataSize == SAI_DATASIZE_8) && (hsai->Init.CompandingMode == SAI_NOCOMPANDING)) |
mbed_official | 573:ad23fe03a082 | 769 | { |
mbed_official | 573:ad23fe03a082 | 770 | hsai->InterruptServiceRoutine = SAI_Transmit_IT8Bit; |
mbed_official | 573:ad23fe03a082 | 771 | } |
mbed_official | 573:ad23fe03a082 | 772 | else if(hsai->Init.DataSize <= SAI_DATASIZE_16) |
mbed_official | 573:ad23fe03a082 | 773 | { |
mbed_official | 573:ad23fe03a082 | 774 | hsai->InterruptServiceRoutine = SAI_Transmit_IT16Bit; |
mbed_official | 573:ad23fe03a082 | 775 | } |
mbed_official | 573:ad23fe03a082 | 776 | else |
mbed_official | 573:ad23fe03a082 | 777 | { |
mbed_official | 573:ad23fe03a082 | 778 | hsai->InterruptServiceRoutine = SAI_Transmit_IT32Bit; |
mbed_official | 573:ad23fe03a082 | 779 | } |
mbed_official | 573:ad23fe03a082 | 780 | |
mbed_official | 573:ad23fe03a082 | 781 | /* Enable FRQ and OVRUDR interrupts */ |
mbed_official | 573:ad23fe03a082 | 782 | __HAL_SAI_ENABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_IT)); |
mbed_official | 573:ad23fe03a082 | 783 | |
mbed_official | 573:ad23fe03a082 | 784 | /* Check if the SAI is already enabled */ |
mbed_official | 573:ad23fe03a082 | 785 | if((hsai->Instance->CR1 & SAI_xCR1_SAIEN) != SAI_xCR1_SAIEN) |
mbed_official | 573:ad23fe03a082 | 786 | { |
mbed_official | 573:ad23fe03a082 | 787 | /* Fill the fifo before starting the communication */ |
mbed_official | 573:ad23fe03a082 | 788 | SAI_FillFifo(hsai); |
mbed_official | 573:ad23fe03a082 | 789 | |
mbed_official | 573:ad23fe03a082 | 790 | /* Enable SAI peripheral */ |
mbed_official | 573:ad23fe03a082 | 791 | __HAL_SAI_ENABLE(hsai); |
mbed_official | 573:ad23fe03a082 | 792 | } |
mbed_official | 573:ad23fe03a082 | 793 | /* Process Unlocked */ |
mbed_official | 573:ad23fe03a082 | 794 | __HAL_UNLOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 795 | |
mbed_official | 573:ad23fe03a082 | 796 | return HAL_OK; |
mbed_official | 573:ad23fe03a082 | 797 | } |
mbed_official | 573:ad23fe03a082 | 798 | else |
mbed_official | 573:ad23fe03a082 | 799 | { |
mbed_official | 573:ad23fe03a082 | 800 | return HAL_BUSY; |
mbed_official | 573:ad23fe03a082 | 801 | } |
mbed_official | 573:ad23fe03a082 | 802 | } |
mbed_official | 573:ad23fe03a082 | 803 | |
mbed_official | 573:ad23fe03a082 | 804 | /** |
mbed_official | 573:ad23fe03a082 | 805 | * @brief Receives an amount of data in no-blocking mode with Interrupt. |
mbed_official | 573:ad23fe03a082 | 806 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 807 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 808 | * @param pData: Pointer to data buffer |
mbed_official | 573:ad23fe03a082 | 809 | * @param Size: Amount of data to be received |
mbed_official | 573:ad23fe03a082 | 810 | * @retval HAL status |
mbed_official | 573:ad23fe03a082 | 811 | */ |
mbed_official | 573:ad23fe03a082 | 812 | HAL_StatusTypeDef HAL_SAI_Receive_IT(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size) |
mbed_official | 573:ad23fe03a082 | 813 | { |
mbed_official | 573:ad23fe03a082 | 814 | |
mbed_official | 573:ad23fe03a082 | 815 | if(hsai->State == HAL_SAI_STATE_READY) |
mbed_official | 573:ad23fe03a082 | 816 | { |
mbed_official | 573:ad23fe03a082 | 817 | if((pData == NULL) || (Size == 0)) |
mbed_official | 573:ad23fe03a082 | 818 | { |
mbed_official | 573:ad23fe03a082 | 819 | return HAL_ERROR; |
mbed_official | 573:ad23fe03a082 | 820 | } |
mbed_official | 573:ad23fe03a082 | 821 | |
mbed_official | 573:ad23fe03a082 | 822 | hsai->pBuffPtr = pData; |
mbed_official | 573:ad23fe03a082 | 823 | hsai->XferSize = Size; |
mbed_official | 573:ad23fe03a082 | 824 | hsai->XferCount = Size; |
mbed_official | 573:ad23fe03a082 | 825 | |
mbed_official | 573:ad23fe03a082 | 826 | /* Process Locked */ |
mbed_official | 573:ad23fe03a082 | 827 | __HAL_LOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 828 | |
mbed_official | 573:ad23fe03a082 | 829 | hsai->State = HAL_SAI_STATE_BUSY_RX; |
mbed_official | 573:ad23fe03a082 | 830 | |
mbed_official | 573:ad23fe03a082 | 831 | if((hsai->Init.DataSize == SAI_DATASIZE_8) && (hsai->Init.CompandingMode == SAI_NOCOMPANDING)) |
mbed_official | 573:ad23fe03a082 | 832 | { |
mbed_official | 573:ad23fe03a082 | 833 | hsai->InterruptServiceRoutine = SAI_Receive_IT8Bit; |
mbed_official | 573:ad23fe03a082 | 834 | } |
mbed_official | 573:ad23fe03a082 | 835 | else if(hsai->Init.DataSize <= SAI_DATASIZE_16) |
mbed_official | 573:ad23fe03a082 | 836 | { |
mbed_official | 573:ad23fe03a082 | 837 | hsai->InterruptServiceRoutine = SAI_Receive_IT16Bit; |
mbed_official | 573:ad23fe03a082 | 838 | } |
mbed_official | 573:ad23fe03a082 | 839 | else |
mbed_official | 573:ad23fe03a082 | 840 | { |
mbed_official | 573:ad23fe03a082 | 841 | hsai->InterruptServiceRoutine = SAI_Receive_IT32Bit; |
mbed_official | 573:ad23fe03a082 | 842 | } |
mbed_official | 573:ad23fe03a082 | 843 | /* Enable TXE and OVRUDR interrupts */ |
mbed_official | 573:ad23fe03a082 | 844 | __HAL_SAI_ENABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_IT)); |
mbed_official | 573:ad23fe03a082 | 845 | |
mbed_official | 573:ad23fe03a082 | 846 | /* Check if the SAI is already enabled */ |
mbed_official | 573:ad23fe03a082 | 847 | if((hsai->Instance->CR1 & SAI_xCR1_SAIEN) != SAI_xCR1_SAIEN) |
mbed_official | 573:ad23fe03a082 | 848 | { |
mbed_official | 573:ad23fe03a082 | 849 | /* Enable SAI peripheral */ |
mbed_official | 573:ad23fe03a082 | 850 | __HAL_SAI_ENABLE(hsai); |
mbed_official | 573:ad23fe03a082 | 851 | } |
mbed_official | 573:ad23fe03a082 | 852 | |
mbed_official | 573:ad23fe03a082 | 853 | /* Process Unlocked */ |
mbed_official | 573:ad23fe03a082 | 854 | __HAL_UNLOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 855 | |
mbed_official | 573:ad23fe03a082 | 856 | return HAL_OK; |
mbed_official | 573:ad23fe03a082 | 857 | } |
mbed_official | 573:ad23fe03a082 | 858 | else |
mbed_official | 573:ad23fe03a082 | 859 | { |
mbed_official | 573:ad23fe03a082 | 860 | return HAL_BUSY; |
mbed_official | 573:ad23fe03a082 | 861 | } |
mbed_official | 573:ad23fe03a082 | 862 | } |
mbed_official | 573:ad23fe03a082 | 863 | |
mbed_official | 573:ad23fe03a082 | 864 | /** |
mbed_official | 573:ad23fe03a082 | 865 | * @brief Pauses the audio stream playing from the Media. |
mbed_official | 573:ad23fe03a082 | 866 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 867 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 868 | * @retval HAL status |
mbed_official | 573:ad23fe03a082 | 869 | */ |
mbed_official | 573:ad23fe03a082 | 870 | HAL_StatusTypeDef HAL_SAI_DMAPause(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 871 | { |
mbed_official | 573:ad23fe03a082 | 872 | /* Process Locked */ |
mbed_official | 573:ad23fe03a082 | 873 | __HAL_LOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 874 | |
mbed_official | 573:ad23fe03a082 | 875 | /* Pause the audio file playing by disabling the SAI DMA requests */ |
mbed_official | 573:ad23fe03a082 | 876 | hsai->Instance->CR1 &= ~SAI_xCR1_DMAEN; |
mbed_official | 573:ad23fe03a082 | 877 | |
mbed_official | 573:ad23fe03a082 | 878 | /* Process Unlocked */ |
mbed_official | 573:ad23fe03a082 | 879 | __HAL_UNLOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 880 | |
mbed_official | 573:ad23fe03a082 | 881 | return HAL_OK; |
mbed_official | 573:ad23fe03a082 | 882 | } |
mbed_official | 573:ad23fe03a082 | 883 | |
mbed_official | 573:ad23fe03a082 | 884 | /** |
mbed_official | 573:ad23fe03a082 | 885 | * @brief Resumes the audio stream playing from the Media. |
mbed_official | 573:ad23fe03a082 | 886 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 887 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 888 | * @retval HAL status |
mbed_official | 573:ad23fe03a082 | 889 | */ |
mbed_official | 573:ad23fe03a082 | 890 | HAL_StatusTypeDef HAL_SAI_DMAResume(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 891 | { |
mbed_official | 573:ad23fe03a082 | 892 | /* Process Locked */ |
mbed_official | 573:ad23fe03a082 | 893 | __HAL_LOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 894 | |
mbed_official | 573:ad23fe03a082 | 895 | /* Enable the SAI DMA requests */ |
mbed_official | 573:ad23fe03a082 | 896 | hsai->Instance->CR1 |= SAI_xCR1_DMAEN; |
mbed_official | 573:ad23fe03a082 | 897 | |
mbed_official | 573:ad23fe03a082 | 898 | /* If the SAI peripheral is still not enabled, enable it */ |
mbed_official | 573:ad23fe03a082 | 899 | if ((hsai->Instance->CR1 & SAI_xCR1_SAIEN) == RESET) |
mbed_official | 573:ad23fe03a082 | 900 | { |
mbed_official | 573:ad23fe03a082 | 901 | /* Enable SAI peripheral */ |
mbed_official | 573:ad23fe03a082 | 902 | __HAL_SAI_ENABLE(hsai); |
mbed_official | 573:ad23fe03a082 | 903 | } |
mbed_official | 573:ad23fe03a082 | 904 | |
mbed_official | 573:ad23fe03a082 | 905 | /* Process Unlocked */ |
mbed_official | 573:ad23fe03a082 | 906 | __HAL_UNLOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 907 | |
mbed_official | 573:ad23fe03a082 | 908 | return HAL_OK; |
mbed_official | 573:ad23fe03a082 | 909 | } |
mbed_official | 573:ad23fe03a082 | 910 | |
mbed_official | 573:ad23fe03a082 | 911 | /** |
mbed_official | 573:ad23fe03a082 | 912 | * @brief Stops the audio stream playing from the Media. |
mbed_official | 573:ad23fe03a082 | 913 | * @param hsai : pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 914 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 915 | * @retval HAL status |
mbed_official | 573:ad23fe03a082 | 916 | */ |
mbed_official | 573:ad23fe03a082 | 917 | HAL_StatusTypeDef HAL_SAI_DMAStop(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 918 | { |
mbed_official | 573:ad23fe03a082 | 919 | /* Process Locked */ |
mbed_official | 573:ad23fe03a082 | 920 | __HAL_LOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 921 | |
mbed_official | 573:ad23fe03a082 | 922 | /* Disable the SAI DMA request */ |
mbed_official | 573:ad23fe03a082 | 923 | hsai->Instance->CR1 &= ~SAI_xCR1_DMAEN; |
mbed_official | 573:ad23fe03a082 | 924 | |
mbed_official | 573:ad23fe03a082 | 925 | /* Abort the SAI DMA Tx Stream */ |
mbed_official | 573:ad23fe03a082 | 926 | if(hsai->hdmatx != NULL) |
mbed_official | 573:ad23fe03a082 | 927 | { |
mbed_official | 573:ad23fe03a082 | 928 | HAL_DMA_Abort(hsai->hdmatx); |
mbed_official | 573:ad23fe03a082 | 929 | } |
mbed_official | 573:ad23fe03a082 | 930 | /* Abort the SAI DMA Rx Stream */ |
mbed_official | 573:ad23fe03a082 | 931 | if(hsai->hdmarx != NULL) |
mbed_official | 573:ad23fe03a082 | 932 | { |
mbed_official | 573:ad23fe03a082 | 933 | HAL_DMA_Abort(hsai->hdmarx); |
mbed_official | 573:ad23fe03a082 | 934 | } |
mbed_official | 573:ad23fe03a082 | 935 | |
mbed_official | 573:ad23fe03a082 | 936 | /* Disable SAI peripheral */ |
mbed_official | 573:ad23fe03a082 | 937 | SAI_Disable(hsai); |
mbed_official | 573:ad23fe03a082 | 938 | |
mbed_official | 573:ad23fe03a082 | 939 | hsai->State = HAL_SAI_STATE_READY; |
mbed_official | 573:ad23fe03a082 | 940 | |
mbed_official | 573:ad23fe03a082 | 941 | /* Process Unlocked */ |
mbed_official | 573:ad23fe03a082 | 942 | __HAL_UNLOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 943 | |
mbed_official | 573:ad23fe03a082 | 944 | return HAL_OK; |
mbed_official | 573:ad23fe03a082 | 945 | } |
mbed_official | 573:ad23fe03a082 | 946 | |
mbed_official | 573:ad23fe03a082 | 947 | /** |
mbed_official | 573:ad23fe03a082 | 948 | * @brief Abort the current transfer and disbaled the SAI. |
mbed_official | 573:ad23fe03a082 | 949 | * @param hsai : pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 950 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 951 | * @retval HAL status |
mbed_official | 573:ad23fe03a082 | 952 | */ |
mbed_official | 573:ad23fe03a082 | 953 | HAL_StatusTypeDef HAL_SAI_Abort(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 954 | { |
mbed_official | 573:ad23fe03a082 | 955 | /* Disable the SAI DMA request */ |
mbed_official | 573:ad23fe03a082 | 956 | hsai->Instance->CR1 &= ~SAI_xCR1_DMAEN; |
mbed_official | 573:ad23fe03a082 | 957 | |
mbed_official | 573:ad23fe03a082 | 958 | /* Abort the SAI DMA Tx Stream */ |
mbed_official | 573:ad23fe03a082 | 959 | if(hsai->hdmatx != NULL) |
mbed_official | 573:ad23fe03a082 | 960 | { |
mbed_official | 573:ad23fe03a082 | 961 | HAL_DMA_Abort(hsai->hdmatx); |
mbed_official | 573:ad23fe03a082 | 962 | } |
mbed_official | 573:ad23fe03a082 | 963 | /* Abort the SAI DMA Rx Stream */ |
mbed_official | 573:ad23fe03a082 | 964 | if(hsai->hdmarx != NULL) |
mbed_official | 573:ad23fe03a082 | 965 | { |
mbed_official | 573:ad23fe03a082 | 966 | HAL_DMA_Abort(hsai->hdmarx); |
mbed_official | 573:ad23fe03a082 | 967 | } |
mbed_official | 573:ad23fe03a082 | 968 | |
mbed_official | 573:ad23fe03a082 | 969 | /* Disabled All interrupt and clear all the flag */ |
mbed_official | 573:ad23fe03a082 | 970 | hsai->Instance->IMR = 0; |
mbed_official | 573:ad23fe03a082 | 971 | hsai->Instance->CLRFR = 0xFFFFFFFF; |
mbed_official | 573:ad23fe03a082 | 972 | |
mbed_official | 573:ad23fe03a082 | 973 | /* Disable SAI peripheral */ |
mbed_official | 573:ad23fe03a082 | 974 | SAI_Disable(hsai); |
mbed_official | 573:ad23fe03a082 | 975 | |
mbed_official | 573:ad23fe03a082 | 976 | /* Flush the fifo */ |
mbed_official | 573:ad23fe03a082 | 977 | SET_BIT(hsai->Instance->CR2, SAI_xCR2_FFLUSH); |
mbed_official | 573:ad23fe03a082 | 978 | |
mbed_official | 573:ad23fe03a082 | 979 | hsai->State = HAL_SAI_STATE_READY; |
mbed_official | 573:ad23fe03a082 | 980 | |
mbed_official | 573:ad23fe03a082 | 981 | /* Process Unlocked */ |
mbed_official | 573:ad23fe03a082 | 982 | __HAL_UNLOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 983 | |
mbed_official | 573:ad23fe03a082 | 984 | return HAL_OK; |
mbed_official | 573:ad23fe03a082 | 985 | } |
mbed_official | 573:ad23fe03a082 | 986 | |
mbed_official | 573:ad23fe03a082 | 987 | /** |
mbed_official | 573:ad23fe03a082 | 988 | * @brief Transmits an amount of data in no-blocking mode with DMA. |
mbed_official | 573:ad23fe03a082 | 989 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 990 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 991 | * @param pData: Pointer to data buffer |
mbed_official | 573:ad23fe03a082 | 992 | * @param Size: Amount of data to be sent |
mbed_official | 573:ad23fe03a082 | 993 | * @retval HAL status |
mbed_official | 573:ad23fe03a082 | 994 | */ |
mbed_official | 573:ad23fe03a082 | 995 | HAL_StatusTypeDef HAL_SAI_Transmit_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size) |
mbed_official | 573:ad23fe03a082 | 996 | { |
mbed_official | 573:ad23fe03a082 | 997 | uint32_t *tmp; |
mbed_official | 573:ad23fe03a082 | 998 | |
mbed_official | 573:ad23fe03a082 | 999 | if((pData == NULL) || (Size == 0)) |
mbed_official | 573:ad23fe03a082 | 1000 | { |
mbed_official | 573:ad23fe03a082 | 1001 | return HAL_ERROR; |
mbed_official | 573:ad23fe03a082 | 1002 | } |
mbed_official | 573:ad23fe03a082 | 1003 | |
mbed_official | 573:ad23fe03a082 | 1004 | if(hsai->State == HAL_SAI_STATE_READY) |
mbed_official | 573:ad23fe03a082 | 1005 | { |
mbed_official | 573:ad23fe03a082 | 1006 | hsai->pBuffPtr = pData; |
mbed_official | 573:ad23fe03a082 | 1007 | hsai->XferSize = Size; |
mbed_official | 573:ad23fe03a082 | 1008 | hsai->XferCount = Size; |
mbed_official | 573:ad23fe03a082 | 1009 | |
mbed_official | 573:ad23fe03a082 | 1010 | /* Process Locked */ |
mbed_official | 573:ad23fe03a082 | 1011 | __HAL_LOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 1012 | |
mbed_official | 573:ad23fe03a082 | 1013 | hsai->State = HAL_SAI_STATE_BUSY_TX; |
mbed_official | 573:ad23fe03a082 | 1014 | |
mbed_official | 573:ad23fe03a082 | 1015 | /* Set the SAI Tx DMA Half transfer complete callback */ |
mbed_official | 573:ad23fe03a082 | 1016 | hsai->hdmatx->XferHalfCpltCallback = SAI_DMATxHalfCplt; |
mbed_official | 573:ad23fe03a082 | 1017 | |
mbed_official | 573:ad23fe03a082 | 1018 | /* Set the SAI TxDMA transfer complete callback */ |
mbed_official | 573:ad23fe03a082 | 1019 | hsai->hdmatx->XferCpltCallback = SAI_DMATxCplt; |
mbed_official | 573:ad23fe03a082 | 1020 | |
mbed_official | 573:ad23fe03a082 | 1021 | /* Set the DMA error callback */ |
mbed_official | 573:ad23fe03a082 | 1022 | hsai->hdmatx->XferErrorCallback = SAI_DMAError; |
mbed_official | 573:ad23fe03a082 | 1023 | |
mbed_official | 573:ad23fe03a082 | 1024 | /* Enable the Tx DMA Stream */ |
mbed_official | 573:ad23fe03a082 | 1025 | tmp = (uint32_t*)&pData; |
mbed_official | 573:ad23fe03a082 | 1026 | HAL_DMA_Start_IT(hsai->hdmatx, *(uint32_t*)tmp, (uint32_t)&hsai->Instance->DR, hsai->XferSize); |
mbed_official | 573:ad23fe03a082 | 1027 | |
mbed_official | 573:ad23fe03a082 | 1028 | /* Check if the SAI is already enabled */ |
mbed_official | 573:ad23fe03a082 | 1029 | if((hsai->Instance->CR1 & SAI_xCR1_SAIEN) != SAI_xCR1_SAIEN) |
mbed_official | 573:ad23fe03a082 | 1030 | { |
mbed_official | 573:ad23fe03a082 | 1031 | /* Enable SAI peripheral */ |
mbed_official | 573:ad23fe03a082 | 1032 | __HAL_SAI_ENABLE(hsai); |
mbed_official | 573:ad23fe03a082 | 1033 | } |
mbed_official | 573:ad23fe03a082 | 1034 | |
mbed_official | 573:ad23fe03a082 | 1035 | /* Enable the interrupts for error handling */ |
mbed_official | 573:ad23fe03a082 | 1036 | __HAL_SAI_ENABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_DMA)); |
mbed_official | 573:ad23fe03a082 | 1037 | |
mbed_official | 573:ad23fe03a082 | 1038 | /* Enable SAI Tx DMA Request */ |
mbed_official | 573:ad23fe03a082 | 1039 | hsai->Instance->CR1 |= SAI_xCR1_DMAEN; |
mbed_official | 573:ad23fe03a082 | 1040 | |
mbed_official | 573:ad23fe03a082 | 1041 | /* Process Unlocked */ |
mbed_official | 573:ad23fe03a082 | 1042 | __HAL_UNLOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 1043 | |
mbed_official | 573:ad23fe03a082 | 1044 | return HAL_OK; |
mbed_official | 573:ad23fe03a082 | 1045 | } |
mbed_official | 573:ad23fe03a082 | 1046 | else |
mbed_official | 573:ad23fe03a082 | 1047 | { |
mbed_official | 573:ad23fe03a082 | 1048 | return HAL_BUSY; |
mbed_official | 573:ad23fe03a082 | 1049 | } |
mbed_official | 573:ad23fe03a082 | 1050 | } |
mbed_official | 573:ad23fe03a082 | 1051 | |
mbed_official | 573:ad23fe03a082 | 1052 | /** |
mbed_official | 573:ad23fe03a082 | 1053 | * @brief Receives an amount of data in no-blocking mode with DMA. |
mbed_official | 573:ad23fe03a082 | 1054 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1055 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1056 | * @param pData: Pointer to data buffer |
mbed_official | 573:ad23fe03a082 | 1057 | * @param Size: Amount of data to be received |
mbed_official | 573:ad23fe03a082 | 1058 | * @retval HAL status |
mbed_official | 573:ad23fe03a082 | 1059 | */ |
mbed_official | 573:ad23fe03a082 | 1060 | HAL_StatusTypeDef HAL_SAI_Receive_DMA(SAI_HandleTypeDef *hsai, uint8_t *pData, uint16_t Size) |
mbed_official | 573:ad23fe03a082 | 1061 | { |
mbed_official | 573:ad23fe03a082 | 1062 | uint32_t *tmp; |
mbed_official | 573:ad23fe03a082 | 1063 | |
mbed_official | 573:ad23fe03a082 | 1064 | if((pData == NULL) || (Size == 0)) |
mbed_official | 573:ad23fe03a082 | 1065 | { |
mbed_official | 573:ad23fe03a082 | 1066 | return HAL_ERROR; |
mbed_official | 573:ad23fe03a082 | 1067 | } |
mbed_official | 573:ad23fe03a082 | 1068 | |
mbed_official | 573:ad23fe03a082 | 1069 | if(hsai->State == HAL_SAI_STATE_READY) |
mbed_official | 573:ad23fe03a082 | 1070 | { |
mbed_official | 573:ad23fe03a082 | 1071 | hsai->pBuffPtr = pData; |
mbed_official | 573:ad23fe03a082 | 1072 | hsai->XferSize = Size; |
mbed_official | 573:ad23fe03a082 | 1073 | hsai->XferCount = Size; |
mbed_official | 573:ad23fe03a082 | 1074 | |
mbed_official | 573:ad23fe03a082 | 1075 | /* Process Locked */ |
mbed_official | 573:ad23fe03a082 | 1076 | __HAL_LOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 1077 | |
mbed_official | 573:ad23fe03a082 | 1078 | hsai->State = HAL_SAI_STATE_BUSY_RX; |
mbed_official | 573:ad23fe03a082 | 1079 | |
mbed_official | 573:ad23fe03a082 | 1080 | /* Set the SAI Rx DMA Half transfer complete callback */ |
mbed_official | 573:ad23fe03a082 | 1081 | hsai->hdmarx->XferHalfCpltCallback = SAI_DMARxHalfCplt; |
mbed_official | 573:ad23fe03a082 | 1082 | |
mbed_official | 573:ad23fe03a082 | 1083 | /* Set the SAI Rx DMA transfer complete callback */ |
mbed_official | 573:ad23fe03a082 | 1084 | hsai->hdmarx->XferCpltCallback = SAI_DMARxCplt; |
mbed_official | 573:ad23fe03a082 | 1085 | |
mbed_official | 573:ad23fe03a082 | 1086 | /* Set the DMA error callback */ |
mbed_official | 573:ad23fe03a082 | 1087 | hsai->hdmarx->XferErrorCallback = SAI_DMAError; |
mbed_official | 573:ad23fe03a082 | 1088 | |
mbed_official | 573:ad23fe03a082 | 1089 | /* Enable the Rx DMA Stream */ |
mbed_official | 573:ad23fe03a082 | 1090 | tmp = (uint32_t*)&pData; |
mbed_official | 573:ad23fe03a082 | 1091 | HAL_DMA_Start_IT(hsai->hdmarx, (uint32_t)&hsai->Instance->DR, *(uint32_t*)tmp, hsai->XferSize); |
mbed_official | 573:ad23fe03a082 | 1092 | |
mbed_official | 573:ad23fe03a082 | 1093 | /* Check if the SAI is already enabled */ |
mbed_official | 573:ad23fe03a082 | 1094 | if((hsai->Instance->CR1 & SAI_xCR1_SAIEN) != SAI_xCR1_SAIEN) |
mbed_official | 573:ad23fe03a082 | 1095 | { |
mbed_official | 573:ad23fe03a082 | 1096 | /* Enable SAI peripheral */ |
mbed_official | 573:ad23fe03a082 | 1097 | __HAL_SAI_ENABLE(hsai); |
mbed_official | 573:ad23fe03a082 | 1098 | } |
mbed_official | 573:ad23fe03a082 | 1099 | |
mbed_official | 573:ad23fe03a082 | 1100 | /* Enable the interrupts for error handling */ |
mbed_official | 573:ad23fe03a082 | 1101 | __HAL_SAI_ENABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_DMA)); |
mbed_official | 573:ad23fe03a082 | 1102 | |
mbed_official | 573:ad23fe03a082 | 1103 | /* Enable SAI Rx DMA Request */ |
mbed_official | 573:ad23fe03a082 | 1104 | hsai->Instance->CR1 |= SAI_xCR1_DMAEN; |
mbed_official | 573:ad23fe03a082 | 1105 | |
mbed_official | 573:ad23fe03a082 | 1106 | /* Process Unlocked */ |
mbed_official | 573:ad23fe03a082 | 1107 | __HAL_UNLOCK(hsai); |
mbed_official | 573:ad23fe03a082 | 1108 | |
mbed_official | 573:ad23fe03a082 | 1109 | return HAL_OK; |
mbed_official | 573:ad23fe03a082 | 1110 | } |
mbed_official | 573:ad23fe03a082 | 1111 | else |
mbed_official | 573:ad23fe03a082 | 1112 | { |
mbed_official | 573:ad23fe03a082 | 1113 | return HAL_BUSY; |
mbed_official | 573:ad23fe03a082 | 1114 | } |
mbed_official | 573:ad23fe03a082 | 1115 | } |
mbed_official | 573:ad23fe03a082 | 1116 | |
mbed_official | 573:ad23fe03a082 | 1117 | /** |
mbed_official | 573:ad23fe03a082 | 1118 | * @brief Enable the tx mute mode. |
mbed_official | 573:ad23fe03a082 | 1119 | * @param hsai : pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1120 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1121 | * @param val : value sent during the mute @ref SAI_Block_Mute_Value |
mbed_official | 573:ad23fe03a082 | 1122 | * @retval HAL status |
mbed_official | 573:ad23fe03a082 | 1123 | */ |
mbed_official | 573:ad23fe03a082 | 1124 | HAL_StatusTypeDef HAL_SAI_EnableTxMuteMode(SAI_HandleTypeDef *hsai, uint16_t val) |
mbed_official | 573:ad23fe03a082 | 1125 | { |
mbed_official | 573:ad23fe03a082 | 1126 | assert_param(IS_SAI_BLOCK_MUTE_VALUE(val)); |
mbed_official | 573:ad23fe03a082 | 1127 | |
mbed_official | 573:ad23fe03a082 | 1128 | if(hsai->State != HAL_SAI_STATE_RESET) |
mbed_official | 573:ad23fe03a082 | 1129 | { |
mbed_official | 573:ad23fe03a082 | 1130 | CLEAR_BIT(hsai->Instance->CR2, SAI_xCR2_MUTEVAL | SAI_xCR2_MUTE); |
mbed_official | 573:ad23fe03a082 | 1131 | SET_BIT(hsai->Instance->CR2, SAI_xCR2_MUTE | val); |
mbed_official | 573:ad23fe03a082 | 1132 | return HAL_OK; |
mbed_official | 573:ad23fe03a082 | 1133 | } |
mbed_official | 573:ad23fe03a082 | 1134 | return HAL_ERROR; |
mbed_official | 573:ad23fe03a082 | 1135 | } |
mbed_official | 573:ad23fe03a082 | 1136 | |
mbed_official | 573:ad23fe03a082 | 1137 | /** |
mbed_official | 573:ad23fe03a082 | 1138 | * @brief Disable the tx mute mode. |
mbed_official | 573:ad23fe03a082 | 1139 | * @param hsai : pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1140 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1141 | * @retval HAL status |
mbed_official | 573:ad23fe03a082 | 1142 | */ |
mbed_official | 573:ad23fe03a082 | 1143 | HAL_StatusTypeDef HAL_SAI_DisableTxMuteMode(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 1144 | { |
mbed_official | 573:ad23fe03a082 | 1145 | if(hsai->State != HAL_SAI_STATE_RESET) |
mbed_official | 573:ad23fe03a082 | 1146 | { |
mbed_official | 573:ad23fe03a082 | 1147 | CLEAR_BIT(hsai->Instance->CR2, SAI_xCR2_MUTEVAL | SAI_xCR2_MUTE); |
mbed_official | 573:ad23fe03a082 | 1148 | return HAL_OK; |
mbed_official | 573:ad23fe03a082 | 1149 | } |
mbed_official | 573:ad23fe03a082 | 1150 | return HAL_ERROR; |
mbed_official | 573:ad23fe03a082 | 1151 | } |
mbed_official | 573:ad23fe03a082 | 1152 | |
mbed_official | 573:ad23fe03a082 | 1153 | /** |
mbed_official | 573:ad23fe03a082 | 1154 | * @brief Enable the rx mute detection. |
mbed_official | 573:ad23fe03a082 | 1155 | * @param hsai : pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1156 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1157 | * @param callback : function called when the mute is detected |
mbed_official | 573:ad23fe03a082 | 1158 | * @param counter : number a data before mute detection max 63. |
mbed_official | 573:ad23fe03a082 | 1159 | * @retval HAL status |
mbed_official | 573:ad23fe03a082 | 1160 | */ |
mbed_official | 573:ad23fe03a082 | 1161 | HAL_StatusTypeDef HAL_SAI_EnableRxMuteMode(SAI_HandleTypeDef *hsai, SAIcallback callback, uint16_t counter) |
mbed_official | 573:ad23fe03a082 | 1162 | { |
mbed_official | 573:ad23fe03a082 | 1163 | assert_param(IS_SAI_BLOCK_MUTE_COUNTER(counter)); |
mbed_official | 573:ad23fe03a082 | 1164 | |
mbed_official | 573:ad23fe03a082 | 1165 | if(hsai->State != HAL_SAI_STATE_RESET) |
mbed_official | 573:ad23fe03a082 | 1166 | { |
mbed_official | 573:ad23fe03a082 | 1167 | /* set the mute counter */ |
mbed_official | 573:ad23fe03a082 | 1168 | CLEAR_BIT(hsai->Instance->CR2, SAI_xCR2_MUTECNT); |
mbed_official | 573:ad23fe03a082 | 1169 | SET_BIT(hsai->Instance->CR2, (uint32_t)((uint32_t)counter << 6)); |
mbed_official | 573:ad23fe03a082 | 1170 | hsai->mutecallback = callback; |
mbed_official | 573:ad23fe03a082 | 1171 | /* enable the IT interrupt */ |
mbed_official | 573:ad23fe03a082 | 1172 | __HAL_SAI_ENABLE_IT(hsai, SAI_IT_MUTEDET); |
mbed_official | 573:ad23fe03a082 | 1173 | return HAL_OK; |
mbed_official | 573:ad23fe03a082 | 1174 | } |
mbed_official | 573:ad23fe03a082 | 1175 | return HAL_ERROR; |
mbed_official | 573:ad23fe03a082 | 1176 | } |
mbed_official | 573:ad23fe03a082 | 1177 | |
mbed_official | 573:ad23fe03a082 | 1178 | /** |
mbed_official | 573:ad23fe03a082 | 1179 | * @brief Disable the rx mute detection. |
mbed_official | 573:ad23fe03a082 | 1180 | * @param hsai : pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1181 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1182 | * @retval HAL status |
mbed_official | 573:ad23fe03a082 | 1183 | */ |
mbed_official | 573:ad23fe03a082 | 1184 | HAL_StatusTypeDef HAL_SAI_DisableRxMuteMode(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 1185 | { |
mbed_official | 573:ad23fe03a082 | 1186 | if(hsai->State != HAL_SAI_STATE_RESET) |
mbed_official | 573:ad23fe03a082 | 1187 | { |
mbed_official | 573:ad23fe03a082 | 1188 | /* set the mutecallback to NULL */ |
mbed_official | 573:ad23fe03a082 | 1189 | hsai->mutecallback = (SAIcallback)NULL; |
mbed_official | 573:ad23fe03a082 | 1190 | /* enable the IT interrupt */ |
mbed_official | 573:ad23fe03a082 | 1191 | __HAL_SAI_DISABLE_IT(hsai, SAI_IT_MUTEDET); |
mbed_official | 573:ad23fe03a082 | 1192 | return HAL_OK; |
mbed_official | 573:ad23fe03a082 | 1193 | } |
mbed_official | 573:ad23fe03a082 | 1194 | return HAL_ERROR; |
mbed_official | 573:ad23fe03a082 | 1195 | } |
mbed_official | 573:ad23fe03a082 | 1196 | |
mbed_official | 573:ad23fe03a082 | 1197 | /** |
mbed_official | 573:ad23fe03a082 | 1198 | * @brief This function handles SAI interrupt request. |
mbed_official | 573:ad23fe03a082 | 1199 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1200 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1201 | * @retval HAL status |
mbed_official | 573:ad23fe03a082 | 1202 | */ |
mbed_official | 573:ad23fe03a082 | 1203 | void HAL_SAI_IRQHandler(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 1204 | { |
mbed_official | 573:ad23fe03a082 | 1205 | if(hsai->State != HAL_SAI_STATE_RESET) |
mbed_official | 573:ad23fe03a082 | 1206 | { |
mbed_official | 573:ad23fe03a082 | 1207 | uint32_t tmpFlag = hsai->Instance->SR; |
mbed_official | 573:ad23fe03a082 | 1208 | uint32_t tmpItSource = hsai->Instance->IMR; |
mbed_official | 573:ad23fe03a082 | 1209 | |
mbed_official | 573:ad23fe03a082 | 1210 | if(((tmpFlag & SAI_xSR_FREQ) == SAI_xSR_FREQ) && ((tmpItSource & SAI_IT_FREQ) == SAI_IT_FREQ)) |
mbed_official | 573:ad23fe03a082 | 1211 | { |
mbed_official | 573:ad23fe03a082 | 1212 | hsai->InterruptServiceRoutine(hsai); |
mbed_official | 573:ad23fe03a082 | 1213 | } |
mbed_official | 573:ad23fe03a082 | 1214 | |
mbed_official | 573:ad23fe03a082 | 1215 | /* check the flag only if one of them is set */ |
mbed_official | 573:ad23fe03a082 | 1216 | if(tmpFlag != 0x00000000) |
mbed_official | 573:ad23fe03a082 | 1217 | { |
mbed_official | 573:ad23fe03a082 | 1218 | /* SAI Overrun error interrupt occurred ----------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 1219 | if(((tmpFlag & SAI_FLAG_OVRUDR) == SAI_FLAG_OVRUDR) && ((tmpItSource & SAI_IT_OVRUDR) == SAI_IT_OVRUDR)) |
mbed_official | 573:ad23fe03a082 | 1220 | { |
mbed_official | 573:ad23fe03a082 | 1221 | /* Clear the SAI Overrun flag */ |
mbed_official | 573:ad23fe03a082 | 1222 | __HAL_SAI_CLEAR_FLAG(hsai, SAI_FLAG_OVRUDR); |
mbed_official | 573:ad23fe03a082 | 1223 | /* Change the SAI error code */ |
mbed_official | 573:ad23fe03a082 | 1224 | hsai->ErrorCode = ((hsai->State == HAL_SAI_STATE_BUSY_RX) ? HAL_SAI_ERROR_OVR : HAL_SAI_ERROR_UDR); |
mbed_official | 573:ad23fe03a082 | 1225 | /* the transfer is not stopped, we will forward the information to the user and we let the user decide what needs to be done */ |
mbed_official | 573:ad23fe03a082 | 1226 | HAL_SAI_ErrorCallback(hsai); |
mbed_official | 573:ad23fe03a082 | 1227 | } |
mbed_official | 573:ad23fe03a082 | 1228 | |
mbed_official | 573:ad23fe03a082 | 1229 | /* SAI mutedet interrupt occurred ----------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 1230 | if(((tmpFlag & SAI_FLAG_MUTEDET) == SAI_FLAG_MUTEDET) && ((tmpItSource & SAI_IT_MUTEDET) == SAI_IT_MUTEDET)) |
mbed_official | 573:ad23fe03a082 | 1231 | { |
mbed_official | 573:ad23fe03a082 | 1232 | /* Clear the SAI mutedet flag */ |
mbed_official | 573:ad23fe03a082 | 1233 | __HAL_SAI_CLEAR_FLAG(hsai, SAI_FLAG_MUTEDET); |
mbed_official | 573:ad23fe03a082 | 1234 | /* call the call back function */ |
mbed_official | 573:ad23fe03a082 | 1235 | if(hsai->mutecallback != (SAIcallback)NULL) |
mbed_official | 573:ad23fe03a082 | 1236 | { |
mbed_official | 573:ad23fe03a082 | 1237 | /* inform the user that an RX mute event has been detected */ |
mbed_official | 573:ad23fe03a082 | 1238 | hsai->mutecallback(); |
mbed_official | 573:ad23fe03a082 | 1239 | } |
mbed_official | 573:ad23fe03a082 | 1240 | } |
mbed_official | 573:ad23fe03a082 | 1241 | |
mbed_official | 573:ad23fe03a082 | 1242 | /* SAI AFSDET interrupt occurred ----------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 1243 | if(((tmpFlag & SAI_FLAG_AFSDET) == SAI_FLAG_AFSDET) && ((tmpItSource & SAI_IT_AFSDET) == SAI_IT_AFSDET)) |
mbed_official | 573:ad23fe03a082 | 1244 | { |
mbed_official | 573:ad23fe03a082 | 1245 | /* Change the SAI error code */ |
mbed_official | 573:ad23fe03a082 | 1246 | hsai->ErrorCode = HAL_SAI_ERROR_AFSDET; |
mbed_official | 573:ad23fe03a082 | 1247 | HAL_SAI_Abort(hsai); |
mbed_official | 573:ad23fe03a082 | 1248 | HAL_SAI_ErrorCallback(hsai); |
mbed_official | 573:ad23fe03a082 | 1249 | } |
mbed_official | 573:ad23fe03a082 | 1250 | |
mbed_official | 573:ad23fe03a082 | 1251 | /* SAI LFSDET interrupt occurred ----------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 1252 | if(((tmpFlag & SAI_FLAG_LFSDET) == SAI_FLAG_LFSDET) && ((tmpItSource & SAI_IT_LFSDET) == SAI_IT_LFSDET)) |
mbed_official | 573:ad23fe03a082 | 1253 | { |
mbed_official | 573:ad23fe03a082 | 1254 | /* Change the SAI error code */ |
mbed_official | 573:ad23fe03a082 | 1255 | hsai->ErrorCode = HAL_SAI_ERROR_LFSDET; |
mbed_official | 573:ad23fe03a082 | 1256 | HAL_SAI_Abort(hsai); |
mbed_official | 573:ad23fe03a082 | 1257 | HAL_SAI_ErrorCallback(hsai); |
mbed_official | 573:ad23fe03a082 | 1258 | } |
mbed_official | 573:ad23fe03a082 | 1259 | |
mbed_official | 573:ad23fe03a082 | 1260 | /* SAI WCKCFG interrupt occurred ----------------------------------*/ |
mbed_official | 573:ad23fe03a082 | 1261 | if(((tmpFlag & SAI_FLAG_WCKCFG) == SAI_FLAG_WCKCFG) && ((tmpItSource & SAI_IT_WCKCFG) == SAI_IT_WCKCFG)) |
mbed_official | 573:ad23fe03a082 | 1262 | { |
mbed_official | 573:ad23fe03a082 | 1263 | /* Change the SAI error code */ |
mbed_official | 573:ad23fe03a082 | 1264 | hsai->ErrorCode = HAL_SAI_ERROR_WCKCFG; |
mbed_official | 573:ad23fe03a082 | 1265 | HAL_SAI_Abort(hsai); |
mbed_official | 573:ad23fe03a082 | 1266 | HAL_SAI_ErrorCallback(hsai); |
mbed_official | 573:ad23fe03a082 | 1267 | } |
mbed_official | 573:ad23fe03a082 | 1268 | } |
mbed_official | 573:ad23fe03a082 | 1269 | } |
mbed_official | 573:ad23fe03a082 | 1270 | } |
mbed_official | 573:ad23fe03a082 | 1271 | |
mbed_official | 573:ad23fe03a082 | 1272 | /** |
mbed_official | 573:ad23fe03a082 | 1273 | * @brief Tx Transfer completed callbacks. |
mbed_official | 573:ad23fe03a082 | 1274 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1275 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1276 | * @retval None |
mbed_official | 573:ad23fe03a082 | 1277 | */ |
mbed_official | 573:ad23fe03a082 | 1278 | __weak void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 1279 | { |
mbed_official | 573:ad23fe03a082 | 1280 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 573:ad23fe03a082 | 1281 | the HAL_SAI_TxCpltCallback could be implemented in the user file |
mbed_official | 573:ad23fe03a082 | 1282 | */ |
mbed_official | 573:ad23fe03a082 | 1283 | } |
mbed_official | 573:ad23fe03a082 | 1284 | |
mbed_official | 573:ad23fe03a082 | 1285 | /** |
mbed_official | 573:ad23fe03a082 | 1286 | * @brief Tx Transfer Half completed callbacks |
mbed_official | 573:ad23fe03a082 | 1287 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1288 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1289 | * @retval None |
mbed_official | 573:ad23fe03a082 | 1290 | */ |
mbed_official | 573:ad23fe03a082 | 1291 | __weak void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 1292 | { |
mbed_official | 573:ad23fe03a082 | 1293 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 573:ad23fe03a082 | 1294 | the HAL_SAI_TxHalfCpltCallback could be implemented in the user file |
mbed_official | 573:ad23fe03a082 | 1295 | */ |
mbed_official | 573:ad23fe03a082 | 1296 | } |
mbed_official | 573:ad23fe03a082 | 1297 | |
mbed_official | 573:ad23fe03a082 | 1298 | /** |
mbed_official | 573:ad23fe03a082 | 1299 | * @brief Rx Transfer completed callbacks. |
mbed_official | 573:ad23fe03a082 | 1300 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1301 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1302 | * @retval None |
mbed_official | 573:ad23fe03a082 | 1303 | */ |
mbed_official | 573:ad23fe03a082 | 1304 | __weak void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 1305 | { |
mbed_official | 573:ad23fe03a082 | 1306 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 573:ad23fe03a082 | 1307 | the HAL_SAI_RxCpltCallback could be implemented in the user file |
mbed_official | 573:ad23fe03a082 | 1308 | */ |
mbed_official | 573:ad23fe03a082 | 1309 | } |
mbed_official | 573:ad23fe03a082 | 1310 | |
mbed_official | 573:ad23fe03a082 | 1311 | /** |
mbed_official | 573:ad23fe03a082 | 1312 | * @brief Rx Transfer half completed callbacks |
mbed_official | 573:ad23fe03a082 | 1313 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1314 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1315 | * @retval None |
mbed_official | 573:ad23fe03a082 | 1316 | */ |
mbed_official | 573:ad23fe03a082 | 1317 | __weak void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 1318 | { |
mbed_official | 573:ad23fe03a082 | 1319 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 573:ad23fe03a082 | 1320 | the HAL_SAI_RxCpltCallback could be implemented in the user file |
mbed_official | 573:ad23fe03a082 | 1321 | */ |
mbed_official | 573:ad23fe03a082 | 1322 | } |
mbed_official | 573:ad23fe03a082 | 1323 | |
mbed_official | 573:ad23fe03a082 | 1324 | /** |
mbed_official | 573:ad23fe03a082 | 1325 | * @brief SAI error callbacks. |
mbed_official | 573:ad23fe03a082 | 1326 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1327 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1328 | * @retval None |
mbed_official | 573:ad23fe03a082 | 1329 | */ |
mbed_official | 573:ad23fe03a082 | 1330 | __weak void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 1331 | { |
mbed_official | 573:ad23fe03a082 | 1332 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 573:ad23fe03a082 | 1333 | the HAL_SAI_ErrorCallback could be implemented in the user file |
mbed_official | 573:ad23fe03a082 | 1334 | */ |
mbed_official | 573:ad23fe03a082 | 1335 | } |
mbed_official | 573:ad23fe03a082 | 1336 | |
mbed_official | 573:ad23fe03a082 | 1337 | /** |
mbed_official | 573:ad23fe03a082 | 1338 | * @} |
mbed_official | 573:ad23fe03a082 | 1339 | */ |
mbed_official | 573:ad23fe03a082 | 1340 | |
mbed_official | 573:ad23fe03a082 | 1341 | |
mbed_official | 573:ad23fe03a082 | 1342 | /** @defgroup SAI_Exported_Functions_Group3 Peripheral State functions |
mbed_official | 573:ad23fe03a082 | 1343 | * @brief Peripheral State functions |
mbed_official | 573:ad23fe03a082 | 1344 | * |
mbed_official | 573:ad23fe03a082 | 1345 | @verbatim |
mbed_official | 573:ad23fe03a082 | 1346 | =============================================================================== |
mbed_official | 573:ad23fe03a082 | 1347 | ##### Peripheral State and Errors functions ##### |
mbed_official | 573:ad23fe03a082 | 1348 | =============================================================================== |
mbed_official | 573:ad23fe03a082 | 1349 | [..] |
mbed_official | 573:ad23fe03a082 | 1350 | This subsection permits to get in run-time the status of the peripheral |
mbed_official | 573:ad23fe03a082 | 1351 | and the data flow. |
mbed_official | 573:ad23fe03a082 | 1352 | |
mbed_official | 573:ad23fe03a082 | 1353 | @endverbatim |
mbed_official | 573:ad23fe03a082 | 1354 | * @{ |
mbed_official | 573:ad23fe03a082 | 1355 | */ |
mbed_official | 573:ad23fe03a082 | 1356 | |
mbed_official | 573:ad23fe03a082 | 1357 | /** |
mbed_official | 573:ad23fe03a082 | 1358 | * @brief Returns the SAI state. |
mbed_official | 573:ad23fe03a082 | 1359 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1360 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1361 | * @retval HAL state |
mbed_official | 573:ad23fe03a082 | 1362 | */ |
mbed_official | 573:ad23fe03a082 | 1363 | HAL_SAI_StateTypeDef HAL_SAI_GetState(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 1364 | { |
mbed_official | 573:ad23fe03a082 | 1365 | return hsai->State; |
mbed_official | 573:ad23fe03a082 | 1366 | } |
mbed_official | 573:ad23fe03a082 | 1367 | |
mbed_official | 573:ad23fe03a082 | 1368 | /** |
mbed_official | 573:ad23fe03a082 | 1369 | * @brief Return the SAI error code |
mbed_official | 573:ad23fe03a082 | 1370 | * @param hsai : pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1371 | * the configuration information for the specified SAI Block. |
mbed_official | 573:ad23fe03a082 | 1372 | * @retval SAI Error Code |
mbed_official | 573:ad23fe03a082 | 1373 | */ |
mbed_official | 573:ad23fe03a082 | 1374 | uint32_t HAL_SAI_GetError(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 1375 | { |
mbed_official | 573:ad23fe03a082 | 1376 | return hsai->ErrorCode; |
mbed_official | 573:ad23fe03a082 | 1377 | } |
mbed_official | 573:ad23fe03a082 | 1378 | /** |
mbed_official | 573:ad23fe03a082 | 1379 | * @} |
mbed_official | 573:ad23fe03a082 | 1380 | */ |
mbed_official | 573:ad23fe03a082 | 1381 | |
mbed_official | 573:ad23fe03a082 | 1382 | /** |
mbed_official | 573:ad23fe03a082 | 1383 | * @brief Initializes the SAI I2S protocol according to the specified parameters |
mbed_official | 573:ad23fe03a082 | 1384 | * in the SAI_InitTypeDef and create the associated handle. |
mbed_official | 573:ad23fe03a082 | 1385 | * @param hsai : pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1386 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1387 | * @param protocol : one of the supported protocol |
mbed_official | 573:ad23fe03a082 | 1388 | * @param datasize : one of the supported datasize @ref SAI_Protocol_DataSize |
mbed_official | 573:ad23fe03a082 | 1389 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1390 | * @param nbslot : number of slot minimum value is 2 and max is 16. |
mbed_official | 573:ad23fe03a082 | 1391 | * the value must be a multiple of 2. |
mbed_official | 573:ad23fe03a082 | 1392 | * @retval HAL status |
mbed_official | 573:ad23fe03a082 | 1393 | */ |
mbed_official | 573:ad23fe03a082 | 1394 | static HAL_StatusTypeDef SAI_InitI2S(SAI_HandleTypeDef *hsai, uint32_t protocol, uint32_t datasize, uint32_t nbslot) |
mbed_official | 573:ad23fe03a082 | 1395 | { |
mbed_official | 573:ad23fe03a082 | 1396 | /* Check the parameters */ |
mbed_official | 573:ad23fe03a082 | 1397 | assert_param(IS_SAI_SUPPORTED_PROTOCOL(protocol)); |
mbed_official | 573:ad23fe03a082 | 1398 | assert_param(IS_SAI_PROTOCOL_DATASIZE(datasize)); |
mbed_official | 573:ad23fe03a082 | 1399 | |
mbed_official | 573:ad23fe03a082 | 1400 | hsai->Init.Protocol = SAI_FREE_PROTOCOL; |
mbed_official | 573:ad23fe03a082 | 1401 | hsai->Init.FirstBit = SAI_FIRSTBIT_MSB; |
mbed_official | 573:ad23fe03a082 | 1402 | hsai->Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE; |
mbed_official | 573:ad23fe03a082 | 1403 | hsai->FrameInit.FSDefinition = SAI_FS_CHANNEL_IDENTIFICATION; |
mbed_official | 573:ad23fe03a082 | 1404 | hsai->SlotInit.SlotActive = SAI_SLOTACTIVE_ALL; |
mbed_official | 573:ad23fe03a082 | 1405 | hsai->SlotInit.FirstBitOffset = 0; |
mbed_official | 573:ad23fe03a082 | 1406 | hsai->SlotInit.SlotNumber = nbslot; |
mbed_official | 573:ad23fe03a082 | 1407 | |
mbed_official | 573:ad23fe03a082 | 1408 | /* in IS2 the number of slot must be even */ |
mbed_official | 573:ad23fe03a082 | 1409 | if((nbslot & 0x1) != 0 ) |
mbed_official | 573:ad23fe03a082 | 1410 | { |
mbed_official | 573:ad23fe03a082 | 1411 | return HAL_ERROR; |
mbed_official | 573:ad23fe03a082 | 1412 | } |
mbed_official | 573:ad23fe03a082 | 1413 | |
mbed_official | 573:ad23fe03a082 | 1414 | switch(protocol) |
mbed_official | 573:ad23fe03a082 | 1415 | { |
mbed_official | 573:ad23fe03a082 | 1416 | case SAI_I2S_STANDARD : |
mbed_official | 573:ad23fe03a082 | 1417 | hsai->FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW; |
mbed_official | 573:ad23fe03a082 | 1418 | hsai->FrameInit.FSOffset = SAI_FS_BEFOREFIRSTBIT; |
mbed_official | 573:ad23fe03a082 | 1419 | break; |
mbed_official | 573:ad23fe03a082 | 1420 | case SAI_I2S_MSBJUSTIFIED : |
mbed_official | 573:ad23fe03a082 | 1421 | case SAI_I2S_LSBJUSTIFIED : |
mbed_official | 573:ad23fe03a082 | 1422 | hsai->FrameInit.FSPolarity = SAI_FS_ACTIVE_HIGH; |
mbed_official | 573:ad23fe03a082 | 1423 | hsai->FrameInit.FSOffset = SAI_FS_FIRSTBIT; |
mbed_official | 573:ad23fe03a082 | 1424 | break; |
mbed_official | 573:ad23fe03a082 | 1425 | default : |
mbed_official | 573:ad23fe03a082 | 1426 | return HAL_ERROR; |
mbed_official | 573:ad23fe03a082 | 1427 | } |
mbed_official | 573:ad23fe03a082 | 1428 | |
mbed_official | 573:ad23fe03a082 | 1429 | /* Frame definition */ |
mbed_official | 573:ad23fe03a082 | 1430 | hsai->Init.DataSize = 0xFFFFFFFF; |
mbed_official | 573:ad23fe03a082 | 1431 | switch(datasize) |
mbed_official | 573:ad23fe03a082 | 1432 | { |
mbed_official | 573:ad23fe03a082 | 1433 | case SAI_PROTOCOL_DATASIZE_16BIT: |
mbed_official | 573:ad23fe03a082 | 1434 | hsai->Init.DataSize = SAI_DATASIZE_16; |
mbed_official | 573:ad23fe03a082 | 1435 | hsai->FrameInit.FrameLength = 32*(nbslot/2); |
mbed_official | 573:ad23fe03a082 | 1436 | hsai->FrameInit.ActiveFrameLength = 16*(nbslot/2); |
mbed_official | 573:ad23fe03a082 | 1437 | hsai->SlotInit.SlotSize = SAI_SLOTSIZE_16B; |
mbed_official | 573:ad23fe03a082 | 1438 | break; |
mbed_official | 573:ad23fe03a082 | 1439 | case SAI_PROTOCOL_DATASIZE_16BITEXTENDED : |
mbed_official | 573:ad23fe03a082 | 1440 | if(hsai->Init.DataSize == 0xFFFFFFFF) |
mbed_official | 573:ad23fe03a082 | 1441 | { |
mbed_official | 573:ad23fe03a082 | 1442 | hsai->Init.DataSize = SAI_DATASIZE_16; |
mbed_official | 573:ad23fe03a082 | 1443 | } |
mbed_official | 573:ad23fe03a082 | 1444 | break; |
mbed_official | 573:ad23fe03a082 | 1445 | case SAI_PROTOCOL_DATASIZE_24BIT: |
mbed_official | 573:ad23fe03a082 | 1446 | if(hsai->Init.DataSize == 0xFFFFFFFF) |
mbed_official | 573:ad23fe03a082 | 1447 | { |
mbed_official | 573:ad23fe03a082 | 1448 | hsai->Init.DataSize = SAI_DATASIZE_24; |
mbed_official | 573:ad23fe03a082 | 1449 | } |
mbed_official | 573:ad23fe03a082 | 1450 | break; |
mbed_official | 573:ad23fe03a082 | 1451 | case SAI_PROTOCOL_DATASIZE_32BIT: |
mbed_official | 573:ad23fe03a082 | 1452 | if(hsai->Init.DataSize == 0xFFFFFFFF) |
mbed_official | 573:ad23fe03a082 | 1453 | { |
mbed_official | 573:ad23fe03a082 | 1454 | hsai->Init.DataSize = SAI_DATASIZE_32; |
mbed_official | 573:ad23fe03a082 | 1455 | } |
mbed_official | 573:ad23fe03a082 | 1456 | hsai->FrameInit.FrameLength = 64*(nbslot/2); |
mbed_official | 573:ad23fe03a082 | 1457 | hsai->FrameInit.ActiveFrameLength = 32*(nbslot/2); |
mbed_official | 573:ad23fe03a082 | 1458 | hsai->SlotInit.SlotSize = SAI_SLOTSIZE_32B; |
mbed_official | 573:ad23fe03a082 | 1459 | if(protocol == SAI_I2S_LSBJUSTIFIED) |
mbed_official | 573:ad23fe03a082 | 1460 | { |
mbed_official | 573:ad23fe03a082 | 1461 | if (datasize == SAI_PROTOCOL_DATASIZE_16BITEXTENDED) |
mbed_official | 573:ad23fe03a082 | 1462 | { |
mbed_official | 573:ad23fe03a082 | 1463 | hsai->SlotInit.FirstBitOffset = 16; |
mbed_official | 573:ad23fe03a082 | 1464 | } |
mbed_official | 573:ad23fe03a082 | 1465 | if (datasize == SAI_PROTOCOL_DATASIZE_24BIT) |
mbed_official | 573:ad23fe03a082 | 1466 | { |
mbed_official | 573:ad23fe03a082 | 1467 | hsai->SlotInit.FirstBitOffset = 8; |
mbed_official | 573:ad23fe03a082 | 1468 | } |
mbed_official | 573:ad23fe03a082 | 1469 | } |
mbed_official | 573:ad23fe03a082 | 1470 | break; |
mbed_official | 573:ad23fe03a082 | 1471 | default : |
mbed_official | 573:ad23fe03a082 | 1472 | return HAL_ERROR; |
mbed_official | 573:ad23fe03a082 | 1473 | } |
mbed_official | 573:ad23fe03a082 | 1474 | |
mbed_official | 573:ad23fe03a082 | 1475 | return HAL_OK; |
mbed_official | 573:ad23fe03a082 | 1476 | } |
mbed_official | 573:ad23fe03a082 | 1477 | |
mbed_official | 573:ad23fe03a082 | 1478 | /** |
mbed_official | 573:ad23fe03a082 | 1479 | * @brief Initializes the SAI PCM protocol according to the specified parameters |
mbed_official | 573:ad23fe03a082 | 1480 | * in the SAI_InitTypeDef and create the associated handle. |
mbed_official | 573:ad23fe03a082 | 1481 | * @param hsai : pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1482 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1483 | * @param protocol : one of the supported protocol |
mbed_official | 573:ad23fe03a082 | 1484 | * @param datasize : one of the supported datasize @ref SAI_Protocol_DataSize |
mbed_official | 573:ad23fe03a082 | 1485 | * @param nbslot : number of slot minimum value is 1 and the max is 16. |
mbed_official | 573:ad23fe03a082 | 1486 | * @retval HAL status |
mbed_official | 573:ad23fe03a082 | 1487 | */ |
mbed_official | 573:ad23fe03a082 | 1488 | static HAL_StatusTypeDef SAI_InitPCM(SAI_HandleTypeDef *hsai, uint32_t protocol, uint32_t datasize, uint32_t nbslot) |
mbed_official | 573:ad23fe03a082 | 1489 | { |
mbed_official | 573:ad23fe03a082 | 1490 | /* Check the parameters */ |
mbed_official | 573:ad23fe03a082 | 1491 | assert_param(IS_SAI_SUPPORTED_PROTOCOL(protocol)); |
mbed_official | 573:ad23fe03a082 | 1492 | assert_param(IS_SAI_PROTOCOL_DATASIZE(datasize)); |
mbed_official | 573:ad23fe03a082 | 1493 | |
mbed_official | 573:ad23fe03a082 | 1494 | hsai->Init.Protocol = SAI_FREE_PROTOCOL; |
mbed_official | 573:ad23fe03a082 | 1495 | hsai->Init.FirstBit = SAI_FIRSTBIT_MSB; |
mbed_official | 573:ad23fe03a082 | 1496 | hsai->Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE; |
mbed_official | 573:ad23fe03a082 | 1497 | hsai->FrameInit.FSDefinition = SAI_FS_STARTFRAME; |
mbed_official | 573:ad23fe03a082 | 1498 | hsai->FrameInit.FSPolarity = SAI_FS_ACTIVE_HIGH; |
mbed_official | 573:ad23fe03a082 | 1499 | hsai->FrameInit.FSOffset = SAI_FS_BEFOREFIRSTBIT; |
mbed_official | 573:ad23fe03a082 | 1500 | hsai->SlotInit.FirstBitOffset = 0; |
mbed_official | 573:ad23fe03a082 | 1501 | hsai->SlotInit.SlotNumber = nbslot; |
mbed_official | 573:ad23fe03a082 | 1502 | hsai->SlotInit.SlotActive = SAI_SLOTACTIVE_ALL; |
mbed_official | 573:ad23fe03a082 | 1503 | |
mbed_official | 573:ad23fe03a082 | 1504 | switch(protocol) |
mbed_official | 573:ad23fe03a082 | 1505 | { |
mbed_official | 573:ad23fe03a082 | 1506 | case SAI_PCM_SHORT : |
mbed_official | 573:ad23fe03a082 | 1507 | hsai->FrameInit.ActiveFrameLength = 1; |
mbed_official | 573:ad23fe03a082 | 1508 | break; |
mbed_official | 573:ad23fe03a082 | 1509 | case SAI_PCM_LONG : |
mbed_official | 573:ad23fe03a082 | 1510 | hsai->FrameInit.ActiveFrameLength = 13; |
mbed_official | 573:ad23fe03a082 | 1511 | break; |
mbed_official | 573:ad23fe03a082 | 1512 | default : |
mbed_official | 573:ad23fe03a082 | 1513 | return HAL_ERROR; |
mbed_official | 573:ad23fe03a082 | 1514 | } |
mbed_official | 573:ad23fe03a082 | 1515 | |
mbed_official | 573:ad23fe03a082 | 1516 | switch(datasize) |
mbed_official | 573:ad23fe03a082 | 1517 | { |
mbed_official | 573:ad23fe03a082 | 1518 | case SAI_PROTOCOL_DATASIZE_16BIT: |
mbed_official | 573:ad23fe03a082 | 1519 | hsai->Init.DataSize = SAI_DATASIZE_16; |
mbed_official | 573:ad23fe03a082 | 1520 | hsai->FrameInit.FrameLength = 16 * nbslot; |
mbed_official | 573:ad23fe03a082 | 1521 | hsai->SlotInit.SlotSize = SAI_SLOTSIZE_16B; |
mbed_official | 573:ad23fe03a082 | 1522 | break; |
mbed_official | 573:ad23fe03a082 | 1523 | case SAI_PROTOCOL_DATASIZE_16BITEXTENDED : |
mbed_official | 573:ad23fe03a082 | 1524 | hsai->Init.DataSize = SAI_DATASIZE_16; |
mbed_official | 573:ad23fe03a082 | 1525 | hsai->FrameInit.FrameLength = 32 * nbslot; |
mbed_official | 573:ad23fe03a082 | 1526 | hsai->SlotInit.SlotSize = SAI_SLOTSIZE_32B; |
mbed_official | 573:ad23fe03a082 | 1527 | break; |
mbed_official | 573:ad23fe03a082 | 1528 | |
mbed_official | 573:ad23fe03a082 | 1529 | case SAI_PROTOCOL_DATASIZE_32BIT: |
mbed_official | 573:ad23fe03a082 | 1530 | hsai->Init.DataSize = SAI_DATASIZE_32; |
mbed_official | 573:ad23fe03a082 | 1531 | hsai->FrameInit.FrameLength = 32 * nbslot; |
mbed_official | 573:ad23fe03a082 | 1532 | hsai->SlotInit.SlotSize = SAI_SLOTSIZE_32B; |
mbed_official | 573:ad23fe03a082 | 1533 | break; |
mbed_official | 573:ad23fe03a082 | 1534 | default : |
mbed_official | 573:ad23fe03a082 | 1535 | return HAL_ERROR; |
mbed_official | 573:ad23fe03a082 | 1536 | } |
mbed_official | 573:ad23fe03a082 | 1537 | |
mbed_official | 573:ad23fe03a082 | 1538 | return HAL_OK; |
mbed_official | 573:ad23fe03a082 | 1539 | } |
mbed_official | 573:ad23fe03a082 | 1540 | |
mbed_official | 573:ad23fe03a082 | 1541 | /** |
mbed_official | 573:ad23fe03a082 | 1542 | * @brief Fill the fifo |
mbed_official | 573:ad23fe03a082 | 1543 | * @param hsai : pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1544 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1545 | * @retval None. |
mbed_official | 573:ad23fe03a082 | 1546 | */ |
mbed_official | 573:ad23fe03a082 | 1547 | static void SAI_FillFifo(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 1548 | { |
mbed_official | 573:ad23fe03a082 | 1549 | /* fill the fifo with data before to enabled the SAI */ |
mbed_official | 573:ad23fe03a082 | 1550 | while((hsai->Instance->SR & SAI_xSR_FLVL) != SAI_FIFOSTATUS_FULL) |
mbed_official | 573:ad23fe03a082 | 1551 | { |
mbed_official | 573:ad23fe03a082 | 1552 | if((hsai->Init.DataSize == SAI_DATASIZE_8) && (hsai->Init.CompandingMode == SAI_NOCOMPANDING)) |
mbed_official | 573:ad23fe03a082 | 1553 | { |
mbed_official | 573:ad23fe03a082 | 1554 | hsai->Instance->DR = (*hsai->pBuffPtr++); |
mbed_official | 573:ad23fe03a082 | 1555 | } |
mbed_official | 573:ad23fe03a082 | 1556 | else if(hsai->Init.DataSize <= SAI_DATASIZE_16) |
mbed_official | 573:ad23fe03a082 | 1557 | { |
mbed_official | 573:ad23fe03a082 | 1558 | hsai->Instance->DR = *((uint32_t *)hsai->pBuffPtr); |
mbed_official | 573:ad23fe03a082 | 1559 | hsai->pBuffPtr+= 2; |
mbed_official | 573:ad23fe03a082 | 1560 | } |
mbed_official | 573:ad23fe03a082 | 1561 | else |
mbed_official | 573:ad23fe03a082 | 1562 | { |
mbed_official | 573:ad23fe03a082 | 1563 | hsai->Instance->DR = *((uint32_t *)hsai->pBuffPtr); |
mbed_official | 573:ad23fe03a082 | 1564 | hsai->pBuffPtr+= 4; |
mbed_official | 573:ad23fe03a082 | 1565 | } |
mbed_official | 573:ad23fe03a082 | 1566 | hsai->XferCount--; |
mbed_official | 573:ad23fe03a082 | 1567 | } |
mbed_official | 573:ad23fe03a082 | 1568 | } |
mbed_official | 573:ad23fe03a082 | 1569 | |
mbed_official | 573:ad23fe03a082 | 1570 | /** |
mbed_official | 573:ad23fe03a082 | 1571 | * @brief return the interrupt flag to set according the SAI setup |
mbed_official | 573:ad23fe03a082 | 1572 | * @param hsai : pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1573 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1574 | * @param mode : SAI_MODE_DMA or SAI_MODE_IT |
mbed_official | 573:ad23fe03a082 | 1575 | * @retval the list of the IT flag to enable |
mbed_official | 573:ad23fe03a082 | 1576 | */ |
mbed_official | 573:ad23fe03a082 | 1577 | static uint32_t SAI_InterruptFlag(SAI_HandleTypeDef *hsai, uint32_t mode) |
mbed_official | 573:ad23fe03a082 | 1578 | { |
mbed_official | 573:ad23fe03a082 | 1579 | uint32_t tmpIT = SAI_IT_OVRUDR; |
mbed_official | 573:ad23fe03a082 | 1580 | |
mbed_official | 573:ad23fe03a082 | 1581 | if(mode == SAI_MODE_IT) |
mbed_official | 573:ad23fe03a082 | 1582 | { |
mbed_official | 573:ad23fe03a082 | 1583 | tmpIT|= SAI_IT_FREQ; |
mbed_official | 573:ad23fe03a082 | 1584 | } |
mbed_official | 573:ad23fe03a082 | 1585 | |
mbed_official | 573:ad23fe03a082 | 1586 | if((hsai->Init.AudioMode == SAI_MODESLAVE_RX) || (hsai->Init.AudioMode == SAI_MODESLAVE_TX)) |
mbed_official | 573:ad23fe03a082 | 1587 | { |
mbed_official | 573:ad23fe03a082 | 1588 | tmpIT|= SAI_IT_AFSDET | SAI_IT_LFSDET; |
mbed_official | 573:ad23fe03a082 | 1589 | } |
mbed_official | 573:ad23fe03a082 | 1590 | else |
mbed_official | 573:ad23fe03a082 | 1591 | { |
mbed_official | 573:ad23fe03a082 | 1592 | /* hsai has been configured in master mode */ |
mbed_official | 573:ad23fe03a082 | 1593 | tmpIT|= SAI_IT_WCKCFG; |
mbed_official | 573:ad23fe03a082 | 1594 | } |
mbed_official | 573:ad23fe03a082 | 1595 | return tmpIT; |
mbed_official | 573:ad23fe03a082 | 1596 | } |
mbed_official | 573:ad23fe03a082 | 1597 | |
mbed_official | 573:ad23fe03a082 | 1598 | /** |
mbed_official | 573:ad23fe03a082 | 1599 | * @brief disable the SAI and wait the disabling |
mbed_official | 573:ad23fe03a082 | 1600 | * @param hsai : pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1601 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1602 | * @retval None. |
mbed_official | 573:ad23fe03a082 | 1603 | */ |
mbed_official | 573:ad23fe03a082 | 1604 | static HAL_StatusTypeDef SAI_Disable(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 1605 | { |
mbed_official | 573:ad23fe03a082 | 1606 | uint32_t tickstart = HAL_GetTick(); |
mbed_official | 573:ad23fe03a082 | 1607 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 573:ad23fe03a082 | 1608 | |
mbed_official | 573:ad23fe03a082 | 1609 | __HAL_SAI_DISABLE(hsai); |
mbed_official | 573:ad23fe03a082 | 1610 | while((hsai->Instance->CR1 & SAI_xCR1_SAIEN) != RESET) |
mbed_official | 573:ad23fe03a082 | 1611 | { |
mbed_official | 573:ad23fe03a082 | 1612 | /* Check for the Timeout */ |
mbed_official | 573:ad23fe03a082 | 1613 | if((HAL_GetTick() - tickstart ) > SAI_TIMEOUT_VALUE) |
mbed_official | 573:ad23fe03a082 | 1614 | { |
mbed_official | 573:ad23fe03a082 | 1615 | /* Update error code */ |
mbed_official | 573:ad23fe03a082 | 1616 | hsai->ErrorCode |= HAL_SAI_ERROR_TIMEOUT; |
mbed_official | 573:ad23fe03a082 | 1617 | |
mbed_official | 573:ad23fe03a082 | 1618 | status = HAL_TIMEOUT; |
mbed_official | 573:ad23fe03a082 | 1619 | |
mbed_official | 573:ad23fe03a082 | 1620 | /* Change the SAI state */ |
mbed_official | 573:ad23fe03a082 | 1621 | HAL_SAI_ErrorCallback(hsai); |
mbed_official | 573:ad23fe03a082 | 1622 | } |
mbed_official | 573:ad23fe03a082 | 1623 | } |
mbed_official | 573:ad23fe03a082 | 1624 | return status; |
mbed_official | 573:ad23fe03a082 | 1625 | } |
mbed_official | 573:ad23fe03a082 | 1626 | |
mbed_official | 573:ad23fe03a082 | 1627 | /** |
mbed_official | 573:ad23fe03a082 | 1628 | * @brief Tx Handler for Transmit in Interrupt mode 8Bit transfer |
mbed_official | 573:ad23fe03a082 | 1629 | * @param hsai : pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1630 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1631 | * @retval None. |
mbed_official | 573:ad23fe03a082 | 1632 | */ |
mbed_official | 573:ad23fe03a082 | 1633 | static void SAI_Transmit_IT8Bit(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 1634 | { |
mbed_official | 573:ad23fe03a082 | 1635 | /* Write data on DR register */ |
mbed_official | 573:ad23fe03a082 | 1636 | hsai->Instance->DR = (*hsai->pBuffPtr++); |
mbed_official | 573:ad23fe03a082 | 1637 | hsai->XferCount--; |
mbed_official | 573:ad23fe03a082 | 1638 | |
mbed_official | 573:ad23fe03a082 | 1639 | /* Handle the end of the transmission */ |
mbed_official | 573:ad23fe03a082 | 1640 | if(hsai->XferCount == 0) |
mbed_official | 573:ad23fe03a082 | 1641 | { |
mbed_official | 573:ad23fe03a082 | 1642 | /* Disable FREQ and OVRUDR interrupts */ |
mbed_official | 573:ad23fe03a082 | 1643 | __HAL_SAI_DISABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_IT)); |
mbed_official | 573:ad23fe03a082 | 1644 | hsai->State = HAL_SAI_STATE_READY; |
mbed_official | 573:ad23fe03a082 | 1645 | HAL_SAI_TxCpltCallback(hsai); |
mbed_official | 573:ad23fe03a082 | 1646 | } |
mbed_official | 573:ad23fe03a082 | 1647 | } |
mbed_official | 573:ad23fe03a082 | 1648 | |
mbed_official | 573:ad23fe03a082 | 1649 | /** |
mbed_official | 573:ad23fe03a082 | 1650 | * @brief Tx Handler for Transmit in Interrupt mode for 16Bit transfer |
mbed_official | 573:ad23fe03a082 | 1651 | * @param hsai : pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1652 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1653 | * @retval None. |
mbed_official | 573:ad23fe03a082 | 1654 | */ |
mbed_official | 573:ad23fe03a082 | 1655 | static void SAI_Transmit_IT16Bit(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 1656 | { |
mbed_official | 573:ad23fe03a082 | 1657 | /* Write data on DR register */ |
mbed_official | 573:ad23fe03a082 | 1658 | hsai->Instance->DR = *(uint16_t *)hsai->pBuffPtr; |
mbed_official | 573:ad23fe03a082 | 1659 | hsai->pBuffPtr+=2; |
mbed_official | 573:ad23fe03a082 | 1660 | hsai->XferCount--; |
mbed_official | 573:ad23fe03a082 | 1661 | |
mbed_official | 573:ad23fe03a082 | 1662 | /* Handle the end of the transmission */ |
mbed_official | 573:ad23fe03a082 | 1663 | if(hsai->XferCount == 0) |
mbed_official | 573:ad23fe03a082 | 1664 | { |
mbed_official | 573:ad23fe03a082 | 1665 | /* Disable FREQ and OVRUDR interrupts */ |
mbed_official | 573:ad23fe03a082 | 1666 | __HAL_SAI_DISABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_IT)); |
mbed_official | 573:ad23fe03a082 | 1667 | hsai->State = HAL_SAI_STATE_READY; |
mbed_official | 573:ad23fe03a082 | 1668 | HAL_SAI_TxCpltCallback(hsai); |
mbed_official | 573:ad23fe03a082 | 1669 | } |
mbed_official | 573:ad23fe03a082 | 1670 | } |
mbed_official | 573:ad23fe03a082 | 1671 | |
mbed_official | 573:ad23fe03a082 | 1672 | /** |
mbed_official | 573:ad23fe03a082 | 1673 | * @brief Tx Handler for Transmit in Interrupt mode for 32Bit transfer |
mbed_official | 573:ad23fe03a082 | 1674 | * @param hsai : pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1675 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1676 | * @retval None. |
mbed_official | 573:ad23fe03a082 | 1677 | */ |
mbed_official | 573:ad23fe03a082 | 1678 | static void SAI_Transmit_IT32Bit(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 1679 | { |
mbed_official | 573:ad23fe03a082 | 1680 | /* Write data on DR register */ |
mbed_official | 573:ad23fe03a082 | 1681 | hsai->Instance->DR = *(uint32_t *)hsai->pBuffPtr; |
mbed_official | 573:ad23fe03a082 | 1682 | hsai->pBuffPtr+=4; |
mbed_official | 573:ad23fe03a082 | 1683 | hsai->XferCount--; |
mbed_official | 573:ad23fe03a082 | 1684 | |
mbed_official | 573:ad23fe03a082 | 1685 | /* Handle the end of the transmission */ |
mbed_official | 573:ad23fe03a082 | 1686 | if(hsai->XferCount == 0) |
mbed_official | 573:ad23fe03a082 | 1687 | { |
mbed_official | 573:ad23fe03a082 | 1688 | /* Disable FREQ and OVRUDR interrupts */ |
mbed_official | 573:ad23fe03a082 | 1689 | __HAL_SAI_DISABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_IT)); |
mbed_official | 573:ad23fe03a082 | 1690 | hsai->State = HAL_SAI_STATE_READY; |
mbed_official | 573:ad23fe03a082 | 1691 | HAL_SAI_TxCpltCallback(hsai); |
mbed_official | 573:ad23fe03a082 | 1692 | } |
mbed_official | 573:ad23fe03a082 | 1693 | } |
mbed_official | 573:ad23fe03a082 | 1694 | |
mbed_official | 573:ad23fe03a082 | 1695 | /** |
mbed_official | 573:ad23fe03a082 | 1696 | * @brief Rx Handler for Receive in Interrupt mode 8Bit transfer |
mbed_official | 573:ad23fe03a082 | 1697 | * @param hsai : pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1698 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1699 | * @retval None. |
mbed_official | 573:ad23fe03a082 | 1700 | */ |
mbed_official | 573:ad23fe03a082 | 1701 | static void SAI_Receive_IT8Bit(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 1702 | { |
mbed_official | 573:ad23fe03a082 | 1703 | /* Receive data */ |
mbed_official | 573:ad23fe03a082 | 1704 | (*hsai->pBuffPtr++) = hsai->Instance->DR; |
mbed_official | 573:ad23fe03a082 | 1705 | hsai->XferCount--; |
mbed_official | 573:ad23fe03a082 | 1706 | |
mbed_official | 573:ad23fe03a082 | 1707 | /* Check end of the transfer */ |
mbed_official | 573:ad23fe03a082 | 1708 | if(hsai->XferCount == 0) |
mbed_official | 573:ad23fe03a082 | 1709 | { |
mbed_official | 573:ad23fe03a082 | 1710 | /* Disable TXE and OVRUDR interrupts */ |
mbed_official | 573:ad23fe03a082 | 1711 | __HAL_SAI_DISABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_IT)); |
mbed_official | 573:ad23fe03a082 | 1712 | |
mbed_official | 573:ad23fe03a082 | 1713 | /* Clear the SAI Overrun flag */ |
mbed_official | 573:ad23fe03a082 | 1714 | __HAL_SAI_CLEAR_FLAG(hsai, SAI_FLAG_OVRUDR); |
mbed_official | 573:ad23fe03a082 | 1715 | |
mbed_official | 573:ad23fe03a082 | 1716 | hsai->State = HAL_SAI_STATE_READY; |
mbed_official | 573:ad23fe03a082 | 1717 | HAL_SAI_RxCpltCallback(hsai); |
mbed_official | 573:ad23fe03a082 | 1718 | } |
mbed_official | 573:ad23fe03a082 | 1719 | } |
mbed_official | 573:ad23fe03a082 | 1720 | |
mbed_official | 573:ad23fe03a082 | 1721 | /** |
mbed_official | 573:ad23fe03a082 | 1722 | * @brief Rx Handler for Receive in Interrupt mode for 16Bit transfer |
mbed_official | 573:ad23fe03a082 | 1723 | * @param hsai : pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1724 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1725 | * @retval None. |
mbed_official | 573:ad23fe03a082 | 1726 | */ |
mbed_official | 573:ad23fe03a082 | 1727 | static void SAI_Receive_IT16Bit(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 1728 | { |
mbed_official | 573:ad23fe03a082 | 1729 | /* Receive data */ |
mbed_official | 573:ad23fe03a082 | 1730 | *(uint16_t*)hsai->pBuffPtr = hsai->Instance->DR; |
mbed_official | 573:ad23fe03a082 | 1731 | hsai->pBuffPtr+=2; |
mbed_official | 573:ad23fe03a082 | 1732 | hsai->XferCount--; |
mbed_official | 573:ad23fe03a082 | 1733 | |
mbed_official | 573:ad23fe03a082 | 1734 | /* Check end of the transfer */ |
mbed_official | 573:ad23fe03a082 | 1735 | if(hsai->XferCount == 0) |
mbed_official | 573:ad23fe03a082 | 1736 | { |
mbed_official | 573:ad23fe03a082 | 1737 | /* Disable TXE and OVRUDR interrupts */ |
mbed_official | 573:ad23fe03a082 | 1738 | __HAL_SAI_DISABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_IT)); |
mbed_official | 573:ad23fe03a082 | 1739 | |
mbed_official | 573:ad23fe03a082 | 1740 | /* Clear the SAI Overrun flag */ |
mbed_official | 573:ad23fe03a082 | 1741 | __HAL_SAI_CLEAR_FLAG(hsai, SAI_FLAG_OVRUDR); |
mbed_official | 573:ad23fe03a082 | 1742 | |
mbed_official | 573:ad23fe03a082 | 1743 | hsai->State = HAL_SAI_STATE_READY; |
mbed_official | 573:ad23fe03a082 | 1744 | HAL_SAI_RxCpltCallback(hsai); |
mbed_official | 573:ad23fe03a082 | 1745 | } |
mbed_official | 573:ad23fe03a082 | 1746 | } |
mbed_official | 573:ad23fe03a082 | 1747 | /** |
mbed_official | 573:ad23fe03a082 | 1748 | * @brief Rx Handler for Receive in Interrupt mode for 32Bit transfer |
mbed_official | 573:ad23fe03a082 | 1749 | * @param hsai : pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1750 | * the configuration information for SAI module. |
mbed_official | 573:ad23fe03a082 | 1751 | * @retval None. |
mbed_official | 573:ad23fe03a082 | 1752 | */ |
mbed_official | 573:ad23fe03a082 | 1753 | static void SAI_Receive_IT32Bit(SAI_HandleTypeDef *hsai) |
mbed_official | 573:ad23fe03a082 | 1754 | { |
mbed_official | 573:ad23fe03a082 | 1755 | /* Receive data */ |
mbed_official | 573:ad23fe03a082 | 1756 | *(uint32_t*)hsai->pBuffPtr = hsai->Instance->DR; |
mbed_official | 573:ad23fe03a082 | 1757 | hsai->pBuffPtr+=4; |
mbed_official | 573:ad23fe03a082 | 1758 | hsai->XferCount--; |
mbed_official | 573:ad23fe03a082 | 1759 | |
mbed_official | 573:ad23fe03a082 | 1760 | /* Check end of the transfer */ |
mbed_official | 573:ad23fe03a082 | 1761 | if(hsai->XferCount == 0) |
mbed_official | 573:ad23fe03a082 | 1762 | { |
mbed_official | 573:ad23fe03a082 | 1763 | /* Disable TXE and OVRUDR interrupts */ |
mbed_official | 573:ad23fe03a082 | 1764 | __HAL_SAI_DISABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_IT)); |
mbed_official | 573:ad23fe03a082 | 1765 | |
mbed_official | 573:ad23fe03a082 | 1766 | /* Clear the SAI Overrun flag */ |
mbed_official | 573:ad23fe03a082 | 1767 | __HAL_SAI_CLEAR_FLAG(hsai, SAI_FLAG_OVRUDR); |
mbed_official | 573:ad23fe03a082 | 1768 | |
mbed_official | 573:ad23fe03a082 | 1769 | hsai->State = HAL_SAI_STATE_READY; |
mbed_official | 573:ad23fe03a082 | 1770 | HAL_SAI_RxCpltCallback(hsai); |
mbed_official | 573:ad23fe03a082 | 1771 | } |
mbed_official | 573:ad23fe03a082 | 1772 | } |
mbed_official | 573:ad23fe03a082 | 1773 | |
mbed_official | 573:ad23fe03a082 | 1774 | /** |
mbed_official | 573:ad23fe03a082 | 1775 | * @brief DMA SAI transmit process complete callback. |
mbed_official | 573:ad23fe03a082 | 1776 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1777 | * the configuration information for the specified DMA module. |
mbed_official | 573:ad23fe03a082 | 1778 | * @retval None |
mbed_official | 573:ad23fe03a082 | 1779 | */ |
mbed_official | 573:ad23fe03a082 | 1780 | static void SAI_DMATxCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 573:ad23fe03a082 | 1781 | { |
mbed_official | 573:ad23fe03a082 | 1782 | uint32_t tickstart = 0; |
mbed_official | 573:ad23fe03a082 | 1783 | |
mbed_official | 573:ad23fe03a082 | 1784 | SAI_HandleTypeDef* hsai = (SAI_HandleTypeDef*)((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 573:ad23fe03a082 | 1785 | |
mbed_official | 573:ad23fe03a082 | 1786 | if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0) |
mbed_official | 573:ad23fe03a082 | 1787 | { |
mbed_official | 573:ad23fe03a082 | 1788 | hsai->XferCount = 0; |
mbed_official | 573:ad23fe03a082 | 1789 | |
mbed_official | 573:ad23fe03a082 | 1790 | /* Disable SAI Tx DMA Request */ |
mbed_official | 573:ad23fe03a082 | 1791 | hsai->Instance->CR1 &= (uint32_t)(~SAI_xCR1_DMAEN); |
mbed_official | 573:ad23fe03a082 | 1792 | |
mbed_official | 573:ad23fe03a082 | 1793 | /* Get tick */ |
mbed_official | 573:ad23fe03a082 | 1794 | tickstart = HAL_GetTick(); |
mbed_official | 573:ad23fe03a082 | 1795 | |
mbed_official | 573:ad23fe03a082 | 1796 | /* Set timeout: 10 is the max delay to send the remaining data in the SAI FIFO */ |
mbed_official | 573:ad23fe03a082 | 1797 | /* Wait until FIFO is empty */ |
mbed_official | 573:ad23fe03a082 | 1798 | while(__HAL_SAI_GET_FLAG(hsai, SAI_xSR_FLVL) != RESET) |
mbed_official | 573:ad23fe03a082 | 1799 | { |
mbed_official | 573:ad23fe03a082 | 1800 | /* Check for the Timeout */ |
mbed_official | 573:ad23fe03a082 | 1801 | if((HAL_GetTick() - tickstart ) > SAI_TIMEOUT_VALUE) |
mbed_official | 573:ad23fe03a082 | 1802 | { |
mbed_official | 573:ad23fe03a082 | 1803 | /* Update error code */ |
mbed_official | 573:ad23fe03a082 | 1804 | hsai->ErrorCode |= HAL_SAI_ERROR_TIMEOUT; |
mbed_official | 573:ad23fe03a082 | 1805 | |
mbed_official | 573:ad23fe03a082 | 1806 | /* Change the SAI state */ |
mbed_official | 573:ad23fe03a082 | 1807 | HAL_SAI_ErrorCallback(hsai); |
mbed_official | 573:ad23fe03a082 | 1808 | } |
mbed_official | 573:ad23fe03a082 | 1809 | } |
mbed_official | 573:ad23fe03a082 | 1810 | |
mbed_official | 573:ad23fe03a082 | 1811 | /* Stop the interrupts error handling */ |
mbed_official | 573:ad23fe03a082 | 1812 | __HAL_SAI_DISABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_DMA)); |
mbed_official | 573:ad23fe03a082 | 1813 | |
mbed_official | 573:ad23fe03a082 | 1814 | hsai->State= HAL_SAI_STATE_READY; |
mbed_official | 573:ad23fe03a082 | 1815 | } |
mbed_official | 573:ad23fe03a082 | 1816 | HAL_SAI_TxCpltCallback(hsai); |
mbed_official | 573:ad23fe03a082 | 1817 | } |
mbed_official | 573:ad23fe03a082 | 1818 | |
mbed_official | 573:ad23fe03a082 | 1819 | /** |
mbed_official | 573:ad23fe03a082 | 1820 | * @brief DMA SAI transmit process half complete callback |
mbed_official | 573:ad23fe03a082 | 1821 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1822 | * the configuration information for the specified DMA module. |
mbed_official | 573:ad23fe03a082 | 1823 | * @retval None |
mbed_official | 573:ad23fe03a082 | 1824 | */ |
mbed_official | 573:ad23fe03a082 | 1825 | static void SAI_DMATxHalfCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 573:ad23fe03a082 | 1826 | { |
mbed_official | 573:ad23fe03a082 | 1827 | SAI_HandleTypeDef* hsai = (SAI_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; |
mbed_official | 573:ad23fe03a082 | 1828 | |
mbed_official | 573:ad23fe03a082 | 1829 | HAL_SAI_TxHalfCpltCallback(hsai); |
mbed_official | 573:ad23fe03a082 | 1830 | } |
mbed_official | 573:ad23fe03a082 | 1831 | |
mbed_official | 573:ad23fe03a082 | 1832 | /** |
mbed_official | 573:ad23fe03a082 | 1833 | * @brief DMA SAI receive process complete callback. |
mbed_official | 573:ad23fe03a082 | 1834 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1835 | * the configuration information for the specified DMA module. |
mbed_official | 573:ad23fe03a082 | 1836 | * @retval None |
mbed_official | 573:ad23fe03a082 | 1837 | */ |
mbed_official | 573:ad23fe03a082 | 1838 | static void SAI_DMARxCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 573:ad23fe03a082 | 1839 | { |
mbed_official | 573:ad23fe03a082 | 1840 | SAI_HandleTypeDef* hsai = ( SAI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 573:ad23fe03a082 | 1841 | if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0) |
mbed_official | 573:ad23fe03a082 | 1842 | { |
mbed_official | 573:ad23fe03a082 | 1843 | /* Disable Rx DMA Request */ |
mbed_official | 573:ad23fe03a082 | 1844 | hsai->Instance->CR1 &= (uint32_t)(~SAI_xCR1_DMAEN); |
mbed_official | 573:ad23fe03a082 | 1845 | hsai->XferCount = 0; |
mbed_official | 573:ad23fe03a082 | 1846 | |
mbed_official | 573:ad23fe03a082 | 1847 | /* Stop the interrupts error handling */ |
mbed_official | 573:ad23fe03a082 | 1848 | __HAL_SAI_DISABLE_IT(hsai, SAI_InterruptFlag(hsai, SAI_MODE_DMA)); |
mbed_official | 573:ad23fe03a082 | 1849 | |
mbed_official | 573:ad23fe03a082 | 1850 | hsai->State = HAL_SAI_STATE_READY; |
mbed_official | 573:ad23fe03a082 | 1851 | } |
mbed_official | 573:ad23fe03a082 | 1852 | HAL_SAI_RxCpltCallback(hsai); |
mbed_official | 573:ad23fe03a082 | 1853 | } |
mbed_official | 573:ad23fe03a082 | 1854 | |
mbed_official | 573:ad23fe03a082 | 1855 | /** |
mbed_official | 573:ad23fe03a082 | 1856 | * @brief DMA SAI receive process half complete callback |
mbed_official | 573:ad23fe03a082 | 1857 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1858 | * the configuration information for the specified DMA module. |
mbed_official | 573:ad23fe03a082 | 1859 | * @retval None |
mbed_official | 573:ad23fe03a082 | 1860 | */ |
mbed_official | 573:ad23fe03a082 | 1861 | static void SAI_DMARxHalfCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 573:ad23fe03a082 | 1862 | { |
mbed_official | 573:ad23fe03a082 | 1863 | SAI_HandleTypeDef* hsai = (SAI_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; |
mbed_official | 573:ad23fe03a082 | 1864 | |
mbed_official | 573:ad23fe03a082 | 1865 | HAL_SAI_RxHalfCpltCallback(hsai); |
mbed_official | 573:ad23fe03a082 | 1866 | } |
mbed_official | 573:ad23fe03a082 | 1867 | /** |
mbed_official | 573:ad23fe03a082 | 1868 | * @brief DMA SAI communication error callback. |
mbed_official | 573:ad23fe03a082 | 1869 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
mbed_official | 573:ad23fe03a082 | 1870 | * the configuration information for the specified DMA module. |
mbed_official | 573:ad23fe03a082 | 1871 | * @retval None |
mbed_official | 573:ad23fe03a082 | 1872 | */ |
mbed_official | 573:ad23fe03a082 | 1873 | static void SAI_DMAError(DMA_HandleTypeDef *hdma) |
mbed_official | 573:ad23fe03a082 | 1874 | { |
mbed_official | 573:ad23fe03a082 | 1875 | SAI_HandleTypeDef* hsai = ( SAI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 573:ad23fe03a082 | 1876 | |
mbed_official | 573:ad23fe03a082 | 1877 | /* Stop the DMA transfer */ |
mbed_official | 573:ad23fe03a082 | 1878 | HAL_SAI_DMAStop(hsai); |
mbed_official | 573:ad23fe03a082 | 1879 | |
mbed_official | 573:ad23fe03a082 | 1880 | /* Set the SAI state ready to be able to start again the process */ |
mbed_official | 573:ad23fe03a082 | 1881 | hsai->State= HAL_SAI_STATE_READY; |
mbed_official | 573:ad23fe03a082 | 1882 | HAL_SAI_ErrorCallback(hsai); |
mbed_official | 573:ad23fe03a082 | 1883 | |
mbed_official | 573:ad23fe03a082 | 1884 | hsai->XferCount = 0; |
mbed_official | 573:ad23fe03a082 | 1885 | } |
mbed_official | 573:ad23fe03a082 | 1886 | |
mbed_official | 573:ad23fe03a082 | 1887 | /** |
mbed_official | 573:ad23fe03a082 | 1888 | * @} |
mbed_official | 573:ad23fe03a082 | 1889 | */ |
mbed_official | 573:ad23fe03a082 | 1890 | |
mbed_official | 573:ad23fe03a082 | 1891 | #endif /* HAL_SAI_MODULE_ENABLED */ |
mbed_official | 573:ad23fe03a082 | 1892 | /** |
mbed_official | 573:ad23fe03a082 | 1893 | * @} |
mbed_official | 573:ad23fe03a082 | 1894 | */ |
mbed_official | 573:ad23fe03a082 | 1895 | |
mbed_official | 573:ad23fe03a082 | 1896 | /** |
mbed_official | 573:ad23fe03a082 | 1897 | * @} |
mbed_official | 573:ad23fe03a082 | 1898 | */ |
mbed_official | 573:ad23fe03a082 | 1899 | |
mbed_official | 573:ad23fe03a082 | 1900 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |