1 /**
2   ******************************************************************************
3   * @file    stm32wbaxx_hal_hsem.h
4   * @author  MCD Application Team
5   * @brief   Header file of HSEM HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2022 STMicroelectronics.
10   * All rights reserved.
11   *
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.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32WBAxx_HAL_HSEM_H
21 #define STM32WBAxx_HAL_HSEM_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32wbaxx_hal_def.h"
29 
30 /** @addtogroup STM32WBAxx_HAL_Driver
31    * @{
32    */
33 
34 /** @addtogroup HSEM
35    * @{
36    */
37 
38 /* Exported constants --------------------------------------------------------*/
39 
40 /** @defgroup HSEM_Exported_Constants HSEM
41   * @{
42   */
43 /** @defgroup HSEM_Attributes HSEM Attributes
44   * @brief HSEM Privilege/NPrivilege and Secure/NSecure Attributes
45   * @{
46   */
47 #define HSEM_NSEC_PRIV    HSEM_R_PRIV                 /*!< NSecure and Privileged attribute  */
48 #define HSEM_NSEC_NPRIV   0x0U                        /*!< NSecure and NPrivileged attribute */
49 #define HSEM_SEC_PRIV     (HSEM_R_SEC  | HSEM_R_PRIV) /*!< Secure and Privileged attribute   */
50 #define HSEM_SEC_NPRIV    HSEM_R_SEC                  /*!< Secure and NPrivileged attribute  */
51 /**
52   * @}
53   */
54 
55 /**
56   * @}
57   */
58 /* Exported macro ------------------------------------------------------------*/
59 /** @defgroup HSEM_Exported_Macros HSEM Exported Macros
60   * @{
61   */
62 
63 /**
64   * @brief  SemID to mask helper Macro.
65   * @param  __SEMID__: semaphore ID from 0 to 15
66   * @retval Semaphore Mask.
67   */
68 #define __HAL_HSEM_SEMID_TO_MASK(__SEMID__) (1 << (__SEMID__))
69 
70 /**
71   * @brief  Enables the specified HSEM interrupts.
72   * @param  __SEM_MASK__: semaphores Mask
73   * @retval None.
74   */
75 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
76 #define __HAL_HSEM_ENABLE_IT(__SEM_MASK__) (HSEM->SIER |= (__SEM_MASK__))
77 #else
78 #define __HAL_HSEM_ENABLE_IT(__SEM_MASK__) (HSEM->IER |= (__SEM_MASK__))
79 #endif /* (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */
80 /**
81   * @brief  Disables the specified HSEM interrupts.
82   * @param  __SEM_MASK__: semaphores Mask
83   * @retval None.
84   */
85 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
86 #define __HAL_HSEM_DISABLE_IT(__SEM_MASK__) (HSEM->SIER &= ~(__SEM_MASK__))
87 #else
88 #define __HAL_HSEM_DISABLE_IT(__SEM_MASK__) (HSEM->IER &= ~(__SEM_MASK__))
89 #endif /* (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */
90 
91 /**
92   * @brief  Checks whether interrupt has occurred or not for semaphores specified by a mask.
93   * @param  __SEM_MASK__: semaphores Mask
94   * @retval semaphores Mask : Semaphores where an interrupt occurred.
95   */
96 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
97 #define __HAL_HSEM_GET_IT(__SEM_MASK__) ((__SEM_MASK__) & HSEM->SMISR)
98 #else
99 #define __HAL_HSEM_GET_IT(__SEM_MASK__) ((__SEM_MASK__) & HSEM->MISR)
100 #endif /* (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */
101 
102 /**
103   * @brief  Get the semaphores release status flags.
104   * @param  __SEM_MASK__: semaphores Mask
105   * @retval semaphores Mask : Semaphores where Release flags rise.
106   */
107 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
108 #define __HAL_HSEM_GET_FLAG(__SEM_MASK__) ((__SEM_MASK__) & HSEM->SISR)
109 #else
110 #define __HAL_HSEM_GET_FLAG(__SEM_MASK__) ((__SEM_MASK__) & HSEM->ISR)
111 #endif /* (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */
112 
113 /**
114   * @brief  Clears the HSEM Interrupt flags.
115   * @param  __SEM_MASK__: semaphores Mask
116   * @retval None.
117   */
118 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
119 #define __HAL_HSEM_CLEAR_FLAG(__SEM_MASK__) (HSEM->SICR |= (__SEM_MASK__))
120 #else
121 #define __HAL_HSEM_CLEAR_FLAG(__SEM_MASK__) (HSEM->ICR |= (__SEM_MASK__))
122 #endif /* (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */
123 
124 /**
125   * @}
126   */
127 
128 /* Exported functions --------------------------------------------------------*/
129 /** @defgroup HSEM_Exported_Functions HSEM Exported Functions
130   * @{
131   */
132 
133 /** @addtogroup HSEM_Exported_Functions_Group1 Take and Release functions
134   * @brief    HSEM Take and Release functions
135   * @{
136   */
137 
138 /* HSEM semaphore take (lock) using 2-Step  method ****************************/
139 HAL_StatusTypeDef  HAL_HSEM_Take(uint32_t SemID, uint32_t ProcessID, uint32_t Attribute);
140 /* HSEM semaphore fast take (lock) using 1-Step  method ***********************/
141 HAL_StatusTypeDef  HAL_HSEM_FastTake(uint32_t SemID, uint32_t Attribute);
142 /* HSEM Release  **************************************************************/
143 void  HAL_HSEM_Release(uint32_t SemID, uint32_t ProcessID, uint32_t Attribute);
144 /* HSEM Release All************************************************************/
145 void  HAL_HSEM_ReleaseAll(uint32_t Key, uint32_t CoreID, uint32_t Attribute);
146 /* HSEM Check semaphore state Taken or not   **********************************/
147 uint32_t HAL_HSEM_IsSemTaken(uint32_t SemID);
148 
149 /**
150   * @}
151   */
152 
153 /** @addtogroup HSEM_Exported_Functions_Group2 HSEM Set and Get Key functions
154   * @brief    HSEM Set and Get Key functions.
155   * @{
156   */
157 /* HSEM Set Clear Key *********************************************************/
158 void  HAL_HSEM_SetClearKey(uint32_t Key);
159 /* HSEM Get Clear Key *********************************************************/
160 uint32_t HAL_HSEM_GetClearKey(void);
161 /**
162   * @}
163   */
164 
165 /** @addtogroup HSEM_Exported_Functions_Group3
166   * @brief   HSEM Notification functions
167   * @{
168   */
169 /* HSEM Activate HSEM Notification (When a semaphore is released) ) *****************/
170 void HAL_HSEM_ActivateNotification(uint32_t SemMask);
171 /* HSEM Deactivate HSEM Notification (When a semaphore is released)  ****************/
172 void HAL_HSEM_DeactivateNotification(uint32_t SemMask);
173 /* HSEM Free Callback (When a semaphore is released)  *******************************/
174 void HAL_HSEM_FreeCallback(uint32_t SemMask);
175 /* HSEM IRQ Handler  **********************************************************/
176 void HAL_HSEM_IRQHandler(void);
177 
178 /**
179   * @}
180   */
181 
182 /** @addtogroup HSEM_Exported_Functions_Group4
183   *  @brief    HSEM Attributes functions.
184   * @{
185   */
186 #if defined(HSEM_SECCFGR_SEC0)
187 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
188 void HAL_HSEM_SetSemaphoreSecure(uint32_t SemMask);
189 void HAL_HSEM_SetSemaphoreNonSecure(uint32_t SemMask);
190 #endif /* (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */
191 uint32_t HAL_HSEM_GetSemaphoreSecure(void);
192 #endif /* (HSEM_SECCFGR_SEC0) */
193 
194 #if defined(HSEM_PRIVCFGR_PRIV0)
195 void HAL_HSEM_SetSemaphorePrivilege(uint32_t SemMask);
196 void HAL_HSEM_SetSemaphoreNonPrivilege(uint32_t SemMask);
197 uint32_t HAL_HSEM_GetSemaphorePrivilege(void);
198 #endif /* (HSEM_PRIVCFGR_PRIV0) */
199 
200 /**
201   * @}
202   */
203 
204 /**
205   * @}
206   */
207 
208 /* Private macros ------------------------------------------------------------*/
209 /** @defgroup HSEM_Private_Macros HSEM Private Macros
210   * @{
211   */
212 
213 #define IS_HSEM_SEMID(__SEMID__) ((__SEMID__) <= HSEM_SEMID_MAX )
214 
215 #define IS_HSEM_PROCESSID(__PROCESSID__) ((__PROCESSID__) <= HSEM_PROCESSID_MAX )
216 
217 #define IS_HSEM_KEY(__KEY__) ((__KEY__) <= HSEM_CLEAR_KEY_MAX )
218 
219 #define IS_HSEM_LOCKID(__LOCKID__) ((__LOCKID__) == HSEM_CPU1_LOCKID)
220 
221 
222 /**
223   * @}
224   */
225 
226 /**
227   * @}
228   */
229 
230 /**
231   * @}
232   */
233 
234 #ifdef __cplusplus
235 }
236 #endif
237 
238 #endif /* STM32WBAxx_HAL_HSEM_H */
239