stm32h7xx_hal_hsem.c
Go to the documentation of this file.
1 
87 /* Includes ------------------------------------------------------------------*/
88 #include "stm32h7xx_hal.h"
89 
99 #ifdef HAL_HSEM_MODULE_ENABLED
100 
101 /* Private typedef -----------------------------------------------------------*/
102 /* Private define ------------------------------------------------------------*/
103 #if defined(DUAL_CORE)
104 
108 #ifndef HSEM_R_MASTERID
109 #define HSEM_R_MASTERID HSEM_R_COREID
110 #endif
111 
112 #ifndef HSEM_RLR_MASTERID
113 #define HSEM_RLR_MASTERID HSEM_RLR_COREID
114 #endif
115 
116 #ifndef HSEM_CR_MASTERID
117 #define HSEM_CR_MASTERID HSEM_CR_COREID
118 #endif
119 
123 #endif /* DUAL_CORE */
124 /* Private macro -------------------------------------------------------------*/
125 /* Private variables ---------------------------------------------------------*/
126 /* Private function prototypes -----------------------------------------------*/
127 /* Private functions ---------------------------------------------------------*/
128 /* Exported functions --------------------------------------------------------*/
129 
159 HAL_StatusTypeDef HAL_HSEM_Take(uint32_t SemID, uint32_t ProcessID)
160 {
161  /* Check the parameters */
162  assert_param(IS_HSEM_SEMID(SemID));
163  assert_param(IS_HSEM_PROCESSID(ProcessID));
164 
165 #if USE_MULTI_CORE_SHARED_CODE != 0U
166  /* First step write R register with MasterID, processID and take bit=1*/
167  HSEM->R[SemID] = ((ProcessID & HSEM_R_PROCID) | ((HAL_GetCurrentCPUID() << POSITION_VAL(HSEM_R_MASTERID)) & HSEM_R_MASTERID) | HSEM_R_LOCK);
168 
169  /* second step : read the R register . Take achieved if MasterID and processID match and take bit set to 1 */
170  if (HSEM->R[SemID] == ((ProcessID & HSEM_R_PROCID) | ((HAL_GetCurrentCPUID() << POSITION_VAL(HSEM_R_MASTERID)) & HSEM_R_MASTERID) | HSEM_R_LOCK))
171  {
172  /*take success when MasterID and ProcessID match and take bit set*/
173  return HAL_OK;
174  }
175 #else
176  /* First step write R register with MasterID, processID and take bit=1*/
177  HSEM->R[SemID] = (ProcessID | HSEM_CR_COREID_CURRENT | HSEM_R_LOCK);
178 
179  /* second step : read the R register . Take achieved if MasterID and processID match and take bit set to 1 */
180  if (HSEM->R[SemID] == (ProcessID | HSEM_CR_COREID_CURRENT | HSEM_R_LOCK))
181  {
182  /*take success when MasterID and ProcessID match and take bit set*/
183  return HAL_OK;
184  }
185 #endif
186 
187  /* Semaphore take fails*/
188  return HAL_ERROR;
189 }
190 
196 HAL_StatusTypeDef HAL_HSEM_FastTake(uint32_t SemID)
197 {
198  /* Check the parameters */
199  assert_param(IS_HSEM_SEMID(SemID));
200 
201 #if USE_MULTI_CORE_SHARED_CODE != 0U
202  /* Read the RLR register to take the semaphore */
203  if (HSEM->RLR[SemID] == (((HAL_GetCurrentCPUID() << POSITION_VAL(HSEM_R_MASTERID)) & HSEM_RLR_MASTERID) | HSEM_RLR_LOCK))
204  {
205  /*take success when MasterID match and take bit set*/
206  return HAL_OK;
207  }
208 #else
209  /* Read the RLR register to take the semaphore */
210  if (HSEM->RLR[SemID] == (HSEM_CR_COREID_CURRENT | HSEM_RLR_LOCK))
211  {
212  /*take success when MasterID match and take bit set*/
213  return HAL_OK;
214  }
215 #endif
216 
217  /* Semaphore take fails */
218  return HAL_ERROR;
219 }
225 uint32_t HAL_HSEM_IsSemTaken(uint32_t SemID)
226 {
227  return (((HSEM->R[SemID] & HSEM_R_LOCK) != 0U) ? 1UL : 0UL);
228 }
229 
230 
237 void HAL_HSEM_Release(uint32_t SemID, uint32_t ProcessID)
238 {
239  /* Check the parameters */
240  assert_param(IS_HSEM_SEMID(SemID));
241  assert_param(IS_HSEM_PROCESSID(ProcessID));
242 
243  /* Clear the semaphore by writing to the R register : the MasterID , the processID and take bit = 0 */
244 #if USE_MULTI_CORE_SHARED_CODE != 0U
245  HSEM->R[SemID] = (ProcessID | ((HAL_GetCurrentCPUID() << POSITION_VAL(HSEM_R_MASTERID)) & HSEM_R_MASTERID));
246 #else
247  HSEM->R[SemID] = (ProcessID | HSEM_CR_COREID_CURRENT);
248 #endif
249 
250 }
251 
258 void HAL_HSEM_ReleaseAll(uint32_t Key, uint32_t CoreID)
259 {
261  assert_param(IS_HSEM_COREID(CoreID));
262 
263  HSEM->CR = ((Key << HSEM_CR_KEY_Pos) | (CoreID << HSEM_CR_COREID_Pos));
264 }
265 
290 void HAL_HSEM_SetClearKey(uint32_t Key)
291 {
293 
295 
296 }
297 
302 uint32_t HAL_HSEM_GetClearKey(void)
303 {
304  return (HSEM->KEYR >> HSEM_KEYR_KEY_Pos);
305 }
306 
329 void HAL_HSEM_ActivateNotification(uint32_t SemMask)
330 {
331 #if USE_MULTI_CORE_SHARED_CODE != 0U
332  /*enable the semaphore mask interrupts */
334  {
335  /*Use interrupt line 0 for CPU1 Master */
336  HSEM->C1IER |= SemMask;
337  }
338  else /* HSEM_CPU2_COREID */
339  {
340  /*Use interrupt line 1 for CPU2 Master*/
341  HSEM->C2IER |= SemMask;
342  }
343 #else
344  HSEM_COMMON->IER |= SemMask;
345 #endif
346 }
347 
353 void HAL_HSEM_DeactivateNotification(uint32_t SemMask)
354 {
355 #if USE_MULTI_CORE_SHARED_CODE != 0U
356  /*enable the semaphore mask interrupts */
358  {
359  /*Use interrupt line 0 for CPU1 Master */
360  HSEM->C1IER &= ~SemMask;
361  }
362  else /* HSEM_CPU2_COREID */
363  {
364  /*Use interrupt line 1 for CPU2 Master*/
365  HSEM->C2IER &= ~SemMask;
366  }
367 #else
368  HSEM_COMMON->IER &= ~SemMask;
369 #endif
370 }
371 
376 void HAL_HSEM_IRQHandler(void)
377 {
378  uint32_t statusreg;
379 #if USE_MULTI_CORE_SHARED_CODE != 0U
381  {
382  /* Get the list of masked freed semaphores*/
383  statusreg = HSEM->C1MISR; /*Use interrupt line 0 for CPU1 Master*/
384 
385  /*Disable Interrupts*/
386  HSEM->C1IER &= ~((uint32_t)statusreg);
387 
388  /*Clear Flags*/
389  HSEM->C1ICR = ((uint32_t)statusreg);
390  }
391  else /* HSEM_CPU2_COREID */
392  {
393  /* Get the list of masked freed semaphores*/
394  statusreg = HSEM->C2MISR;/*Use interrupt line 1 for CPU2 Master*/
395 
396  /*Disable Interrupts*/
397  HSEM->C2IER &= ~((uint32_t)statusreg);
398 
399  /*Clear Flags*/
400  HSEM->C2ICR = ((uint32_t)statusreg);
401  }
402 #else
403  /* Get the list of masked freed semaphores*/
404  statusreg = HSEM_COMMON->MISR;
405 
406  /*Disable Interrupts*/
407  HSEM_COMMON->IER &= ~((uint32_t)statusreg);
408 
409  /*Clear Flags*/
410  HSEM_COMMON->ICR = ((uint32_t)statusreg);
411 
412 #endif
413  /* Call FreeCallback */
414  HAL_HSEM_FreeCallback(statusreg);
415 }
416 
422 __weak void HAL_HSEM_FreeCallback(uint32_t SemMask)
423 {
424  /* Prevent unused argument(s) compilation warning */
425  UNUSED(SemMask);
426 
427  /* NOTE : This function should not be modified, when the callback is needed,
428  the HAL_HSEM_FreeCallback can be implemented in the user file
429  */
430 }
431 
440 #endif /* HAL_HSEM_MODULE_ENABLED */
441 
449 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
HAL_HSEM_ActivateNotification
void HAL_HSEM_ActivateNotification(uint32_t SemMask)
assert_param
#define assert_param(expr)
Include module's header file.
Definition: stm32f407/stm32f407g-disc1/Inc/stm32f4xx_hal_conf.h:353
HAL_StatusTypeDef
HAL_StatusTypeDef
HAL Status structures definition
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:40
HSEM_CR_COREID_CURRENT
#define HSEM_CR_COREID_CURRENT
Definition: stm32h735xx.h:23992
HAL_HSEM_FastTake
HAL_StatusTypeDef HAL_HSEM_FastTake(uint32_t SemID)
HSEM_RLR_LOCK
#define HSEM_RLR_LOCK
Definition: stm32h735xx.h:12774
HAL_HSEM_DeactivateNotification
void HAL_HSEM_DeactivateNotification(uint32_t SemMask)
IS_HSEM_PROCESSID
#define IS_HSEM_PROCESSID(__PROCESSID__)
Definition: stm32h735/stm32h735g-dk/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_hsem.h:184
HAL_ERROR
@ HAL_ERROR
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:43
POSITION_VAL
#define POSITION_VAL(VAL)
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:226
HSEM_CPU1_COREID
#define HSEM_CPU1_COREID
Definition: stm32h735xx.h:23990
HAL_HSEM_ReleaseAll
void HAL_HSEM_ReleaseAll(uint32_t Key, uint32_t CoreID)
IS_HSEM_COREID
#define IS_HSEM_COREID(__COREID__)
Definition: stm32h735/stm32h735g-dk/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_hsem.h:192
HAL_OK
@ HAL_OK
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:42
UNUSED
#define UNUSED(x)
Definition: porcupine/demo/c/dr_libs/old/dr.h:92
HAL_HSEM_FreeCallback
void HAL_HSEM_FreeCallback(uint32_t SemMask)
HAL_GetCurrentCPUID
uint32_t HAL_GetCurrentCPUID(void)
IS_HSEM_KEY
#define IS_HSEM_KEY(__KEY__)
Definition: stm32h735/stm32h735g-dk/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_hsem.h:186
IS_HSEM_SEMID
#define IS_HSEM_SEMID(__SEMID__)
Definition: stm32h735/stm32h735g-dk/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_hsem.h:182
MODIFY_REG
#define MODIFY_REG(REG, CLEARMASK, SETMASK)
Definition: stm32f407/stm32f407g-disc1/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h:224
HAL_HSEM_Release
void HAL_HSEM_Release(uint32_t SemID, uint32_t ProcessID)
HSEM
#define HSEM
Definition: stm32h735xx.h:2794
HAL_HSEM_SetClearKey
void HAL_HSEM_SetClearKey(uint32_t Key)
HSEM_CR_COREID_Pos
#define HSEM_CR_COREID_Pos
Definition: stm32h735xx.h:13169
HAL_HSEM_IsSemTaken
uint32_t HAL_HSEM_IsSemTaken(uint32_t SemID)
HSEM_R_PROCID
#define HSEM_R_PROCID
Definition: stm32h735xx.h:12757
HSEM_COMMON
#define HSEM_COMMON
Definition: stm32h735xx.h:2795
HSEM_CR_KEY_Pos
#define HSEM_CR_KEY_Pos
Definition: stm32h735xx.h:13172
HSEM_KEYR_KEY
#define HSEM_KEYR_KEY
Definition: stm32h735xx.h:13179
HAL_HSEM_Take
HAL_StatusTypeDef HAL_HSEM_Take(uint32_t SemID, uint32_t ProcessID)
HAL_HSEM_GetClearKey
uint32_t HAL_HSEM_GetClearKey(void)
HSEM_R_LOCK
#define HSEM_R_LOCK
Definition: stm32h735xx.h:12763
HAL_HSEM_IRQHandler
void HAL_HSEM_IRQHandler(void)
HSEM_KEYR_KEY_Pos
#define HSEM_KEYR_KEY_Pos
Definition: stm32h735xx.h:13177


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:54