1 /*
2 * Copyright 2020-2023 NXP
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6 /**
7 * @file Clock_Ip_Gate.c
8 * @version 3.0.0
9 *
10 * @brief CLOCK driver implementations.
11 * @details CLOCK driver implementations.
12 *
13 * @addtogroup CLOCK_DRIVER Clock Ip Driver
14 * @{
15 */
16
17
18 #ifdef __cplusplus
19 extern "C"{
20 #endif
21
22
23 /*==================================================================================================
24 * INCLUDE FILES
25 * 1) system and project includes
26 * 2) needed interfaces from external units
27 * 3) internal and external interfaces from this unit
28 ==================================================================================================*/
29
30
31 #include "Clock_Ip_Private.h"
32
33 /*==================================================================================================
34 SOURCE FILE VERSION INFORMATION
35 ==================================================================================================*/
36 #define CLOCK_IP_GATE_VENDOR_ID_C 43
37 #define CLOCK_IP_GATE_AR_RELEASE_MAJOR_VERSION_C 4
38 #define CLOCK_IP_GATE_AR_RELEASE_MINOR_VERSION_C 7
39 #define CLOCK_IP_GATE_AR_RELEASE_REVISION_VERSION_C 0
40 #define CLOCK_IP_GATE_SW_MAJOR_VERSION_C 3
41 #define CLOCK_IP_GATE_SW_MINOR_VERSION_C 0
42 #define CLOCK_IP_GATE_SW_PATCH_VERSION_C 0
43
44 /*==================================================================================================
45 * FILE VERSION CHECKS
46 ==================================================================================================*/
47 /* Check if Clock_Ip_Gate.c file and Clock_Ip_Private.h file are of the same vendor */
48 #if (CLOCK_IP_GATE_VENDOR_ID_C != CLOCK_IP_PRIVATE_VENDOR_ID)
49 #error "Clock_Ip_Gate.c and Clock_Ip_Private.h have different vendor ids"
50 #endif
51
52 /* Check if Clock_Ip_Gate.c file and Clock_Ip_Private.h file are of the same Autosar version */
53 #if ((CLOCK_IP_GATE_AR_RELEASE_MAJOR_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_MAJOR_VERSION) || \
54 (CLOCK_IP_GATE_AR_RELEASE_MINOR_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_MINOR_VERSION) || \
55 (CLOCK_IP_GATE_AR_RELEASE_REVISION_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_REVISION_VERSION) \
56 )
57 #error "AutoSar Version Numbers of Clock_Ip_Gate.c and Clock_Ip_Private.h are different"
58 #endif
59
60 /* Check if Clock_Ip_Gate.c file and Clock_Ip_Private.h file are of the same Software version */
61 #if ((CLOCK_IP_GATE_SW_MAJOR_VERSION_C != CLOCK_IP_PRIVATE_SW_MAJOR_VERSION) || \
62 (CLOCK_IP_GATE_SW_MINOR_VERSION_C != CLOCK_IP_PRIVATE_SW_MINOR_VERSION) || \
63 (CLOCK_IP_GATE_SW_PATCH_VERSION_C != CLOCK_IP_PRIVATE_SW_PATCH_VERSION) \
64 )
65 #error "Software Version Numbers of Clock_Ip_Gate.c and Clock_Ip_Private.h are different"
66 #endif
67
68 /*==================================================================================================
69 * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
70 ==================================================================================================*/
71
72 /*==================================================================================================
73 * LOCAL MACROS
74 ==================================================================================================*/
75
76 /*==================================================================================================
77 * LOCAL CONSTANTS
78 ==================================================================================================*/
79
80 /*==================================================================================================
81 * LOCAL VARIABLES
82 ==================================================================================================*/
83
84 /*==================================================================================================
85 * GLOBAL CONSTANTS
86 ==================================================================================================*/
87
88 /*==================================================================================================
89 * GLOBAL VARIABLES
90 ==================================================================================================*/
91
92 /*==================================================================================================
93 * GLOBAL FUNCTION PROTOTYPES
94 ==================================================================================================*/
95 /* Clock start section code */
96 #define MCU_START_SEC_CODE
97
98 #include "Mcu_MemMap.h"
99 /*==================================================================================================
100 * LOCAL FUNCTION PROTOTYPES
101 ==================================================================================================*/
102
103 static void Clock_Ip_ClockSetGateEmpty(Clock_Ip_GateConfigType const* Config);
104 static void Clock_Ip_ClockUpdateGateEmpty(Clock_Ip_NameType ClockName, boolean Gate);
105 #ifdef CLOCK_IP_MC_ME_PARTITION_COFB_ENABLE_REQUEST
106 static void Clock_Ip_ClockSetGateMcMePartitionCollectionClockRequest(Clock_Ip_GateConfigType const* Config);
107 static void Clock_Ip_ClockUpdateGateMcMePartitionCollectionClockRequest(Clock_Ip_NameType ClockName, boolean Gate);
108 #endif
109
110 /* Clock stop section code */
111 #define MCU_STOP_SEC_CODE
112
113 #include "Mcu_MemMap.h"
114 /*==================================================================================================
115 * LOCAL FUNCTIONS
116 ==================================================================================================*/
117
118 /* Clock start section code */
119 #define MCU_START_SEC_CODE
120
121 #include "Mcu_MemMap.h"
122
Clock_Ip_ClockSetGateEmpty(Clock_Ip_GateConfigType const * Config)123 static void Clock_Ip_ClockSetGateEmpty(Clock_Ip_GateConfigType const* Config)
124 {
125 (void)Config;
126 /* No implementation */
127 }
Clock_Ip_ClockUpdateGateEmpty(Clock_Ip_NameType ClockName,boolean Gate)128 static void Clock_Ip_ClockUpdateGateEmpty(Clock_Ip_NameType ClockName, boolean Gate)
129 {
130 (void)ClockName;
131 (void)Gate;
132 /* No implementation */
133 }
134
135 #ifdef CLOCK_IP_MC_ME_PARTITION_COFB_ENABLE_REQUEST
Clock_Ip_ClockSetGateMcMePartitionCollectionClockRequest(Clock_Ip_GateConfigType const * Config)136 static void Clock_Ip_ClockSetGateMcMePartitionCollectionClockRequest(Clock_Ip_GateConfigType const* Config)
137 {
138 boolean TimeoutOccurred = FALSE;
139 uint32 StartTime;
140 uint32 ElapsedTime;
141 uint32 TimeoutTicks;
142
143 const Clock_Ip_GateInfoType * GateInformation;
144 uint32 Partition;
145 uint32 Collection;
146 uint32 EnableRequest;
147
148 if (NULL_PTR != Config)
149 {
150 GateInformation = &Clock_Ip_axGateInfo[Clock_Ip_au8ClockFeatures[Config->Name][CLOCK_IP_GATE_INDEX]];
151 Partition = GateInformation->PartitionValue;
152 Collection = GateInformation->ColectionValue;
153 EnableRequest = GateInformation->RequestValueMask;
154
155 if (Config->Enable != 0U)
156 {
157 /* Partition PRTN_COFB_STAT is reserved in S32G2XX and S32G3XX */
158 #ifdef CLOCK_IP_PLATFORM_SPECIFIC1
159 if (0U == (Clock_Ip_apxMcMeGetPartitions[Partition]->PRTN_COFB_STAT[Collection] & EnableRequest))
160 #else
161 if (0U == (Clock_Ip_apxMcMeSetPartitions[Partition]->PRTN_COFB_CLKEN[Collection] & EnableRequest))
162 #endif
163 {
164
165 Clock_Ip_apxMcMeSetPartitions[Partition]->PRTN_COFB_CLKEN[Collection] |= EnableRequest;
166 Clock_Ip_apxMcMeTriggerPartitions[Partition]->PRTN_PCONF |= MC_ME_PRTN1_PCONF_PCE_MASK;
167 Clock_Ip_apxMcMeTriggerPartitions[Partition]->PRTN_PUPD |= MC_ME_PRTN1_PUPD_PCUD_MASK;
168 Clock_Ip_McMeEnterKey();
169
170 /* Wait until clock gate is updated */
171 Clock_Ip_StartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_IP_TIMEOUT_VALUE_US);
172 do
173 {
174 TimeoutOccurred = Clock_Ip_TimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
175 }
176 while ((0U == (Clock_Ip_apxMcMeGetPartitions[Partition]->PRTN_COFB_STAT[Collection] & EnableRequest)) && (FALSE == TimeoutOccurred));
177 /* timeout notification */
178 if (TRUE == TimeoutOccurred)
179 {
180 /* Report timeout error */
181 Clock_Ip_ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, Config->Name);
182 }
183 }
184 }
185 else
186 {
187 /* Partition PRTN_COFB_STAT is reserved in S32G2XX and S32G3XX */
188 #ifdef CLOCK_IP_PLATFORM_SPECIFIC1
189 if (0U != (Clock_Ip_apxMcMeGetPartitions[Partition]->PRTN_COFB_STAT[Collection] & EnableRequest))
190 #else
191 if (0U != (Clock_Ip_apxMcMeSetPartitions[Partition]->PRTN_COFB_CLKEN[Collection] & EnableRequest))
192 #endif
193 {
194
195 Clock_Ip_apxMcMeSetPartitions[Partition]->PRTN_COFB_CLKEN[Collection] &= (~EnableRequest);
196 Clock_Ip_apxMcMeTriggerPartitions[Partition]->PRTN_PCONF |= MC_ME_PRTN1_PCONF_PCE_MASK;
197 Clock_Ip_apxMcMeTriggerPartitions[Partition]->PRTN_PUPD |= MC_ME_PRTN1_PUPD_PCUD_MASK;
198 Clock_Ip_McMeEnterKey();
199
200 /* Wait until clock gate is updated */
201 Clock_Ip_StartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_IP_TIMEOUT_VALUE_US);
202 do
203 {
204 TimeoutOccurred = Clock_Ip_TimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
205 }
206 while (((Clock_Ip_apxMcMeGetPartitions[Partition]->PRTN_COFB_STAT[Collection] & EnableRequest) != 0U) && (FALSE == TimeoutOccurred));
207 /* timeout notification */
208 if (TRUE == TimeoutOccurred)
209 {
210 /* Report timeout error */
211 Clock_Ip_ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, Config->Name);
212 }
213 }
214 }
215 }
216 else
217 {
218 (void)TimeoutOccurred;
219 (void)StartTime;
220 (void)ElapsedTime;
221 (void)TimeoutTicks;
222 (void)GateInformation;
223 (void)Partition;
224 (void)Collection;
225 (void)EnableRequest;
226 }
227 }
228
Clock_Ip_ClockUpdateGateMcMePartitionCollectionClockRequest(Clock_Ip_NameType ClockName,boolean Gate)229 static void Clock_Ip_ClockUpdateGateMcMePartitionCollectionClockRequest(Clock_Ip_NameType ClockName, boolean Gate)
230 {
231 Clock_Ip_GateConfigType Config;
232
233 Config.Name = ClockName;
234 if (TRUE == Gate)
235 {
236 Config.Enable = 0U;
237 }
238 else
239 {
240 Config.Enable = 1U;
241 }
242 /* Write configuration to register */
243 Clock_Ip_ClockSetGateMcMePartitionCollectionClockRequest(&Config);
244 }
245 #endif
246
247
248 /*==================================================================================================
249 * GLOBAL FUNCTIONS
250 ==================================================================================================*/
251 /* Clock stop section code */
252 #define MCU_STOP_SEC_CODE
253
254 #include "Mcu_MemMap.h"
255
256 /*==================================================================================================
257 * GLOBAL CONSTANTS
258 ==================================================================================================*/
259 /* Clock start constant section data */
260 #define MCU_START_SEC_CONST_UNSPECIFIED
261
262 #include "Mcu_MemMap.h"
263
264 const Clock_Ip_GateCallbackType Clock_Ip_axGateCallbacks[CLOCK_IP_GATE_CALLBACKS_COUNT] =
265 {
266 {
267 Clock_Ip_ClockSetGateEmpty, /* Set */
268 Clock_Ip_ClockUpdateGateEmpty, /* Update */
269 },
270 #ifdef CLOCK_IP_MC_ME_PARTITION_COFB_ENABLE_REQUEST
271 {
272 Clock_Ip_ClockSetGateMcMePartitionCollectionClockRequest, /* Set */
273 Clock_Ip_ClockUpdateGateMcMePartitionCollectionClockRequest, /* Update */
274 },
275 #endif
276
277 };
278
279
280 /* Clock stop constant section data */
281 #define MCU_STOP_SEC_CONST_UNSPECIFIED
282
283 #include "Mcu_MemMap.h"
284
285
286 #ifdef __cplusplus
287 }
288 #endif
289
290 /** @} */
291
292