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