1 /*
2 * Copyright 2020-2023 NXP
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6 /**
7 * @file Clock_Ip_IntOsc.c
8 * @version 2.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 #ifdef __cplusplus
18 extern "C"{
19 #endif
20
21
22 /*==================================================================================================
23 * INCLUDE FILES
24 * 1) system and project includes
25 * 2) needed interfaces from external units
26 * 3) internal and external interfaces from this unit
27 ==================================================================================================*/
28
29
30 #include "Clock_Ip_Private.h"
31
32 /*==================================================================================================
33 SOURCE FILE VERSION INFORMATION
34 ==================================================================================================*/
35 #define CLOCK_IP_INTOSC_VENDOR_ID_C 43
36 #define CLOCK_IP_INTOSC_AR_RELEASE_MAJOR_VERSION_C 4
37 #define CLOCK_IP_INTOSC_AR_RELEASE_MINOR_VERSION_C 7
38 #define CLOCK_IP_INTOSC_AR_RELEASE_REVISION_VERSION_C 0
39 #define CLOCK_IP_INTOSC_SW_MAJOR_VERSION_C 2
40 #define CLOCK_IP_INTOSC_SW_MINOR_VERSION_C 0
41 #define CLOCK_IP_INTOSC_SW_PATCH_VERSION_C 0
42
43 /*==================================================================================================
44 * FILE VERSION CHECKS
45 ==================================================================================================*/
46 /* Check if Clock_Ip_IntOsc.c file and Clock_Ip_Private.h file are of the same vendor */
47 #if (CLOCK_IP_INTOSC_VENDOR_ID_C != CLOCK_IP_PRIVATE_VENDOR_ID)
48 #error "Clock_Ip_IntOsc.c and Clock_Ip_Private.h have different vendor ids"
49 #endif
50
51 /* Check if Clock_Ip_IntOsc.c file and Clock_Ip_Private.h file are of the same Autosar version */
52 #if ((CLOCK_IP_INTOSC_AR_RELEASE_MAJOR_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_MAJOR_VERSION) || \
53 (CLOCK_IP_INTOSC_AR_RELEASE_MINOR_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_MINOR_VERSION) || \
54 (CLOCK_IP_INTOSC_AR_RELEASE_REVISION_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_REVISION_VERSION) \
55 )
56 #error "AutoSar Version Numbers of Clock_Ip_IntOsc.c and Clock_Ip_Private.h are different"
57 #endif
58
59 /* Check if Clock_Ip_IntOsc.c file and Clock_Ip_Private.h file are of the same Software version */
60 #if ((CLOCK_IP_INTOSC_SW_MAJOR_VERSION_C != CLOCK_IP_PRIVATE_SW_MAJOR_VERSION) || \
61 (CLOCK_IP_INTOSC_SW_MINOR_VERSION_C != CLOCK_IP_PRIVATE_SW_MINOR_VERSION) || \
62 (CLOCK_IP_INTOSC_SW_PATCH_VERSION_C != CLOCK_IP_PRIVATE_SW_PATCH_VERSION) \
63 )
64 #error "Software Version Numbers of Clock_Ip_IntOsc.c and Clock_Ip_Private.h are different"
65 #endif
66
67 /*==================================================================================================
68 * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
69 ==================================================================================================*/
70
71 /*==================================================================================================
72 * LOCAL MACROS
73 ==================================================================================================*/
74
75 /*==================================================================================================
76 * LOCAL CONSTANTS
77 ==================================================================================================*/
78
79 /*==================================================================================================
80 * LOCAL VARIABLES
81 ==================================================================================================*/
82
83 /*==================================================================================================
84 * GLOBAL CONSTANTS
85 ==================================================================================================*/
86
87 /*==================================================================================================
88 * GLOBAL VARIABLES
89 ==================================================================================================*/
90
91 /*==================================================================================================
92 * GLOBAL FUNCTION PROTOTYPES
93 ==================================================================================================*/
94 /* Clock start section code */
95 #define MCU_START_SEC_CODE
96
97 #include "Mcu_MemMap.h"
98 #ifdef CLOCK_IP_SIRC_ENABLE
99 void Clock_Ip_SetSirc_TrustedCall(Clock_Ip_IrcoscConfigType const* Config);
100 void Clock_Ip_EnableSirc_TrustedCall(Clock_Ip_IrcoscConfigType const* Config);
101 void Clock_Ip_DisableSirc_TrustedCall(Clock_Ip_NameType Name);
102 #endif
103
104 #ifdef CLOCK_IP_SIRC_VLP_ENABLE
105 void Clock_Ip_SetSircVlp_TrustedCall(Clock_Ip_IrcoscConfigType const* Config);
106 void Clock_Ip_EnableSircVlp_TrustedCall(Clock_Ip_IrcoscConfigType const* Config);
107 void Clock_Ip_DisableSircVlp_TrustedCall(Clock_Ip_NameType Name);
108 #endif
109
110 #ifdef CLOCK_IP_SIRC_STOP_ENABLE
111 void Clock_Ip_SetSircStop_TrustedCall(Clock_Ip_IrcoscConfigType const* Config);
112 void Clock_Ip_EnableSircStop_TrustedCall(Clock_Ip_IrcoscConfigType const* Config);
113 void Clock_Ip_DisableSircStop_TrustedCall(Clock_Ip_NameType Name);
114 #endif
115
116 #ifdef CLOCK_IP_FIRC_ENABLE
117 void Clock_Ip_SetFirc_TrustedCall(Clock_Ip_IrcoscConfigType const* Config);
118 void Clock_Ip_EnableFirc_TrustedCall(Clock_Ip_IrcoscConfigType const* Config);
119 void Clock_Ip_DisableFirc_TrustedCall(Clock_Ip_NameType Name);
120 #endif
121
122 /*==================================================================================================
123 * LOCAL FUNCTION PROTOTYPES
124 ==================================================================================================*/
125
126 static void Clock_Ip_InternalOscillatorEmpty(Clock_Ip_IrcoscConfigType const* Config);
127 static void Clock_Ip_InternalOscillatorEmpty_Disable(Clock_Ip_NameType Name);
128 #ifdef CLOCK_IP_FIRC_DIV_SEL_HSEb_CONFIG_REG_GPR
129 static void Clock_Ip_SetFircDivSelHSEb(Clock_Ip_IrcoscConfigType const* Config);
130 #endif
131 #ifdef CLOCK_IP_SIRC_ENABLE
132 static void Clock_Ip_SetSirc(Clock_Ip_IrcoscConfigType const* Config);
133 static void Clock_Ip_EnableSirc(Clock_Ip_IrcoscConfigType const* Config);
134 static void Clock_Ip_DisableSirc(Clock_Ip_NameType Name);
135 #endif
136 #ifdef CLOCK_IP_SIRC_VLP_ENABLE
137 static void Clock_Ip_SetSircVlp(Clock_Ip_IrcoscConfigType const* Config);
138 static void Clock_Ip_EnableSircVlp(Clock_Ip_IrcoscConfigType const* Config);
139 static void Clock_Ip_DisableSircVlp(Clock_Ip_NameType Name);
140 #endif
141 #ifdef CLOCK_IP_SIRC_STOP_ENABLE
142 static void Clock_Ip_SetSircStop(Clock_Ip_IrcoscConfigType const* Config);
143 static void Clock_Ip_EnableSircStop(Clock_Ip_IrcoscConfigType const* Config);
144 static void Clock_Ip_DisableSircStop(Clock_Ip_NameType Name);
145 #endif
146 #ifdef CLOCK_IP_FIRC_ENABLE
147 static void Clock_Ip_SetFirc(Clock_Ip_IrcoscConfigType const* Config);
148 static void Clock_Ip_EnableFirc(Clock_Ip_IrcoscConfigType const* Config);
149 static void Clock_Ip_DisableFirc(Clock_Ip_NameType Name);
150 #endif
151 /* Clock stop section code */
152 #define MCU_STOP_SEC_CODE
153
154 #include "Mcu_MemMap.h"
155 /*==================================================================================================
156 * LOCAL FUNCTIONS
157 ==================================================================================================*/
158
159 /* Clock start section code */
160 #define MCU_START_SEC_CODE
161
162 #include "Mcu_MemMap.h"
163
Clock_Ip_InternalOscillatorEmpty(Clock_Ip_IrcoscConfigType const * Config)164 static void Clock_Ip_InternalOscillatorEmpty(Clock_Ip_IrcoscConfigType const* Config)
165 {
166 (void)Config;
167 /* No implementation */
168 }
Clock_Ip_InternalOscillatorEmpty_Disable(Clock_Ip_NameType Name)169 static void Clock_Ip_InternalOscillatorEmpty_Disable(Clock_Ip_NameType Name)
170 {
171 (void)Name;
172 /* No implementation */
173 }
174
175
176 #ifdef CLOCK_IP_FIRC_DIV_SEL_HSEb_CONFIG_REG_GPR
177 #define CLOCK_IP_WFI_EXECUTED MC_ME_PRTN0_CORE2_STAT_WFI_MASK
178 #define CLOCK_IP_APP_CAN_WRITE 5U
179 /* Set Firc Div Sel */
Clock_Ip_SetFircDivSelHSEb(Clock_Ip_IrcoscConfigType const * Config)180 static void Clock_Ip_SetFircDivSelHSEb(Clock_Ip_IrcoscConfigType const* Config)
181 {
182 uint32 RegValue;
183 uint32 DividerValue = 0U;
184
185 boolean TimeoutOccurred = FALSE;
186 uint32 StartTime;
187 uint32 ElapsedTime;
188 uint32 TimeoutTicks;
189 uint32 WfiStatus;
190
191 if (NULL_PTR != Config)
192 {
193 switch(Config->Range)
194 {
195 case CLOCK_IP_SUPPORTS_48MHZ_FREQUENCY:
196 DividerValue = 3U;
197 break;
198 case CLOCK_IP_SUPPORTS_24MHZ_FREQUENCY:
199 DividerValue = 1U;
200 break;
201 case CLOCK_IP_SUPPORTS_3MHZ_FREQUENCY:
202 DividerValue = 2U;
203 break;
204 default:
205 /* No option in hardware for this value */
206 break;
207 }
208
209 /* If divider value option from configuration is valid */
210 if (DividerValue != 0U)
211 {
212 /* Application can write this divider */
213 if ( ((IP_CONFIGURATION_GPR->CONFIG_REG_GPR & CONFIGURATION_GPR_CONFIG_REG_GPR_APP_CORE_ACC_MASK)>>CONFIGURATION_GPR_CONFIG_REG_GPR_APP_CORE_ACC_SHIFT) == CLOCK_IP_APP_CAN_WRITE)
214 {
215 /* Before access to CONFIG_REG_GPR register, driver should wait for Secure BAF to go in WFI
216 by reading register PRTN0_CORE2_STAT. Wfi status will be checked. */
217 Clock_Ip_StartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_IP_TIMEOUT_VALUE_US);
218 /* Wait for acknowledge to be cleared. */
219 do
220 {
221 WfiStatus = (IP_MC_ME->PRTN0_CORE2_STAT & MC_ME_PRTN0_CORE2_STAT_WFI_MASK);
222 TimeoutOccurred = Clock_Ip_TimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
223 }
224 while ((CLOCK_IP_WFI_EXECUTED != WfiStatus) && (FALSE == TimeoutOccurred));
225
226 if (FALSE == TimeoutOccurred)
227 {
228 RegValue = IP_CONFIGURATION_GPR->CONFIG_REG_GPR;
229 RegValue &= ~CONFIGURATION_GPR_CONFIG_REG_GPR_FIRC_DIV_SEL_MASK;
230 RegValue |= CONFIGURATION_GPR_CONFIG_REG_GPR_FIRC_DIV_SEL(DividerValue);
231 IP_CONFIGURATION_GPR->CONFIG_REG_GPR = RegValue;
232 }
233 else
234 {
235 Clock_Ip_ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, Config->Name);
236 }
237 }
238 else
239 {
240 /* HSE firmware doesn't allow to write FIRC post divider. Firc range cannot be set as it's configured. */
241 Clock_Ip_ReportClockErrors(CLOCK_IP_REPORT_WRITE_PROTECTION_ERROR, Config->Name);
242 }
243 }
244 }
245 else
246 {
247 (void)RegValue;
248 (void)DividerValue;
249 (void)TimeoutOccurred;
250 (void)StartTime;
251 (void)ElapsedTime;
252 (void)TimeoutTicks;
253 (void)WfiStatus;
254 }
255 }
256 #endif
257
258 #ifdef CLOCK_IP_SIRC_ENABLE
Clock_Ip_SetSirc(Clock_Ip_IrcoscConfigType const * Config)259 static void Clock_Ip_SetSirc(Clock_Ip_IrcoscConfigType const* Config)
260 {
261 if (NULL_PTR != Config)
262 {
263 #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
264 #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
265 OsIf_Trusted_Call1param(Clock_Ip_SetSirc_TrustedCall,(Config));
266 #else
267 Clock_Ip_SetSirc_TrustedCall(Config);
268 #endif
269 #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
270 }
271 }
Clock_Ip_EnableSirc(Clock_Ip_IrcoscConfigType const * Config)272 static void Clock_Ip_EnableSirc(Clock_Ip_IrcoscConfigType const* Config)
273 {
274 if (NULL_PTR != Config)
275 {
276 #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
277 #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
278 OsIf_Trusted_Call1param(Clock_Ip_EnableSirc_TrustedCall,(Config));
279 #else
280 Clock_Ip_EnableSirc_TrustedCall(Config);
281 #endif
282 #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
283 }
284 }
Clock_Ip_DisableSirc(Clock_Ip_NameType Name)285 static void Clock_Ip_DisableSirc(Clock_Ip_NameType Name)
286 {
287 #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
288 #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
289 OsIf_Trusted_Call1param(Clock_Ip_DisableSirc_TrustedCall,(Name));
290 #else
291 Clock_Ip_DisableSirc_TrustedCall(Name);
292 #endif
293 #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
294 }
295 #endif
296
297 #ifdef CLOCK_IP_SIRC_VLP_ENABLE
Clock_Ip_SetSircVlp(Clock_Ip_IrcoscConfigType const * Config)298 static void Clock_Ip_SetSircVlp(Clock_Ip_IrcoscConfigType const* Config)
299 {
300 if (NULL_PTR != Config)
301 {
302 #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
303 #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
304 OsIf_Trusted_Call1param(Clock_Ip_SetSircVlp_TrustedCall,(Config));
305 #else
306 Clock_Ip_SetSircVlp_TrustedCall(Config);
307 #endif
308 #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
309 }
310 }
Clock_Ip_EnableSircVlp(Clock_Ip_IrcoscConfigType const * Config)311 static void Clock_Ip_EnableSircVlp(Clock_Ip_IrcoscConfigType const* Config)
312 {
313 if (NULL_PTR != Config)
314 {
315 #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
316 #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
317 OsIf_Trusted_Call1param(Clock_Ip_EnableSircVlp_TrustedCall,(Config));
318 #else
319 Clock_Ip_EnableSircVlp_TrustedCall(Config);
320 #endif
321 #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
322 }
323 }
Clock_Ip_DisableSircVlp(Clock_Ip_NameType Name)324 static void Clock_Ip_DisableSircVlp(Clock_Ip_NameType Name)
325 {
326 #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
327 #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
328 OsIf_Trusted_Call1param(Clock_Ip_DisableSircVlp_TrustedCall,(Name));
329 #else
330 Clock_Ip_DisableSircVlp_TrustedCall(Name);
331 #endif
332 #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
333 }
334 #endif
335
336 #ifdef CLOCK_IP_SIRC_STOP_ENABLE
Clock_Ip_SetSircStop(Clock_Ip_IrcoscConfigType const * Config)337 static void Clock_Ip_SetSircStop(Clock_Ip_IrcoscConfigType const* Config)
338 {
339 if (NULL_PTR != Config)
340 {
341 #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
342 #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
343 OsIf_Trusted_Call1param(Clock_Ip_SetSircStop_TrustedCall,(Config));
344 #else
345 Clock_Ip_SetSircStop_TrustedCall(Config);
346 #endif
347 #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
348 }
349 }
Clock_Ip_EnableSircStop(Clock_Ip_IrcoscConfigType const * Config)350 static void Clock_Ip_EnableSircStop(Clock_Ip_IrcoscConfigType const* Config)
351 {
352 if (NULL_PTR != Config)
353 {
354 #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
355 #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
356 OsIf_Trusted_Call1param(Clock_Ip_EnableSircStop_TrustedCall,(Config));
357 #else
358 Clock_Ip_EnableSircStop_TrustedCall(Config);
359 #endif
360 #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
361 }
362 }
Clock_Ip_DisableSircStop(Clock_Ip_NameType Name)363 static void Clock_Ip_DisableSircStop(Clock_Ip_NameType Name)
364 {
365 #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
366 #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
367 OsIf_Trusted_Call1param(Clock_Ip_DisableSircStop_TrustedCall,(Name));
368 #else
369 Clock_Ip_DisableSircStop_TrustedCall(Name);
370 #endif
371 #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
372 }
373 #endif
374
375 #ifdef CLOCK_IP_FIRC_ENABLE
376 #define CLOCK_IP_SIRC_CLK_SOURCE 2U
377 #define CLOCK_IP_FIRC_CLK_SOURCE 3U
SetInputSouceSytemClock(uint32 SourceClock)378 static void SetInputSouceSytemClock(uint32 SourceClock)
379 {
380 uint32 RegValue;
381 boolean TimeoutOccurred = FALSE;
382 uint32 StartTime;
383 uint32 ElapsedTime;
384 uint32 TimeoutTicks;
385 uint32 ScsStatus;
386
387 RegValue = IP_SCG->RCCR;
388 RegValue &= ~SCG_RCCR_SCS_MASK;
389 RegValue |= (SourceClock << SCG_RCCR_SCS_SHIFT);
390 IP_SCG->RCCR = RegValue;
391
392 Clock_Ip_StartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_IP_TIMEOUT_VALUE_US);
393 do
394 {
395 ScsStatus = (((IP_SCG->CSR & SCG_CSR_SCS_MASK) >> SCG_CSR_SCS_SHIFT) != (SourceClock))?0U:1U;
396 TimeoutOccurred = Clock_Ip_TimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
397 }
398 while ((0U == ScsStatus) && (FALSE == TimeoutOccurred));
399
400 if (FALSE != TimeoutOccurred)
401 {
402 /* Report timeout error */
403 Clock_Ip_ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, FIRC_CLK);
404 }
405 }
Clock_Ip_SetFirc(Clock_Ip_IrcoscConfigType const * Config)406 static void Clock_Ip_SetFirc(Clock_Ip_IrcoscConfigType const* Config)
407 {
408 if (NULL_PTR != Config)
409 {
410 #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
411 #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
412 OsIf_Trusted_Call1param(Clock_Ip_SetFirc_TrustedCall,(Config));
413 #else
414 Clock_Ip_SetFirc_TrustedCall(Config);
415 #endif
416 #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
417 }
418 }
Clock_Ip_EnableFirc(Clock_Ip_IrcoscConfigType const * Config)419 static void Clock_Ip_EnableFirc(Clock_Ip_IrcoscConfigType const* Config)
420 {
421 if (NULL_PTR != Config)
422 {
423 #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
424 #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
425 OsIf_Trusted_Call1param(Clock_Ip_EnableFirc_TrustedCall,(Config));
426 #else
427 Clock_Ip_EnableFirc_TrustedCall(Config);
428 #endif
429 #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
430 }
431 }
Clock_Ip_DisableFirc(Clock_Ip_NameType Name)432 static void Clock_Ip_DisableFirc(Clock_Ip_NameType Name)
433 {
434 #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
435 #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
436 OsIf_Trusted_Call1param(Clock_Ip_DisableFirc_TrustedCall,(Name));
437 #else
438 Clock_Ip_DisableFirc_TrustedCall(Name);
439 #endif
440 #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
441 }
442 #endif
443
444
445
446 /*==================================================================================================
447 * GLOBAL FUNCTIONS
448 ==================================================================================================*/
449 #ifdef CLOCK_IP_SIRC_ENABLE
Clock_Ip_SetSirc_TrustedCall(Clock_Ip_IrcoscConfigType const * Config)450 void Clock_Ip_SetSirc_TrustedCall(Clock_Ip_IrcoscConfigType const* Config)
451 {
452 boolean TimeoutOccurred = FALSE;
453 uint32 StartTime;
454 uint32 ElapsedTime;
455 uint32 TimeoutTicks;
456 uint32 IrcoscStatus;
457 Clock_Ip_IrcoscConfigType SircConfig;
458
459 if (NULL_PTR == Config)
460 {
461 SircConfig.Name = FIRC_CLK;
462 SircConfig.Range = 1U; /* 8MHz */
463 SircConfig.Enable = 1U; /* enabled */
464 SircConfig.LowPowerModeEnable =1U;
465 }
466 else
467 {
468 SircConfig.Name = Config->Name;
469 SircConfig.Range = Config->Range;
470 SircConfig.Enable = Config->Enable;
471 SircConfig.LowPowerModeEnable = Config->LowPowerModeEnable;
472 }
473
474 /* Clear LK bit field */
475 IP_SCG->SIRCCSR &= (~((uint32)SCG_SIRCCSR_LK_MASK));
476
477 /* Disable clock */
478 IP_SCG->SIRCCSR &= (~((uint32)SCG_SIRCCSR_SIRCEN_MASK));
479
480 /* Disable SIRC Low Power */
481 IP_SCG->SIRCCSR &= (~((uint32)SCG_SIRCCSR_SIRCLPEN_MASK));
482
483 /* Configure SIRC. */
484 if (1U == SircConfig.Enable)
485 {
486 /* Step frequency range. */
487 IP_SCG->SIRCCFG = SCG_SIRCCFG_RANGE(SircConfig.Range);
488
489 /* Enable clock. */
490 IP_SCG->SIRCCSR |= SCG_SIRCCSR_SIRCEN(1U);
491
492 /* Set SIRC in VLP modes */
493 IP_SCG->SIRCCSR |= SCG_SIRCCSR_SIRCLPEN(SircConfig.LowPowerModeEnable);
494
495 Clock_Ip_StartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_IP_TIMEOUT_VALUE_US);
496 /* Wait until ircosc is locked */
497 do
498 {
499 IrcoscStatus = (((IP_SCG->SIRCCSR & SCG_SIRCCSR_SIRCVLD_MASK) >> SCG_SIRCCSR_SIRCVLD_SHIFT));
500 TimeoutOccurred = Clock_Ip_TimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
501 }
502 while ((0U == IrcoscStatus) && (FALSE == TimeoutOccurred));
503
504 if (FALSE != TimeoutOccurred)
505 {
506 /* Report timeout error */
507 Clock_Ip_ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, SircConfig.Name);
508 }
509 }
510 }
Clock_Ip_EnableSirc_TrustedCall(Clock_Ip_IrcoscConfigType const * Config)511 void Clock_Ip_EnableSirc_TrustedCall(Clock_Ip_IrcoscConfigType const* Config)
512 {
513 boolean TimeoutOccurred = FALSE;
514 uint32 StartTime;
515 uint32 ElapsedTime;
516 uint32 TimeoutTicks;
517 uint32 IrcoscStatus;
518
519 /* Enable clock. */
520 IP_SCG->SIRCCSR |= SCG_SIRCCSR_SIRCEN(1U);
521
522 /* Enable SIRC Low Power */
523 IP_SCG->SIRCCSR |= SCG_SIRCCSR_SIRCLPEN(1UL);
524
525 Clock_Ip_StartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_IP_TIMEOUT_VALUE_US);
526 /* Wait until ircosc is locked */
527 do
528 {
529 IrcoscStatus = (((IP_SCG->SIRCCSR & SCG_SIRCCSR_SIRCVLD_MASK) >> SCG_SIRCCSR_SIRCVLD_SHIFT));
530 TimeoutOccurred = Clock_Ip_TimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
531 }
532 while ((0U == IrcoscStatus) && (FALSE == TimeoutOccurred));
533
534 if (FALSE != TimeoutOccurred)
535 {
536 /* Report timeout error */
537 Clock_Ip_ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, Config->Name);
538 }
539 }
Clock_Ip_DisableSirc_TrustedCall(Clock_Ip_NameType Name)540 void Clock_Ip_DisableSirc_TrustedCall(Clock_Ip_NameType Name)
541 {
542 (void)Name;
543
544 /* Disable clock. */
545 IP_SCG->SIRCCSR &= ~SCG_SIRCCSR_SIRCEN_MASK;
546
547 /* Disable SIRC Low Power */
548 IP_SCG->SIRCCSR &= (~((uint32)SCG_SIRCCSR_SIRCLPEN_MASK));
549 }
550 #endif
551
552 #ifdef CLOCK_IP_SIRC_VLP_ENABLE
Clock_Ip_SetSircVlp_TrustedCall(Clock_Ip_IrcoscConfigType const * Config)553 void Clock_Ip_SetSircVlp_TrustedCall(Clock_Ip_IrcoscConfigType const* Config)
554 {
555 /* Clear LK bit field */
556 IP_SCG->SIRCCSR &= (~((uint32)SCG_SIRCCSR_LK_MASK));
557
558 IP_SCG->SIRCCSR &= (~((uint32)SCG_SIRCCSR_SIRCLPEN_MASK));
559
560 /* Configure SIRC in VLP mode */
561 IP_SCG->SIRCCSR |= SCG_SIRCCSR_SIRCLPEN(Config->LowPowerModeEnable);
562 }
Clock_Ip_EnableSircVlp_TrustedCall(Clock_Ip_IrcoscConfigType const * Config)563 void Clock_Ip_EnableSircVlp_TrustedCall(Clock_Ip_IrcoscConfigType const* Config)
564 {
565 if (1U == Config->Enable)
566 {
567 /* Enable clock in VLP mode */
568 IP_SCG->SIRCCSR |= SCG_SIRCCSR_SIRCLPEN(1U);
569 }
570 }
Clock_Ip_DisableSircVlp_TrustedCall(Clock_Ip_NameType Name)571 void Clock_Ip_DisableSircVlp_TrustedCall(Clock_Ip_NameType Name)
572 {
573 (void)Name;
574
575 /* Disable clock */
576 IP_SCG->SIRCCSR &= (~((uint32)SCG_SIRCCSR_SIRCLPEN_MASK));
577 }
578 #endif
579
580 #ifdef CLOCK_IP_SIRC_STOP_ENABLE
Clock_Ip_SetSircStop_TrustedCall(Clock_Ip_IrcoscConfigType const * Config)581 void Clock_Ip_SetSircStop_TrustedCall(Clock_Ip_IrcoscConfigType const* Config)
582 {
583 (void)Config;
584
585 /* Clear LK bit field */
586 IP_SCG->SIRCCSR &= (~((uint32)SCG_SIRCCSR_LK_MASK));
587
588 IP_SCG->SIRCCSR &= (~((uint32)SCG_SIRCCSR_SIRCSTEN_MASK));
589
590 /* Configure SIRC in STOP mode */
591 IP_SCG->SIRCCSR |= SCG_SIRCCSR_SIRCSTEN(Config->StopModeEnable);
592 }
Clock_Ip_EnableSircStop_TrustedCall(Clock_Ip_IrcoscConfigType const * Config)593 void Clock_Ip_EnableSircStop_TrustedCall(Clock_Ip_IrcoscConfigType const* Config)
594 {
595 if (1U == Config->Enable)
596 {
597 /* Enable clock in VLP mode */
598 IP_SCG->SIRCCSR |= SCG_SIRCCSR_SIRCSTEN(1U);
599 }
600 }
Clock_Ip_DisableSircStop_TrustedCall(Clock_Ip_NameType Name)601 void Clock_Ip_DisableSircStop_TrustedCall(Clock_Ip_NameType Name)
602 {
603 (void)Name;
604
605 /* Disable clock */
606 IP_SCG->SIRCCSR &= (~((uint32)SCG_SIRCCSR_SIRCSTEN_MASK));
607 }
608 #endif
609
610 #ifdef CLOCK_IP_FIRC_ENABLE
Clock_Ip_SetFirc_TrustedCall(Clock_Ip_IrcoscConfigType const * Config)611 void Clock_Ip_SetFirc_TrustedCall(Clock_Ip_IrcoscConfigType const* Config)
612 {
613 uint32 Instance = Clock_Ip_au8ClockFeatures[Config->Name][CLOCK_IP_MODULE_INSTANCE];
614 boolean TimeoutOccurred = FALSE;
615 boolean SircWasDisabled = FALSE;
616 uint32 StartTime;
617 uint32 ElapsedTime;
618 uint32 TimeoutTicks;
619 uint32 IrcoscStatus;
620
621 (void)Instance;
622
623 /* Clear LK bit field */
624 IP_SCG->FIRCCSR &= (uint32)(~(SCG_FIRCCSR_LK_MASK));
625
626 /* Check that FIRC is used by system clock) */
627 if ((IP_SCG->FIRCCSR & SCG_FIRCCSR_FIRCSEL_MASK) != 0U)
628 {
629 /* Check whether FIRC is already configured as required */
630 if ( (Config->Range != ((IP_SCG->FIRCCFG & SCG_FIRCCFG_RANGE_MASK) >> SCG_FIRCCFG_RANGE_SHIFT)) ||
631 (Config->Regulator != ((IP_SCG->FIRCCSR & SCG_FIRCCSR_FIRCREGOFF_MASK) >> SCG_FIRCCSR_FIRCREGOFF_SHIFT)) )
632 {
633 /* Enable SIRC if it is disabled. */
634 if (0U == (IP_SCG->SIRCCSR & SCG_SIRCCSR_SIRCEN_MASK))
635 {
636 SircWasDisabled = TRUE;
637 Clock_Ip_SetSirc(NULL_PTR);
638 }
639
640 /* Switch to SIRC */
641 SetInputSouceSytemClock(CLOCK_IP_SIRC_CLK_SOURCE);
642
643 /* Disable clock */
644 IP_SCG->FIRCCSR &= (~((uint32)SCG_FIRCCSR_FIRCEN_MASK));
645
646 /* Configure FIRC. */
647 if (1U == Config->Enable)
648 {
649 /* Step frequency range. */
650 IP_SCG->FIRCCFG = SCG_FIRCCFG_RANGE(Config->Range);
651
652 /* Enable clock. */
653 IP_SCG->FIRCCSR |= (SCG_FIRCCSR_FIRCEN(1U) | SCG_FIRCCSR_FIRCREGOFF(Config->Regulator));
654
655 Clock_Ip_StartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_IP_TIMEOUT_VALUE_US);
656 /* Wait until ircosc is locked */
657 do
658 {
659 IrcoscStatus = (((IP_SCG->FIRCCSR & SCG_FIRCCSR_FIRCVLD_MASK) >> SCG_FIRCCSR_FIRCVLD_SHIFT));
660 TimeoutOccurred = Clock_Ip_TimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
661 }
662 while ((0U == IrcoscStatus) && (FALSE == TimeoutOccurred));
663
664 if (FALSE != TimeoutOccurred)
665 {
666 /* Report timeout error */
667 Clock_Ip_ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, Config->Name);
668 }
669
670 /* Switch back to FIRC */
671 SetInputSouceSytemClock(CLOCK_IP_FIRC_CLK_SOURCE);
672
673 if (SircWasDisabled)
674 {
675 Clock_Ip_DisableSirc(SIRC_CLK);
676 }
677 }
678 }
679 }
680 else
681 {
682 /* Configure FIRC. */
683
684 /* Disable clock */
685 IP_SCG->FIRCCSR &= (~((uint32)SCG_FIRCCSR_FIRCEN_MASK));
686
687 if (1U == Config->Enable)
688 {
689 /* Step frequency range. */
690 IP_SCG->FIRCCFG = SCG_FIRCCFG_RANGE(Config->Range);
691
692 /* Enable clock. */
693 IP_SCG->FIRCCSR |= (SCG_FIRCCSR_FIRCEN(1U) | SCG_FIRCCSR_FIRCREGOFF(Config->Regulator));
694
695 Clock_Ip_StartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_IP_TIMEOUT_VALUE_US);
696 /* Wait until ircosc is locked */
697 do
698 {
699 IrcoscStatus = (((IP_SCG->FIRCCSR & SCG_FIRCCSR_FIRCVLD_MASK) >> SCG_FIRCCSR_FIRCVLD_SHIFT));
700 TimeoutOccurred = Clock_Ip_TimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
701 }
702 while ((0U == IrcoscStatus) && (FALSE == TimeoutOccurred));
703
704 if (FALSE != TimeoutOccurred)
705 {
706 /* Report timeout error */
707 Clock_Ip_ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, Config->Name);
708 }
709 }
710 }
711 }
Clock_Ip_EnableFirc_TrustedCall(Clock_Ip_IrcoscConfigType const * Config)712 void Clock_Ip_EnableFirc_TrustedCall(Clock_Ip_IrcoscConfigType const* Config)
713 {
714 boolean TimeoutOccurred = FALSE;
715 uint32 StartTime;
716 uint32 ElapsedTime;
717 uint32 TimeoutTicks;
718 uint32 IrcoscStatus;
719
720 if (1U == Config->Enable)
721 {
722 /* Enable clock. */
723 IP_SCG->FIRCCSR |= SCG_FIRCCSR_FIRCEN(1U);
724
725 Clock_Ip_StartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_IP_TIMEOUT_VALUE_US);
726 /* Wait until ircosc is locked */
727 do
728 {
729 IrcoscStatus = (((IP_SCG->FIRCCSR & SCG_FIRCCSR_FIRCVLD_MASK) >> SCG_FIRCCSR_FIRCVLD_SHIFT));
730 TimeoutOccurred = Clock_Ip_TimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
731 }
732 while ((0U == IrcoscStatus) && (FALSE == TimeoutOccurred));
733
734 if (FALSE != TimeoutOccurred)
735 {
736 /* Report timeout error */
737 Clock_Ip_ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, Config->Name);
738 }
739 }
740 }
Clock_Ip_DisableFirc_TrustedCall(Clock_Ip_NameType Name)741 void Clock_Ip_DisableFirc_TrustedCall(Clock_Ip_NameType Name)
742 {
743 (void) Name;
744
745 /* Disable clock. */
746 IP_SCG->FIRCCSR &= ~SCG_FIRCCSR_FIRCEN_MASK;
747 }
748 #endif
749
750 /* Clock stop section code */
751 #define MCU_STOP_SEC_CODE
752
753 #include "Mcu_MemMap.h"
754
755 /*==================================================================================================
756 * GLOBAL CONSTANTS
757 ==================================================================================================*/
758 /* Clock start constant section data */
759 #define MCU_START_SEC_CONST_UNSPECIFIED
760
761 #include "Mcu_MemMap.h"
762
763 const Clock_Ip_IntOscCallbackType Clock_Ip_axIntOscCallbacks[CLOCK_IP_IRCOSC_CALLBACKS_COUNT] =
764 {
765 {
766 Clock_Ip_InternalOscillatorEmpty, /* Set */
767 Clock_Ip_InternalOscillatorEmpty, /* Enable */
768 Clock_Ip_InternalOscillatorEmpty_Disable, /* Disable */
769 },
770 #ifdef CLOCK_IP_FIRC_DIV_SEL_HSEb_CONFIG_REG_GPR
771 {
772 Clock_Ip_SetFircDivSelHSEb, /* Set */
773 Clock_Ip_InternalOscillatorEmpty, /* Enable */
774 Clock_Ip_InternalOscillatorEmpty_Disable, /* Disable */
775 },
776 #endif
777 #ifdef CLOCK_IP_SIRC_ENABLE
778 {
779 Clock_Ip_SetSirc, /* Set */
780 Clock_Ip_EnableSirc, /* Enable */
781 Clock_Ip_DisableSirc, /* Disable */
782 },
783 #endif
784
785 #ifdef CLOCK_IP_SIRC_VLP_ENABLE
786 {
787 Clock_Ip_SetSircVlp, /* Set */
788 Clock_Ip_EnableSircVlp, /* Enable */
789 Clock_Ip_DisableSircVlp, /* Disable */
790 },
791 #endif
792
793 #ifdef CLOCK_IP_SIRC_STOP_ENABLE
794 {
795 Clock_Ip_SetSircStop, /* Set */
796 Clock_Ip_EnableSircStop, /* Enable */
797 Clock_Ip_DisableSircStop, /* Disable */
798 },
799 #endif
800
801 #ifdef CLOCK_IP_FIRC_ENABLE
802 {
803 Clock_Ip_SetFirc, /* Set */
804 Clock_Ip_EnableFirc, /* Enable */
805 Clock_Ip_DisableFirc, /* Disable */
806 },
807 #endif
808 };
809
810
811
812
813 /* Clock stop constant section data */
814 #define MCU_STOP_SEC_CONST_UNSPECIFIED
815
816 #include "Mcu_MemMap.h"
817
818 #ifdef __cplusplus
819 }
820 #endif
821
822 /** @} */
823