2 ******************************************************************************
\r
3 * @file stm32f7xx_hal_spdifrx.c
\r
4 * @author MCD Application Team
\r
6 * @date 06-March-2015
\r
7 * @brief This file provides firmware functions to manage the following
\r
8 * functionalities of the SPDIFRX audio interface:
\r
9 * + Initialization and Configuration
\r
10 * + Data transfers functions
\r
11 * + DMA transfers management
\r
12 * + Interrupts and flags management
\r
14 ===============================================================================
\r
15 ##### How to use this driver #####
\r
16 ===============================================================================
\r
18 The SPDIFRX HAL driver can be used as follow:
\r
20 (#) Declare SPDIFRX_HandleTypeDef handle structure.
\r
21 (#) Initialize the SPDIFRX low level resources by implement the HAL_SPDIFRX_MspInit() API:
\r
22 (##) Enable the SPDIFRX interface clock.
\r
23 (##) SPDIFRX pins configuration:
\r
24 (+++) Enable the clock for the SPDIFRX GPIOs.
\r
25 (+++) Configure these SPDIFRX pins as alternate function pull-up.
\r
26 (##) NVIC configuration if you need to use interrupt process (HAL_SPDIFRX_ReceiveControlFlow_IT() and HAL_SPDIFRX_ReceiveDataFlow_IT() API's).
\r
27 (+++) Configure the SPDIFRX interrupt priority.
\r
28 (+++) Enable the NVIC SPDIFRX IRQ handle.
\r
29 (##) DMA Configuration if you need to use DMA process (HAL_SPDIFRX_ReceiveDataFlow_DMA() and HAL_SPDIFRX_ReceiveControlFlow_DMA() API's).
\r
30 (+++) Declare a DMA handle structure for the reception of the Data Flow channel.
\r
31 (+++) Declare a DMA handle structure for the reception of the Control Flow channel.
\r
32 (+++) Enable the DMAx interface clock.
\r
33 (+++) Configure the declared DMA handle structure CtrlRx/DataRx with the required parameters.
\r
34 (+++) Configure the DMA Channel.
\r
35 (+++) Associate the initialized DMA handle to the SPDIFRX DMA CtrlRx/DataRx handle.
\r
36 (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the
\r
37 DMA CtrlRx/DataRx channel.
\r
39 (#) Program the input selection, re-tries number, wait for activity, channel status selection, data format, stereo mode and masking of user bits
\r
40 using HAL_SPDIFRX_Init() function.
\r
42 -@- The specific SPDIFRX interrupts (RXNE/CSRNE and Error Interrupts) will be managed using the macros
\r
43 __SPDIFRX_ENABLE_IT() and __SPDIFRX_DISABLE_IT() inside the receive process.
\r
44 -@- Make sure that ck_spdif clock is configured.
\r
46 (#) Three operation modes are available within this driver :
\r
48 *** Polling mode for reception operation (for debug purpose) ***
\r
49 ================================================================
\r
51 (+) Receive data flow in blocking mode using HAL_SPDIFRX_ReceiveDataFlow()
\r
52 (+) Receive control flow of data in blocking mode using HAL_SPDIFRX_ReceiveControlFlow()
\r
54 *** Interrupt mode for reception operation ***
\r
55 =========================================
\r
57 (+) Receive an amount of data (Data Flow) in non blocking mode using HAL_SPDIFRX_ReceiveDataFlow_IT()
\r
58 (+) Receive an amount of data (Control Flow) in non blocking mode using HAL_SPDIFRX_ReceiveControlFlow_IT()
\r
59 (+) At reception end of half transfer HAL_SPDIFRX_RxHalfCpltCallback is executed and user can
\r
60 add his own code by customization of function pointer HAL_SPDIFRX_RxHalfCpltCallback
\r
61 (+) At reception end of transfer HAL_SPDIFRX_RxCpltCallback is executed and user can
\r
62 add his own code by customization of function pointer HAL_SPDIFRX_RxCpltCallback
\r
63 (+) In case of transfer Error, HAL_SPDIFRX_ErrorCallback() function is executed and user can
\r
64 add his own code by customization of function pointer HAL_SPDIFRX_ErrorCallback
\r
66 *** DMA mode for reception operation ***
\r
67 ========================================
\r
69 (+) Receive an amount of data (Data Flow) in non blocking mode (DMA) using HAL_SPDIFRX_ReceiveDataFlow_DMA()
\r
70 (+) Receive an amount of data (Control Flow) in non blocking mode (DMA) using HAL_SPDIFRX_ReceiveControlFlow_DMA()
\r
71 (+) At reception end of half transfer HAL_SPDIFRX_RxHalfCpltCallback is executed and user can
\r
72 add his own code by customization of function pointer HAL_SPDIFRX_RxHalfCpltCallback
\r
73 (+) At reception end of transfer HAL_SPDIFRX_RxCpltCallback is executed and user can
\r
74 add his own code by customization of function pointer HAL_SPDIFRX_RxCpltCallback
\r
75 (+) In case of transfer Error, HAL_SPDIFRX_ErrorCallback() function is executed and user can
\r
76 add his own code by customization of function pointer HAL_SPDIFRX_ErrorCallback
\r
77 (+) Stop the DMA Transfer using HAL_SPDIFRX_DMAStop()
\r
79 *** SPDIFRX HAL driver macros list ***
\r
80 =============================================
\r
82 Below the list of most used macros in USART HAL driver.
\r
83 (+) __HAL_SPDIFRX_IDLE: Disable the specified SPDIFRX peripheral (IDEL State)
\r
84 (+) __HAL_SPDIFRX_SYNC: Enable the synchronization state of the specified SPDIFRX peripheral (SYNC State)
\r
85 (+) __HAL_SPDIFRX_RCV: Enable the receive state of the specified SPDIFRX peripheral (RCV State)
\r
86 (+) __HAL_SPDIFRX_ENABLE_IT : Enable the specified SPDIFRX interrupts
\r
87 (+) __HAL_SPDIFRX_DISABLE_IT : Disable the specified SPDIFRX interrupts
\r
88 (+) __HAL_SPDIFRX_GET_FLAG: Check whether the specified SPDIFRX flag is set or not.
\r
91 (@) You can refer to the SPDIFRX HAL driver header file for more useful macros
\r
94 ******************************************************************************
\r
97 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
\r
99 * Redistribution and use in source and binary forms, with or without modification,
\r
100 * are permitted provided that the following conditions are met:
\r
101 * 1. Redistributions of source code must retain the above copyright notice,
\r
102 * this list of conditions and the following disclaimer.
\r
103 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
104 * this list of conditions and the following disclaimer in the documentation
\r
105 * and/or other materials provided with the distribution.
\r
106 * 3. Neither the name of STMicroelectronics nor the names of its contributors
\r
107 * may be used to endorse or promote products derived from this software
\r
108 * without specific prior written permission.
\r
110 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
111 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
112 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
113 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
\r
114 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
115 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
\r
116 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
\r
117 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
\r
118 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
119 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
121 ******************************************************************************
\r
124 /* Includes ------------------------------------------------------------------*/
\r
125 #include "stm32f7xx_hal.h"
\r
127 /** @addtogroup STM32F7xx_HAL_Driver
\r
130 /** @defgroup SPDIFRX SPDIFRX
\r
131 * @brief SPDIFRX HAL module driver
\r
135 #ifdef HAL_SPDIFRX_MODULE_ENABLED
\r
137 /* Private typedef -----------------------------------------------------------*/
\r
138 /* Private define ------------------------------------------------------------*/
\r
139 #define SPDIFRX_TIMEOUT_VALUE 0xFFFF
\r
141 /* Private macro -------------------------------------------------------------*/
\r
142 /* Private variables ---------------------------------------------------------*/
\r
143 /* Private function prototypes -----------------------------------------------*/
\r
144 /** @addtogroup SPDIFRX_Private_Functions
\r
147 static void SPDIFRX_DMARxCplt(DMA_HandleTypeDef *hdma);
\r
148 static void SPDIFRX_DMARxHalfCplt(DMA_HandleTypeDef *hdma);
\r
149 static void SPDIFRX_DMACxCplt(DMA_HandleTypeDef *hdma);
\r
150 static void SPDIFRX_DMACxHalfCplt(DMA_HandleTypeDef *hdma);
\r
151 static void SPDIFRX_DMAError(DMA_HandleTypeDef *hdma);
\r
152 static void SPDIFRX_ReceiveControlFlow_IT(SPDIFRX_HandleTypeDef *hspdif);
\r
153 static void SPDIFRX_ReceiveDataFlow_IT(SPDIFRX_HandleTypeDef *hspdif);
\r
154 static HAL_StatusTypeDef SPDIFRX_WaitOnFlagUntilTimeout(SPDIFRX_HandleTypeDef *hspdif, uint32_t Flag, FlagStatus Status, uint32_t Timeout);
\r
158 /* Exported functions ---------------------------------------------------------*/
\r
160 /** @defgroup SPDIFRX_Exported_Functions SPDIFRX Exported Functions
\r
164 /** @defgroup SPDIFRX_Exported_Functions_Group1 Initialization and de-initialization functions
\r
165 * @brief Initialization and Configuration functions
\r
168 ===============================================================================
\r
169 ##### Initialization and de-initialization functions #####
\r
170 ===============================================================================
\r
171 [..] This subsection provides a set of functions allowing to initialize and
\r
172 de-initialize the SPDIFRX peripheral:
\r
174 (+) User must Implement HAL_SPDIFRX_MspInit() function in which he configures
\r
175 all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ).
\r
177 (+) Call the function HAL_SPDIFRX_Init() to configure the SPDIFRX peripheral with
\r
178 the selected configuration:
\r
179 (++) Input Selection (IN0, IN1,...)
\r
180 (++) Maximum allowed re-tries during synchronization phase
\r
181 (++) Wait for activity on SPDIF selected input
\r
182 (++) Channel status selection (from channel A or B)
\r
183 (++) Data format (LSB, MSB, ...)
\r
185 (++) User bits masking (PT,C,U,V,...)
\r
187 (+) Call the function HAL_SPDIFRX_DeInit() to restore the default configuration
\r
188 of the selected SPDIFRXx peripheral.
\r
194 * @brief Initializes the SPDIFRX according to the specified parameters
\r
195 * in the SPDIFRX_InitTypeDef and create the associated handle.
\r
196 * @param hspdif: SPDIFRX handle
\r
197 * @retval HAL status
\r
199 HAL_StatusTypeDef HAL_SPDIFRX_Init(SPDIFRX_HandleTypeDef *hspdif)
\r
201 uint32_t tmpreg = 0;
\r
203 /* Check the SPDIFRX handle allocation */
\r
209 /* Check the SPDIFRX parameters */
\r
210 assert_param(IS_STEREO_MODE(hspdif->Init.StereoMode));
\r
211 assert_param(IS_SPDIFRX_INPUT_SELECT(hspdif->Init.InputSelection));
\r
212 assert_param(IS_SPDIFRX_MAX_RETRIES(hspdif->Init.Retries));
\r
213 assert_param(IS_SPDIFRX_WAIT_FOR_ACTIVITY(hspdif->Init.WaitForActivity));
\r
214 assert_param(IS_SPDIFRX_CHANNEL(hspdif->Init.ChannelSelection));
\r
215 assert_param(IS_SPDIFRX_DATA_FORMAT(hspdif->Init.DataFormat));
\r
216 assert_param(IS_PREAMBLE_TYPE_MASK(hspdif->Init.PreambleTypeMask));
\r
217 assert_param(IS_CHANNEL_STATUS_MASK(hspdif->Init.ChannelStatusMask));
\r
218 assert_param(IS_VALIDITY_MASK(hspdif->Init.ValidityBitMask));
\r
219 assert_param(IS_PARITY_ERROR_MASK(hspdif->Init.ParityErrorMask));
\r
221 if(hspdif->State == HAL_SPDIFRX_STATE_RESET)
\r
223 /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
\r
224 HAL_SPDIFRX_MspInit(hspdif);
\r
227 /* SPDIFRX peripheral state is BUSY*/
\r
228 hspdif->State = HAL_SPDIFRX_STATE_BUSY;
\r
230 /* Disable SPDIFRX interface (IDLE State) */
\r
231 __HAL_SPDIFRX_IDLE(hspdif);
\r
233 /* Reset the old SPDIFRX CR configuration */
\r
234 tmpreg = hspdif->Instance->CR;
\r
236 tmpreg &= ~((uint16_t) SPDIFRX_CR_RXSTEO | SPDIFRX_CR_DRFMT | SPDIFRX_CR_PMSK |
\r
237 SPDIFRX_CR_VMSK | SPDIFRX_CR_CUMSK | SPDIFRX_CR_PTMSK |
\r
238 SPDIFRX_CR_CHSEL | SPDIFRX_CR_NBTR | SPDIFRX_CR_WFA |
\r
239 SPDIFRX_CR_INSEL);
\r
241 /* Sets the new configuration of the SPDIFRX peripheral */
\r
242 tmpreg |= ((uint16_t) hspdif->Init.StereoMode |
\r
243 hspdif->Init.InputSelection |
\r
244 hspdif->Init.Retries |
\r
245 hspdif->Init.WaitForActivity |
\r
246 hspdif->Init.ChannelSelection |
\r
247 hspdif->Init.DataFormat |
\r
248 hspdif->Init.PreambleTypeMask |
\r
249 hspdif->Init.ChannelStatusMask |
\r
250 hspdif->Init.ValidityBitMask |
\r
251 hspdif->Init.ParityErrorMask);
\r
253 hspdif->Instance->CR = tmpreg;
\r
255 hspdif->ErrorCode = HAL_SPDIFRX_ERROR_NONE;
\r
257 /* SPDIFRX peripheral state is READY*/
\r
258 hspdif->State = HAL_SPDIFRX_STATE_READY;
\r
264 * @brief DeInitializes the SPDIFRX peripheral
\r
265 * @param hspdif: SPDIFRX handle
\r
266 * @retval HAL status
\r
268 HAL_StatusTypeDef HAL_SPDIFRX_DeInit(SPDIFRX_HandleTypeDef *hspdif)
\r
270 /* Check the SPDIFRX handle allocation */
\r
276 /* Check the parameters */
\r
277 assert_param(IS_SPDIFRX_ALL_INSTANCE(hspdif->Instance));
\r
279 hspdif->State = HAL_SPDIFRX_STATE_BUSY;
\r
281 /* Disable SPDIFRX interface (IDLE state) */
\r
282 __HAL_SPDIFRX_IDLE(hspdif);
\r
284 /* DeInit the low level hardware: GPIO, CLOCK, NVIC... */
\r
285 HAL_SPDIFRX_MspDeInit(hspdif);
\r
287 hspdif->ErrorCode = HAL_SPDIFRX_ERROR_NONE;
\r
289 /* SPDIFRX peripheral state is RESET*/
\r
290 hspdif->State = HAL_SPDIFRX_STATE_RESET;
\r
293 __HAL_UNLOCK(hspdif);
\r
299 * @brief SPDIFRX MSP Init
\r
300 * @param hspdif: SPDIFRX handle
\r
303 __weak void HAL_SPDIFRX_MspInit(SPDIFRX_HandleTypeDef *hspdif)
\r
305 /* NOTE : This function Should not be modified, when the callback is needed,
\r
306 the HAL_SPDIFRX_MspInit could be implemented in the user file
\r
311 * @brief SPDIFRX MSP DeInit
\r
312 * @param hspdif: SPDIFRX handle
\r
315 __weak void HAL_SPDIFRX_MspDeInit(SPDIFRX_HandleTypeDef *hspdif)
\r
317 /* NOTE : This function Should not be modified, when the callback is needed,
\r
318 the HAL_SPDIFRX_MspDeInit could be implemented in the user file
\r
323 * @brief Sets the SPDIFRX dtat format according to the specified parameters
\r
324 * in the SPDIFRX_InitTypeDef.
\r
325 * @param hspdif: SPDIFRX handle
\r
326 * @param sDataFormat: SPDIFRX data format
\r
327 * @retval HAL status
\r
329 HAL_StatusTypeDef HAL_SPDIFRX_SetDataFormat(SPDIFRX_HandleTypeDef *hspdif, SPDIFRX_SetDataFormatTypeDef sDataFormat)
\r
331 uint32_t tmpreg = 0;
\r
333 /* Check the SPDIFRX handle allocation */
\r
339 /* Check the SPDIFRX parameters */
\r
340 assert_param(IS_STEREO_MODE(sDataFormat.StereoMode));
\r
341 assert_param(IS_SPDIFRX_DATA_FORMAT(sDataFormat.DataFormat));
\r
342 assert_param(IS_PREAMBLE_TYPE_MASK(sDataFormat.PreambleTypeMask));
\r
343 assert_param(IS_CHANNEL_STATUS_MASK(sDataFormat.ChannelStatusMask));
\r
344 assert_param(IS_VALIDITY_MASK(sDataFormat.ValidityBitMask));
\r
345 assert_param(IS_PARITY_ERROR_MASK(sDataFormat.ParityErrorMask));
\r
347 /* Reset the old SPDIFRX CR configuration */
\r
348 tmpreg = hspdif->Instance->CR;
\r
350 if(((tmpreg & SPDIFRX_STATE_RCV) == SPDIFRX_STATE_RCV) &&
\r
351 (((tmpreg & SPDIFRX_CR_DRFMT) != sDataFormat.DataFormat) ||
\r
352 ((tmpreg & SPDIFRX_CR_RXSTEO) != sDataFormat.StereoMode)))
\r
357 tmpreg &= ~((uint16_t) SPDIFRX_CR_RXSTEO | SPDIFRX_CR_DRFMT | SPDIFRX_CR_PMSK |
\r
358 SPDIFRX_CR_VMSK | SPDIFRX_CR_CUMSK | SPDIFRX_CR_PTMSK);
\r
360 /* Sets the new configuration of the SPDIFRX peripheral */
\r
361 tmpreg |= ((uint16_t) sDataFormat.StereoMode |
\r
362 sDataFormat.DataFormat |
\r
363 sDataFormat.PreambleTypeMask |
\r
364 sDataFormat.ChannelStatusMask |
\r
365 sDataFormat.ValidityBitMask |
\r
366 sDataFormat.ParityErrorMask);
\r
368 hspdif->Instance->CR = tmpreg;
\r
377 /** @defgroup SPDIFRX_Exported_Functions_Group2 IO operation functions
\r
378 * @brief Data transfers functions
\r
381 ===============================================================================
\r
382 ##### IO operation functions #####
\r
383 ===============================================================================
\r
385 This subsection provides a set of functions allowing to manage the SPDIFRX data
\r
388 (#) There is two mode of transfer:
\r
389 (++) Blocking mode : The communication is performed in the polling mode.
\r
390 The status of all data processing is returned by the same function
\r
391 after finishing transfer.
\r
392 (++) No-Blocking mode : The communication is performed using Interrupts
\r
393 or DMA. These functions return the status of the transfer start-up.
\r
394 The end of the data processing will be indicated through the
\r
395 dedicated SPDIFRX IRQ when using Interrupt mode or the DMA IRQ when
\r
398 (#) Blocking mode functions are :
\r
399 (++) HAL_SPDIFRX_ReceiveDataFlow()
\r
400 (++) HAL_SPDIFRX_ReceiveControlFlow()
\r
401 (+@) Do not use blocking mode to receive both control and data flow at the same time.
\r
403 (#) No-Blocking mode functions with Interrupt are :
\r
404 (++) HAL_SPDIFRX_ReceiveControlFlow_IT()
\r
405 (++) HAL_SPDIFRX_ReceiveDataFlow_IT()
\r
407 (#) No-Blocking mode functions with DMA are :
\r
408 (++) HAL_SPDIFRX_ReceiveControlFlow_DMA()
\r
409 (++) HAL_SPDIFRX_ReceiveDataFlow_DMA()
\r
411 (#) A set of Transfer Complete Callbacks are provided in No_Blocking mode:
\r
412 (++) HAL_SPDIFRX_RxCpltCallback()
\r
413 (++) HAL_SPDIFRX_ErrorCallback()
\r
421 * @brief Receives an amount of data (Data Flow) in blocking mode.
\r
422 * @param hspdif: pointer to SPDIFRX_HandleTypeDef structure that contains
\r
423 * the configuration information for SPDIFRX module.
\r
424 * @param pData: Pointer to data buffer
\r
425 * @param Size: Amount of data to be received
\r
426 * @param Timeout: Timeout duration
\r
427 * @retval HAL status
\r
429 HAL_StatusTypeDef HAL_SPDIFRX_ReceiveDataFlow(SPDIFRX_HandleTypeDef *hspdif, uint32_t *pData, uint16_t Size, uint32_t Timeout)
\r
432 if((pData == NULL ) || (Size == 0))
\r
437 if(hspdif->State == HAL_SPDIFRX_STATE_READY)
\r
439 /* Process Locked */
\r
440 __HAL_LOCK(hspdif);
\r
442 hspdif->State = HAL_SPDIFRX_STATE_BUSY;
\r
444 /* Start synchronisation */
\r
445 __HAL_SPDIFRX_SYNC(hspdif);
\r
447 /* Wait until SYNCD flag is set */
\r
448 if(SPDIFRX_WaitOnFlagUntilTimeout(hspdif, SPDIFRX_FLAG_SYNCD, RESET, Timeout) != HAL_OK)
\r
450 return HAL_TIMEOUT;
\r
453 /* Start reception */
\r
454 __HAL_SPDIFRX_RCV(hspdif);
\r
456 /* Receive data flow */
\r
459 /* Wait until RXNE flag is set */
\r
460 if(SPDIFRX_WaitOnFlagUntilTimeout(hspdif, SPDIFRX_FLAG_RXNE, RESET, Timeout) != HAL_OK)
\r
462 return HAL_TIMEOUT;
\r
465 (*pData++) = hspdif->Instance->DR;
\r
469 /* SPDIFRX ready */
\r
470 hspdif->State = HAL_SPDIFRX_STATE_READY;
\r
472 /* Process Unlocked */
\r
473 __HAL_UNLOCK(hspdif);
\r
484 * @brief Receives an amount of data (Control Flow) in blocking mode.
\r
485 * @param hspdif: pointer to a SPDIFRX_HandleTypeDef structure that contains
\r
486 * the configuration information for SPDIFRX module.
\r
487 * @param pData: Pointer to data buffer
\r
488 * @param Size: Amount of data to be received
\r
489 * @param Timeout: Timeout duration
\r
490 * @retval HAL status
\r
492 HAL_StatusTypeDef HAL_SPDIFRX_ReceiveControlFlow(SPDIFRX_HandleTypeDef *hspdif, uint32_t *pData, uint16_t Size, uint32_t Timeout)
\r
495 if((pData == NULL ) || (Size == 0))
\r
500 if(hspdif->State == HAL_SPDIFRX_STATE_READY)
\r
502 /* Process Locked */
\r
503 __HAL_LOCK(hspdif);
\r
505 hspdif->State = HAL_SPDIFRX_STATE_BUSY;
\r
507 /* Start synchronization */
\r
508 __HAL_SPDIFRX_SYNC(hspdif);
\r
510 /* Wait until SYNCD flag is set */
\r
511 if(SPDIFRX_WaitOnFlagUntilTimeout(hspdif, SPDIFRX_FLAG_SYNCD, RESET, Timeout) != HAL_OK)
\r
513 return HAL_TIMEOUT;
\r
516 /* Start reception */
\r
517 __HAL_SPDIFRX_RCV(hspdif);
\r
519 /* Receive control flow */
\r
522 /* Wait until CSRNE flag is set */
\r
523 if(SPDIFRX_WaitOnFlagUntilTimeout(hspdif, SPDIFRX_FLAG_CSRNE, RESET, Timeout) != HAL_OK)
\r
525 return HAL_TIMEOUT;
\r
528 (*pData++) = hspdif->Instance->CSR;
\r
532 /* SPDIFRX ready */
\r
533 hspdif->State = HAL_SPDIFRX_STATE_READY;
\r
535 /* Process Unlocked */
\r
536 __HAL_UNLOCK(hspdif);
\r
546 * @brief Receive an amount of data (Data Flow) in non-blocking mode with Interrupt
\r
547 * @param hspdif: SPDIFRX handle
\r
548 * @param pData: a 32-bit pointer to the Receive data buffer.
\r
549 * @param Size: number of data sample to be received .
\r
550 * @retval HAL status
\r
552 HAL_StatusTypeDef HAL_SPDIFRX_ReceiveDataFlow_IT(SPDIFRX_HandleTypeDef *hspdif, uint32_t *pData, uint16_t Size)
\r
554 if((hspdif->State == HAL_SPDIFRX_STATE_READY) || (hspdif->State == HAL_SPDIFRX_STATE_BUSY_CX))
\r
556 if((pData == NULL) || (Size == 0))
\r
561 /* Process Locked */
\r
562 __HAL_LOCK(hspdif);
\r
564 hspdif->pRxBuffPtr = pData;
\r
565 hspdif->RxXferSize = Size;
\r
566 hspdif->RxXferCount = Size;
\r
568 hspdif->ErrorCode = HAL_SPDIFRX_ERROR_NONE;
\r
570 /* Check if a receive process is ongoing or not */
\r
571 hspdif->State = HAL_SPDIFRX_STATE_BUSY_RX;
\r
574 /* Enable the SPDIFRX PE Error Interrupt */
\r
575 __HAL_SPDIFRX_ENABLE_IT(hspdif, SPDIFRX_IT_PERRIE);
\r
577 /* Enable the SPDIFRX OVR Error Interrupt */
\r
578 __HAL_SPDIFRX_ENABLE_IT(hspdif, SPDIFRX_IT_OVRIE);
\r
580 /* Process Unlocked */
\r
581 __HAL_UNLOCK(hspdif);
\r
583 /* Enable the SPDIFRX RXNE interrupt */
\r
584 __HAL_SPDIFRX_ENABLE_IT(hspdif, SPDIFRX_IT_RXNE);
\r
586 if (((SPDIFRX->CR & SPDIFRX_CR_SPDIFEN) != SPDIFRX_STATE_SYNC) || ((SPDIFRX->CR & SPDIFRX_CR_SPDIFEN) != 0x00))
\r
588 /* Start synchronization */
\r
589 __HAL_SPDIFRX_SYNC(hspdif);
\r
591 /* Wait until SYNCD flag is set */
\r
592 if(SPDIFRX_WaitOnFlagUntilTimeout(hspdif, SPDIFRX_FLAG_SYNCD, RESET, SPDIFRX_TIMEOUT_VALUE) != HAL_OK)
\r
594 return HAL_TIMEOUT;
\r
597 /* Start reception */
\r
598 __HAL_SPDIFRX_RCV(hspdif);
\r
610 * @brief Receive an amount of data (Control Flow) with Interrupt
\r
611 * @param hspdif: SPDIFRX handle
\r
612 * @param pData: a 32-bit pointer to the Receive data buffer.
\r
613 * @param Size: number of data sample (Control Flow) to be received :
\r
614 * @retval HAL status
\r
616 HAL_StatusTypeDef HAL_SPDIFRX_ReceiveControlFlow_IT(SPDIFRX_HandleTypeDef *hspdif, uint32_t *pData, uint16_t Size)
\r
618 if((hspdif->State == HAL_SPDIFRX_STATE_READY) || (hspdif->State == HAL_SPDIFRX_STATE_BUSY_RX))
\r
620 if((pData == NULL ) || (Size == 0))
\r
625 /* Process Locked */
\r
626 __HAL_LOCK(hspdif);
\r
628 hspdif->pCsBuffPtr = pData;
\r
629 hspdif->CsXferSize = Size;
\r
630 hspdif->CsXferCount = Size;
\r
632 hspdif->ErrorCode = HAL_SPDIFRX_ERROR_NONE;
\r
634 /* Check if a receive process is ongoing or not */
\r
635 hspdif->State = HAL_SPDIFRX_STATE_BUSY_CX;
\r
638 /* Enable the SPDIFRX PE Error Interrupt */
\r
639 __HAL_SPDIFRX_ENABLE_IT(hspdif, SPDIFRX_IT_PERRIE);
\r
641 /* Enable the SPDIFRX OVR Error Interrupt */
\r
642 __HAL_SPDIFRX_ENABLE_IT(hspdif, SPDIFRX_IT_OVRIE);
\r
644 /* Process Unlocked */
\r
645 __HAL_UNLOCK(hspdif);
\r
647 /* Enable the SPDIFRX CSRNE interrupt */
\r
648 __HAL_SPDIFRX_ENABLE_IT(hspdif, SPDIFRX_IT_CSRNE);
\r
650 if (((SPDIFRX->CR & SPDIFRX_CR_SPDIFEN) != SPDIFRX_STATE_SYNC) || ((SPDIFRX->CR & SPDIFRX_CR_SPDIFEN) != 0x00))
\r
652 /* Start synchronization */
\r
653 __HAL_SPDIFRX_SYNC(hspdif);
\r
655 /* Wait until SYNCD flag is set */
\r
656 if(SPDIFRX_WaitOnFlagUntilTimeout(hspdif, SPDIFRX_FLAG_SYNCD, RESET, SPDIFRX_TIMEOUT_VALUE) != HAL_OK)
\r
658 return HAL_TIMEOUT;
\r
661 /* Start reception */
\r
662 __HAL_SPDIFRX_RCV(hspdif);
\r
674 * @brief Receive an amount of data (Data Flow) mode with DMA
\r
675 * @param hspdif: SPDIFRX handle
\r
676 * @param pData: a 32-bit pointer to the Receive data buffer.
\r
677 * @param Size: number of data sample to be received :
\r
678 * @retval HAL status
\r
680 HAL_StatusTypeDef HAL_SPDIFRX_ReceiveDataFlow_DMA(SPDIFRX_HandleTypeDef *hspdif, uint32_t *pData, uint16_t Size)
\r
683 if((pData == NULL) || (Size == 0))
\r
688 if((hspdif->State == HAL_SPDIFRX_STATE_READY) || (hspdif->State == HAL_SPDIFRX_STATE_BUSY_CX))
\r
690 hspdif->pRxBuffPtr = pData;
\r
691 hspdif->RxXferSize = Size;
\r
692 hspdif->RxXferCount = Size;
\r
694 /* Process Locked */
\r
695 __HAL_LOCK(hspdif);
\r
697 hspdif->ErrorCode = HAL_SPDIFRX_ERROR_NONE;
\r
698 hspdif->State = HAL_SPDIFRX_STATE_BUSY_RX;
\r
700 /* Set the SPDIFRX Rx DMA Half transfer complete callback */
\r
701 hspdif->hdmaDrRx->XferHalfCpltCallback = SPDIFRX_DMARxHalfCplt;
\r
703 /* Set the SPDIFRX Rx DMA transfer complete callback */
\r
704 hspdif->hdmaDrRx->XferCpltCallback = SPDIFRX_DMARxCplt;
\r
706 /* Set the DMA error callback */
\r
707 hspdif->hdmaDrRx->XferErrorCallback = SPDIFRX_DMAError;
\r
709 /* Enable the DMA request */
\r
710 HAL_DMA_Start_IT(hspdif->hdmaDrRx, (uint32_t)&hspdif->Instance->DR, (uint32_t)hspdif->pRxBuffPtr, Size);
\r
712 /* Enable RXDMAEN bit in SPDIFRX CR register for data flow reception*/
\r
713 hspdif->Instance->CR |= SPDIFRX_CR_RXDMAEN;
\r
715 if (((SPDIFRX->CR & SPDIFRX_CR_SPDIFEN) != SPDIFRX_STATE_SYNC) || ((SPDIFRX->CR & SPDIFRX_CR_SPDIFEN) != 0x00))
\r
717 /* Start synchronization */
\r
718 __HAL_SPDIFRX_SYNC(hspdif);
\r
720 /* Wait until SYNCD flag is set */
\r
721 if(SPDIFRX_WaitOnFlagUntilTimeout(hspdif, SPDIFRX_FLAG_SYNCD, RESET, SPDIFRX_TIMEOUT_VALUE) != HAL_OK)
\r
723 return HAL_TIMEOUT;
\r
726 /* Start reception */
\r
727 __HAL_SPDIFRX_RCV(hspdif);
\r
730 /* Process Unlocked */
\r
731 __HAL_UNLOCK(hspdif);
\r
742 * @brief Receive an amount of data (Control Flow) with DMA
\r
743 * @param hspdif: SPDIFRX handle
\r
744 * @param pData: a 32-bit pointer to the Receive data buffer.
\r
745 * @param Size: number of data (Control Flow) sample to be received :
\r
746 * @retval HAL status
\r
748 HAL_StatusTypeDef HAL_SPDIFRX_ReceiveControlFlow_DMA(SPDIFRX_HandleTypeDef *hspdif, uint32_t *pData, uint16_t Size)
\r
751 if((pData == NULL) || (Size == 0))
\r
756 if((hspdif->State == HAL_SPDIFRX_STATE_READY) || (hspdif->State == HAL_SPDIFRX_STATE_BUSY_RX))
\r
758 hspdif->pCsBuffPtr = pData;
\r
759 hspdif->CsXferSize = Size;
\r
760 hspdif->CsXferCount = Size;
\r
762 /* Process Locked */
\r
763 __HAL_LOCK(hspdif);
\r
765 hspdif->ErrorCode = HAL_SPDIFRX_ERROR_NONE;
\r
766 hspdif->State = HAL_SPDIFRX_STATE_BUSY_CX;
\r
768 /* Set the SPDIFRX Rx DMA Half transfer complete callback */
\r
769 hspdif->hdmaCsRx->XferHalfCpltCallback = SPDIFRX_DMACxHalfCplt;
\r
771 /* Set the SPDIFRX Rx DMA transfer complete callback */
\r
772 hspdif->hdmaCsRx->XferCpltCallback = SPDIFRX_DMACxCplt;
\r
774 /* Set the DMA error callback */
\r
775 hspdif->hdmaCsRx->XferErrorCallback = SPDIFRX_DMAError;
\r
777 /* Enable the DMA request */
\r
778 HAL_DMA_Start_IT(hspdif->hdmaCsRx, (uint32_t)&hspdif->Instance->CSR, (uint32_t)hspdif->pCsBuffPtr, Size);
\r
780 /* Enable CBDMAEN bit in SPDIFRX CR register for control flow reception*/
\r
781 hspdif->Instance->CR |= SPDIFRX_CR_CBDMAEN;
\r
783 if (((SPDIFRX->CR & SPDIFRX_CR_SPDIFEN) != SPDIFRX_STATE_SYNC) || ((SPDIFRX->CR & SPDIFRX_CR_SPDIFEN) != 0x00))
\r
785 /* Start synchronization */
\r
786 __HAL_SPDIFRX_SYNC(hspdif);
\r
788 /* Wait until SYNCD flag is set */
\r
789 if(SPDIFRX_WaitOnFlagUntilTimeout(hspdif, SPDIFRX_FLAG_SYNCD, RESET, SPDIFRX_TIMEOUT_VALUE) != HAL_OK)
\r
791 return HAL_TIMEOUT;
\r
794 /* Start reception */
\r
795 __HAL_SPDIFRX_RCV(hspdif);
\r
798 /* Process Unlocked */
\r
799 __HAL_UNLOCK(hspdif);
\r
810 * @brief stop the audio stream receive from the Media.
\r
811 * @param hspdif: SPDIFRX handle
\r
814 HAL_StatusTypeDef HAL_SPDIFRX_DMAStop(SPDIFRX_HandleTypeDef *hspdif)
\r
816 /* Process Locked */
\r
817 __HAL_LOCK(hspdif);
\r
819 /* Disable the SPDIFRX DMA requests */
\r
820 hspdif->Instance->CR &= (uint16_t)(~SPDIFRX_CR_RXDMAEN);
\r
821 hspdif->Instance->CR &= (uint16_t)(~SPDIFRX_CR_CBDMAEN);
\r
823 /* Disable the SPDIFRX DMA channel */
\r
824 __HAL_DMA_DISABLE(hspdif->hdmaDrRx);
\r
825 __HAL_DMA_DISABLE(hspdif->hdmaCsRx);
\r
827 /* Disable SPDIFRX peripheral */
\r
828 __HAL_SPDIFRX_IDLE(hspdif);
\r
830 hspdif->State = HAL_SPDIFRX_STATE_READY;
\r
832 /* Process Unlocked */
\r
833 __HAL_UNLOCK(hspdif);
\r
839 * @brief This function handles SPDIFRX interrupt request.
\r
840 * @param hspdif: SPDIFRX handle
\r
841 * @retval HAL status
\r
843 void HAL_SPDIFRX_IRQHandler(SPDIFRX_HandleTypeDef *hspdif)
\r
845 /* SPDIFRX in mode Data Flow Reception ------------------------------------------------*/
\r
846 if((__HAL_SPDIFRX_GET_FLAG(hspdif, SPDIFRX_FLAG_RXNE) != RESET) && (__HAL_SPDIFRX_GET_IT_SOURCE(hspdif, SPDIFRX_IT_RXNE) != RESET))
\r
848 __HAL_SPDIFRX_CLEAR_IT(hspdif, SPDIFRX_IT_RXNE);
\r
849 SPDIFRX_ReceiveDataFlow_IT(hspdif);
\r
852 /* SPDIFRX in mode Control Flow Reception ------------------------------------------------*/
\r
853 if((__HAL_SPDIFRX_GET_FLAG(hspdif, SPDIFRX_FLAG_CSRNE) != RESET) && (__HAL_SPDIFRX_GET_IT_SOURCE(hspdif, SPDIFRX_IT_CSRNE) != RESET))
\r
855 __HAL_SPDIFRX_CLEAR_IT(hspdif, SPDIFRX_IT_CSRNE);
\r
856 SPDIFRX_ReceiveControlFlow_IT(hspdif);
\r
859 /* SPDIFRX Overrun error interrupt occurred ---------------------------------*/
\r
860 if((__HAL_SPDIFRX_GET_FLAG(hspdif, SPDIFRX_FLAG_OVR) != RESET) && (__HAL_SPDIFRX_GET_IT_SOURCE(hspdif, SPDIFRX_IT_OVRIE) != RESET))
\r
862 __HAL_SPDIFRX_CLEAR_IT(hspdif, SPDIFRX_FLAG_OVR);
\r
864 /* Change the SPDIFRX error code */
\r
865 hspdif->ErrorCode |= HAL_SPDIFRX_ERROR_OVR;
\r
867 /* the transfer is not stopped */
\r
868 HAL_SPDIFRX_ErrorCallback(hspdif);
\r
871 /* SPDIFRX Parity error interrupt occurred ---------------------------------*/
\r
872 if((__HAL_SPDIFRX_GET_FLAG(hspdif, SPDIFRX_FLAG_PERR) != RESET) && (__HAL_SPDIFRX_GET_IT_SOURCE(hspdif, SPDIFRX_IT_PERRIE) != RESET))
\r
874 __HAL_SPDIFRX_CLEAR_IT(hspdif, SPDIFRX_FLAG_PERR);
\r
876 /* Change the SPDIFRX error code */
\r
877 hspdif->ErrorCode |= HAL_SPDIFRX_ERROR_PE;
\r
879 /* the transfer is not stopped */
\r
880 HAL_SPDIFRX_ErrorCallback(hspdif);
\r
886 * @brief Rx Transfer (Data flow) half completed callbacks
\r
887 * @param hspdif: SPDIFRX handle
\r
890 __weak void HAL_SPDIFRX_RxHalfCpltCallback(SPDIFRX_HandleTypeDef *hspdif)
\r
892 /* NOTE : This function Should not be modified, when the callback is needed,
\r
893 the HAL_SPDIFRX_RxCpltCallback could be implemented in the user file
\r
898 * @brief Rx Transfer (Data flow) completed callbacks
\r
899 * @param hspdif: SPDIFRX handle
\r
902 __weak void HAL_SPDIFRX_RxCpltCallback(SPDIFRX_HandleTypeDef *hspdif)
\r
904 /* NOTE : This function Should not be modified, when the callback is needed,
\r
905 the HAL_SPDIFRX_RxCpltCallback could be implemented in the user file
\r
910 * @brief Rx (Control flow) Transfer half completed callbacks
\r
911 * @param hspdif: SPDIFRX handle
\r
914 __weak void HAL_SPDIFRX_CxHalfCpltCallback(SPDIFRX_HandleTypeDef *hspdif)
\r
916 /* NOTE : This function Should not be modified, when the callback is needed,
\r
917 the HAL_SPDIFRX_RxCpltCallback could be implemented in the user file
\r
922 * @brief Rx Transfer (Control flow) completed callbacks
\r
923 * @param hspdif: SPDIFRX handle
\r
926 __weak void HAL_SPDIFRX_CxCpltCallback(SPDIFRX_HandleTypeDef *hspdif)
\r
928 /* NOTE : This function Should not be modified, when the callback is needed,
\r
929 the HAL_SPDIFRX_RxCpltCallback could be implemented in the user file
\r
934 * @brief SPDIFRX error callbacks
\r
935 * @param hspdif: SPDIFRX handle
\r
938 __weak void HAL_SPDIFRX_ErrorCallback(SPDIFRX_HandleTypeDef *hspdif)
\r
940 /* NOTE : This function Should not be modified, when the callback is needed,
\r
941 the HAL_SPDIFRX_ErrorCallback could be implemented in the user file
\r
949 /** @defgroup SPDIFRX_Exported_Functions_Group3 Peripheral State and Errors functions
\r
950 * @brief Peripheral State functions
\r
953 ===============================================================================
\r
954 ##### Peripheral State and Errors functions #####
\r
955 ===============================================================================
\r
957 This subsection permit to get in run-time the status of the peripheral
\r
965 * @brief Return the SPDIFRX state
\r
966 * @param hspdif : SPDIFRX handle
\r
967 * @retval HAL state
\r
969 HAL_SPDIFRX_StateTypeDef HAL_SPDIFRX_GetState(SPDIFRX_HandleTypeDef *hspdif)
\r
971 return hspdif->State;
\r
975 * @brief Return the SPDIFRX error code
\r
976 * @param hspdif : SPDIFRX handle
\r
977 * @retval SPDIFRX Error Code
\r
979 uint32_t HAL_SPDIFRX_GetError(SPDIFRX_HandleTypeDef *hspdif)
\r
981 return hspdif->ErrorCode;
\r
989 * @brief DMA SPDIFRX receive process (Data flow) complete callback
\r
990 * @param hdma : DMA handle
\r
993 static void SPDIFRX_DMARxCplt(DMA_HandleTypeDef *hdma)
\r
995 SPDIFRX_HandleTypeDef* hspdif = ( SPDIFRX_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
997 /* Disable Rx DMA Request */
\r
998 hspdif->Instance->CR &= (uint16_t)(~SPDIFRX_CR_RXDMAEN);
\r
999 hspdif->RxXferCount = 0;
\r
1001 hspdif->State = HAL_SPDIFRX_STATE_READY;
\r
1002 HAL_SPDIFRX_RxCpltCallback(hspdif);
\r
1006 * @brief DMA SPDIFRX receive process (Data flow) half complete callback
\r
1007 * @param hdma : DMA handle
\r
1010 static void SPDIFRX_DMARxHalfCplt(DMA_HandleTypeDef *hdma)
\r
1012 SPDIFRX_HandleTypeDef* hspdif = (SPDIFRX_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
\r
1014 HAL_SPDIFRX_RxHalfCpltCallback(hspdif);
\r
1019 * @brief DMA SPDIFRX receive process (Control flow) complete callback
\r
1020 * @param hdma : DMA handle
\r
1023 static void SPDIFRX_DMACxCplt(DMA_HandleTypeDef *hdma)
\r
1025 SPDIFRX_HandleTypeDef* hspdif = ( SPDIFRX_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
1027 /* Disable Cb DMA Request */
\r
1028 hspdif->Instance->CR &= (uint16_t)(~SPDIFRX_CR_CBDMAEN);
\r
1029 hspdif->CsXferCount = 0;
\r
1031 hspdif->State = HAL_SPDIFRX_STATE_READY;
\r
1032 HAL_SPDIFRX_CxCpltCallback(hspdif);
\r
1036 * @brief DMA SPDIFRX receive process (Control flow) half complete callback
\r
1037 * @param hdma : DMA handle
\r
1040 static void SPDIFRX_DMACxHalfCplt(DMA_HandleTypeDef *hdma)
\r
1042 SPDIFRX_HandleTypeDef* hspdif = (SPDIFRX_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
\r
1044 HAL_SPDIFRX_CxHalfCpltCallback(hspdif);
\r
1048 * @brief DMA SPDIFRX communication error callback
\r
1049 * @param hdma : DMA handle
\r
1052 static void SPDIFRX_DMAError(DMA_HandleTypeDef *hdma)
\r
1054 SPDIFRX_HandleTypeDef* hspdif = ( SPDIFRX_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
1056 /* Disable Rx and Cb DMA Request */
\r
1057 hspdif->Instance->CR &= (uint16_t)(~(SPDIFRX_CR_RXDMAEN | SPDIFRX_CR_CBDMAEN));
\r
1058 hspdif->RxXferCount = 0;
\r
1060 hspdif->State= HAL_SPDIFRX_STATE_READY;
\r
1062 /* Set the error code and execute error callback*/
\r
1063 hspdif->ErrorCode |= HAL_SPDIFRX_ERROR_DMA;
\r
1064 HAL_SPDIFRX_ErrorCallback(hspdif);
\r
1069 * @brief Receive an amount of data (Data Flow) with Interrupt
\r
1070 * @param hspdif: SPDIFRX handle
\r
1073 static void SPDIFRX_ReceiveDataFlow_IT(SPDIFRX_HandleTypeDef *hspdif)
\r
1075 /* Receive data */
\r
1076 (*hspdif->pRxBuffPtr++) = hspdif->Instance->DR;
\r
1077 hspdif->RxXferCount--;
\r
1079 if(hspdif->RxXferCount == 0)
\r
1081 /* Disable RXNE/PE and OVR interrupts */
\r
1082 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_OVRIE | SPDIFRX_IT_PERRIE | SPDIFRX_IT_RXNE);
\r
1084 hspdif->State = HAL_SPDIFRX_STATE_READY;
\r
1086 /* Process Unlocked */
\r
1087 __HAL_UNLOCK(hspdif);
\r
1089 HAL_SPDIFRX_RxCpltCallback(hspdif);
\r
1094 * @brief Receive an amount of data (Control Flow) with Interrupt
\r
1095 * @param hspdif: SPDIFRX handle
\r
1098 static void SPDIFRX_ReceiveControlFlow_IT(SPDIFRX_HandleTypeDef *hspdif)
\r
1100 /* Receive data */
\r
1101 (*hspdif->pCsBuffPtr++) = hspdif->Instance->CSR;
\r
1102 hspdif->CsXferCount--;
\r
1104 if(hspdif->CsXferCount == 0)
\r
1106 /* Disable CSRNE interrupt */
\r
1107 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_CSRNE);
\r
1109 hspdif->State = HAL_SPDIFRX_STATE_READY;
\r
1111 /* Process Unlocked */
\r
1112 __HAL_UNLOCK(hspdif);
\r
1114 HAL_SPDIFRX_CxCpltCallback(hspdif);
\r
1119 * @brief This function handles SPDIFRX Communication Timeout.
\r
1120 * @param hspdif: SPDIFRX handle
\r
1121 * @param Flag: Flag checked
\r
1122 * @param Status: Value of the flag expected
\r
1123 * @param Timeout: Duration of the timeout
\r
1124 * @retval HAL status
\r
1126 static HAL_StatusTypeDef SPDIFRX_WaitOnFlagUntilTimeout(SPDIFRX_HandleTypeDef *hspdif, uint32_t Flag, FlagStatus Status, uint32_t Timeout)
\r
1128 uint32_t tickstart = 0;
\r
1131 tickstart = HAL_GetTick();
\r
1133 /* Wait until flag is set */
\r
1134 if(Status == RESET)
\r
1136 while(__HAL_SPDIFRX_GET_FLAG(hspdif, Flag) == RESET)
\r
1138 /* Check for the Timeout */
\r
1139 if(Timeout != HAL_MAX_DELAY)
\r
1141 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
\r
1143 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
\r
1144 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_RXNE);
\r
1145 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_CSRNE);
\r
1146 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_PERRIE);
\r
1147 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_OVRIE);
\r
1148 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SBLKIE);
\r
1149 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SYNCDIE);
\r
1150 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_IFEIE);
\r
1152 hspdif->State= HAL_SPDIFRX_STATE_READY;
\r
1154 /* Process Unlocked */
\r
1155 __HAL_UNLOCK(hspdif);
\r
1157 return HAL_TIMEOUT;
\r
1164 while(__HAL_SPDIFRX_GET_FLAG(hspdif, Flag) != RESET)
\r
1166 /* Check for the Timeout */
\r
1167 if(Timeout != HAL_MAX_DELAY)
\r
1169 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
\r
1171 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
\r
1172 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_RXNE);
\r
1173 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_CSRNE);
\r
1174 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_PERRIE);
\r
1175 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_OVRIE);
\r
1176 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SBLKIE);
\r
1177 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_SYNCDIE);
\r
1178 __HAL_SPDIFRX_DISABLE_IT(hspdif, SPDIFRX_IT_IFEIE);
\r
1180 hspdif->State= HAL_SPDIFRX_STATE_READY;
\r
1182 /* Process Unlocked */
\r
1183 __HAL_UNLOCK(hspdif);
\r
1185 return HAL_TIMEOUT;
\r
1197 #endif /* HAL_SPDIFRX_MODULE_ENABLED */
\r
1206 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r