001

Committer:
ganlikun
Date:
Sun Jun 12 14:02:44 2022 +0000
Revision:
0:13413ea9a877
00

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ganlikun 0:13413ea9a877 1 /**
ganlikun 0:13413ea9a877 2 ******************************************************************************
ganlikun 0:13413ea9a877 3 * @file stm32f4xx_hal_spdifrx.c
ganlikun 0:13413ea9a877 4 * @author MCD Application Team
ganlikun 0:13413ea9a877 5 * @version V1.7.1
ganlikun 0:13413ea9a877 6 * @date 14-April-2017
ganlikun 0:13413ea9a877 7 * @brief This file provides firmware functions to manage the following
ganlikun 0:13413ea9a877 8 * functionalities of the SPDIFRX audio interface:
ganlikun 0:13413ea9a877 9 * + Initialization and Configuration
ganlikun 0:13413ea9a877 10 * + Data transfers functions
ganlikun 0:13413ea9a877 11 * + DMA transfers management
ganlikun 0:13413ea9a877 12 * + Interrupts and flags management
ganlikun 0:13413ea9a877 13 @verbatim
ganlikun 0:13413ea9a877 14 ===============================================================================
ganlikun 0:13413ea9a877 15 ##### How to use this driver #####
ganlikun 0:13413ea9a877 16 ===============================================================================
ganlikun 0:13413ea9a877 17 [..]
ganlikun 0:13413ea9a877 18 The SPDIFRX HAL driver can be used as follow:
ganlikun 0:13413ea9a877 19
ganlikun 0:13413ea9a877 20 (#) Declare SPDIFRX_HandleTypeDef handle structure.
ganlikun 0:13413ea9a877 21 (#) Initialize the SPDIFRX low level resources by implement the HAL_SPDIFRX_MspInit() API:
ganlikun 0:13413ea9a877 22 (##) Enable the SPDIFRX interface clock.
ganlikun 0:13413ea9a877 23 (##) SPDIFRX pins configuration:
ganlikun 0:13413ea9a877 24 (+++) Enable the clock for the SPDIFRX GPIOs.
ganlikun 0:13413ea9a877 25 (+++) Configure these SPDIFRX pins as alternate function pull-up.
ganlikun 0:13413ea9a877 26 (##) NVIC configuration if you need to use interrupt process (HAL_SPDIFRX_ReceiveControlFlow_IT() and HAL_SPDIFRX_ReceiveDataFlow_IT() API's).
ganlikun 0:13413ea9a877 27 (+++) Configure the SPDIFRX interrupt priority.
ganlikun 0:13413ea9a877 28 (+++) Enable the NVIC SPDIFRX IRQ handle.
ganlikun 0:13413ea9a877 29 (##) DMA Configuration if you need to use DMA process (HAL_SPDIFRX_ReceiveDataFlow_DMA() and HAL_SPDIFRX_ReceiveControlFlow_DMA() API's).
ganlikun 0:13413ea9a877 30 (+++) Declare a DMA handle structure for the reception of the Data Flow channel.
ganlikun 0:13413ea9a877 31 (+++) Declare a DMA handle structure for the reception of the Control Flow channel.
ganlikun 0:13413ea9a877 32 (+++) Enable the DMAx interface clock.
ganlikun 0:13413ea9a877 33 (+++) Configure the declared DMA handle structure CtrlRx/DataRx with the required parameters.
ganlikun 0:13413ea9a877 34 (+++) Configure the DMA Channel.
ganlikun 0:13413ea9a877 35 (+++) Associate the initialized DMA handle to the SPDIFRX DMA CtrlRx/DataRx handle.
ganlikun 0:13413ea9a877 36 (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the
ganlikun 0:13413ea9a877 37 DMA CtrlRx/DataRx channel.
ganlikun 0:13413ea9a877 38
ganlikun 0:13413ea9a877 39 (#) Program the input selection, re-tries number, wait for activity, channel status selection, data format, stereo mode and masking of user bits
ganlikun 0:13413ea9a877 40 using HAL_SPDIFRX_Init() function.
ganlikun 0:13413ea9a877 41
ganlikun 0:13413ea9a877 42 -@- The specific SPDIFRX interrupts (RXNE/CSRNE and Error Interrupts) will be managed using the macros
ganlikun 0:13413ea9a877 43 __SPDIFRX_ENABLE_IT() and __SPDIFRX_DISABLE_IT() inside the receive process.
ganlikun 0:13413ea9a877 44 -@- Make sure that ck_spdif clock is configured.
ganlikun 0:13413ea9a877 45
ganlikun 0:13413ea9a877 46 (#) Three operation modes are available within this driver :
ganlikun 0:13413ea9a877 47
ganlikun 0:13413ea9a877 48 *** Polling mode for reception operation (for debug purpose) ***
ganlikun 0:13413ea9a877 49 ================================================================
ganlikun 0:13413ea9a877 50 [..]
ganlikun 0:13413ea9a877 51 (+) Receive data flow in blocking mode using HAL_SPDIFRX_ReceiveDataFlow()
ganlikun 0:13413ea9a877 52 (+) Receive control flow of data in blocking mode using HAL_SPDIFRX_ReceiveControlFlow()
ganlikun 0:13413ea9a877 53
ganlikun 0:13413ea9a877 54 *** Interrupt mode for reception operation ***
ganlikun 0:13413ea9a877 55 =========================================
ganlikun 0:13413ea9a877 56 [..]
ganlikun 0:13413ea9a877 57 (+) Receive an amount of data (Data Flow) in non blocking mode using HAL_SPDIFRX_ReceiveDataFlow_IT()
ganlikun 0:13413ea9a877 58 (+) Receive an amount of data (Control Flow) in non blocking mode using HAL_SPDIFRX_ReceiveControlFlow_IT()
ganlikun 0:13413ea9a877 59 (+) At reception end of half transfer HAL_SPDIFRX_RxHalfCpltCallback is executed and user can
ganlikun 0:13413ea9a877 60 add his own code by customization of function pointer HAL_SPDIFRX_RxHalfCpltCallback
ganlikun 0:13413ea9a877 61 (+) At reception end of transfer HAL_SPDIFRX_RxCpltCallback is executed and user can
ganlikun 0:13413ea9a877 62 add his own code by customization of function pointer HAL_SPDIFRX_RxCpltCallback
ganlikun 0:13413ea9a877 63 (+) In case of transfer Error, HAL_SPDIFRX_ErrorCallback() function is executed and user can
ganlikun 0:13413ea9a877 64 add his own code by customization of function pointer HAL_SPDIFRX_ErrorCallback
ganlikun 0:13413ea9a877 65
ganlikun 0:13413ea9a877 66 *** DMA mode for reception operation ***
ganlikun 0:13413ea9a877 67 ========================================
ganlikun 0:13413ea9a877 68 [..]
ganlikun 0:13413ea9a877 69 (+) Receive an amount of data (Data Flow) in non blocking mode (DMA) using HAL_SPDIFRX_ReceiveDataFlow_DMA()
ganlikun 0:13413ea9a877 70 (+) Receive an amount of data (Control Flow) in non blocking mode (DMA) using HAL_SPDIFRX_ReceiveControlFlow_DMA()
ganlikun 0:13413ea9a877 71 (+) At reception end of half transfer HAL_SPDIFRX_RxHalfCpltCallback is executed and user can
ganlikun 0:13413ea9a877 72 add his own code by customization of function pointer HAL_SPDIFRX_RxHalfCpltCallback
ganlikun 0:13413ea9a877 73 (+) At reception end of transfer HAL_SPDIFRX_RxCpltCallback is executed and user can
ganlikun 0:13413ea9a877 74 add his own code by customization of function pointer HAL_SPDIFRX_RxCpltCallback
ganlikun 0:13413ea9a877 75 (+) In case of transfer Error, HAL_SPDIFRX_ErrorCallback() function is executed and user can
ganlikun 0:13413ea9a877 76 add his own code by customization of function pointer HAL_SPDIFRX_ErrorCallback
ganlikun 0:13413ea9a877 77 (+) Stop the DMA Transfer using HAL_SPDIFRX_DMAStop()
ganlikun 0:13413ea9a877 78
ganlikun 0:13413ea9a877 79 *** SPDIFRX HAL driver macros list ***
ganlikun 0:13413ea9a877 80 =============================================
ganlikun 0:13413ea9a877 81 [..]
ganlikun 0:13413ea9a877 82 Below the list of most used macros in SPDIFRX HAL driver.
ganlikun 0:13413ea9a877 83 (+) __HAL_SPDIFRX_IDLE: Disable the specified SPDIFRX peripheral (IDEL State)
ganlikun 0:13413ea9a877 84 (+) __HAL_SPDIFRX_SYNC: Enable the synchronization state of the specified SPDIFRX peripheral (SYNC State)
ganlikun 0:13413ea9a877 85 (+) __HAL_SPDIFRX_RCV: Enable the receive state of the specified SPDIFRX peripheral (RCV State)
ganlikun 0:13413ea9a877 86 (+) __HAL_SPDIFRX_ENABLE_IT : Enable the specified SPDIFRX interrupts
ganlikun 0:13413ea9a877 87 (+) __HAL_SPDIFRX_DISABLE_IT : Disable the specified SPDIFRX interrupts
ganlikun 0:13413ea9a877 88 (+) __HAL_SPDIFRX_GET_FLAG: Check whether the specified SPDIFRX flag is set or not.
ganlikun 0:13413ea9a877 89
ganlikun 0:13413ea9a877 90 [..]
ganlikun 0:13413ea9a877 91 (@) You can refer to the SPDIFRX HAL driver header file for more useful macros
ganlikun 0:13413ea9a877 92
ganlikun 0:13413ea9a877 93 @endverbatim
ganlikun 0:13413ea9a877 94 ******************************************************************************
ganlikun 0:13413ea9a877 95 * @attention
ganlikun 0:13413ea9a877 96 *
ganlikun 0:13413ea9a877 97 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
ganlikun 0:13413ea9a877 98 *
ganlikun 0:13413ea9a877 99 * Redistribution and use in source and binary forms, with or without modification,
ganlikun 0:13413ea9a877 100 * are permitted provided that the following conditions are met:
ganlikun 0:13413ea9a877 101 * 1. Redistributions of source code must retain the above copyright notice,
ganlikun 0:13413ea9a877 102 * this list of conditions and the following disclaimer.
ganlikun 0:13413ea9a877 103 * 2. Redistributions in binary form must reproduce the above copyright notice,
ganlikun 0:13413ea9a877 104 * this list of conditions and the following disclaimer in the documentation
ganlikun 0:13413ea9a877 105 * and/or other materials provided with the distribution.
ganlikun 0:13413ea9a877 106 * 3. Neither the name of STMicroelectronics nor the names of its contributors
ganlikun 0:13413ea9a877 107 * may be used to endorse or promote products derived from this software
ganlikun 0:13413ea9a877 108 * without specific prior written permission.
ganlikun 0:13413ea9a877 109 *
ganlikun 0:13413ea9a877 110 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
ganlikun 0:13413ea9a877 111 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ganlikun 0:13413ea9a877 112 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
ganlikun 0:13413ea9a877 113 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
ganlikun 0:13413ea9a877 114 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ganlikun 0:13413ea9a877 115 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
ganlikun 0:13413ea9a877 116 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
ganlikun 0:13413ea9a877 117 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
ganlikun 0:13413ea9a877 118 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
ganlikun 0:13413ea9a877 119 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ganlikun 0:13413ea9a877 120 *
ganlikun 0:13413ea9a877 121 ******************************************************************************
ganlikun 0:13413ea9a877 122 */
ganlikun 0:13413ea9a877 123
ganlikun 0:13413ea9a877 124 /* Includes ------------------------------------------------------------------*/
ganlikun 0:13413ea9a877 125 #include "stm32f4xx_hal.h"
ganlikun 0:13413ea9a877 126
ganlikun 0:13413ea9a877 127 /** @addtogroup STM32F4xx_HAL_Driver
ganlikun 0:13413ea9a877 128 * @{
ganlikun 0:13413ea9a877 129 */
ganlikun 0:13413ea9a877 130 /** @defgroup SPDIFRX SPDIFRX
ganlikun 0:13413ea9a877 131 * @brief SPDIFRX HAL module driver
ganlikun 0:13413ea9a877 132 * @{
ganlikun 0:13413ea9a877 133 */
ganlikun 0:13413ea9a877 134
ganlikun 0:13413ea9a877 135 #ifdef HAL_SPDIFRX_MODULE_ENABLED
ganlikun 0:13413ea9a877 136
ganlikun 0:13413ea9a877 137 #if defined(STM32F446xx)
ganlikun 0:13413ea9a877 138
ganlikun 0:13413ea9a877 139 /* Private typedef -----------------------------------------------------------*/
ganlikun 0:13413ea9a877 140 /* Private define ------------------------------------------------------------*/
ganlikun 0:13413ea9a877 141 #define SPDIFRX_TIMEOUT_VALUE 0xFFFF
ganlikun 0:13413ea9a877 142
ganlikun 0:13413ea9a877 143 /* Private macro -------------------------------------------------------------*/
ganlikun 0:13413ea9a877 144 /* Private variables ---------------------------------------------------------*/
ganlikun 0:13413ea9a877 145 /* Private function prototypes -----------------------------------------------*/
ganlikun 0:13413ea9a877 146
ganlikun 0:13413ea9a877 147 /** @addtogroup SPDIFRX_Private_Functions
ganlikun 0:13413ea9a877 148 * @{
ganlikun 0:13413ea9a877 149 */
ganlikun 0:13413ea9a877 150 static void SPDIFRX_DMARxCplt(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 151 static void SPDIFRX_DMARxHalfCplt(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 152 static void SPDIFRX_DMACxCplt(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 153 static void SPDIFRX_DMACxHalfCplt(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 154 static void SPDIFRX_DMAError(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 155 static void SPDIFRX_ReceiveControlFlow_IT(SPDIFRX_HandleTypeDef *hspdif);
ganlikun 0:13413ea9a877 156 static void SPDIFRX_ReceiveDataFlow_IT(SPDIFRX_HandleTypeDef *hspdif);
ganlikun 0:13413ea9a877 157 static HAL_StatusTypeDef SPDIFRX_WaitOnFlagUntilTimeout(SPDIFRX_HandleTypeDef *hspdif, uint32_t Flag, FlagStatus Status, uint32_t Timeout);
ganlikun 0:13413ea9a877 158
ganlikun 0:13413ea9a877 159 /**
ganlikun 0:13413ea9a877 160 * @}
ganlikun 0:13413ea9a877 161 */
ganlikun 0:13413ea9a877 162 /* Exported functions ---------------------------------------------------------*/
ganlikun 0:13413ea9a877 163
ganlikun 0:13413ea9a877 164 /** @defgroup SPDIFRX_Exported_Functions SPDIFRX Exported Functions
ganlikun 0:13413ea9a877 165 * @{
ganlikun 0:13413ea9a877 166 */
ganlikun 0:13413ea9a877 167
ganlikun 0:13413ea9a877 168 /** @defgroup SPDIFRX_Exported_Functions_Group1 Initialization and de-initialization functions
ganlikun 0:13413ea9a877 169 * @brief Initialization and Configuration functions
ganlikun 0:13413ea9a877 170 *
ganlikun 0:13413ea9a877 171 @verbatim
ganlikun 0:13413ea9a877 172 ===============================================================================
ganlikun 0:13413ea9a877 173 ##### Initialization and de-initialization functions #####
ganlikun 0:13413ea9a877 174 ===============================================================================
ganlikun 0:13413ea9a877 175 [..] This subsection provides a set of functions allowing to initialize and
ganlikun 0:13413ea9a877 176 de-initialize the SPDIFRX peripheral:
ganlikun 0:13413ea9a877 177
ganlikun 0:13413ea9a877 178 (+) User must Implement HAL_SPDIFRX_MspInit() function in which he configures
ganlikun 0:13413ea9a877 179 all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ).
ganlikun 0:13413ea9a877 180
ganlikun 0:13413ea9a877 181 (+) Call the function HAL_SPDIFRX_Init() to configure the SPDIFRX peripheral with
ganlikun 0:13413ea9a877 182 the selected configuration:
ganlikun 0:13413ea9a877 183 (++) Input Selection (IN0, IN1,...)
ganlikun 0:13413ea9a877 184 (++) Maximum allowed re-tries during synchronization phase
ganlikun 0:13413ea9a877 185 (++) Wait for activity on SPDIF selected input
ganlikun 0:13413ea9a877 186 (++) Channel status selection (from channel A or B)
ganlikun 0:13413ea9a877 187 (++) Data format (LSB, MSB, ...)
ganlikun 0:13413ea9a877 188 (++) Stereo mode
ganlikun 0:13413ea9a877 189 (++) User bits masking (PT,C,U,V,...)
ganlikun 0:13413ea9a877 190
ganlikun 0:13413ea9a877 191 (+) Call the function HAL_SPDIFRX_DeInit() to restore the default configuration
ganlikun 0:13413ea9a877 192 of the selected SPDIFRXx peripheral.
ganlikun 0:13413ea9a877 193 @endverbatim
ganlikun 0:13413ea9a877 194 * @{
ganlikun 0:13413ea9a877 195 */
ganlikun 0:13413ea9a877 196
ganlikun 0:13413ea9a877 197 /**
ganlikun 0:13413ea9a877 198 * @brief Initializes the SPDIFRX according to the specified parameters
ganlikun 0:13413ea9a877 199 * in the SPDIFRX_InitTypeDef and create the associated handle.
ganlikun 0:13413ea9a877 200 * @param hspdif: SPDIFRX handle
ganlikun 0:13413ea9a877 201 * @retval HAL status
ganlikun 0:13413ea9a877 202 */
ganlikun 0:13413ea9a877 203 HAL_StatusTypeDef HAL_SPDIFRX_Init(SPDIFRX_HandleTypeDef *hspdif)
ganlikun 0:13413ea9a877 204 {
ganlikun 0:13413ea9a877 205 uint32_t tmpreg = 0U;
ganlikun 0:13413ea9a877 206
ganlikun 0:13413ea9a877 207 /* Check the SPDIFRX handle allocation */
ganlikun 0:13413ea9a877 208 if(hspdif == NULL)
ganlikun 0:13413ea9a877 209 {
ganlikun 0:13413ea9a877 210 return HAL_ERROR;
ganlikun 0:13413ea9a877 211 }
ganlikun 0:13413ea9a877 212
ganlikun 0:13413ea9a877 213 /* Check the SPDIFRX parameters */
ganlikun 0:13413ea9a877 214 assert_param(IS_STEREO_MODE(hspdif->Init.StereoMode));
ganlikun 0:13413ea9a877 215 assert_param(IS_SPDIFRX_INPUT_SELECT(hspdif->Init.InputSelection));
ganlikun 0:13413ea9a877 216 assert_param(IS_SPDIFRX_MAX_RETRIES(hspdif->Init.Retries));
ganlikun 0:13413ea9a877 217 assert_param(IS_SPDIFRX_WAIT_FOR_ACTIVITY(hspdif->Init.WaitForActivity));
ganlikun 0:13413ea9a877 218 assert_param(IS_SPDIFRX_CHANNEL(hspdif->Init.ChannelSelection));
ganlikun 0:13413ea9a877 219 assert_param(IS_SPDIFRX_DATA_FORMAT(hspdif->Init.DataFormat));
ganlikun 0:13413ea9a877 220 assert_param(IS_PREAMBLE_TYPE_MASK(hspdif->Init.PreambleTypeMask));
ganlikun 0:13413ea9a877 221 assert_param(IS_CHANNEL_STATUS_MASK(hspdif->Init.ChannelStatusMask));
ganlikun 0:13413ea9a877 222 assert_param(IS_VALIDITY_MASK(hspdif->Init.ValidityBitMask));
ganlikun 0:13413ea9a877 223 assert_param(IS_PARITY_ERROR_MASK(hspdif->Init.ParityErrorMask));
ganlikun 0:13413ea9a877 224
ganlikun 0:13413ea9a877 225 if(hspdif->State == HAL_SPDIFRX_STATE_RESET)
ganlikun 0:13413ea9a877 226 {
ganlikun 0:13413ea9a877 227 /* Allocate lock resource and initialize it */
ganlikun 0:13413ea9a877 228 hspdif->Lock = HAL_UNLOCKED;
ganlikun 0:13413ea9a877 229 /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
ganlikun 0:13413ea9a877 230 HAL_SPDIFRX_MspInit(hspdif);
ganlikun 0:13413ea9a877 231 }
ganlikun 0:13413ea9a877 232
ganlikun 0:13413ea9a877 233 /* SPDIFRX peripheral state is BUSY*/
ganlikun 0:13413ea9a877 234 hspdif->State = HAL_SPDIFRX_STATE_BUSY;
ganlikun 0:13413ea9a877 235
ganlikun 0:13413ea9a877 236 /* Disable SPDIFRX interface (IDLE State) */
ganlikun 0:13413ea9a877 237 __HAL_SPDIFRX_IDLE(hspdif);
ganlikun 0:13413ea9a877 238
ganlikun 0:13413ea9a877 239 /* Reset the old SPDIFRX CR configuration */
ganlikun 0:13413ea9a877 240 tmpreg = hspdif->Instance->CR;
ganlikun 0:13413ea9a877 241
ganlikun 0:13413ea9a877 242 tmpreg &= ~((uint16_t) SPDIFRX_CR_RXSTEO | SPDIFRX_CR_DRFMT | SPDIFRX_CR_PMSK |
ganlikun 0:13413ea9a877 243 SPDIFRX_CR_VMSK | SPDIFRX_CR_CUMSK | SPDIFRX_CR_PTMSK |
ganlikun 0:13413ea9a877 244 SPDIFRX_CR_CHSEL | SPDIFRX_CR_NBTR | SPDIFRX_CR_WFA |
ganlikun 0:13413ea9a877 245 SPDIFRX_CR_INSEL);
ganlikun 0:13413ea9a877 246
ganlikun 0:13413ea9a877 247 /* Sets the new configuration of the SPDIFRX peripheral */
ganlikun 0:13413ea9a877 248 tmpreg |= ((uint16_t) hspdif->Init.StereoMode |
ganlikun 0:13413ea9a877 249 hspdif->Init.InputSelection |
ganlikun 0:13413ea9a877 250 hspdif->Init.Retries |
ganlikun 0:13413ea9a877 251 hspdif->Init.WaitForActivity |
ganlikun 0:13413ea9a877 252 hspdif->Init.ChannelSelection |
ganlikun 0:13413ea9a877 253 hspdif->Init.DataFormat |
ganlikun 0:13413ea9a877 254 hspdif->Init.PreambleTypeMask |
ganlikun 0:13413ea9a877 255 hspdif->Init.ChannelStatusMask |
ganlikun 0:13413ea9a877 256 hspdif->Init.ValidityBitMask |
ganlikun 0:13413ea9a877 257 hspdif->Init.ParityErrorMask);
ganlikun 0:13413ea9a877 258
ganlikun 0:13413ea9a877 259 hspdif->Instance->CR = tmpreg;
ganlikun 0:13413ea9a877 260
ganlikun 0:13413ea9a877 261 hspdif->ErrorCode = HAL_SPDIFRX_ERROR_NONE;
ganlikun 0:13413ea9a877 262
ganlikun 0:13413ea9a877 263 /* SPDIFRX peripheral state is READY*/
ganlikun 0:13413ea9a877 264 hspdif->State = HAL_SPDIFRX_STATE_READY;
ganlikun 0:13413ea9a877 265
ganlikun 0:13413ea9a877 266 return HAL_OK;
ganlikun 0:13413ea9a877 267 }
ganlikun 0:13413ea9a877 268
ganlikun 0:13413ea9a877 269 /**
ganlikun 0:13413ea9a877 270 * @brief DeInitializes the SPDIFRX peripheral
ganlikun 0:13413ea9a877 271 * @param hspdif: SPDIFRX handle
ganlikun 0:13413ea9a877 272 * @retval HAL status
ganlikun 0:13413ea9a877 273 */
ganlikun 0:13413ea9a877 274 HAL_StatusTypeDef HAL_SPDIFRX_DeInit(SPDIFRX_HandleTypeDef *hspdif)
ganlikun 0:13413ea9a877 275 {
ganlikun 0:13413ea9a877 276 /* Check the SPDIFRX handle allocation */
ganlikun 0:13413ea9a877 277 if(hspdif == NULL)
ganlikun 0:13413ea9a877 278 {
ganlikun 0:13413ea9a877 279 return HAL_ERROR;
ganlikun 0:13413ea9a877 280 }
ganlikun 0:13413ea9a877 281
ganlikun 0:13413ea9a877 282 /* Check the parameters */
ganlikun 0:13413ea9a877 283 assert_param(IS_SPDIFRX_ALL_INSTANCE(hspdif->Instance));
ganlikun 0:13413ea9a877 284
ganlikun 0:13413ea9a877 285 hspdif->State = HAL_SPDIFRX_STATE_BUSY;
ganlikun 0:13413ea9a877 286
ganlikun 0:13413ea9a877 287 /* Disable SPDIFRX interface (IDLE state) */
ganlikun 0:13413ea9a877 288 __HAL_SPDIFRX_IDLE(hspdif);
ganlikun 0:13413ea9a877 289
ganlikun 0:13413ea9a877 290 /* DeInit the low level hardware: GPIO, CLOCK, NVIC... */
ganlikun 0:13413ea9a877 291 HAL_SPDIFRX_MspDeInit(hspdif);
ganlikun 0:13413ea9a877 292
ganlikun 0:13413ea9a877 293 hspdif->ErrorCode = HAL_SPDIFRX_ERROR_NONE;
ganlikun 0:13413ea9a877 294
ganlikun 0:13413ea9a877 295 /* SPDIFRX peripheral state is RESET*/
ganlikun 0:13413ea9a877 296 hspdif->State = HAL_SPDIFRX_STATE_RESET;
ganlikun 0:13413ea9a877 297
ganlikun 0:13413ea9a877 298 /* Release Lock */
ganlikun 0:13413ea9a877 299 __HAL_UNLOCK(hspdif);
ganlikun 0:13413ea9a877 300
ganlikun 0:13413ea9a877 301 return HAL_OK;
ganlikun 0:13413ea9a877 302 }
ganlikun 0:13413ea9a877 303
ganlikun 0:13413ea9a877 304 /**
ganlikun 0:13413ea9a877 305 * @brief SPDIFRX MSP Init
ganlikun 0:13413ea9a877 306 * @param hspdif: SPDIFRX handle
ganlikun 0:13413ea9a877 307 * @retval None
ganlikun 0:13413ea9a877 308 */
ganlikun 0:13413ea9a877 309 __weak void HAL_SPDIFRX_MspInit(SPDIFRX_HandleTypeDef *hspdif)
ganlikun 0:13413ea9a877 310 {
ganlikun 0:13413ea9a877 311 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 312 UNUSED(hspdif);
ganlikun 0:13413ea9a877 313 /* NOTE : This function Should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 314 the HAL_SPDIFRX_MspInit could be implemented in the user file
ganlikun 0:13413ea9a877 315 */
ganlikun 0:13413ea9a877 316 }
ganlikun 0:13413ea9a877 317
ganlikun 0:13413ea9a877 318 /**
ganlikun 0:13413ea9a877 319 * @brief SPDIFRX MSP DeInit
ganlikun 0:13413ea9a877 320 * @param hspdif: SPDIFRX handle
ganlikun 0:13413ea9a877 321 * @retval None
ganlikun 0:13413ea9a877 322 */
ganlikun 0:13413ea9a877 323 __weak void HAL_SPDIFRX_MspDeInit(SPDIFRX_HandleTypeDef *hspdif)
ganlikun 0:13413ea9a877 324 {
ganlikun 0:13413ea9a877 325 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 326 UNUSED(hspdif);
ganlikun 0:13413ea9a877 327 /* NOTE : This function Should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 328 the HAL_SPDIFRX_MspDeInit could be implemented in the user file
ganlikun 0:13413ea9a877 329 */
ganlikun 0:13413ea9a877 330 }
ganlikun 0:13413ea9a877 331
ganlikun 0:13413ea9a877 332 /**
ganlikun 0:13413ea9a877 333 * @brief Sets the SPDIFRX dtat format according to the specified parameters
ganlikun 0:13413ea9a877 334 * in the SPDIFRX_InitTypeDef.
ganlikun 0:13413ea9a877 335 * @param hspdif: SPDIFRX handle
ganlikun 0:13413ea9a877 336 * @param sDataFormat: SPDIFRX data format
ganlikun 0:13413ea9a877 337 * @retval HAL status
ganlikun 0:13413ea9a877 338 */
ganlikun 0:13413ea9a877 339 HAL_StatusTypeDef HAL_SPDIFRX_SetDataFormat(SPDIFRX_HandleTypeDef *hspdif, SPDIFRX_SetDataFormatTypeDef sDataFormat)
ganlikun 0:13413ea9a877 340 {
ganlikun 0:13413ea9a877 341 uint32_t tmpreg = 0U;
ganlikun 0:13413ea9a877 342
ganlikun 0:13413ea9a877 343 /* Check the SPDIFRX handle allocation */
ganlikun 0:13413ea9a877 344 if(hspdif == NULL)
ganlikun 0:13413ea9a877 345 {
ganlikun 0:13413ea9a877 346 return HAL_ERROR;
ganlikun 0:13413ea9a877 347 }
ganlikun 0:13413ea9a877 348
ganlikun 0:13413ea9a877 349 /* Check the SPDIFRX parameters */
ganlikun 0:13413ea9a877 350 assert_param(IS_STEREO_MODE(sDataFormat.StereoMode));
ganlikun 0:13413ea9a877 351 assert_param(IS_SPDIFRX_DATA_FORMAT(sDataFormat.DataFormat));
ganlikun 0:13413ea9a877 352 assert_param(IS_PREAMBLE_TYPE_MASK(sDataFormat.PreambleTypeMask));
ganlikun 0:13413ea9a877 353 assert_param(IS_CHANNEL_STATUS_MASK(sDataFormat.ChannelStatusMask));
ganlikun 0:13413ea9a877 354 assert_param(IS_VALIDITY_MASK(sDataFormat.ValidityBitMask));
ganlikun 0:13413ea9a877 355 assert_param(IS_PARITY_ERROR_MASK(sDataFormat.ParityErrorMask));
ganlikun 0:13413ea9a877 356
ganlikun 0:13413ea9a877 357 /* Reset the old SPDIFRX CR configuration */
ganlikun 0:13413ea9a877 358 tmpreg = hspdif->Instance->CR;
ganlikun 0:13413ea9a877 359
ganlikun 0:13413ea9a877 360 if(((tmpreg & SPDIFRX_STATE_RCV) == SPDIFRX_STATE_RCV) &&
ganlikun 0:13413ea9a877 361 (((tmpreg & SPDIFRX_CR_DRFMT) != sDataFormat.DataFormat) ||
ganlikun 0:13413ea9a877 362 ((tmpreg & SPDIFRX_CR_RXSTEO) != sDataFormat.StereoMode)))
ganlikun 0:13413ea9a877 363 {
ganlikun 0:13413ea9a877 364 return HAL_ERROR;
ganlikun 0:13413ea9a877 365 }
ganlikun 0:13413ea9a877 366
ganlikun 0:13413ea9a877 367 tmpreg &= ~((uint16_t) SPDIFRX_CR_RXSTEO | SPDIFRX_CR_DRFMT | SPDIFRX_CR_PMSK |
ganlikun 0:13413ea9a877 368 SPDIFRX_CR_VMSK | SPDIFRX_CR_CUMSK | SPDIFRX_CR_PTMSK);
ganlikun 0:13413ea9a877 369
ganlikun 0:13413ea9a877 370 /* Sets the new configuration of the SPDIFRX peripheral */
ganlikun 0:13413ea9a877 371 tmpreg |= ((uint16_t) sDataFormat.StereoMode |
ganlikun 0:13413ea9a877 372 sDataFormat.DataFormat |
ganlikun 0:13413ea9a877 373 sDataFormat.PreambleTypeMask |
ganlikun 0:13413ea9a877 374 sDataFormat.ChannelStatusMask |
ganlikun 0:13413ea9a877 375 sDataFormat.ValidityBitMask |
ganlikun 0:13413ea9a877 376 sDataFormat.ParityErrorMask);
ganlikun 0:13413ea9a877 377
ganlikun 0:13413ea9a877 378 hspdif->Instance->CR = tmpreg;
ganlikun 0:13413ea9a877 379
ganlikun 0:13413ea9a877 380 return HAL_OK;
ganlikun 0:13413ea9a877 381 }
ganlikun 0:13413ea9a877 382
ganlikun 0:13413ea9a877 383 /**
ganlikun 0:13413ea9a877 384 * @}
ganlikun 0:13413ea9a877 385 */
ganlikun 0:13413ea9a877 386
ganlikun 0:13413ea9a877 387 /** @defgroup SPDIFRX_Exported_Functions_Group2 IO operation functions
ganlikun 0:13413ea9a877 388 * @brief Data transfers functions
ganlikun 0:13413ea9a877 389 *
ganlikun 0:13413ea9a877 390 @verbatim
ganlikun 0:13413ea9a877 391 ===============================================================================
ganlikun 0:13413ea9a877 392 ##### IO operation functions #####
ganlikun 0:13413ea9a877 393 ===============================================================================
ganlikun 0:13413ea9a877 394 [..]
ganlikun 0:13413ea9a877 395 This subsection provides a set of functions allowing to manage the SPDIFRX data
ganlikun 0:13413ea9a877 396 transfers.
ganlikun 0:13413ea9a877 397
ganlikun 0:13413ea9a877 398 (#) There is two mode of transfer:
ganlikun 0:13413ea9a877 399 (++) Blocking mode : The communication is performed in the polling mode.
ganlikun 0:13413ea9a877 400 The status of all data processing is returned by the same function
ganlikun 0:13413ea9a877 401 after finishing transfer.
ganlikun 0:13413ea9a877 402 (++) No-Blocking mode : The communication is performed using Interrupts
ganlikun 0:13413ea9a877 403 or DMA. These functions return the status of the transfer start-up.
ganlikun 0:13413ea9a877 404 The end of the data processing will be indicated through the
ganlikun 0:13413ea9a877 405 dedicated SPDIFRX IRQ when using Interrupt mode or the DMA IRQ when
ganlikun 0:13413ea9a877 406 using DMA mode.
ganlikun 0:13413ea9a877 407
ganlikun 0:13413ea9a877 408 (#) Blocking mode functions are :
ganlikun 0:13413ea9a877 409 (++) HAL_SPDIFRX_ReceiveDataFlow()
ganlikun 0:13413ea9a877 410 (++) HAL_SPDIFRX_ReceiveControlFlow()
ganlikun 0:13413ea9a877 411 (+@) Do not use blocking mode to receive both control and data flow at the same time.
ganlikun 0:13413ea9a877 412
ganlikun 0:13413ea9a877 413 (#) No-Blocking mode functions with Interrupt are :
ganlikun 0:13413ea9a877 414 (++) HAL_SPDIFRX_ReceiveControlFlow_IT()
ganlikun 0:13413ea9a877 415 (++) HAL_SPDIFRX_ReceiveDataFlow_IT()
ganlikun 0:13413ea9a877 416
ganlikun 0:13413ea9a877 417 (#) No-Blocking mode functions with DMA are :
ganlikun 0:13413ea9a877 418 (++) HAL_SPDIFRX_ReceiveControlFlow_DMA()
ganlikun 0:13413ea9a877 419 (++) HAL_SPDIFRX_ReceiveDataFlow_DMA()
ganlikun 0:13413ea9a877 420
ganlikun 0:13413ea9a877 421 (#) A set of Transfer Complete Callbacks are provided in No_Blocking mode:
ganlikun 0:13413ea9a877 422 (++) HAL_SPDIFRX_RxCpltCallback()
ganlikun 0:13413ea9a877 423 (++) HAL_SPDIFRX_ErrorCallback()
ganlikun 0:13413ea9a877 424
ganlikun 0:13413ea9a877 425 @endverbatim
ganlikun 0:13413ea9a877 426 * @{
ganlikun 0:13413ea9a877 427 */
ganlikun 0:13413ea9a877 428
ganlikun 0:13413ea9a877 429 /**
ganlikun 0:13413ea9a877 430 * @brief Receives an amount of data (Data Flow) in blocking mode.
ganlikun 0:13413ea9a877 431 * @param hspdif: pointer to SPDIFRX_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 432 * the configuration information for SPDIFRX module.
ganlikun 0:13413ea9a877 433 * @param pData: Pointer to data buffer
ganlikun 0:13413ea9a877 434 * @param Size: Amount of data to be received
ganlikun 0:13413ea9a877 435 * @param Timeout: Timeout duration
ganlikun 0:13413ea9a877 436 * @retval HAL status
ganlikun 0:13413ea9a877 437 */
ganlikun 0:13413ea9a877 438 HAL_StatusTypeDef HAL_SPDIFRX_ReceiveDataFlow(SPDIFRX_HandleTypeDef *hspdif, uint32_t *pData, uint16_t Size, uint32_t Timeout)
ganlikun 0:13413ea9a877 439 {
ganlikun 0:13413ea9a877 440 if((pData == NULL ) || (Size == 0))
ganlikun 0:13413ea9a877 441 {
ganlikun 0:13413ea9a877 442 return HAL_ERROR;
ganlikun 0:13413ea9a877 443 }
ganlikun 0:13413ea9a877 444
ganlikun 0:13413ea9a877 445 if(hspdif->State == HAL_SPDIFRX_STATE_READY)
ganlikun 0:13413ea9a877 446 {
ganlikun 0:13413ea9a877 447 /* Process Locked */
ganlikun 0:13413ea9a877 448 __HAL_LOCK(hspdif);
ganlikun 0:13413ea9a877 449
ganlikun 0:13413ea9a877 450 hspdif->State = HAL_SPDIFRX_STATE_BUSY;
ganlikun 0:13413ea9a877 451
ganlikun 0:13413ea9a877 452 /* Start synchronisation */
ganlikun 0:13413ea9a877 453 __HAL_SPDIFRX_SYNC(hspdif);
ganlikun 0:13413ea9a877 454
ganlikun 0:13413ea9a877 455 /* Wait until SYNCD flag is set */
ganlikun 0:13413ea9a877 456 if(SPDIFRX_WaitOnFlagUntilTimeout(hspdif, SPDIFRX_FLAG_SYNCD, RESET, Timeout) != HAL_OK)
ganlikun 0:13413ea9a877 457 {
ganlikun 0:13413ea9a877 458 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 459 }
ganlikun 0:13413ea9a877 460
ganlikun 0:13413ea9a877 461 /* Start reception */
ganlikun 0:13413ea9a877 462 __HAL_SPDIFRX_RCV(hspdif);
ganlikun 0:13413ea9a877 463
ganlikun 0:13413ea9a877 464 /* Receive data flow */
ganlikun 0:13413ea9a877 465 while(Size > 0)
ganlikun 0:13413ea9a877 466 {
ganlikun 0:13413ea9a877 467 /* Wait until RXNE flag is set */
ganlikun 0:13413ea9a877 468 if(SPDIFRX_WaitOnFlagUntilTimeout(hspdif, SPDIFRX_FLAG_RXNE, RESET, Timeout) != HAL_OK)
ganlikun 0:13413ea9a877 469 {
ganlikun 0:13413ea9a877 470 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 471 }
ganlikun 0:13413ea9a877 472
ganlikun 0:13413ea9a877 473 (*pData++) = hspdif->Instance->DR;
ganlikun 0:13413ea9a877 474 Size--;
ganlikun 0:13413ea9a877 475 }
ganlikun 0:13413ea9a877 476
ganlikun 0:13413ea9a877 477 /* SPDIFRX ready */
ganlikun 0:13413ea9a877 478 hspdif->State = HAL_SPDIFRX_STATE_READY;
ganlikun 0:13413ea9a877 479
ganlikun 0:13413ea9a877 480 /* Process Unlocked */
ganlikun 0:13413ea9a877 481 __HAL_UNLOCK(hspdif);
ganlikun 0:13413ea9a877 482
ganlikun 0:13413ea9a877 483 return HAL_OK;
ganlikun 0:13413ea9a877 484 }
ganlikun 0:13413ea9a877 485 else
ganlikun 0:13413ea9a877 486 {
ganlikun 0:13413ea9a877 487 return HAL_BUSY;
ganlikun 0:13413ea9a877 488 }
ganlikun 0:13413ea9a877 489 }
ganlikun 0:13413ea9a877 490
ganlikun 0:13413ea9a877 491 /**
ganlikun 0:13413ea9a877 492 * @brief Receives an amount of data (Control Flow) in blocking mode.
ganlikun 0:13413ea9a877 493 * @param hspdif: pointer to a SPDIFRX_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 494 * the configuration information for SPDIFRX module.
ganlikun 0:13413ea9a877 495 * @param pData: Pointer to data buffer
ganlikun 0:13413ea9a877 496 * @param Size: Amount of data to be received
ganlikun 0:13413ea9a877 497 * @param Timeout: Timeout duration
ganlikun 0:13413ea9a877 498 * @retval HAL status
ganlikun 0:13413ea9a877 499 */
ganlikun 0:13413ea9a877 500 HAL_StatusTypeDef HAL_SPDIFRX_ReceiveControlFlow(SPDIFRX_HandleTypeDef *hspdif, uint32_t *pData, uint16_t Size, uint32_t Timeout)
ganlikun 0:13413ea9a877 501 {
ganlikun 0:13413ea9a877 502 if((pData == NULL ) || (Size == 0))
ganlikun 0:13413ea9a877 503 {
ganlikun 0:13413ea9a877 504 return HAL_ERROR;
ganlikun 0:13413ea9a877 505 }
ganlikun 0:13413ea9a877 506
ganlikun 0:13413ea9a877 507 if(hspdif->State == HAL_SPDIFRX_STATE_READY)
ganlikun 0:13413ea9a877 508 {
ganlikun 0:13413ea9a877 509 /* Process Locked */
ganlikun 0:13413ea9a877 510 __HAL_LOCK(hspdif);
ganlikun 0:13413ea9a877 511
ganlikun 0:13413ea9a877 512 hspdif->State = HAL_SPDIFRX_STATE_BUSY;
ganlikun 0:13413ea9a877 513
ganlikun 0:13413ea9a877 514 /* Start synchronization */
ganlikun 0:13413ea9a877 515 __HAL_SPDIFRX_SYNC(hspdif);
ganlikun 0:13413ea9a877 516
ganlikun 0:13413ea9a877 517 /* Wait until SYNCD flag is set */
ganlikun 0:13413ea9a877 518 if(SPDIFRX_WaitOnFlagUntilTimeout(hspdif, SPDIFRX_FLAG_SYNCD, RESET, Timeout) != HAL_OK)
ganlikun 0:13413ea9a877 519 {
ganlikun 0:13413ea9a877 520 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 521 }
ganlikun 0:13413ea9a877 522
ganlikun 0:13413ea9a877 523 /* Start reception */
ganlikun 0:13413ea9a877 524 __HAL_SPDIFRX_RCV(hspdif);
ganlikun 0:13413ea9a877 525
ganlikun 0:13413ea9a877 526 /* Receive control flow */
ganlikun 0:13413ea9a877 527 while(Size > 0)
ganlikun 0:13413ea9a877 528 {
ganlikun 0:13413ea9a877 529 /* Wait until CSRNE flag is set */
ganlikun 0:13413ea9a877 530 if(SPDIFRX_WaitOnFlagUntilTimeout(hspdif, SPDIFRX_FLAG_CSRNE, RESET, Timeout) != HAL_OK)
ganlikun 0:13413ea9a877 531 {
ganlikun 0:13413ea9a877 532 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 533 }
ganlikun 0:13413ea9a877 534
ganlikun 0:13413ea9a877 535 (*pData++) = hspdif->Instance->CSR;
ganlikun 0:13413ea9a877 536 Size--;
ganlikun 0:13413ea9a877 537 }
ganlikun 0:13413ea9a877 538
ganlikun 0:13413ea9a877 539 /* SPDIFRX ready */
ganlikun 0:13413ea9a877 540 hspdif->State = HAL_SPDIFRX_STATE_READY;
ganlikun 0:13413ea9a877 541
ganlikun 0:13413ea9a877 542 /* Process Unlocked */
ganlikun 0:13413ea9a877 543 __HAL_UNLOCK(hspdif);
ganlikun 0:13413ea9a877 544
ganlikun 0:13413ea9a877 545 return HAL_OK;
ganlikun 0:13413ea9a877 546 }
ganlikun 0:13413ea9a877 547 else
ganlikun 0:13413ea9a877 548 {
ganlikun 0:13413ea9a877 549 return HAL_BUSY;
ganlikun 0:13413ea9a877 550 }
ganlikun 0:13413ea9a877 551 }
ganlikun 0:13413ea9a877 552 /**
ganlikun 0:13413ea9a877 553 * @brief Receive an amount of data (Data Flow) in non-blocking mode with Interrupt
ganlikun 0:13413ea9a877 554 * @param hspdif: SPDIFRX handle
ganlikun 0:13413ea9a877 555 * @param pData: a 32-bit pointer to the Receive data buffer.
ganlikun 0:13413ea9a877 556 * @param Size: number of data sample to be received .
ganlikun 0:13413ea9a877 557 * @retval HAL status
ganlikun 0:13413ea9a877 558 */
ganlikun 0:13413ea9a877 559 HAL_StatusTypeDef HAL_SPDIFRX_ReceiveDataFlow_IT(SPDIFRX_HandleTypeDef *hspdif, uint32_t *pData, uint16_t Size)
ganlikun 0:13413ea9a877 560 {
ganlikun 0:13413ea9a877 561 __IO uint32_t count = SPDIFRX_TIMEOUT_VALUE * (SystemCoreClock / 24U / 1000U);
ganlikun 0:13413ea9a877 562
ganlikun 0:13413ea9a877 563 if((hspdif->State == HAL_SPDIFRX_STATE_READY) || (hspdif->State == HAL_SPDIFRX_STATE_BUSY_CX))
ganlikun 0:13413ea9a877 564 {
ganlikun 0:13413ea9a877 565 if((pData == NULL) || (Size == 0))
ganlikun 0:13413ea9a877 566 {
ganlikun 0:13413ea9a877 567 return HAL_ERROR;
ganlikun 0:13413ea9a877 568 }
ganlikun 0:13413ea9a877 569
ganlikun 0:13413ea9a877 570 /* Process Locked */
ganlikun 0:13413ea9a877 571 __HAL_LOCK(hspdif);
ganlikun 0:13413ea9a877 572
ganlikun 0:13413ea9a877 573 hspdif->pRxBuffPtr = pData;
ganlikun 0:13413ea9a877 574 hspdif->RxXferSize = Size;
ganlikun 0:13413ea9a877 575 hspdif->RxXferCount = Size;
ganlikun 0:13413ea9a877 576
ganlikun 0:13413ea9a877 577 hspdif->ErrorCode = HAL_SPDIFRX_ERROR_NONE;
ganlikun 0:13413ea9a877 578
ganlikun 0:13413ea9a877 579 /* Check if a receive process is ongoing or not */
ganlikun 0:13413ea9a877 580 hspdif->State = HAL_SPDIFRX_STATE_BUSY_RX;
ganlikun 0:13413ea9a877 581
ganlikun 0:13413ea9a877 582 /* Enable the SPDIFRX PE Error Interrupt */
ganlikun 0:13413ea9a877 583 __HAL_SPDIFRX_ENABLE_IT(hspdif, SPDIFRX_IT_PERRIE);
ganlikun 0:13413ea9a877 584
ganlikun 0:13413ea9a877 585 /* Enable the SPDIFRX OVR Error Interrupt */
ganlikun 0:13413ea9a877 586 __HAL_SPDIFRX_ENABLE_IT(hspdif, SPDIFRX_IT_OVRIE);
ganlikun 0:13413ea9a877 587
ganlikun 0:13413ea9a877 588 /* Process Unlocked */
ganlikun 0:13413ea9a877 589 __HAL_UNLOCK(hspdif);
ganlikun 0:13413ea9a877 590
ganlikun 0:13413ea9a877 591 /* Enable the SPDIFRX RXNE interrupt */
ganlikun 0:13413ea9a877 592 __HAL_SPDIFRX_ENABLE_IT(hspdif, SPDIFRX_IT_RXNE);
ganlikun 0:13413ea9a877 593
ganlikun 0:13413ea9a877 594 if ((SPDIFRX->CR & SPDIFRX_CR_SPDIFEN) != SPDIFRX_STATE_SYNC || (SPDIFRX->CR & SPDIFRX_CR_SPDIFEN) != 0x00U)
ganlikun 0:13413ea9a877 595 {
ganlikun 0:13413ea9a877 596 /* Start synchronization */
ganlikun 0:13413ea9a877 597 __HAL_SPDIFRX_SYNC(hspdif);
ganlikun 0:13413ea9a877 598
ganlikun 0:13413ea9a877 599 /* Wait until SYNCD flag is set */
ganlikun 0:13413ea9a877 600 do
ganlikun 0:13413ea9a877 601 {
ganlikun 0:13413ea9a877 602 if (count-- == 0U)
ganlikun 0:13413ea9a877 603 {
ganlikun 0:13413ea9a877 604 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
ganlikun 0:13413ea9a877 605 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_RXNE);
ganlikun 0:13413ea9a877 606 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_CSRNE);
ganlikun 0:13413ea9a877 607 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_PERRIE);
ganlikun 0:13413ea9a877 608 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_OVRIE);
ganlikun 0:13413ea9a877 609 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SBLKIE);
ganlikun 0:13413ea9a877 610 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SYNCDIE);
ganlikun 0:13413ea9a877 611 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_IFEIE);
ganlikun 0:13413ea9a877 612
ganlikun 0:13413ea9a877 613 hspdif->State= HAL_SPDIFRX_STATE_READY;
ganlikun 0:13413ea9a877 614
ganlikun 0:13413ea9a877 615 /* Process Unlocked */
ganlikun 0:13413ea9a877 616 __HAL_UNLOCK(hspdif);
ganlikun 0:13413ea9a877 617
ganlikun 0:13413ea9a877 618 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 619 }
ganlikun 0:13413ea9a877 620 }
ganlikun 0:13413ea9a877 621 while (__HAL_SPDIFRX_GET_FLAG(hspdif, SPDIFRX_FLAG_SYNCD) == RESET);
ganlikun 0:13413ea9a877 622
ganlikun 0:13413ea9a877 623 /* Start reception */
ganlikun 0:13413ea9a877 624 __HAL_SPDIFRX_RCV(hspdif);
ganlikun 0:13413ea9a877 625 }
ganlikun 0:13413ea9a877 626
ganlikun 0:13413ea9a877 627 return HAL_OK;
ganlikun 0:13413ea9a877 628 }
ganlikun 0:13413ea9a877 629 else
ganlikun 0:13413ea9a877 630 {
ganlikun 0:13413ea9a877 631 return HAL_BUSY;
ganlikun 0:13413ea9a877 632 }
ganlikun 0:13413ea9a877 633 }
ganlikun 0:13413ea9a877 634
ganlikun 0:13413ea9a877 635 /**
ganlikun 0:13413ea9a877 636 * @brief Receive an amount of data (Control Flow) with Interrupt
ganlikun 0:13413ea9a877 637 * @param hspdif: SPDIFRX handle
ganlikun 0:13413ea9a877 638 * @param pData: a 32-bit pointer to the Receive data buffer.
ganlikun 0:13413ea9a877 639 * @param Size: number of data sample (Control Flow) to be received :
ganlikun 0:13413ea9a877 640 * @retval HAL status
ganlikun 0:13413ea9a877 641 */
ganlikun 0:13413ea9a877 642 HAL_StatusTypeDef HAL_SPDIFRX_ReceiveControlFlow_IT(SPDIFRX_HandleTypeDef *hspdif, uint32_t *pData, uint16_t Size)
ganlikun 0:13413ea9a877 643 {
ganlikun 0:13413ea9a877 644 __IO uint32_t count = SPDIFRX_TIMEOUT_VALUE * (SystemCoreClock / 24U / 1000U);
ganlikun 0:13413ea9a877 645
ganlikun 0:13413ea9a877 646 if((hspdif->State == HAL_SPDIFRX_STATE_READY) || (hspdif->State == HAL_SPDIFRX_STATE_BUSY_RX))
ganlikun 0:13413ea9a877 647 {
ganlikun 0:13413ea9a877 648 if((pData == NULL ) || (Size == 0))
ganlikun 0:13413ea9a877 649 {
ganlikun 0:13413ea9a877 650 return HAL_ERROR;
ganlikun 0:13413ea9a877 651 }
ganlikun 0:13413ea9a877 652
ganlikun 0:13413ea9a877 653 /* Process Locked */
ganlikun 0:13413ea9a877 654 __HAL_LOCK(hspdif);
ganlikun 0:13413ea9a877 655
ganlikun 0:13413ea9a877 656 hspdif->pCsBuffPtr = pData;
ganlikun 0:13413ea9a877 657 hspdif->CsXferSize = Size;
ganlikun 0:13413ea9a877 658 hspdif->CsXferCount = Size;
ganlikun 0:13413ea9a877 659
ganlikun 0:13413ea9a877 660 hspdif->ErrorCode = HAL_SPDIFRX_ERROR_NONE;
ganlikun 0:13413ea9a877 661
ganlikun 0:13413ea9a877 662 /* Check if a receive process is ongoing or not */
ganlikun 0:13413ea9a877 663 hspdif->State = HAL_SPDIFRX_STATE_BUSY_CX;
ganlikun 0:13413ea9a877 664
ganlikun 0:13413ea9a877 665 /* Enable the SPDIFRX PE Error Interrupt */
ganlikun 0:13413ea9a877 666 __HAL_SPDIFRX_ENABLE_IT(hspdif, SPDIFRX_IT_PERRIE);
ganlikun 0:13413ea9a877 667
ganlikun 0:13413ea9a877 668 /* Enable the SPDIFRX OVR Error Interrupt */
ganlikun 0:13413ea9a877 669 __HAL_SPDIFRX_ENABLE_IT(hspdif, SPDIFRX_IT_OVRIE);
ganlikun 0:13413ea9a877 670
ganlikun 0:13413ea9a877 671 /* Process Unlocked */
ganlikun 0:13413ea9a877 672 __HAL_UNLOCK(hspdif);
ganlikun 0:13413ea9a877 673
ganlikun 0:13413ea9a877 674 /* Enable the SPDIFRX CSRNE interrupt */
ganlikun 0:13413ea9a877 675 __HAL_SPDIFRX_ENABLE_IT(hspdif, SPDIFRX_IT_CSRNE);
ganlikun 0:13413ea9a877 676
ganlikun 0:13413ea9a877 677 if ((SPDIFRX->CR & SPDIFRX_CR_SPDIFEN) != SPDIFRX_STATE_SYNC || (SPDIFRX->CR & SPDIFRX_CR_SPDIFEN) != 0x00U)
ganlikun 0:13413ea9a877 678 {
ganlikun 0:13413ea9a877 679 /* Start synchronization */
ganlikun 0:13413ea9a877 680 __HAL_SPDIFRX_SYNC(hspdif);
ganlikun 0:13413ea9a877 681
ganlikun 0:13413ea9a877 682 /* Wait until SYNCD flag is set */
ganlikun 0:13413ea9a877 683 do
ganlikun 0:13413ea9a877 684 {
ganlikun 0:13413ea9a877 685 if (count-- == 0U)
ganlikun 0:13413ea9a877 686 {
ganlikun 0:13413ea9a877 687 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
ganlikun 0:13413ea9a877 688 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_RXNE);
ganlikun 0:13413ea9a877 689 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_CSRNE);
ganlikun 0:13413ea9a877 690 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_PERRIE);
ganlikun 0:13413ea9a877 691 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_OVRIE);
ganlikun 0:13413ea9a877 692 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SBLKIE);
ganlikun 0:13413ea9a877 693 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SYNCDIE);
ganlikun 0:13413ea9a877 694 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_IFEIE);
ganlikun 0:13413ea9a877 695
ganlikun 0:13413ea9a877 696 hspdif->State= HAL_SPDIFRX_STATE_READY;
ganlikun 0:13413ea9a877 697
ganlikun 0:13413ea9a877 698 /* Process Unlocked */
ganlikun 0:13413ea9a877 699 __HAL_UNLOCK(hspdif);
ganlikun 0:13413ea9a877 700
ganlikun 0:13413ea9a877 701 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 702 }
ganlikun 0:13413ea9a877 703 }
ganlikun 0:13413ea9a877 704 while (__HAL_SPDIFRX_GET_FLAG(hspdif, SPDIFRX_FLAG_SYNCD) == RESET);
ganlikun 0:13413ea9a877 705
ganlikun 0:13413ea9a877 706 /* Start reception */
ganlikun 0:13413ea9a877 707 __HAL_SPDIFRX_RCV(hspdif);
ganlikun 0:13413ea9a877 708 }
ganlikun 0:13413ea9a877 709
ganlikun 0:13413ea9a877 710 return HAL_OK;
ganlikun 0:13413ea9a877 711 }
ganlikun 0:13413ea9a877 712 else
ganlikun 0:13413ea9a877 713 {
ganlikun 0:13413ea9a877 714 return HAL_BUSY;
ganlikun 0:13413ea9a877 715 }
ganlikun 0:13413ea9a877 716 }
ganlikun 0:13413ea9a877 717
ganlikun 0:13413ea9a877 718 /**
ganlikun 0:13413ea9a877 719 * @brief Receive an amount of data (Data Flow) mode with DMA
ganlikun 0:13413ea9a877 720 * @param hspdif: SPDIFRX handle
ganlikun 0:13413ea9a877 721 * @param pData: a 32-bit pointer to the Receive data buffer.
ganlikun 0:13413ea9a877 722 * @param Size: number of data sample to be received :
ganlikun 0:13413ea9a877 723 * @retval HAL status
ganlikun 0:13413ea9a877 724 */
ganlikun 0:13413ea9a877 725 HAL_StatusTypeDef HAL_SPDIFRX_ReceiveDataFlow_DMA(SPDIFRX_HandleTypeDef *hspdif, uint32_t *pData, uint16_t Size)
ganlikun 0:13413ea9a877 726 {
ganlikun 0:13413ea9a877 727 __IO uint32_t count = SPDIFRX_TIMEOUT_VALUE * (SystemCoreClock / 24U / 1000U);
ganlikun 0:13413ea9a877 728
ganlikun 0:13413ea9a877 729 if((pData == NULL) || (Size == 0))
ganlikun 0:13413ea9a877 730 {
ganlikun 0:13413ea9a877 731 return HAL_ERROR;
ganlikun 0:13413ea9a877 732 }
ganlikun 0:13413ea9a877 733
ganlikun 0:13413ea9a877 734 if((hspdif->State == HAL_SPDIFRX_STATE_READY) || (hspdif->State == HAL_SPDIFRX_STATE_BUSY_CX))
ganlikun 0:13413ea9a877 735 {
ganlikun 0:13413ea9a877 736 hspdif->pRxBuffPtr = pData;
ganlikun 0:13413ea9a877 737 hspdif->RxXferSize = Size;
ganlikun 0:13413ea9a877 738 hspdif->RxXferCount = Size;
ganlikun 0:13413ea9a877 739
ganlikun 0:13413ea9a877 740 /* Process Locked */
ganlikun 0:13413ea9a877 741 __HAL_LOCK(hspdif);
ganlikun 0:13413ea9a877 742
ganlikun 0:13413ea9a877 743 hspdif->ErrorCode = HAL_SPDIFRX_ERROR_NONE;
ganlikun 0:13413ea9a877 744 hspdif->State = HAL_SPDIFRX_STATE_BUSY_RX;
ganlikun 0:13413ea9a877 745
ganlikun 0:13413ea9a877 746 /* Set the SPDIFRX Rx DMA Half transfer complete callback */
ganlikun 0:13413ea9a877 747 hspdif->hdmaDrRx->XferHalfCpltCallback = SPDIFRX_DMARxHalfCplt;
ganlikun 0:13413ea9a877 748
ganlikun 0:13413ea9a877 749 /* Set the SPDIFRX Rx DMA transfer complete callback */
ganlikun 0:13413ea9a877 750 hspdif->hdmaDrRx->XferCpltCallback = SPDIFRX_DMARxCplt;
ganlikun 0:13413ea9a877 751
ganlikun 0:13413ea9a877 752 /* Set the DMA error callback */
ganlikun 0:13413ea9a877 753 hspdif->hdmaDrRx->XferErrorCallback = SPDIFRX_DMAError;
ganlikun 0:13413ea9a877 754
ganlikun 0:13413ea9a877 755 /* Enable the DMA request */
ganlikun 0:13413ea9a877 756 HAL_DMA_Start_IT(hspdif->hdmaDrRx, (uint32_t)&hspdif->Instance->DR, (uint32_t)hspdif->pRxBuffPtr, Size);
ganlikun 0:13413ea9a877 757
ganlikun 0:13413ea9a877 758 /* Enable RXDMAEN bit in SPDIFRX CR register for data flow reception*/
ganlikun 0:13413ea9a877 759 hspdif->Instance->CR |= SPDIFRX_CR_RXDMAEN;
ganlikun 0:13413ea9a877 760
ganlikun 0:13413ea9a877 761 if ((SPDIFRX->CR & SPDIFRX_CR_SPDIFEN) != SPDIFRX_STATE_SYNC || (SPDIFRX->CR & SPDIFRX_CR_SPDIFEN) != 0x00U)
ganlikun 0:13413ea9a877 762 {
ganlikun 0:13413ea9a877 763 /* Start synchronization */
ganlikun 0:13413ea9a877 764 __HAL_SPDIFRX_SYNC(hspdif);
ganlikun 0:13413ea9a877 765
ganlikun 0:13413ea9a877 766 /* Wait until SYNCD flag is set */
ganlikun 0:13413ea9a877 767 do
ganlikun 0:13413ea9a877 768 {
ganlikun 0:13413ea9a877 769 if (count-- == 0U)
ganlikun 0:13413ea9a877 770 {
ganlikun 0:13413ea9a877 771 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
ganlikun 0:13413ea9a877 772 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_RXNE);
ganlikun 0:13413ea9a877 773 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_CSRNE);
ganlikun 0:13413ea9a877 774 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_PERRIE);
ganlikun 0:13413ea9a877 775 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_OVRIE);
ganlikun 0:13413ea9a877 776 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SBLKIE);
ganlikun 0:13413ea9a877 777 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SYNCDIE);
ganlikun 0:13413ea9a877 778 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_IFEIE);
ganlikun 0:13413ea9a877 779
ganlikun 0:13413ea9a877 780 hspdif->State= HAL_SPDIFRX_STATE_READY;
ganlikun 0:13413ea9a877 781
ganlikun 0:13413ea9a877 782 /* Process Unlocked */
ganlikun 0:13413ea9a877 783 __HAL_UNLOCK(hspdif);
ganlikun 0:13413ea9a877 784
ganlikun 0:13413ea9a877 785 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 786 }
ganlikun 0:13413ea9a877 787 }
ganlikun 0:13413ea9a877 788 while (__HAL_SPDIFRX_GET_FLAG(hspdif, SPDIFRX_FLAG_SYNCD) == RESET);
ganlikun 0:13413ea9a877 789
ganlikun 0:13413ea9a877 790 /* Start reception */
ganlikun 0:13413ea9a877 791 __HAL_SPDIFRX_RCV(hspdif);
ganlikun 0:13413ea9a877 792 }
ganlikun 0:13413ea9a877 793
ganlikun 0:13413ea9a877 794 /* Process Unlocked */
ganlikun 0:13413ea9a877 795 __HAL_UNLOCK(hspdif);
ganlikun 0:13413ea9a877 796
ganlikun 0:13413ea9a877 797 return HAL_OK;
ganlikun 0:13413ea9a877 798 }
ganlikun 0:13413ea9a877 799 else
ganlikun 0:13413ea9a877 800 {
ganlikun 0:13413ea9a877 801 return HAL_BUSY;
ganlikun 0:13413ea9a877 802 }
ganlikun 0:13413ea9a877 803 }
ganlikun 0:13413ea9a877 804
ganlikun 0:13413ea9a877 805 /**
ganlikun 0:13413ea9a877 806 * @brief Receive an amount of data (Control Flow) with DMA
ganlikun 0:13413ea9a877 807 * @param hspdif: SPDIFRX handle
ganlikun 0:13413ea9a877 808 * @param pData: a 32-bit pointer to the Receive data buffer.
ganlikun 0:13413ea9a877 809 * @param Size: number of data (Control Flow) sample to be received :
ganlikun 0:13413ea9a877 810 * @retval HAL status
ganlikun 0:13413ea9a877 811 */
ganlikun 0:13413ea9a877 812 HAL_StatusTypeDef HAL_SPDIFRX_ReceiveControlFlow_DMA(SPDIFRX_HandleTypeDef *hspdif, uint32_t *pData, uint16_t Size)
ganlikun 0:13413ea9a877 813 {
ganlikun 0:13413ea9a877 814 __IO uint32_t count = SPDIFRX_TIMEOUT_VALUE * (SystemCoreClock / 24U / 1000U);
ganlikun 0:13413ea9a877 815
ganlikun 0:13413ea9a877 816 if((pData == NULL) || (Size == 0))
ganlikun 0:13413ea9a877 817 {
ganlikun 0:13413ea9a877 818 return HAL_ERROR;
ganlikun 0:13413ea9a877 819 }
ganlikun 0:13413ea9a877 820
ganlikun 0:13413ea9a877 821 if((hspdif->State == HAL_SPDIFRX_STATE_READY) || (hspdif->State == HAL_SPDIFRX_STATE_BUSY_RX))
ganlikun 0:13413ea9a877 822 {
ganlikun 0:13413ea9a877 823 hspdif->pCsBuffPtr = pData;
ganlikun 0:13413ea9a877 824 hspdif->CsXferSize = Size;
ganlikun 0:13413ea9a877 825 hspdif->CsXferCount = Size;
ganlikun 0:13413ea9a877 826
ganlikun 0:13413ea9a877 827 /* Process Locked */
ganlikun 0:13413ea9a877 828 __HAL_LOCK(hspdif);
ganlikun 0:13413ea9a877 829
ganlikun 0:13413ea9a877 830 hspdif->ErrorCode = HAL_SPDIFRX_ERROR_NONE;
ganlikun 0:13413ea9a877 831 hspdif->State = HAL_SPDIFRX_STATE_BUSY_CX;
ganlikun 0:13413ea9a877 832
ganlikun 0:13413ea9a877 833 /* Set the SPDIFRX Rx DMA Half transfer complete callback */
ganlikun 0:13413ea9a877 834 hspdif->hdmaCsRx->XferHalfCpltCallback = SPDIFRX_DMACxHalfCplt;
ganlikun 0:13413ea9a877 835
ganlikun 0:13413ea9a877 836 /* Set the SPDIFRX Rx DMA transfer complete callback */
ganlikun 0:13413ea9a877 837 hspdif->hdmaCsRx->XferCpltCallback = SPDIFRX_DMACxCplt;
ganlikun 0:13413ea9a877 838
ganlikun 0:13413ea9a877 839 /* Set the DMA error callback */
ganlikun 0:13413ea9a877 840 hspdif->hdmaCsRx->XferErrorCallback = SPDIFRX_DMAError;
ganlikun 0:13413ea9a877 841
ganlikun 0:13413ea9a877 842 /* Enable the DMA request */
ganlikun 0:13413ea9a877 843 HAL_DMA_Start_IT(hspdif->hdmaCsRx, (uint32_t)&hspdif->Instance->CSR, (uint32_t)hspdif->pCsBuffPtr, Size);
ganlikun 0:13413ea9a877 844
ganlikun 0:13413ea9a877 845 /* Enable CBDMAEN bit in SPDIFRX CR register for control flow reception*/
ganlikun 0:13413ea9a877 846 hspdif->Instance->CR |= SPDIFRX_CR_CBDMAEN;
ganlikun 0:13413ea9a877 847
ganlikun 0:13413ea9a877 848 if ((SPDIFRX->CR & SPDIFRX_CR_SPDIFEN) != SPDIFRX_STATE_SYNC || (SPDIFRX->CR & SPDIFRX_CR_SPDIFEN) != 0x00U)
ganlikun 0:13413ea9a877 849 {
ganlikun 0:13413ea9a877 850 /* Start synchronization */
ganlikun 0:13413ea9a877 851 __HAL_SPDIFRX_SYNC(hspdif);
ganlikun 0:13413ea9a877 852
ganlikun 0:13413ea9a877 853 /* Wait until SYNCD flag is set */
ganlikun 0:13413ea9a877 854 do
ganlikun 0:13413ea9a877 855 {
ganlikun 0:13413ea9a877 856 if (count-- == 0U)
ganlikun 0:13413ea9a877 857 {
ganlikun 0:13413ea9a877 858 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
ganlikun 0:13413ea9a877 859 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_RXNE);
ganlikun 0:13413ea9a877 860 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_CSRNE);
ganlikun 0:13413ea9a877 861 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_PERRIE);
ganlikun 0:13413ea9a877 862 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_OVRIE);
ganlikun 0:13413ea9a877 863 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SBLKIE);
ganlikun 0:13413ea9a877 864 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SYNCDIE);
ganlikun 0:13413ea9a877 865 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_IFEIE);
ganlikun 0:13413ea9a877 866
ganlikun 0:13413ea9a877 867 hspdif->State= HAL_SPDIFRX_STATE_READY;
ganlikun 0:13413ea9a877 868
ganlikun 0:13413ea9a877 869 /* Process Unlocked */
ganlikun 0:13413ea9a877 870 __HAL_UNLOCK(hspdif);
ganlikun 0:13413ea9a877 871
ganlikun 0:13413ea9a877 872 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 873 }
ganlikun 0:13413ea9a877 874 }
ganlikun 0:13413ea9a877 875 while (__HAL_SPDIFRX_GET_FLAG(hspdif, SPDIFRX_FLAG_SYNCD) == RESET);
ganlikun 0:13413ea9a877 876
ganlikun 0:13413ea9a877 877 /* Start reception */
ganlikun 0:13413ea9a877 878 __HAL_SPDIFRX_RCV(hspdif);
ganlikun 0:13413ea9a877 879 }
ganlikun 0:13413ea9a877 880
ganlikun 0:13413ea9a877 881 /* Process Unlocked */
ganlikun 0:13413ea9a877 882 __HAL_UNLOCK(hspdif);
ganlikun 0:13413ea9a877 883
ganlikun 0:13413ea9a877 884 return HAL_OK;
ganlikun 0:13413ea9a877 885 }
ganlikun 0:13413ea9a877 886 else
ganlikun 0:13413ea9a877 887 {
ganlikun 0:13413ea9a877 888 return HAL_BUSY;
ganlikun 0:13413ea9a877 889 }
ganlikun 0:13413ea9a877 890 }
ganlikun 0:13413ea9a877 891
ganlikun 0:13413ea9a877 892 /**
ganlikun 0:13413ea9a877 893 * @brief stop the audio stream receive from the Media.
ganlikun 0:13413ea9a877 894 * @param hspdif: SPDIFRX handle
ganlikun 0:13413ea9a877 895 * @retval None
ganlikun 0:13413ea9a877 896 */
ganlikun 0:13413ea9a877 897 HAL_StatusTypeDef HAL_SPDIFRX_DMAStop(SPDIFRX_HandleTypeDef *hspdif)
ganlikun 0:13413ea9a877 898 {
ganlikun 0:13413ea9a877 899 /* Process Locked */
ganlikun 0:13413ea9a877 900 __HAL_LOCK(hspdif);
ganlikun 0:13413ea9a877 901
ganlikun 0:13413ea9a877 902 /* Disable the SPDIFRX DMA requests */
ganlikun 0:13413ea9a877 903 hspdif->Instance->CR &= (uint16_t)(~SPDIFRX_CR_RXDMAEN);
ganlikun 0:13413ea9a877 904 hspdif->Instance->CR &= (uint16_t)(~SPDIFRX_CR_CBDMAEN);
ganlikun 0:13413ea9a877 905
ganlikun 0:13413ea9a877 906 /* Disable the SPDIFRX DMA channel */
ganlikun 0:13413ea9a877 907 __HAL_DMA_DISABLE(hspdif->hdmaDrRx);
ganlikun 0:13413ea9a877 908 __HAL_DMA_DISABLE(hspdif->hdmaCsRx);
ganlikun 0:13413ea9a877 909
ganlikun 0:13413ea9a877 910 /* Disable SPDIFRX peripheral */
ganlikun 0:13413ea9a877 911 __HAL_SPDIFRX_IDLE(hspdif);
ganlikun 0:13413ea9a877 912
ganlikun 0:13413ea9a877 913 hspdif->State = HAL_SPDIFRX_STATE_READY;
ganlikun 0:13413ea9a877 914
ganlikun 0:13413ea9a877 915 /* Process Unlocked */
ganlikun 0:13413ea9a877 916 __HAL_UNLOCK(hspdif);
ganlikun 0:13413ea9a877 917
ganlikun 0:13413ea9a877 918 return HAL_OK;
ganlikun 0:13413ea9a877 919 }
ganlikun 0:13413ea9a877 920
ganlikun 0:13413ea9a877 921 /**
ganlikun 0:13413ea9a877 922 * @brief This function handles SPDIFRX interrupt request.
ganlikun 0:13413ea9a877 923 * @param hspdif: SPDIFRX handle
ganlikun 0:13413ea9a877 924 * @retval HAL status
ganlikun 0:13413ea9a877 925 */
ganlikun 0:13413ea9a877 926 void HAL_SPDIFRX_IRQHandler(SPDIFRX_HandleTypeDef *hspdif)
ganlikun 0:13413ea9a877 927 {
ganlikun 0:13413ea9a877 928 /* SPDIFRX in mode Data Flow Reception ------------------------------------------------*/
ganlikun 0:13413ea9a877 929 if((__HAL_SPDIFRX_GET_FLAG(hspdif, SPDIFRX_FLAG_RXNE) != RESET) && (__HAL_SPDIFRX_GET_IT_SOURCE(hspdif, SPDIFRX_IT_RXNE) != RESET))
ganlikun 0:13413ea9a877 930 {
ganlikun 0:13413ea9a877 931 __HAL_SPDIFRX_CLEAR_IT(hspdif, SPDIFRX_IT_RXNE);
ganlikun 0:13413ea9a877 932 SPDIFRX_ReceiveDataFlow_IT(hspdif);
ganlikun 0:13413ea9a877 933 }
ganlikun 0:13413ea9a877 934
ganlikun 0:13413ea9a877 935 /* SPDIFRX in mode Control Flow Reception ------------------------------------------------*/
ganlikun 0:13413ea9a877 936 if((__HAL_SPDIFRX_GET_FLAG(hspdif, SPDIFRX_FLAG_CSRNE) != RESET) && (__HAL_SPDIFRX_GET_IT_SOURCE(hspdif, SPDIFRX_IT_CSRNE) != RESET))
ganlikun 0:13413ea9a877 937 {
ganlikun 0:13413ea9a877 938 __HAL_SPDIFRX_CLEAR_IT(hspdif, SPDIFRX_IT_CSRNE);
ganlikun 0:13413ea9a877 939 SPDIFRX_ReceiveControlFlow_IT(hspdif);
ganlikun 0:13413ea9a877 940 }
ganlikun 0:13413ea9a877 941
ganlikun 0:13413ea9a877 942 /* SPDIFRX Overrun error interrupt occurred ---------------------------------*/
ganlikun 0:13413ea9a877 943 if((__HAL_SPDIFRX_GET_FLAG(hspdif, SPDIFRX_FLAG_OVR) != RESET) && (__HAL_SPDIFRX_GET_IT_SOURCE(hspdif, SPDIFRX_IT_OVRIE) != RESET))
ganlikun 0:13413ea9a877 944 {
ganlikun 0:13413ea9a877 945 __HAL_SPDIFRX_CLEAR_IT(hspdif, SPDIFRX_FLAG_OVR);
ganlikun 0:13413ea9a877 946
ganlikun 0:13413ea9a877 947 /* Change the SPDIFRX error code */
ganlikun 0:13413ea9a877 948 hspdif->ErrorCode |= HAL_SPDIFRX_ERROR_OVR;
ganlikun 0:13413ea9a877 949
ganlikun 0:13413ea9a877 950 /* the transfer is not stopped */
ganlikun 0:13413ea9a877 951 HAL_SPDIFRX_ErrorCallback(hspdif);
ganlikun 0:13413ea9a877 952 }
ganlikun 0:13413ea9a877 953
ganlikun 0:13413ea9a877 954 /* SPDIFRX Parity error interrupt occurred ---------------------------------*/
ganlikun 0:13413ea9a877 955 if((__HAL_SPDIFRX_GET_FLAG(hspdif, SPDIFRX_FLAG_PERR) != RESET) && (__HAL_SPDIFRX_GET_IT_SOURCE(hspdif, SPDIFRX_IT_PERRIE) != RESET))
ganlikun 0:13413ea9a877 956 {
ganlikun 0:13413ea9a877 957 __HAL_SPDIFRX_CLEAR_IT(hspdif, SPDIFRX_FLAG_PERR);
ganlikun 0:13413ea9a877 958
ganlikun 0:13413ea9a877 959 /* Change the SPDIFRX error code */
ganlikun 0:13413ea9a877 960 hspdif->ErrorCode |= HAL_SPDIFRX_ERROR_PE;
ganlikun 0:13413ea9a877 961
ganlikun 0:13413ea9a877 962 /* the transfer is not stopped */
ganlikun 0:13413ea9a877 963 HAL_SPDIFRX_ErrorCallback(hspdif);
ganlikun 0:13413ea9a877 964 }
ganlikun 0:13413ea9a877 965 }
ganlikun 0:13413ea9a877 966
ganlikun 0:13413ea9a877 967 /**
ganlikun 0:13413ea9a877 968 * @brief Rx Transfer (Data flow) half completed callbacks
ganlikun 0:13413ea9a877 969 * @param hspdif: SPDIFRX handle
ganlikun 0:13413ea9a877 970 * @retval None
ganlikun 0:13413ea9a877 971 */
ganlikun 0:13413ea9a877 972 __weak void HAL_SPDIFRX_RxHalfCpltCallback(SPDIFRX_HandleTypeDef *hspdif)
ganlikun 0:13413ea9a877 973 {
ganlikun 0:13413ea9a877 974 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 975 UNUSED(hspdif);
ganlikun 0:13413ea9a877 976 /* NOTE : This function Should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 977 the HAL_SPDIFRX_RxCpltCallback could be implemented in the user file
ganlikun 0:13413ea9a877 978 */
ganlikun 0:13413ea9a877 979 }
ganlikun 0:13413ea9a877 980
ganlikun 0:13413ea9a877 981 /**
ganlikun 0:13413ea9a877 982 * @brief Rx Transfer (Data flow) completed callbacks
ganlikun 0:13413ea9a877 983 * @param hspdif: SPDIFRX handle
ganlikun 0:13413ea9a877 984 * @retval None
ganlikun 0:13413ea9a877 985 */
ganlikun 0:13413ea9a877 986 __weak void HAL_SPDIFRX_RxCpltCallback(SPDIFRX_HandleTypeDef *hspdif)
ganlikun 0:13413ea9a877 987 {
ganlikun 0:13413ea9a877 988 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 989 UNUSED(hspdif);
ganlikun 0:13413ea9a877 990 /* NOTE : This function Should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 991 the HAL_SPDIFRX_RxCpltCallback could be implemented in the user file
ganlikun 0:13413ea9a877 992 */
ganlikun 0:13413ea9a877 993 }
ganlikun 0:13413ea9a877 994
ganlikun 0:13413ea9a877 995 /**
ganlikun 0:13413ea9a877 996 * @brief Rx (Control flow) Transfer half completed callbacks
ganlikun 0:13413ea9a877 997 * @param hspdif: SPDIFRX handle
ganlikun 0:13413ea9a877 998 * @retval None
ganlikun 0:13413ea9a877 999 */
ganlikun 0:13413ea9a877 1000 __weak void HAL_SPDIFRX_CxHalfCpltCallback(SPDIFRX_HandleTypeDef *hspdif)
ganlikun 0:13413ea9a877 1001 {
ganlikun 0:13413ea9a877 1002 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 1003 UNUSED(hspdif);
ganlikun 0:13413ea9a877 1004 /* NOTE : This function Should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 1005 the HAL_SPDIFRX_RxCpltCallback could be implemented in the user file
ganlikun 0:13413ea9a877 1006 */
ganlikun 0:13413ea9a877 1007 }
ganlikun 0:13413ea9a877 1008
ganlikun 0:13413ea9a877 1009 /**
ganlikun 0:13413ea9a877 1010 * @brief Rx Transfer (Control flow) completed callbacks
ganlikun 0:13413ea9a877 1011 * @param hspdif: SPDIFRX handle
ganlikun 0:13413ea9a877 1012 * @retval None
ganlikun 0:13413ea9a877 1013 */
ganlikun 0:13413ea9a877 1014 __weak void HAL_SPDIFRX_CxCpltCallback(SPDIFRX_HandleTypeDef *hspdif)
ganlikun 0:13413ea9a877 1015 {
ganlikun 0:13413ea9a877 1016 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 1017 UNUSED(hspdif);
ganlikun 0:13413ea9a877 1018 /* NOTE : This function Should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 1019 the HAL_SPDIFRX_RxCpltCallback could be implemented in the user file
ganlikun 0:13413ea9a877 1020 */
ganlikun 0:13413ea9a877 1021 }
ganlikun 0:13413ea9a877 1022
ganlikun 0:13413ea9a877 1023 /**
ganlikun 0:13413ea9a877 1024 * @brief SPDIFRX error callbacks
ganlikun 0:13413ea9a877 1025 * @param hspdif: SPDIFRX handle
ganlikun 0:13413ea9a877 1026 * @retval None
ganlikun 0:13413ea9a877 1027 */
ganlikun 0:13413ea9a877 1028 __weak void HAL_SPDIFRX_ErrorCallback(SPDIFRX_HandleTypeDef *hspdif)
ganlikun 0:13413ea9a877 1029 {
ganlikun 0:13413ea9a877 1030 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 1031 UNUSED(hspdif);
ganlikun 0:13413ea9a877 1032 /* NOTE : This function Should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 1033 the HAL_SPDIFRX_ErrorCallback could be implemented in the user file
ganlikun 0:13413ea9a877 1034 */
ganlikun 0:13413ea9a877 1035 }
ganlikun 0:13413ea9a877 1036
ganlikun 0:13413ea9a877 1037 /**
ganlikun 0:13413ea9a877 1038 * @}
ganlikun 0:13413ea9a877 1039 */
ganlikun 0:13413ea9a877 1040
ganlikun 0:13413ea9a877 1041 /** @defgroup SPDIFRX_Exported_Functions_Group3 Peripheral State and Errors functions
ganlikun 0:13413ea9a877 1042 * @brief Peripheral State functions
ganlikun 0:13413ea9a877 1043 *
ganlikun 0:13413ea9a877 1044 @verbatim
ganlikun 0:13413ea9a877 1045 ===============================================================================
ganlikun 0:13413ea9a877 1046 ##### Peripheral State and Errors functions #####
ganlikun 0:13413ea9a877 1047 ===============================================================================
ganlikun 0:13413ea9a877 1048 [..]
ganlikun 0:13413ea9a877 1049 This subsection permit to get in run-time the status of the peripheral
ganlikun 0:13413ea9a877 1050 and the data flow.
ganlikun 0:13413ea9a877 1051
ganlikun 0:13413ea9a877 1052 @endverbatim
ganlikun 0:13413ea9a877 1053 * @{
ganlikun 0:13413ea9a877 1054 */
ganlikun 0:13413ea9a877 1055
ganlikun 0:13413ea9a877 1056 /**
ganlikun 0:13413ea9a877 1057 * @brief Return the SPDIFRX state
ganlikun 0:13413ea9a877 1058 * @param hspdif : SPDIFRX handle
ganlikun 0:13413ea9a877 1059 * @retval HAL state
ganlikun 0:13413ea9a877 1060 */
ganlikun 0:13413ea9a877 1061 HAL_SPDIFRX_StateTypeDef HAL_SPDIFRX_GetState(SPDIFRX_HandleTypeDef *hspdif)
ganlikun 0:13413ea9a877 1062 {
ganlikun 0:13413ea9a877 1063 return hspdif->State;
ganlikun 0:13413ea9a877 1064 }
ganlikun 0:13413ea9a877 1065
ganlikun 0:13413ea9a877 1066 /**
ganlikun 0:13413ea9a877 1067 * @brief Return the SPDIFRX error code
ganlikun 0:13413ea9a877 1068 * @param hspdif : SPDIFRX handle
ganlikun 0:13413ea9a877 1069 * @retval SPDIFRX Error Code
ganlikun 0:13413ea9a877 1070 */
ganlikun 0:13413ea9a877 1071 uint32_t HAL_SPDIFRX_GetError(SPDIFRX_HandleTypeDef *hspdif)
ganlikun 0:13413ea9a877 1072 {
ganlikun 0:13413ea9a877 1073 return hspdif->ErrorCode;
ganlikun 0:13413ea9a877 1074 }
ganlikun 0:13413ea9a877 1075
ganlikun 0:13413ea9a877 1076 /**
ganlikun 0:13413ea9a877 1077 * @}
ganlikun 0:13413ea9a877 1078 */
ganlikun 0:13413ea9a877 1079
ganlikun 0:13413ea9a877 1080 /**
ganlikun 0:13413ea9a877 1081 * @brief DMA SPDIFRX receive process (Data flow) complete callback
ganlikun 0:13413ea9a877 1082 * @param hdma : DMA handle
ganlikun 0:13413ea9a877 1083 * @retval None
ganlikun 0:13413ea9a877 1084 */
ganlikun 0:13413ea9a877 1085 static void SPDIFRX_DMARxCplt(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 1086 {
ganlikun 0:13413ea9a877 1087 SPDIFRX_HandleTypeDef* hspdif = ( SPDIFRX_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
ganlikun 0:13413ea9a877 1088
ganlikun 0:13413ea9a877 1089 /* Disable Rx DMA Request */
ganlikun 0:13413ea9a877 1090 hspdif->Instance->CR &= (uint16_t)(~SPDIFRX_CR_RXDMAEN);
ganlikun 0:13413ea9a877 1091 hspdif->RxXferCount = 0U;
ganlikun 0:13413ea9a877 1092
ganlikun 0:13413ea9a877 1093 hspdif->State = HAL_SPDIFRX_STATE_READY;
ganlikun 0:13413ea9a877 1094 HAL_SPDIFRX_RxCpltCallback(hspdif);
ganlikun 0:13413ea9a877 1095 }
ganlikun 0:13413ea9a877 1096
ganlikun 0:13413ea9a877 1097 /**
ganlikun 0:13413ea9a877 1098 * @brief DMA SPDIFRX receive process (Data flow) half complete callback
ganlikun 0:13413ea9a877 1099 * @param hdma : DMA handle
ganlikun 0:13413ea9a877 1100 * @retval None
ganlikun 0:13413ea9a877 1101 */
ganlikun 0:13413ea9a877 1102 static void SPDIFRX_DMARxHalfCplt(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 1103 {
ganlikun 0:13413ea9a877 1104 SPDIFRX_HandleTypeDef* hspdif = (SPDIFRX_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
ganlikun 0:13413ea9a877 1105
ganlikun 0:13413ea9a877 1106 HAL_SPDIFRX_RxHalfCpltCallback(hspdif);
ganlikun 0:13413ea9a877 1107 }
ganlikun 0:13413ea9a877 1108
ganlikun 0:13413ea9a877 1109 /**
ganlikun 0:13413ea9a877 1110 * @brief DMA SPDIFRX receive process (Control flow) complete callback
ganlikun 0:13413ea9a877 1111 * @param hdma : DMA handle
ganlikun 0:13413ea9a877 1112 * @retval None
ganlikun 0:13413ea9a877 1113 */
ganlikun 0:13413ea9a877 1114 static void SPDIFRX_DMACxCplt(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 1115 {
ganlikun 0:13413ea9a877 1116 SPDIFRX_HandleTypeDef* hspdif = ( SPDIFRX_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
ganlikun 0:13413ea9a877 1117
ganlikun 0:13413ea9a877 1118 /* Disable Cb DMA Request */
ganlikun 0:13413ea9a877 1119 hspdif->Instance->CR &= (uint16_t)(~SPDIFRX_CR_CBDMAEN);
ganlikun 0:13413ea9a877 1120 hspdif->CsXferCount = 0U;
ganlikun 0:13413ea9a877 1121
ganlikun 0:13413ea9a877 1122 hspdif->State = HAL_SPDIFRX_STATE_READY;
ganlikun 0:13413ea9a877 1123 HAL_SPDIFRX_CxCpltCallback(hspdif);
ganlikun 0:13413ea9a877 1124 }
ganlikun 0:13413ea9a877 1125
ganlikun 0:13413ea9a877 1126 /**
ganlikun 0:13413ea9a877 1127 * @brief DMA SPDIFRX receive process (Control flow) half complete callback
ganlikun 0:13413ea9a877 1128 * @param hdma : DMA handle
ganlikun 0:13413ea9a877 1129 * @retval None
ganlikun 0:13413ea9a877 1130 */
ganlikun 0:13413ea9a877 1131 static void SPDIFRX_DMACxHalfCplt(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 1132 {
ganlikun 0:13413ea9a877 1133 SPDIFRX_HandleTypeDef* hspdif = (SPDIFRX_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
ganlikun 0:13413ea9a877 1134
ganlikun 0:13413ea9a877 1135 HAL_SPDIFRX_CxHalfCpltCallback(hspdif);
ganlikun 0:13413ea9a877 1136 }
ganlikun 0:13413ea9a877 1137
ganlikun 0:13413ea9a877 1138 /**
ganlikun 0:13413ea9a877 1139 * @brief DMA SPDIFRX communication error callback
ganlikun 0:13413ea9a877 1140 * @param hdma : DMA handle
ganlikun 0:13413ea9a877 1141 * @retval None
ganlikun 0:13413ea9a877 1142 */
ganlikun 0:13413ea9a877 1143 static void SPDIFRX_DMAError(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 1144 {
ganlikun 0:13413ea9a877 1145 SPDIFRX_HandleTypeDef* hspdif = ( SPDIFRX_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
ganlikun 0:13413ea9a877 1146
ganlikun 0:13413ea9a877 1147 /* Disable Rx and Cb DMA Request */
ganlikun 0:13413ea9a877 1148 hspdif->Instance->CR &= (uint16_t)(~(SPDIFRX_CR_RXDMAEN | SPDIFRX_CR_CBDMAEN));
ganlikun 0:13413ea9a877 1149 hspdif->RxXferCount = 0U;
ganlikun 0:13413ea9a877 1150
ganlikun 0:13413ea9a877 1151 hspdif->State= HAL_SPDIFRX_STATE_READY;
ganlikun 0:13413ea9a877 1152
ganlikun 0:13413ea9a877 1153 /* Set the error code and execute error callback*/
ganlikun 0:13413ea9a877 1154 hspdif->ErrorCode |= HAL_SPDIFRX_ERROR_DMA;
ganlikun 0:13413ea9a877 1155 HAL_SPDIFRX_ErrorCallback(hspdif);
ganlikun 0:13413ea9a877 1156 }
ganlikun 0:13413ea9a877 1157
ganlikun 0:13413ea9a877 1158 /**
ganlikun 0:13413ea9a877 1159 * @brief Receive an amount of data (Data Flow) with Interrupt
ganlikun 0:13413ea9a877 1160 * @param hspdif: SPDIFRX handle
ganlikun 0:13413ea9a877 1161 * @retval None
ganlikun 0:13413ea9a877 1162 */
ganlikun 0:13413ea9a877 1163 static void SPDIFRX_ReceiveDataFlow_IT(SPDIFRX_HandleTypeDef *hspdif)
ganlikun 0:13413ea9a877 1164 {
ganlikun 0:13413ea9a877 1165 /* Receive data */
ganlikun 0:13413ea9a877 1166 (*hspdif->pRxBuffPtr++) = hspdif->Instance->DR;
ganlikun 0:13413ea9a877 1167 hspdif->RxXferCount--;
ganlikun 0:13413ea9a877 1168
ganlikun 0:13413ea9a877 1169 if(hspdif->RxXferCount == 0U)
ganlikun 0:13413ea9a877 1170 {
ganlikun 0:13413ea9a877 1171 /* Disable RXNE/PE and OVR interrupts */
ganlikun 0:13413ea9a877 1172 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_OVRIE | SPDIFRX_IT_PERRIE | SPDIFRX_IT_RXNE);
ganlikun 0:13413ea9a877 1173
ganlikun 0:13413ea9a877 1174 hspdif->State = HAL_SPDIFRX_STATE_READY;
ganlikun 0:13413ea9a877 1175
ganlikun 0:13413ea9a877 1176 /* Process Unlocked */
ganlikun 0:13413ea9a877 1177 __HAL_UNLOCK(hspdif);
ganlikun 0:13413ea9a877 1178
ganlikun 0:13413ea9a877 1179 HAL_SPDIFRX_RxCpltCallback(hspdif);
ganlikun 0:13413ea9a877 1180 }
ganlikun 0:13413ea9a877 1181 }
ganlikun 0:13413ea9a877 1182
ganlikun 0:13413ea9a877 1183 /**
ganlikun 0:13413ea9a877 1184 * @brief Receive an amount of data (Control Flow) with Interrupt
ganlikun 0:13413ea9a877 1185 * @param hspdif: SPDIFRX handle
ganlikun 0:13413ea9a877 1186 * @retval None
ganlikun 0:13413ea9a877 1187 */
ganlikun 0:13413ea9a877 1188 static void SPDIFRX_ReceiveControlFlow_IT(SPDIFRX_HandleTypeDef *hspdif)
ganlikun 0:13413ea9a877 1189 {
ganlikun 0:13413ea9a877 1190 /* Receive data */
ganlikun 0:13413ea9a877 1191 (*hspdif->pCsBuffPtr++) = hspdif->Instance->CSR;
ganlikun 0:13413ea9a877 1192 hspdif->CsXferCount--;
ganlikun 0:13413ea9a877 1193
ganlikun 0:13413ea9a877 1194 if(hspdif->CsXferCount == 0U)
ganlikun 0:13413ea9a877 1195 {
ganlikun 0:13413ea9a877 1196 /* Disable CSRNE interrupt */
ganlikun 0:13413ea9a877 1197 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_CSRNE);
ganlikun 0:13413ea9a877 1198
ganlikun 0:13413ea9a877 1199 hspdif->State = HAL_SPDIFRX_STATE_READY;
ganlikun 0:13413ea9a877 1200
ganlikun 0:13413ea9a877 1201 /* Process Unlocked */
ganlikun 0:13413ea9a877 1202 __HAL_UNLOCK(hspdif);
ganlikun 0:13413ea9a877 1203
ganlikun 0:13413ea9a877 1204 HAL_SPDIFRX_CxCpltCallback(hspdif);
ganlikun 0:13413ea9a877 1205 }
ganlikun 0:13413ea9a877 1206 }
ganlikun 0:13413ea9a877 1207
ganlikun 0:13413ea9a877 1208 /**
ganlikun 0:13413ea9a877 1209 * @brief This function handles SPDIFRX Communication Timeout.
ganlikun 0:13413ea9a877 1210 * @param hspdif: SPDIFRX handle
ganlikun 0:13413ea9a877 1211 * @param Flag: Flag checked
ganlikun 0:13413ea9a877 1212 * @param Status: Value of the flag expected
ganlikun 0:13413ea9a877 1213 * @param Timeout: Duration of the timeout
ganlikun 0:13413ea9a877 1214 * @retval HAL status
ganlikun 0:13413ea9a877 1215 */
ganlikun 0:13413ea9a877 1216 static HAL_StatusTypeDef SPDIFRX_WaitOnFlagUntilTimeout(SPDIFRX_HandleTypeDef *hspdif, uint32_t Flag, FlagStatus Status, uint32_t Timeout)
ganlikun 0:13413ea9a877 1217 {
ganlikun 0:13413ea9a877 1218 uint32_t tickstart = 0U;
ganlikun 0:13413ea9a877 1219
ganlikun 0:13413ea9a877 1220 /* Get tick */
ganlikun 0:13413ea9a877 1221 tickstart = HAL_GetTick();
ganlikun 0:13413ea9a877 1222
ganlikun 0:13413ea9a877 1223 /* Wait until flag is set */
ganlikun 0:13413ea9a877 1224 if(Status == RESET)
ganlikun 0:13413ea9a877 1225 {
ganlikun 0:13413ea9a877 1226 while(__HAL_SPDIFRX_GET_FLAG(hspdif, Flag) == RESET)
ganlikun 0:13413ea9a877 1227 {
ganlikun 0:13413ea9a877 1228 /* Check for the Timeout */
ganlikun 0:13413ea9a877 1229 if(Timeout != HAL_MAX_DELAY)
ganlikun 0:13413ea9a877 1230 {
ganlikun 0:13413ea9a877 1231 if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
ganlikun 0:13413ea9a877 1232 {
ganlikun 0:13413ea9a877 1233 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
ganlikun 0:13413ea9a877 1234 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_RXNE);
ganlikun 0:13413ea9a877 1235 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_CSRNE);
ganlikun 0:13413ea9a877 1236 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_PERRIE);
ganlikun 0:13413ea9a877 1237 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_OVRIE);
ganlikun 0:13413ea9a877 1238 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SBLKIE);
ganlikun 0:13413ea9a877 1239 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SYNCDIE);
ganlikun 0:13413ea9a877 1240 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_IFEIE);
ganlikun 0:13413ea9a877 1241
ganlikun 0:13413ea9a877 1242 hspdif->State= HAL_SPDIFRX_STATE_READY;
ganlikun 0:13413ea9a877 1243
ganlikun 0:13413ea9a877 1244 /* Process Unlocked */
ganlikun 0:13413ea9a877 1245 __HAL_UNLOCK(hspdif);
ganlikun 0:13413ea9a877 1246
ganlikun 0:13413ea9a877 1247 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 1248 }
ganlikun 0:13413ea9a877 1249 }
ganlikun 0:13413ea9a877 1250 }
ganlikun 0:13413ea9a877 1251 }
ganlikun 0:13413ea9a877 1252 else
ganlikun 0:13413ea9a877 1253 {
ganlikun 0:13413ea9a877 1254 while(__HAL_SPDIFRX_GET_FLAG(hspdif, Flag) != RESET)
ganlikun 0:13413ea9a877 1255 {
ganlikun 0:13413ea9a877 1256 /* Check for the Timeout */
ganlikun 0:13413ea9a877 1257 if(Timeout != HAL_MAX_DELAY)
ganlikun 0:13413ea9a877 1258 {
ganlikun 0:13413ea9a877 1259 if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
ganlikun 0:13413ea9a877 1260 {
ganlikun 0:13413ea9a877 1261 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
ganlikun 0:13413ea9a877 1262 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_RXNE);
ganlikun 0:13413ea9a877 1263 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_CSRNE);
ganlikun 0:13413ea9a877 1264 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_PERRIE);
ganlikun 0:13413ea9a877 1265 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_OVRIE);
ganlikun 0:13413ea9a877 1266 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SBLKIE);
ganlikun 0:13413ea9a877 1267 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SYNCDIE);
ganlikun 0:13413ea9a877 1268 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_IFEIE);
ganlikun 0:13413ea9a877 1269
ganlikun 0:13413ea9a877 1270 hspdif->State= HAL_SPDIFRX_STATE_READY;
ganlikun 0:13413ea9a877 1271
ganlikun 0:13413ea9a877 1272 /* Process Unlocked */
ganlikun 0:13413ea9a877 1273 __HAL_UNLOCK(hspdif);
ganlikun 0:13413ea9a877 1274
ganlikun 0:13413ea9a877 1275 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 1276 }
ganlikun 0:13413ea9a877 1277 }
ganlikun 0:13413ea9a877 1278 }
ganlikun 0:13413ea9a877 1279 }
ganlikun 0:13413ea9a877 1280 return HAL_OK;
ganlikun 0:13413ea9a877 1281 }
ganlikun 0:13413ea9a877 1282
ganlikun 0:13413ea9a877 1283 /**
ganlikun 0:13413ea9a877 1284 * @}
ganlikun 0:13413ea9a877 1285 */
ganlikun 0:13413ea9a877 1286 #endif /* STM32F446xx */
ganlikun 0:13413ea9a877 1287
ganlikun 0:13413ea9a877 1288 #endif /* HAL_SPDIFRX_MODULE_ENABLED */
ganlikun 0:13413ea9a877 1289 /**
ganlikun 0:13413ea9a877 1290 * @}
ganlikun 0:13413ea9a877 1291 */
ganlikun 0:13413ea9a877 1292
ganlikun 0:13413ea9a877 1293 /**
ganlikun 0:13413ea9a877 1294 * @}
ganlikun 0:13413ea9a877 1295 */
ganlikun 0:13413ea9a877 1296
ganlikun 0:13413ea9a877 1297 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
ganlikun 0:13413ea9a877 1298
ganlikun 0:13413ea9a877 1299