You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1636 lines
52 KiB

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