stm32h7xx_hal_hsem.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_hsem.h
  4. * @author MCD Application Team
  5. * @brief Header file of HSEM HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2017 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. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32H7xx_HAL_HSEM_H
  20. #define STM32H7xx_HAL_HSEM_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32h7xx_hal_def.h"
  26. /** @addtogroup STM32H7xx_HAL_Driver
  27. * @{
  28. */
  29. /** @addtogroup HSEM
  30. * @{
  31. */
  32. /* Exported macro ------------------------------------------------------------*/
  33. /** @defgroup HSEM_Exported_Macros HSEM Exported Macros
  34. * @{
  35. */
  36. /**
  37. * @brief SemID to mask helper Macro.
  38. * @param __SEMID__: semaphore ID from 0 to 31
  39. * @retval Semaphore Mask.
  40. */
  41. #define __HAL_HSEM_SEMID_TO_MASK(__SEMID__) (1 << (__SEMID__))
  42. /**
  43. * @brief Enables the specified HSEM interrupts.
  44. * @param __SEM_MASK__: semaphores Mask
  45. * @retval None.
  46. */
  47. #if defined(DUAL_CORE)
  48. #define __HAL_HSEM_ENABLE_IT(__SEM_MASK__) ((((SCB->CPUID & 0x000000F0) >> 4 )== 0x7) ? \
  49. (HSEM->C1IER |= (__SEM_MASK__)) : \
  50. (HSEM->C2IER |= (__SEM_MASK__)))
  51. #else
  52. #define __HAL_HSEM_ENABLE_IT(__SEM_MASK__) (HSEM->IER |= (__SEM_MASK__))
  53. #endif /* DUAL_CORE */
  54. /**
  55. * @brief Disables the specified HSEM interrupts.
  56. * @param __SEM_MASK__: semaphores Mask
  57. * @retval None.
  58. */
  59. #if defined(DUAL_CORE)
  60. #define __HAL_HSEM_DISABLE_IT(__SEM_MASK__) ((((SCB->CPUID & 0x000000F0) >> 4 )== 0x7) ? \
  61. (HSEM->C1IER &= ~(__SEM_MASK__)) : \
  62. (HSEM->C2IER &= ~(__SEM_MASK__)))
  63. #else
  64. #define __HAL_HSEM_DISABLE_IT(__SEM_MASK__) (HSEM->IER &= ~(__SEM_MASK__))
  65. #endif /* DUAL_CORE */
  66. /**
  67. * @brief Checks whether interrupt has occurred or not for semaphores specified by a mask.
  68. * @param __SEM_MASK__: semaphores Mask
  69. * @retval semaphores Mask : Semaphores where an interrupt occurred.
  70. */
  71. #if defined(DUAL_CORE)
  72. #define __HAL_HSEM_GET_IT(__SEM_MASK__) ((((SCB->CPUID & 0x000000F0) >> 4 )== 0x7) ? \
  73. ((__SEM_MASK__) & HSEM->C1MISR) : \
  74. ((__SEM_MASK__) & HSEM->C2MISR1))
  75. #else
  76. #define __HAL_HSEM_GET_IT(__SEM_MASK__) ((__SEM_MASK__) & HSEM->MISR)
  77. #endif /* DUAL_CORE */
  78. /**
  79. * @brief Get the semaphores release status flags.
  80. * @param __SEM_MASK__: semaphores Mask
  81. * @retval semaphores Mask : Semaphores where Release flags rise.
  82. */
  83. #if defined(DUAL_CORE)
  84. #define __HAL_HSEM_GET_FLAG(__SEM_MASK__) ((((SCB->CPUID & 0x000000F0) >> 4 )== 0x7) ? \
  85. (__SEM_MASK__) & HSEM->C1ISR : \
  86. (__SEM_MASK__) & HSEM->C2ISR)
  87. #else
  88. #define __HAL_HSEM_GET_FLAG(__SEM_MASK__) ((__SEM_MASK__) & HSEM->ISR)
  89. #endif /* DUAL_CORE */
  90. /**
  91. * @brief Clears the HSEM Interrupt flags.
  92. * @param __SEM_MASK__: semaphores Mask
  93. * @retval None.
  94. */
  95. #if defined(DUAL_CORE)
  96. #define __HAL_HSEM_CLEAR_FLAG(__SEM_MASK__) ((((SCB->CPUID & 0x000000F0) >> 4 )== 0x7) ? \
  97. (HSEM->C1ICR |= (__SEM_MASK__)) : \
  98. (HSEM->C2ICR |= (__SEM_MASK__)))
  99. #else
  100. #define __HAL_HSEM_CLEAR_FLAG(__SEM_MASK__) (HSEM->ICR |= (__SEM_MASK__))
  101. #endif /* DUAL_CORE */
  102. /**
  103. * @}
  104. */
  105. /* Exported functions --------------------------------------------------------*/
  106. /** @defgroup HSEM_Exported_Functions HSEM Exported Functions
  107. * @{
  108. */
  109. /** @addtogroup HSEM_Exported_Functions_Group1 Take and Release functions
  110. * @brief HSEM Take and Release functions
  111. * @{
  112. */
  113. /* HSEM semaphore take (lock) using 2-Step method ****************************/
  114. HAL_StatusTypeDef HAL_HSEM_Take(uint32_t SemID, uint32_t ProcessID);
  115. /* HSEM semaphore fast take (lock) using 1-Step method ***********************/
  116. HAL_StatusTypeDef HAL_HSEM_FastTake(uint32_t SemID);
  117. /* HSEM Release **************************************************************/
  118. void HAL_HSEM_Release(uint32_t SemID, uint32_t ProcessID);
  119. /* HSEM Release All************************************************************/
  120. void HAL_HSEM_ReleaseAll(uint32_t Key, uint32_t CoreID);
  121. /* HSEM Check semaphore state Taken or not **********************************/
  122. uint32_t HAL_HSEM_IsSemTaken(uint32_t SemID);
  123. /**
  124. * @}
  125. */
  126. /** @addtogroup HSEM_Exported_Functions_Group2 HSEM Set and Get Key functions
  127. * @brief HSEM Set and Get Key functions.
  128. * @{
  129. */
  130. /* HSEM Set Clear Key *********************************************************/
  131. void HAL_HSEM_SetClearKey(uint32_t Key);
  132. /* HSEM Get Clear Key *********************************************************/
  133. uint32_t HAL_HSEM_GetClearKey(void);
  134. /**
  135. * @}
  136. */
  137. /** @addtogroup HSEM_Exported_Functions_Group3
  138. * @brief HSEM Notification functions
  139. * @{
  140. */
  141. /* HSEM Activate HSEM Notification (When a semaphore is released) ) *****************/
  142. void HAL_HSEM_ActivateNotification(uint32_t SemMask);
  143. /* HSEM Deactivate HSEM Notification (When a semaphore is released) ****************/
  144. void HAL_HSEM_DeactivateNotification(uint32_t SemMask);
  145. /* HSEM Free Callback (When a semaphore is released) *******************************/
  146. void HAL_HSEM_FreeCallback(uint32_t SemMask);
  147. /* HSEM IRQ Handler **********************************************************/
  148. void HAL_HSEM_IRQHandler(void);
  149. /**
  150. * @}
  151. */
  152. /**
  153. * @}
  154. */
  155. /* Private macros ------------------------------------------------------------*/
  156. /** @defgroup HSEM_Private_Macros HSEM Private Macros
  157. * @{
  158. */
  159. #define IS_HSEM_SEMID(__SEMID__) ((__SEMID__) <= HSEM_SEMID_MAX )
  160. #define IS_HSEM_PROCESSID(__PROCESSID__) ((__PROCESSID__) <= HSEM_PROCESSID_MAX )
  161. #define IS_HSEM_KEY(__KEY__) ((__KEY__) <= HSEM_CLEAR_KEY_MAX )
  162. #if defined(DUAL_CORE)
  163. #define IS_HSEM_COREID(__COREID__) (((__COREID__) == HSEM_CPU1_COREID) || \
  164. ((__COREID__) == HSEM_CPU2_COREID))
  165. #else
  166. #define IS_HSEM_COREID(__COREID__) ((__COREID__) == HSEM_CPU1_COREID)
  167. #endif
  168. /**
  169. * @}
  170. */
  171. /**
  172. * @}
  173. */
  174. /**
  175. * @}
  176. */
  177. #ifdef __cplusplus
  178. }
  179. #endif
  180. #endif /* STM32H7xx_HAL_HSEM_H */