fsl_sema4.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * Copyright 2017-2020 NXP
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef _FSL_SEMA4_H_
  8. #define _FSL_SEMA4_H_
  9. #include "fsl_common.h"
  10. /*!
  11. * @addtogroup sema4
  12. * @{
  13. */
  14. /******************************************************************************
  15. * Definitions
  16. *****************************************************************************/
  17. /*! @name Driver version */
  18. /*@{*/
  19. /*! @brief SEMA4 driver version */
  20. #define FSL_SEMA4_DRIVER_VERSION (MAKE_VERSION(2, 0, 2))
  21. /*@}*/
  22. /*! @brief The number to reset all SEMA4 gates. */
  23. #define SEMA4_GATE_NUM_RESET_ALL (64U)
  24. #if defined(SEMA4_GATE_COUNT)
  25. /*!
  26. * @brief SEMA4 gate n register address.
  27. */
  28. #define SEMA4_GATEn(base, n) ((base)->GATE[(n)])
  29. #ifndef FSL_FEATURE_SEMA4_GATE_COUNT
  30. #define FSL_FEATURE_SEMA4_GATE_COUNT SEMA4_GATE_COUNT
  31. #endif
  32. #else
  33. /*!
  34. * @brief SEMA4 gate n register address.
  35. */
  36. #define SEMA4_GATEn(base, n) (((volatile uint8_t *)(&((base)->Gate00)))[(n)])
  37. #endif
  38. /*******************************************************************************
  39. * API
  40. ******************************************************************************/
  41. #if defined(__cplusplus)
  42. extern "C" {
  43. #endif
  44. /*!
  45. * @brief Initializes the SEMA4 module.
  46. *
  47. * This function initializes the SEMA4 module. It only enables the clock but does
  48. * not reset the gates because the module might be used by other processors
  49. * at the same time. To reset the gates, call either SEMA4_ResetGate or
  50. * SEMA4_ResetAllGates function.
  51. *
  52. * @param base SEMA4 peripheral base address.
  53. */
  54. void SEMA4_Init(SEMA4_Type *base);
  55. /*!
  56. * @brief De-initializes the SEMA4 module.
  57. *
  58. * This function de-initializes the SEMA4 module. It only disables the clock.
  59. *
  60. * @param base SEMA4 peripheral base address.
  61. */
  62. void SEMA4_Deinit(SEMA4_Type *base);
  63. /*!
  64. * @brief Tries to lock the SEMA4 gate.
  65. *
  66. * This function tries to lock the specific SEMA4 gate. If the gate has been
  67. * locked by another processor, this function returns an error code.
  68. *
  69. * @param base SEMA4 peripheral base address.
  70. * @param gateNum Gate number to lock.
  71. * @param procNum Current processor number.
  72. *
  73. * @retval kStatus_Success Lock the sema4 gate successfully.
  74. * @retval kStatus_Fail Sema4 gate has been locked by another processor.
  75. */
  76. status_t SEMA4_TryLock(SEMA4_Type *base, uint8_t gateNum, uint8_t procNum);
  77. /*!
  78. * @brief Locks the SEMA4 gate.
  79. *
  80. * This function locks the specific SEMA4 gate. If the gate has been
  81. * locked by other processors, this function waits until it is unlocked and then
  82. * lock it.
  83. *
  84. * @param base SEMA4 peripheral base address.
  85. * @param gateNum Gate number to lock.
  86. * @param procNum Current processor number.
  87. */
  88. void SEMA4_Lock(SEMA4_Type *base, uint8_t gateNum, uint8_t procNum);
  89. /*!
  90. * @brief Unlocks the SEMA4 gate.
  91. *
  92. * This function unlocks the specific SEMA4 gate. It only writes unlock value
  93. * to the SEMA4 gate register. However, it does not check whether the SEMA4 gate is locked
  94. * by the current processor or not. As a result, if the SEMA4 gate is not locked by the current
  95. * processor, this function has no effect.
  96. *
  97. * @param base SEMA4 peripheral base address.
  98. * @param gateNum Gate number to unlock.
  99. */
  100. static inline void SEMA4_Unlock(SEMA4_Type *base, uint8_t gateNum)
  101. {
  102. assert(gateNum < (uint8_t)FSL_FEATURE_SEMA4_GATE_COUNT);
  103. SEMA4_GATEn(base, gateNum) = 0U;
  104. }
  105. /*!
  106. * @brief Gets the status of the SEMA4 gate.
  107. *
  108. * This function checks the lock status of a specific SEMA4 gate.
  109. *
  110. * @param base SEMA4 peripheral base address.
  111. * @param gateNum Gate number.
  112. *
  113. * @return Return -1 if the gate is unlocked, otherwise return the
  114. * processor number which has locked the gate.
  115. */
  116. static inline int32_t SEMA4_GetLockProc(SEMA4_Type *base, uint8_t gateNum)
  117. {
  118. assert(gateNum < (uint8_t)FSL_FEATURE_SEMA4_GATE_COUNT);
  119. return (int32_t)(SEMA4_GATEn(base, gateNum)) - 1;
  120. }
  121. /*!
  122. * @brief Resets the SEMA4 gate to an unlocked status.
  123. *
  124. * This function resets a SEMA4 gate to an unlocked status.
  125. *
  126. * @param base SEMA4 peripheral base address.
  127. * @param gateNum Gate number.
  128. *
  129. * @retval kStatus_Success SEMA4 gate is reset successfully.
  130. * @retval kStatus_Fail Some other reset process is ongoing.
  131. */
  132. status_t SEMA4_ResetGate(SEMA4_Type *base, uint8_t gateNum);
  133. /*!
  134. * @brief Resets all SEMA4 gates to an unlocked status.
  135. *
  136. * This function resets all SEMA4 gate to an unlocked status.
  137. *
  138. * @param base SEMA4 peripheral base address.
  139. *
  140. * @retval kStatus_Success SEMA4 is reset successfully.
  141. * @retval kStatus_Fail Some other reset process is ongoing.
  142. */
  143. static inline status_t SEMA4_ResetAllGates(SEMA4_Type *base)
  144. {
  145. return SEMA4_ResetGate(base, SEMA4_GATE_NUM_RESET_ALL);
  146. }
  147. /*!
  148. * @brief Enable the gate notification interrupt.
  149. *
  150. * Gate notification provides such feature, when core tried to lock the gate
  151. * and failed, it could get notification when the gate is idle.
  152. *
  153. * @param base SEMA4 peripheral base address.
  154. * @param procNum Current processor number.
  155. * @param mask OR'ed value of the gate index, for example: (1<<0) | (1<<1) means
  156. * gate 0 and gate 1.
  157. */
  158. static inline void SEMA4_EnableGateNotifyInterrupt(SEMA4_Type *base, uint8_t procNum, uint32_t mask)
  159. {
  160. mask = __REV(__RBIT(mask));
  161. base->CPINE[procNum].CPINE |= (uint16_t)mask;
  162. }
  163. /*!
  164. * @brief Disable the gate notification interrupt.
  165. *
  166. * Gate notification provides such feature, when core tried to lock the gate
  167. * and failed, it could get notification when the gate is idle.
  168. *
  169. * @param base SEMA4 peripheral base address.
  170. * @param procNum Current processor number.
  171. * @param mask OR'ed value of the gate index, for example: (1<<0) | (1<<1) means
  172. * gate 0 and gate 1.
  173. */
  174. static inline void SEMA4_DisableGateNotifyInterrupt(SEMA4_Type *base, uint8_t procNum, uint32_t mask)
  175. {
  176. mask = __REV(__RBIT(mask));
  177. base->CPINE[procNum].CPINE &= (uint16_t)(~mask);
  178. }
  179. /*!
  180. * @brief Get the gate notification flags.
  181. *
  182. * Gate notification provides such feature, when core tried to lock the gate
  183. * and failed, it could get notification when the gate is idle. The status flags
  184. * are cleared automatically when the gate is locked by current core or locked
  185. * again before the other core.
  186. *
  187. * @param base SEMA4 peripheral base address.
  188. * @param procNum Current processor number.
  189. * @return OR'ed value of the gate index, for example: (1<<0) | (1<<1) means
  190. * gate 0 and gate 1 flags are pending.
  191. */
  192. static inline uint32_t SEMA4_GetGateNotifyStatus(SEMA4_Type *base, uint8_t procNum)
  193. {
  194. return __REV(__RBIT(base->CPNTF[procNum].CPNTF));
  195. }
  196. /*!
  197. * @brief Resets the SEMA4 gate IRQ notification.
  198. *
  199. * This function resets a SEMA4 gate IRQ notification.
  200. *
  201. * @param base SEMA4 peripheral base address.
  202. * @param gateNum Gate number.
  203. *
  204. * @retval kStatus_Success Reset successfully.
  205. * @retval kStatus_Fail Some other reset process is ongoing.
  206. */
  207. status_t SEMA4_ResetGateNotify(SEMA4_Type *base, uint8_t gateNum);
  208. /*!
  209. * @brief Resets all SEMA4 gates IRQ notification.
  210. *
  211. * This function resets all SEMA4 gate IRQ notifications.
  212. *
  213. * @param base SEMA4 peripheral base address.
  214. *
  215. * @retval kStatus_Success Reset successfully.
  216. * @retval kStatus_Fail Some other reset process is ongoing.
  217. */
  218. static inline status_t SEMA4_ResetAllGateNotify(SEMA4_Type *base)
  219. {
  220. return SEMA4_ResetGateNotify(base, SEMA4_GATE_NUM_RESET_ALL);
  221. }
  222. #if defined(__cplusplus)
  223. }
  224. #endif
  225. /*!
  226. * @}
  227. */
  228. #endif /* _FSL_SEMA4_H_ */