Merge maintenance-8.x.x fixes into master
[inav.git] / lib / main / STM32H7 / Drivers / STM32H7xx_HAL_Driver / Inc / stm32h7xx_hal_hsem.h
blob45f6e07d975979fab3c1333002d3701e3c9de4f9
1 /**
2 ******************************************************************************
3 * @file stm32h7xx_hal_hsem.h
4 * @author MCD Application Team
5 * @brief Header file of HSEM HAL module.
6 ******************************************************************************
7 * @attention
9 * Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.
12 * This software is licensed under terms that can be found in the LICENSE file
13 * in the root directory of this software component.
14 * If no LICENSE file comes with this software, it is provided AS-IS.
16 ******************************************************************************
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32H7xx_HAL_HSEM_H
21 #define STM32H7xx_HAL_HSEM_H
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32h7xx_hal_def.h"
30 /** @addtogroup STM32H7xx_HAL_Driver
31 * @{
34 /** @addtogroup HSEM
35 * @{
38 /* Exported macro ------------------------------------------------------------*/
39 /** @defgroup HSEM_Exported_Macros HSEM Exported Macros
40 * @{
43 /**
44 * @brief SemID to mask helper Macro.
45 * @param __SEMID__: semaphore ID from 0 to 31
46 * @retval Semaphore Mask.
48 #define __HAL_HSEM_SEMID_TO_MASK(__SEMID__) (1 << (__SEMID__))
50 /**
51 * @brief Enables the specified HSEM interrupts.
52 * @param __SEM_MASK__: semaphores Mask
53 * @retval None.
55 #if defined(DUAL_CORE)
56 #define __HAL_HSEM_ENABLE_IT(__SEM_MASK__) ((((SCB->CPUID & 0x000000F0) >> 4 )== 0x7) ? \
57 (HSEM->C1IER |= (__SEM_MASK__)) : \
58 (HSEM->C2IER |= (__SEM_MASK__)))
59 #else
60 #define __HAL_HSEM_ENABLE_IT(__SEM_MASK__) (HSEM->IER |= (__SEM_MASK__))
61 #endif /* DUAL_CORE */
62 /**
63 * @brief Disables the specified HSEM interrupts.
64 * @param __SEM_MASK__: semaphores Mask
65 * @retval None.
67 #if defined(DUAL_CORE)
68 #define __HAL_HSEM_DISABLE_IT(__SEM_MASK__) ((((SCB->CPUID & 0x000000F0) >> 4 )== 0x7) ? \
69 (HSEM->C1IER &= ~(__SEM_MASK__)) : \
70 (HSEM->C2IER &= ~(__SEM_MASK__)))
71 #else
72 #define __HAL_HSEM_DISABLE_IT(__SEM_MASK__) (HSEM->IER &= ~(__SEM_MASK__))
73 #endif /* DUAL_CORE */
75 /**
76 * @brief Checks whether interrupt has occurred or not for semaphores specified by a mask.
77 * @param __SEM_MASK__: semaphores Mask
78 * @retval semaphores Mask : Semaphores where an interrupt occurred.
80 #if defined(DUAL_CORE)
81 #define __HAL_HSEM_GET_IT(__SEM_MASK__) ((((SCB->CPUID & 0x000000F0) >> 4 )== 0x7) ? \
82 ((__SEM_MASK__) & HSEM->C1MISR) : \
83 ((__SEM_MASK__) & HSEM->C2MISR1))
84 #else
85 #define __HAL_HSEM_GET_IT(__SEM_MASK__) ((__SEM_MASK__) & HSEM->MISR)
86 #endif /* DUAL_CORE */
88 /**
89 * @brief Get the semaphores release status flags.
90 * @param __SEM_MASK__: semaphores Mask
91 * @retval semaphores Mask : Semaphores where Release flags rise.
93 #if defined(DUAL_CORE)
94 #define __HAL_HSEM_GET_FLAG(__SEM_MASK__) ((((SCB->CPUID & 0x000000F0) >> 4 )== 0x7) ? \
95 (__SEM_MASK__) & HSEM->C1ISR : \
96 (__SEM_MASK__) & HSEM->C2ISR)
97 #else
98 #define __HAL_HSEM_GET_FLAG(__SEM_MASK__) ((__SEM_MASK__) & HSEM->ISR)
99 #endif /* DUAL_CORE */
102 * @brief Clears the HSEM Interrupt flags.
103 * @param __SEM_MASK__: semaphores Mask
104 * @retval None.
106 #if defined(DUAL_CORE)
107 #define __HAL_HSEM_CLEAR_FLAG(__SEM_MASK__) ((((SCB->CPUID & 0x000000F0) >> 4 )== 0x7) ? \
108 (HSEM->C1ICR |= (__SEM_MASK__)) : \
109 (HSEM->C2ICR |= (__SEM_MASK__)))
110 #else
111 #define __HAL_HSEM_CLEAR_FLAG(__SEM_MASK__) (HSEM->ICR |= (__SEM_MASK__))
112 #endif /* DUAL_CORE */
115 * @}
118 /* Exported functions --------------------------------------------------------*/
119 /** @defgroup HSEM_Exported_Functions HSEM Exported Functions
120 * @{
123 /** @addtogroup HSEM_Exported_Functions_Group1 Take and Release functions
124 * @brief HSEM Take and Release functions
125 * @{
128 /* HSEM semaphore take (lock) using 2-Step method ****************************/
129 HAL_StatusTypeDef HAL_HSEM_Take(uint32_t SemID, uint32_t ProcessID);
130 /* HSEM semaphore fast take (lock) using 1-Step method ***********************/
131 HAL_StatusTypeDef HAL_HSEM_FastTake(uint32_t SemID);
132 /* HSEM Release **************************************************************/
133 void HAL_HSEM_Release(uint32_t SemID, uint32_t ProcessID);
134 /* HSEM Release All************************************************************/
135 void HAL_HSEM_ReleaseAll(uint32_t Key, uint32_t CoreID);
136 /* HSEM Check semaphore state Taken or not **********************************/
137 uint32_t HAL_HSEM_IsSemTaken(uint32_t SemID);
140 * @}
143 /** @addtogroup HSEM_Exported_Functions_Group2 HSEM Set and Get Key functions
144 * @brief HSEM Set and Get Key functions.
145 * @{
147 /* HSEM Set Clear Key *********************************************************/
148 void HAL_HSEM_SetClearKey(uint32_t Key);
149 /* HSEM Get Clear Key *********************************************************/
150 uint32_t HAL_HSEM_GetClearKey(void);
152 * @}
155 /** @addtogroup HSEM_Exported_Functions_Group3
156 * @brief HSEM Notification functions
157 * @{
159 /* HSEM Activate HSEM Notification (When a semaphore is released) ) *****************/
160 void HAL_HSEM_ActivateNotification(uint32_t SemMask);
161 /* HSEM Deactivate HSEM Notification (When a semaphore is released) ****************/
162 void HAL_HSEM_DeactivateNotification(uint32_t SemMask);
163 /* HSEM Free Callback (When a semaphore is released) *******************************/
164 void HAL_HSEM_FreeCallback(uint32_t SemMask);
165 /* HSEM IRQ Handler **********************************************************/
166 void HAL_HSEM_IRQHandler(void);
169 * @}
173 * @}
176 /* Private macros ------------------------------------------------------------*/
177 /** @defgroup HSEM_Private_Macros HSEM Private Macros
178 * @{
181 #define IS_HSEM_SEMID(__SEMID__) ((__SEMID__) <= HSEM_SEMID_MAX )
183 #define IS_HSEM_PROCESSID(__PROCESSID__) ((__PROCESSID__) <= HSEM_PROCESSID_MAX )
185 #define IS_HSEM_KEY(__KEY__) ((__KEY__) <= HSEM_CLEAR_KEY_MAX )
187 #if defined(DUAL_CORE)
188 #define IS_HSEM_COREID(__COREID__) (((__COREID__) == HSEM_CPU1_COREID) || \
189 ((__COREID__) == HSEM_CPU2_COREID))
190 #else
191 #define IS_HSEM_COREID(__COREID__) ((__COREID__) == HSEM_CPU1_COREID)
192 #endif
196 * @}
200 * @}
204 * @}
207 #ifdef __cplusplus
209 #endif
211 #endif /* STM32H7xx_HAL_HSEM_H */