Create release.yml
[betaflight.git] / lib / main / STM32H7 / Drivers / STM32H7xx_HAL_Driver / Src / stm32h7xx_hal_mdios.c
blob5ad0ff7ee7e36b61e83d682b1052fb5877a701f5
1 /**
2 ******************************************************************************
3 * @file stm32h7xx_hal_mdios.c
4 * @author MCD Application Team
5 * @brief MDIOS HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the MDIOS Peripheral.
8 * + Initialization and de-initialization functions
9 * + IO operation functions
10 * + Peripheral Control functions
13 @verbatim
14 ===============================================================================
15 ##### How to use this driver #####
16 ===============================================================================
17 [..]
18 The MDIOS HAL driver can be used as follow:
20 (#) Declare a MDIOS_HandleTypeDef handle structure.
22 (#) Initialize the MDIOS low level resources by implementing the HAL_MDIOS_MspInit() API:
23 (##) Enable the MDIOS interface clock.
24 (##) MDIOS pins configuration:
25 (+++) Enable clocks for the MDIOS GPIOs.
26 (+++) Configure the MDIOS pins as alternate function.
27 (##) NVIC configuration if you need to use interrupt process:
28 (+++) Configure the MDIOS interrupt priority.
29 (+++) Enable the NVIC MDIOS IRQ handle.
31 (#) Program the Port Address and the Preamble Check in the Init structure.
33 (#) Initialize the MDIOS registers by calling the HAL_MDIOS_Init() API.
35 (#) Perform direct slave read/write operations using the following APIs:
36 (##) Read the value of a DINn register: HAL_MDIOS_ReadReg()
37 (##) Write a value to a DOUTn register: HAL_MDIOS_WriteReg()
39 (#) Get the Master read/write operations flags using the following APIs:
40 (##) Bit map of DOUTn registers read by Master: HAL_MDIOS_GetReadRegAddress()
41 (##) Bit map of DINn registers written by Master : HAL_MDIOS_GetWrittenRegAddress()
43 (#) Clear the read/write flags using the following APIs:
44 (##) Clear read flags of a set of registers: HAL_MDIOS_ClearReadRegAddress()
45 (##) Clear write flags of a set of registers: HAL_MDIOS_ClearWriteRegAddress()
47 (#) Enable interrupts on events using HAL_MDIOS_EnableEvents(), when called
48 the MDIOS will generate an interrupt in the following cases:
49 (##) a DINn register written by the Master
50 (##) a DOUTn register read by the Master
51 (##) an error occur
53 (@) A callback is executed for each genereted interrupt, so the driver provide the following
54 HAL_MDIOS_WriteCpltCallback(), HAL_MDIOS_ReadCpltCallback() and HAL_MDIOS_ErrorCallback()
55 (@) HAL_MDIOS_IRQHandler() must be called from the MDIOS IRQ Handler, to handle the interrupt
56 and execute the previous callbacks
58 (#) Reset the MDIOS peripheral and all related ressources by calling the HAL_MDIOS_DeInit() API.
59 (##) HAL_MDIOS_MspDeInit() must be implemented to reset low level ressources
60 (GPIO, Clocks, NVIC configuration ...)
62 *** Callback registration ***
63 =============================================
65 The compilation define USE_HAL_MDIOS_REGISTER_CALLBACKS when set to 1
66 allows the user to configure dynamically the driver callbacks.
67 Use Function @ref HAL_MDIOS_RegisterCallback() to register an interrupt callback.
69 Function @ref HAL_MDIOS_RegisterCallback() allows to register following callbacks:
70 (+) WriteCpltCallback : Write Complete Callback.
71 (+) ReadCpltCallback : Read Complete Callback.
72 (+) ErrorCallback : Error Callback.
73 (+) WakeUpCallback : Wake UP Callback
74 (+) MspInitCallback : MspInit Callback.
75 (+) MspDeInitCallback : MspDeInit Callback.
77 This function takes as parameters the HAL peripheral handle, the Callback ID
78 and a pointer to the user callback function.
80 Use function @ref HAL_MDIOS_UnRegisterCallback() to reset a callback to the default
81 weak function.
82 @ref HAL_MDIOS_UnRegisterCallback takes as parameters the HAL peripheral handle,
83 and the Callback ID.
84 This function allows to reset following callbacks:
85 (+) WriteCpltCallback : Write Complete Callback.
86 (+) ReadCpltCallback : Read Complete Callback.
87 (+) ErrorCallback : Error Callback.
88 (+) WakeUpCallback : Wake UP Callback
89 (+) MspInitCallback : MspInit Callback.
90 (+) MspDeInitCallback : MspDeInit Callback.
92 By default, after the HAL_MDIOS_Init and when the state is HAL_MDIOS_STATE_RESET
93 all callbacks are set to the corresponding weak functions:
94 examples @ref HAL_MDIOS_WriteCpltCallback(), @ref HAL_MDIOS_ReadCpltCallback().
95 Exception done for MspInit and MspDeInit functions that are
96 reset to the legacy weak function in the HAL_MDIOS_Init/ @ref HAL_MDIOS_DeInit only when
97 these callbacks are null (not registered beforehand).
98 if not, MspInit or MspDeInit are not null, the HAL_MDIOS_Init/ @ref HAL_MDIOS_DeInit
99 keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
101 Callbacks can be registered/unregistered in HAL_MDIOS_STATE_READY state only.
102 Exception done MspInit/MspDeInit that can be registered/unregistered
103 in HAL_MDIOS_STATE_READY or HAL_MDIOS_STATE_RESET state,
104 thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
105 In that case first register the MspInit/MspDeInit user callbacks
106 using @ref HAL_MDIOS_RegisterCallback() before calling @ref HAL_MDIOS_DeInit
107 or HAL_MDIOS_Init function.
109 When The compilation define USE_HAL_MDIOS_REGISTER_CALLBACKS is set to 0 or
110 not defined, the callback registration feature is not available and all callbacks
111 are set to the corresponding weak functions.
114 @endverbatim
115 ******************************************************************************
116 * @attention
118 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
119 * All rights reserved.</center></h2>
121 * This software component is licensed by ST under BSD 3-Clause license,
122 * the "License"; You may not use this file except in compliance with the
123 * License. You may obtain a copy of the License at:
124 * opensource.org/licenses/BSD-3-Clause
126 ******************************************************************************
129 /* Includes ------------------------------------------------------------------*/
130 #include "stm32h7xx_hal.h"
132 /** @addtogroup STM32H7xx_HAL_Driver
133 * @{
135 #if defined (MDIOS)
136 /** @defgroup MDIOS MDIOS
137 * @brief HAL MDIOS module driver
138 * @{
140 #ifdef HAL_MDIOS_MODULE_ENABLED
144 /* Private typedef -----------------------------------------------------------*/
145 /* Private define ------------------------------------------------------------*/
146 #define MDIOS_PORT_ADDRESS_SHIFT ((uint32_t)8)
147 #define MDIOS_ALL_REG_FLAG ((uint32_t)0xFFFFFFFFU)
148 #define MDIOS_ALL_ERRORS_FLAG ((uint32_t)(MDIOS_SR_PERF | MDIOS_SR_SERF | MDIOS_SR_TERF))
150 #define MDIOS_DIN_BASE_ADDR (MDIOS_BASE + 0x100U)
151 #define MDIOS_DOUT_BASE_ADDR (MDIOS_BASE + 0x180U)
153 /* Private macro -------------------------------------------------------------*/
154 /* Private variables ---------------------------------------------------------*/
155 /* Private function prototypes -----------------------------------------------*/
156 #if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
157 static void MDIOS_InitCallbacksToDefault(MDIOS_HandleTypeDef *hmdios);
158 #endif /* USE_HAL_MDIOS_REGISTER_CALLBACKS */
159 /* Private functions ---------------------------------------------------------*/
160 /* Exported functions --------------------------------------------------------*/
161 /** @defgroup MDIOS_Exported_Functions MDIOS Exported Functions
162 * @{
165 /** @defgroup MDIOS_Exported_Functions_Group1 Initialization/de-initialization functions
166 * @brief Initialization and Configuration functions
168 @verbatim
169 ===============================================================================
170 ##### Initialization and Configuration functions #####
171 ===============================================================================
172 [..]
173 This subsection provides a set of functions allowing to initialize the MDIOS
174 (+) The following parameters can be configured:
175 (++) Port Address
176 (++) Preamble Check
178 @endverbatim
179 * @{
183 * @brief Initializes the MDIOS according to the specified parameters in
184 * the MDIOS_InitTypeDef and creates the associated handle .
185 * @param hmdios: pointer to a MDIOS_HandleTypeDef structure that contains
186 * the configuration information for MDIOS module
187 * @retval HAL status
189 HAL_StatusTypeDef HAL_MDIOS_Init(MDIOS_HandleTypeDef *hmdios)
191 uint32_t tmpcr;
193 /* Check the MDIOS handle allocation */
194 if(hmdios == NULL)
196 return HAL_ERROR;
199 /* Check the parameters */
200 assert_param(IS_MDIOS_ALL_INSTANCE(hmdios->Instance));
201 assert_param(IS_MDIOS_PORTADDRESS(hmdios->Init.PortAddress));
202 assert_param(IS_MDIOS_PREAMBLECHECK(hmdios->Init.PreambleCheck));
204 #if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
206 if(hmdios->State == HAL_MDIOS_STATE_RESET)
208 MDIOS_InitCallbacksToDefault(hmdios);
210 if(hmdios->MspInitCallback == NULL)
212 hmdios->MspInitCallback = HAL_MDIOS_MspInit;
215 /* Init the low level hardware */
216 hmdios->MspInitCallback(hmdios);
219 #else
221 if(hmdios->State == HAL_MDIOS_STATE_RESET)
223 /* Init the low level hardware */
224 HAL_MDIOS_MspInit(hmdios);
227 #endif /* (USE_HAL_MDIOS_REGISTER_CALLBACKS) */
229 /* Change the MDIOS state */
230 hmdios->State = HAL_MDIOS_STATE_BUSY;
232 /* Get the MDIOS CR value */
233 tmpcr = hmdios->Instance->CR;
235 /* Clear PORT_ADDRESS, DPC and EN bits */
236 tmpcr &= ((uint32_t)~(MDIOS_CR_EN | MDIOS_CR_DPC | MDIOS_CR_PORT_ADDRESS));
238 /* Set MDIOS control parametrs and enable the peripheral */
239 tmpcr |= (uint32_t)(((hmdios->Init.PortAddress) << MDIOS_PORT_ADDRESS_SHIFT) |\
240 (hmdios->Init.PreambleCheck) | \
241 (MDIOS_CR_EN));
243 /* Write the MDIOS CR */
244 hmdios->Instance->CR = tmpcr;
246 hmdios->ErrorCode = HAL_MDIOS_ERROR_NONE;
248 /* Change the MDIOS state */
249 hmdios->State = HAL_MDIOS_STATE_READY;
251 /* Release Lock */
252 __HAL_UNLOCK(hmdios);
254 /* Return function status */
255 return HAL_OK;
260 * @brief DeInitializes the MDIOS peripheral.
261 * @param hmdios: MDIOS handle
262 * @retval HAL status
264 HAL_StatusTypeDef HAL_MDIOS_DeInit(MDIOS_HandleTypeDef *hmdios)
266 /* Check the MDIOS handle allocation */
267 if(hmdios == NULL)
269 return HAL_ERROR;
272 /* Check the parameters */
273 assert_param(IS_MDIOS_ALL_INSTANCE(hmdios->Instance));
275 /* Change the MDIOS state */
276 hmdios->State = HAL_MDIOS_STATE_BUSY;
278 /* Disable the Peripheral */
279 __HAL_MDIOS_DISABLE(hmdios);
281 #if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
283 if(hmdios->MspDeInitCallback == NULL)
285 hmdios->MspDeInitCallback = HAL_MDIOS_MspDeInit;
287 /* DeInit the low level hardware */
288 hmdios->MspDeInitCallback(hmdios);
289 #else
291 /* DeInit the low level hardware */
292 HAL_MDIOS_MspDeInit(hmdios);
294 #endif /* (USE_HAL_MDIOS_REGISTER_CALLBACKS) */
296 /* Change the MDIOS state */
297 hmdios->State = HAL_MDIOS_STATE_RESET;
299 /* Release Lock */
300 __HAL_UNLOCK(hmdios);
302 /* Return function status */
303 return HAL_OK;
307 * @brief MDIOS MSP Init
308 * @param hmdios: mdios handle
309 * @retval None
311 __weak void HAL_MDIOS_MspInit(MDIOS_HandleTypeDef *hmdios)
313 /* Prevent unused argument(s) compilation warning */
314 UNUSED(hmdios);
316 /* NOTE : This function should not be modified, when the callback is needed,
317 the HAL_MDIOS_MspInit can be implemented in the user file
322 * @brief MDIOS MSP DeInit
323 * @param hmdios: mdios handle
324 * @retval None
326 __weak void HAL_MDIOS_MspDeInit(MDIOS_HandleTypeDef *hmdios)
328 /* Prevent unused argument(s) compilation warning */
329 UNUSED(hmdios);
331 /* NOTE : This function should not be modified, when the callback is needed,
332 the HAL_MDIOS_MspDeInit can be implemented in the user file
336 #if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
338 * @brief Register a User MDIOS Callback
339 * To be used instead of the weak predefined callback
340 * @param hmdios mdios handle
341 * @param CallbackID ID of the callback to be registered
342 * This parameter can be one of the following values:
343 * @arg @ref HAL_MDIOS_WRITE_COMPLETE_CB_ID Write Complete Callback ID
344 * @arg @ref HAL_MDIOS_READ_COMPLETE_CB_ID Read Complete Callback ID
345 * @arg @ref HAL_MDIOS_ERROR_CB_ID Error Callback ID
346 * @arg @ref HAL_MDIOS_WAKEUP_CB_ID Wake Up Callback ID
347 * @arg @ref HAL_MDIOS_MSPINIT_CB_ID MspInit callback ID
348 * @arg @ref HAL_MDIOS_MSPDEINIT_CB_ID MspDeInit callback ID
349 * @param pCallback pointer to the Callback function
350 * @retval status
352 HAL_StatusTypeDef HAL_MDIOS_RegisterCallback(MDIOS_HandleTypeDef *hmdios, HAL_MDIOS_CallbackIDTypeDef CallbackID, pMDIOS_CallbackTypeDef pCallback)
354 HAL_StatusTypeDef status = HAL_OK;
356 if(pCallback == NULL)
358 /* Update the error code */
359 hmdios->ErrorCode |= HAL_MDIOS_ERROR_INVALID_CALLBACK;
361 return HAL_ERROR;
363 /* Process locked */
364 __HAL_LOCK(hmdios);
366 if(hmdios->State == HAL_MDIOS_STATE_READY)
368 switch (CallbackID)
370 case HAL_MDIOS_WRITE_COMPLETE_CB_ID :
371 hmdios->WriteCpltCallback = pCallback;
372 break;
374 case HAL_MDIOS_READ_COMPLETE_CB_ID :
375 hmdios->ReadCpltCallback = pCallback;
376 break;
378 case HAL_MDIOS_ERROR_CB_ID :
379 hmdios->ErrorCallback = pCallback;
380 break;
382 case HAL_MDIOS_WAKEUP_CB_ID :
383 hmdios->WakeUpCallback = pCallback;
384 break;
386 case HAL_MDIOS_MSPINIT_CB_ID :
387 hmdios->MspInitCallback = pCallback;
388 break;
390 case HAL_MDIOS_MSPDEINIT_CB_ID :
391 hmdios->MspDeInitCallback = pCallback;
392 break;
394 default :
395 /* Update the error code */
396 hmdios->ErrorCode |= HAL_MDIOS_ERROR_INVALID_CALLBACK;
397 /* Return error status */
398 status = HAL_ERROR;
399 break;
402 else if(hmdios->State == HAL_MDIOS_STATE_RESET)
404 switch (CallbackID)
406 case HAL_MDIOS_MSPINIT_CB_ID :
407 hmdios->MspInitCallback = pCallback;
408 break;
410 case HAL_MDIOS_MSPDEINIT_CB_ID :
411 hmdios->MspDeInitCallback = pCallback;
412 break;
414 default :
415 /* Update the error code */
416 hmdios->ErrorCode |= HAL_MDIOS_ERROR_INVALID_CALLBACK;
417 /* Return error status */
418 status = HAL_ERROR;
419 break;
422 else
424 /* Update the error code */
425 hmdios->ErrorCode |= HAL_MDIOS_ERROR_INVALID_CALLBACK;
426 /* Return error status */
427 status = HAL_ERROR;
430 /* Release Lock */
431 __HAL_UNLOCK(hmdios);
433 return status;
437 * @brief Unregister an MDIOS Callback
438 * MDIOS callabck is redirected to the weak predefined callback
439 * @param hmdios mdios handle
440 * @param CallbackID ID of the callback to be unregistered
441 * This parameter can be one of the following values:
442 * @arg @ref HAL_MDIOS_WRITE_COMPLETE_CB_ID Write Complete Callback ID
443 * @arg @ref HAL_MDIOS_READ_COMPLETE_CB_ID Read Complete Callback ID
444 * @arg @ref HAL_MDIOS_ERROR_CB_ID Error Callback ID
445 * @arg @ref HAL_MDIOS_WAKEUP_CB_ID Wake Up Callback ID
446 * @arg @ref HAL_MDIOS_MSPINIT_CB_ID MspInit callback ID
447 * @arg @ref HAL_MDIOS_MSPDEINIT_CB_ID MspDeInit callback ID
448 * @retval status
450 HAL_StatusTypeDef HAL_MDIOS_UnRegisterCallback(MDIOS_HandleTypeDef *hmdios, HAL_MDIOS_CallbackIDTypeDef CallbackID)
452 HAL_StatusTypeDef status = HAL_OK;
454 /* Process locked */
455 __HAL_LOCK(hmdios);
457 if(hmdios->State == HAL_MDIOS_STATE_READY)
459 switch (CallbackID)
461 case HAL_MDIOS_WRITE_COMPLETE_CB_ID :
462 hmdios->WriteCpltCallback = HAL_MDIOS_WriteCpltCallback;
463 break;
465 case HAL_MDIOS_READ_COMPLETE_CB_ID :
466 hmdios->ReadCpltCallback = HAL_MDIOS_ReadCpltCallback;
467 break;
469 case HAL_MDIOS_ERROR_CB_ID :
470 hmdios->ErrorCallback = HAL_MDIOS_ErrorCallback;
471 break;
473 case HAL_MDIOS_WAKEUP_CB_ID :
474 hmdios->WakeUpCallback = HAL_MDIOS_WakeUpCallback;
475 break;
477 case HAL_MDIOS_MSPINIT_CB_ID :
478 hmdios->MspInitCallback = HAL_MDIOS_MspInit;
479 break;
481 case HAL_MDIOS_MSPDEINIT_CB_ID :
482 hmdios->MspDeInitCallback = HAL_MDIOS_MspDeInit;
483 break;
485 default :
486 /* Update the error code */
487 hmdios->ErrorCode |= HAL_MDIOS_ERROR_INVALID_CALLBACK;
488 /* Return error status */
489 status = HAL_ERROR;
490 break;
493 else if(hmdios->State == HAL_MDIOS_STATE_RESET)
495 switch (CallbackID)
497 case HAL_MDIOS_MSPINIT_CB_ID :
498 hmdios->MspInitCallback = HAL_MDIOS_MspInit;
499 break;
501 case HAL_MDIOS_MSPDEINIT_CB_ID :
502 hmdios->MspDeInitCallback = HAL_MDIOS_MspDeInit;
503 break;
505 default :
506 /* Update the error code */
507 hmdios->ErrorCode |= HAL_MDIOS_ERROR_INVALID_CALLBACK;
508 /* Return error status */
509 status = HAL_ERROR;
510 break;
513 else
515 /* Update the error code */
516 hmdios->ErrorCode |= HAL_MDIOS_ERROR_INVALID_CALLBACK;
517 /* Return error status */
518 status = HAL_ERROR;
521 /* Release Lock */
522 __HAL_UNLOCK(hmdios);
524 return status;
526 #endif /* USE_HAL_MDIOS_REGISTER_CALLBACKS */
529 * @}
532 /** @defgroup MDIOS_Exported_Functions_Group2 IO operation functions
533 * @brief MDIOS Read/Write functions
535 @verbatim
536 ===============================================================================
537 ##### IO operation functions #####
538 ===============================================================================
539 This subsection provides a set of functions allowing to manage the MDIOS
540 read and write operations.
542 (#) APIs that allow to the MDIOS to read/write from/to the
543 values of one of the DINn/DOUTn registers:
544 (+) Read the value of a DINn register: HAL_MDIOS_ReadReg()
545 (+) Write a value to a DOUTn register: HAL_MDIOS_WriteReg()
547 (#) APIs that provide if there are some Slave registres have been
548 read or written by the Master:
549 (+) DOUTn registers read by Master: HAL_MDIOS_GetReadRegAddress()
550 (+) DINn registers written by Master : HAL_MDIOS_GetWrittenRegAddress()
552 (#) APIs that Clear the read/write flags:
553 (+) Clear read registers flags: HAL_MDIOS_ClearReadRegAddress()
554 (+) Clear write registers flags: HAL_MDIOS_ClearWriteRegAddress()
556 (#) A set of Callbacks are provided:
557 (+) HAL_MDIOS_WriteCpltCallback()
558 (+) HAL_MDIOS_ReadCpltCallback()
559 (+) HAL_MDIOS_ErrorCallback()
561 @endverbatim
562 * @{
566 * @brief Writes to an MDIOS output register
567 * @param hmdios: mdios handle
568 * @param RegNum: MDIOS output register address
569 * @param Data: Data to write
570 * @retval HAL status
572 HAL_StatusTypeDef HAL_MDIOS_WriteReg(MDIOS_HandleTypeDef *hmdios, uint32_t RegNum, uint16_t Data)
574 uint32_t tmpreg;
576 /* Check the parameters */
577 assert_param(IS_MDIOS_REGISTER(RegNum));
579 /* Process Locked */
580 __HAL_LOCK(hmdios);
582 /* Get the addr of output register to be written by the MDIOS */
583 tmpreg = MDIOS_DOUT_BASE_ADDR + (4U * RegNum);
585 /* Write to DOUTn register */
586 *((uint32_t *)tmpreg) = Data;
588 /* Process Unlocked */
589 __HAL_UNLOCK(hmdios);
591 return HAL_OK;
595 * @brief Reads an MDIOS input register
596 * @param hmdios: mdios handle
597 * @param RegNum: MDIOS input register address
598 * @param pData: pointer to Data
599 * @retval HAL status
601 HAL_StatusTypeDef HAL_MDIOS_ReadReg(MDIOS_HandleTypeDef *hmdios, uint32_t RegNum, uint16_t *pData)
603 uint32_t tmpreg;
605 /* Check the parameters */
606 assert_param(IS_MDIOS_REGISTER(RegNum));
608 /* Process Locked */
609 __HAL_LOCK(hmdios);
611 /* Get the addr of input register to be read by the MDIOS */
612 tmpreg = MDIOS_DIN_BASE_ADDR + (4U * RegNum);
614 /* Read DINn register */
615 *pData = (uint16_t)(*((uint32_t *)tmpreg));
617 /* Process Unlocked */
618 __HAL_UNLOCK(hmdios);
620 return HAL_OK;
624 * @brief Gets Written registers by MDIO master
625 * @param hmdios: mdios handle
626 * @retval bit map of written registers addresses
628 uint32_t HAL_MDIOS_GetWrittenRegAddress(MDIOS_HandleTypeDef *hmdios)
630 return hmdios->Instance->WRFR;
634 * @brief Gets Read registers by MDIO master
635 * @param hmdios: mdios handle
636 * @retval bit map of read registers addresses
638 uint32_t HAL_MDIOS_GetReadRegAddress(MDIOS_HandleTypeDef *hmdios)
640 return hmdios->Instance->RDFR;
644 * @brief Clears Write registers flag
645 * @param hmdios: mdios handle
646 * @param RegNum: registers addresses to be cleared
647 * @retval HAL status
649 HAL_StatusTypeDef HAL_MDIOS_ClearWriteRegAddress(MDIOS_HandleTypeDef *hmdios, uint32_t RegNum)
651 /* Check the parameters */
652 assert_param(IS_MDIOS_REGISTER(RegNum));
654 /* Process Locked */
655 __HAL_LOCK(hmdios);
657 /* Clear write registers flags */
658 hmdios->Instance->CWRFR |= (RegNum);
660 /* Release Lock */
661 __HAL_UNLOCK(hmdios);
663 return HAL_OK;
667 * @brief Clears Read register flag
668 * @param hmdios: mdios handle
669 * @param RegNum: registers addresses to be cleared
670 * @retval HAL status
672 HAL_StatusTypeDef HAL_MDIOS_ClearReadRegAddress(MDIOS_HandleTypeDef *hmdios, uint32_t RegNum)
674 /* Check the parameters */
675 assert_param(IS_MDIOS_REGISTER(RegNum));
677 /* Process Locked */
678 __HAL_LOCK(hmdios);
680 /* Clear read registers flags */
681 hmdios->Instance->CRDFR |= (RegNum);
683 /* Release Lock */
684 __HAL_UNLOCK(hmdios);
686 return HAL_OK;
690 * @brief Enables Events for MDIOS peripheral
691 * @param hmdios: mdios handle
692 * @retval HAL status
694 HAL_StatusTypeDef HAL_MDIOS_EnableEvents(MDIOS_HandleTypeDef *hmdios)
696 /* Process Locked */
697 __HAL_LOCK(hmdios);
699 /* Enable MDIOS interrupts: Register Write, Register Read and Error ITs */
700 __HAL_MDIOS_ENABLE_IT(hmdios, (MDIOS_IT_WRITE | MDIOS_IT_READ | MDIOS_IT_ERROR));
702 /* Process Unlocked */
703 __HAL_UNLOCK(hmdios);
705 return HAL_OK;
709 * @brief This function handles MDIOS interrupt request.
710 * @param hmdios: MDIOS handle
711 * @retval None
713 void HAL_MDIOS_IRQHandler(MDIOS_HandleTypeDef *hmdios)
715 /* Write Register Interrupt enabled ? */
716 if(__HAL_MDIOS_GET_IT_SOURCE(hmdios, MDIOS_IT_WRITE) != (uint32_t)RESET)
718 /* Write register flag */
719 if(HAL_MDIOS_GetWrittenRegAddress(hmdios) != (uint32_t)RESET)
721 #if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
722 /*Call registered Write complete callback*/
723 hmdios->WriteCpltCallback(hmdios);
724 #else
725 /* Write callback function */
726 HAL_MDIOS_WriteCpltCallback(hmdios);
727 #endif /* USE_HAL_MDIOS_REGISTER_CALLBACKS */
729 /* Clear write register flag */
730 hmdios->Instance->CWRFR |= MDIOS_ALL_REG_FLAG;
734 /* Read Register Interrupt enabled ? */
735 if(__HAL_MDIOS_GET_IT_SOURCE(hmdios, MDIOS_IT_READ) != (uint32_t)RESET)
737 /* Read register flag */
738 if(HAL_MDIOS_GetReadRegAddress(hmdios) != (uint32_t)RESET)
740 #if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
741 /*Call registered Read complete callback*/
742 hmdios->ReadCpltCallback(hmdios);
743 #else
744 /* Read callback function */
745 HAL_MDIOS_ReadCpltCallback(hmdios);
746 #endif /* USE_HAL_MDIOS_REGISTER_CALLBACKS */
748 /* Clear read register flag */
749 hmdios->Instance->CRDFR |= MDIOS_ALL_REG_FLAG;
753 /* Error Interrupt enabled ? */
754 if(__HAL_MDIOS_GET_IT_SOURCE(hmdios, MDIOS_IT_ERROR) != (uint32_t)RESET)
756 /* All Errors Flag */
757 if(__HAL_MDIOS_GET_ERROR_FLAG(hmdios, MDIOS_ALL_ERRORS_FLAG) != (uint32_t)RESET)
759 hmdios->ErrorCode |= HAL_MDIOS_ERROR_DATA;
761 #if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
762 /*Call registered Error callback*/
763 hmdios->ErrorCallback(hmdios);
764 #else
765 /* Error Callback */
766 HAL_MDIOS_ErrorCallback(hmdios);
767 #endif /* USE_HAL_MDIOS_REGISTER_CALLBACKS */
769 /* Clear errors flag */
770 __HAL_MDIOS_CLEAR_ERROR_FLAG(hmdios, MDIOS_ALL_ERRORS_FLAG);
772 hmdios->ErrorCode = HAL_MDIOS_ERROR_NONE;
774 #if defined(DUAL_CORE)
776 if (HAL_GetCurrentCPUID() == CM7_CPUID)
778 if(__HAL_MDIOS_WAKEUP_EXTI_GET_FLAG(MDIOS_WAKEUP_EXTI_LINE) != (uint32_t)RESET)
780 /* Clear MDIOS WAKEUP Exti pending bit */
781 __HAL_MDIOS_WAKEUP_EXTI_CLEAR_FLAG(MDIOS_WAKEUP_EXTI_LINE);
783 #if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
784 /*Call registered WakeUp callback*/
785 hmdios->WakeUpCallback(hmdios);
786 #else
787 /* MDIOS WAKEUP callback */
788 HAL_MDIOS_WakeUpCallback(hmdios);
789 #endif /* USE_HAL_MDIOS_REGISTER_CALLBACKS */
792 else
794 if(__HAL_MDIOS_WAKEUP_EXTID2_GET_FLAG(MDIOS_WAKEUP_EXTI_LINE) != (uint32_t)RESET)
796 /* Clear MDIOS WAKEUP Exti D2 pending bit */
797 __HAL_MDIOS_WAKEUP_EXTID2_CLEAR_FLAG(MDIOS_WAKEUP_EXTI_LINE);
798 #if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
799 /*Call registered WakeUp callback*/
800 hmdios->WakeUpCallback(hmdios);
801 #else
802 /* MDIOS WAKEUP callback */
803 HAL_MDIOS_WakeUpCallback(hmdios);
804 #endif /* USE_HAL_MDIOS_REGISTER_CALLBACKS */
807 #else
808 /* check MDIOS WAKEUP exti flag */
809 if(__HAL_MDIOS_WAKEUP_EXTI_GET_FLAG(MDIOS_WAKEUP_EXTI_LINE) != (uint32_t)RESET)
811 /* Clear MDIOS WAKEUP Exti pending bit */
812 __HAL_MDIOS_WAKEUP_EXTI_CLEAR_FLAG(MDIOS_WAKEUP_EXTI_LINE);
813 #if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
814 /*Call registered WakeUp callback*/
815 hmdios->WakeUpCallback(hmdios);
816 #else
817 /* MDIOS WAKEUP callback */
818 HAL_MDIOS_WakeUpCallback(hmdios);
819 #endif /* USE_HAL_MDIOS_REGISTER_CALLBACKS */
821 #endif
825 * @brief Write Complete Callback
826 * @param hmdios: mdios handle
827 * @retval None
829 __weak void HAL_MDIOS_WriteCpltCallback(MDIOS_HandleTypeDef *hmdios)
831 /* Prevent unused argument(s) compilation warning */
832 UNUSED(hmdios);
834 /* NOTE : This function should not be modified, when the callback is needed,
835 the HAL_MDIOS_WriteCpltCallback can be implemented in the user file
840 * @brief Read Complete Callback
841 * @param hmdios: mdios handle
842 * @retval None
844 __weak void HAL_MDIOS_ReadCpltCallback(MDIOS_HandleTypeDef *hmdios)
846 /* Prevent unused argument(s) compilation warning */
847 UNUSED(hmdios);
849 /* NOTE : This function should not be modified, when the callback is needed,
850 the HAL_MDIOS_ReadCpltCallback can be implemented in the user file
855 * @brief Error Callback
856 * @param hmdios: mdios handle
857 * @retval None
859 __weak void HAL_MDIOS_ErrorCallback(MDIOS_HandleTypeDef *hmdios)
861 /* Prevent unused argument(s) compilation warning */
862 UNUSED(hmdios);
864 /* NOTE : This function should not be modified, when the callback is needed,
865 the HAL_MDIOS_ErrorCallback can be implemented in the user file
870 * @brief MDIOS WAKEUP interrupt callback
871 * @param hmdios: mdios handle
872 * @retval None
874 __weak void HAL_MDIOS_WakeUpCallback(MDIOS_HandleTypeDef *hmdios)
876 /* Prevent unused argument(s) compilation warning */
877 UNUSED(hmdios);
879 /* NOTE : This function Should not be modified, when the callback is needed,
880 the HAL_MDIOS_WakeUpCallback could be implemented in the user file
885 * @}
888 /** @defgroup MDIOS_Exported_Functions_Group3 Peripheral Control functions
889 * @brief MDIOS control functions
891 @verbatim
892 ===============================================================================
893 ##### Peripheral Control functions #####
894 ===============================================================================
895 [..]
896 This subsection provides a set of functions allowing to control the MDIOS.
897 (+) HAL_MDIOS_GetState() API, helpful to check in run-time the state.
898 (+) HAL_MDIOS_GetError() API, returns the errors code of the HAL state machine.
900 @endverbatim
901 * @{
905 * @brief Gets MDIOS error code
906 * @param hmdios: mdios handle
907 * @retval mdios error code
909 uint32_t HAL_MDIOS_GetError(MDIOS_HandleTypeDef *hmdios)
911 /* return the error code */
912 return hmdios->ErrorCode;
916 * @brief Return the MDIOS HAL state
917 * @param hmdios: mdios handle
918 * @retval HAL state
920 HAL_MDIOS_StateTypeDef HAL_MDIOS_GetState(MDIOS_HandleTypeDef *hmdios)
922 /* Return MDIOS state */
923 return hmdios->State;
927 * @}
931 * @}
934 #if (USE_HAL_MDIOS_REGISTER_CALLBACKS == 1)
935 static void MDIOS_InitCallbacksToDefault(MDIOS_HandleTypeDef *hmdios)
937 /* Init the MDIOS Callback settings */
938 hmdios->WriteCpltCallback = HAL_MDIOS_WriteCpltCallback; /* Legacy weak WriteCpltCallback */
939 hmdios->ReadCpltCallback = HAL_MDIOS_ReadCpltCallback; /* Legacy weak ReadCpltCallback */
940 hmdios->ErrorCallback = HAL_MDIOS_ErrorCallback; /* Legacy weak ErrorCallback */
941 hmdios->WakeUpCallback = HAL_MDIOS_WakeUpCallback; /* Legacy weak WakeUpCallback */
943 #endif /* USE_HAL_MDIOS_REGISTER_CALLBACKS */
946 * @}
948 #endif /* HAL_MDIOS_MODULE_ENABLED */
950 * @}
952 #endif /* MDIOS */
954 * @}
957 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/