fsl_rdc_sema42.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Copyright 2017-2020 NXP
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef _FSL_RDC_SEMA42_H_
  8. #define _FSL_RDC_SEMA42_H_
  9. #include "fsl_common.h"
  10. /*!
  11. * @addtogroup rdc_sema42
  12. * @{
  13. */
  14. /******************************************************************************
  15. * Definitions
  16. *****************************************************************************/
  17. /*! @name Driver version */
  18. /*@{*/
  19. /*! @brief RDC_SEMA42 driver version */
  20. #define FSL_RDC_SEMA42_DRIVER_VERSION (MAKE_VERSION(2, 0, 3))
  21. /*@}*/
  22. /*! @brief The number to reset all RDC_SEMA42 gates. */
  23. #define RDC_SEMA42_GATE_NUM_RESET_ALL (64U)
  24. #if defined(RDC_SEMAPHORE_GATE_COUNT)
  25. /*! @brief RDC_SEMA42 gate n register address. */
  26. #define RDC_SEMA42_GATEn(base, n) ((base)->GATE[(n)])
  27. /*! @brief RDC_SEMA42 gate count. */
  28. #define RDC_SEMA42_GATE_COUNT (RDC_SEMAPHORE_GATE_COUNT)
  29. #else /* RDC_SEMAPHORE_GATE_COUNT */
  30. /*! @brief RDC_SEMA42 gate n register address. */
  31. #define RDC_SEMA42_GATEn(base, n) (((volatile uint8_t *)(&((base)->GATE0)))[(n)])
  32. /*! @brief RDC_SEMA42 gate count. */
  33. #define RDC_SEMA42_GATE_COUNT (64U)
  34. /* Compatible remap. */
  35. #define RDC_SEMAPHORE_GATE_GTFSM_MASK RDC_SEMAPHORE_GATE0_GTFSM_MASK
  36. #endif /* RDC_SEMAPHORE_GATE_COUNT */
  37. /*******************************************************************************
  38. * API
  39. ******************************************************************************/
  40. #if defined(__cplusplus)
  41. extern "C" {
  42. #endif
  43. /*!
  44. * @brief Initializes the RDC_SEMA42 module.
  45. *
  46. * This function initializes the RDC_SEMA42 module. It only enables the clock but does
  47. * not reset the gates because the module might be used by other processors
  48. * at the same time. To reset the gates, call either RDC_SEMA42_ResetGate or
  49. * RDC_SEMA42_ResetAllGates function.
  50. *
  51. * @param base RDC_SEMA42 peripheral base address.
  52. */
  53. void RDC_SEMA42_Init(RDC_SEMAPHORE_Type *base);
  54. /*!
  55. * @brief De-initializes the RDC_SEMA42 module.
  56. *
  57. * This function de-initializes the RDC_SEMA42 module. It only disables the clock.
  58. *
  59. * @param base RDC_SEMA42 peripheral base address.
  60. */
  61. void RDC_SEMA42_Deinit(RDC_SEMAPHORE_Type *base);
  62. /*!
  63. * @brief Tries to lock the RDC_SEMA42 gate.
  64. *
  65. * This function tries to lock the specific RDC_SEMA42 gate. If the gate has been
  66. * locked by another processor, this function returns an error code.
  67. *
  68. * @param base RDC_SEMA42 peripheral base address.
  69. * @param gateNum Gate number to lock.
  70. * @param masterIndex Current processor master index.
  71. * @param domainId Current processor domain ID.
  72. *
  73. * @retval kStatus_Success Lock the sema42 gate successfully.
  74. * @retval kStatus_Failed Sema42 gate has been locked by another processor.
  75. */
  76. status_t RDC_SEMA42_TryLock(RDC_SEMAPHORE_Type *base, uint8_t gateNum, uint8_t masterIndex, uint8_t domainId);
  77. /*!
  78. * @brief Locks the RDC_SEMA42 gate.
  79. *
  80. * This function locks the specific RDC_SEMA42 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 RDC_SEMA42 peripheral base address.
  85. * @param gateNum Gate number to lock.
  86. * @param masterIndex Current processor master index.
  87. * @param domainId Current processor domain ID.
  88. */
  89. void RDC_SEMA42_Lock(RDC_SEMAPHORE_Type *base, uint8_t gateNum, uint8_t masterIndex, uint8_t domainId);
  90. /*!
  91. * @brief Unlocks the RDC_SEMA42 gate.
  92. *
  93. * This function unlocks the specific RDC_SEMA42 gate. It only writes unlock value
  94. * to the RDC_SEMA42 gate register. However, it does not check whether the RDC_SEMA42 gate is locked
  95. * by the current processor or not. As a result, if the RDC_SEMA42 gate is not locked by the current
  96. * processor, this function has no effect.
  97. *
  98. * @param base RDC_SEMA42 peripheral base address.
  99. * @param gateNum Gate number to unlock.
  100. */
  101. static inline void RDC_SEMA42_Unlock(RDC_SEMAPHORE_Type *base, uint8_t gateNum)
  102. {
  103. assert(gateNum < RDC_SEMA42_GATE_COUNT);
  104. RDC_SEMA42_GATEn(base, gateNum) = 0U;
  105. }
  106. /*!
  107. * @brief Gets which master has currently locked the gate.
  108. *
  109. * @param base RDC_SEMA42 peripheral base address.
  110. * @param gateNum Gate number.
  111. *
  112. * @return Return -1 if the gate is not locked by any master, otherwise return the
  113. * master index.
  114. */
  115. static inline int32_t RDC_SEMA42_GetLockMasterIndex(RDC_SEMAPHORE_Type *base, uint8_t gateNum)
  116. {
  117. assert(gateNum < RDC_SEMA42_GATE_COUNT);
  118. uint8_t regGate = RDC_SEMA42_GATEn(base, gateNum);
  119. return (int32_t)((uint8_t)(regGate & RDC_SEMAPHORE_GATE_GTFSM_MASK)) - 1;
  120. }
  121. /*!
  122. * @brief Gets which domain has currently locked the gate.
  123. *
  124. * @param base RDC_SEMA42 peripheral base address.
  125. * @param gateNum Gate number.
  126. *
  127. * @return Return -1 if the gate is not locked by any domain, otherwise return the
  128. * domain ID.
  129. */
  130. int32_t RDC_SEMA42_GetLockDomainID(RDC_SEMAPHORE_Type *base, uint8_t gateNum);
  131. /*!
  132. * @brief Resets the RDC_SEMA42 gate to an unlocked status.
  133. *
  134. * This function resets a RDC_SEMA42 gate to an unlocked status.
  135. *
  136. * @param base RDC_SEMA42 peripheral base address.
  137. * @param gateNum Gate number.
  138. *
  139. * @retval kStatus_Success RDC_SEMA42 gate is reset successfully.
  140. * @retval kStatus_Failed Some other reset process is ongoing.
  141. */
  142. status_t RDC_SEMA42_ResetGate(RDC_SEMAPHORE_Type *base, uint8_t gateNum);
  143. /*!
  144. * @brief Resets all RDC_SEMA42 gates to an unlocked status.
  145. *
  146. * This function resets all RDC_SEMA42 gate to an unlocked status.
  147. *
  148. * @param base RDC_SEMA42 peripheral base address.
  149. *
  150. * @retval kStatus_Success RDC_SEMA42 is reset successfully.
  151. * @retval kStatus_RDC_SEMA42_Reseting Some other reset process is ongoing.
  152. */
  153. static inline status_t RDC_SEMA42_ResetAllGates(RDC_SEMAPHORE_Type *base)
  154. {
  155. return RDC_SEMA42_ResetGate(base, RDC_SEMA42_GATE_NUM_RESET_ALL);
  156. }
  157. #if defined(__cplusplus)
  158. }
  159. #endif
  160. /*!
  161. * @}
  162. */
  163. #endif /* _FSL_RDC_SEMA42_H_ */