Clock_Ip_Selector.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral :
  5. * Dependencies : none
  6. *
  7. * Autosar Version : 4.4.0
  8. * Autosar Revision : ASR_REL_4_4_REV_0000
  9. * Autosar Conf.Variant :
  10. * SW Version : 1.0.0
  11. * Build Version : S32K1_RTD_1_0_0_HF01_D2109_ASR_REL_4_4_REV_0000_20210907
  12. *
  13. * (c) Copyright 2020-2021 NXP Semiconductors
  14. * All Rights Reserved.
  15. *
  16. * NXP Confidential. This software is owned or controlled by NXP and may only be
  17. * used strictly in accordance with the applicable license terms. By expressly
  18. * accepting such terms or by downloading, installing, activating and/or otherwise
  19. * using the software, you are agreeing that you have read, and that you agree to
  20. * comply with and are bound by, such license terms. If you do not agree to be
  21. * bound by the applicable license terms, then you may not retain, install,
  22. * activate or otherwise use the software.
  23. ==================================================================================================*/
  24. /**
  25. * @file Clock_Ip_Selector.c
  26. * @version 1.0.0
  27. *
  28. * @brief CLOCK driver implementations.
  29. * @details CLOCK driver implementations.
  30. *
  31. * @addtogroup CLOCK_DRIVER Clock Ip Driver
  32. * @{
  33. */
  34. #include "Clock_Ip_Private.h"
  35. /*==================================================================================================
  36. SOURCE FILE VERSION INFORMATION
  37. ==================================================================================================*/
  38. #define CLOCK_IP_SELECTOR_VENDOR_ID_C 43
  39. #define CLOCK_IP_SELECTOR_AR_RELEASE_MAJOR_VERSION_C 4
  40. #define CLOCK_IP_SELECTOR_AR_RELEASE_MINOR_VERSION_C 4
  41. #define CLOCK_IP_SELECTOR_AR_RELEASE_REVISION_VERSION_C 0
  42. #define CLOCK_IP_SELECTOR_SW_MAJOR_VERSION_C 1
  43. #define CLOCK_IP_SELECTOR_SW_MINOR_VERSION_C 0
  44. #define CLOCK_IP_SELECTOR_SW_PATCH_VERSION_C 0
  45. /*==================================================================================================
  46. * FILE VERSION CHECKS
  47. ==================================================================================================*/
  48. /* Check if Clock_Ip_Selector.c file and Clock_Ip_Private.h file are of the same vendor */
  49. #if (CLOCK_IP_SELECTOR_VENDOR_ID_C != CLOCK_IP_PRIVATE_VENDOR_ID)
  50. #error "Clock_Ip_Selector.c and Clock_Ip_Private.h have different vendor ids"
  51. #endif
  52. /* Check if Clock_Ip_Selector.c file and Clock_Ip_Private.h file are of the same Autosar version */
  53. #if ((CLOCK_IP_SELECTOR_AR_RELEASE_MAJOR_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_MAJOR_VERSION) || \
  54. (CLOCK_IP_SELECTOR_AR_RELEASE_MINOR_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_MINOR_VERSION) || \
  55. (CLOCK_IP_SELECTOR_AR_RELEASE_REVISION_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_REVISION_VERSION) \
  56. )
  57. #error "AutoSar Version Numbers of Clock_Ip_Selector.c and Clock_Ip_Private.h are different"
  58. #endif
  59. /* Check if Clock_Ip_Selector.c file and Clock_Ip_Private.h file are of the same Software version */
  60. #if ((CLOCK_IP_SELECTOR_SW_MAJOR_VERSION_C != CLOCK_IP_PRIVATE_SW_MAJOR_VERSION) || \
  61. (CLOCK_IP_SELECTOR_SW_MINOR_VERSION_C != CLOCK_IP_PRIVATE_SW_MINOR_VERSION) || \
  62. (CLOCK_IP_SELECTOR_SW_PATCH_VERSION_C != CLOCK_IP_PRIVATE_SW_PATCH_VERSION) \
  63. )
  64. #error "Software Version Numbers of Clock_Ip_Selector.c and Clock_Ip_Private.h are different"
  65. #endif
  66. #ifdef GENCTRL1_CTRL_SUPPORT
  67. #if (defined(CLOCK_IP_ENABLE_USER_MODE_SUPPORT))
  68. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  69. #define Call_ConfigureResetGenCtrl1() \
  70. OsIf_Trusted_Call(ConfigureResetGenCtrl1)
  71. #define Call_ConfigureSetGenCtrl1() \
  72. OsIf_Trusted_Call(ConfigureSetGenCtrl1)
  73. #else
  74. #define Call_ConfigureResetGenCtrl1() \
  75. ConfigureResetGenCtrl1()
  76. #define Call_ConfigureSetGenCtrl1() \
  77. ConfigureSetGenCtrl1()
  78. #endif
  79. #else
  80. #define Call_ConfigureResetGenCtrl1() \
  81. ConfigureResetGenCtrl1()
  82. #define Call_ConfigureSetGenCtrl1() \
  83. ConfigureSetGenCtrl1()
  84. #endif
  85. #endif
  86. /* Clock start section code */
  87. #define MCU_START_SEC_CODE
  88. #include "Mcu_MemMap.h"
  89. static void Callback_SelectorEmpty(Clock_Ip_SelectorConfigType const* config);
  90. #ifdef CGM_X_CSC_CSS_CLK_SW_SWIP
  91. static void ResetCgmXCscCssClkswSwip(Clock_Ip_SelectorConfigType const *config);
  92. static void SetCgmXCscCssClkswSwip(Clock_Ip_SelectorConfigType const *config);
  93. #endif
  94. #ifdef CGM_X_CSC_CSS_CLK_SW_RAMPDOWN_RAMPUP_SWIP
  95. static void ResetCgmXCscCssClkswRampupRampdownSwip(Clock_Ip_SelectorConfigType const *config);
  96. static void SetCgmXCscCssClkswRampupRampdownSwip(Clock_Ip_SelectorConfigType const *config);
  97. #endif
  98. #ifdef CGM_X_CSC_CSS_CS_GRIP
  99. static void SetCgmXCscCssCsGrip(Clock_Ip_SelectorConfigType const *config);
  100. static void ResetCgmXCscCssCsGrip(Clock_Ip_SelectorConfigType const *config);
  101. #endif
  102. #ifdef GENCTRL1_CTRL_SUPPORT
  103. static void SetGenctrl1Ctrl(Clock_Ip_SelectorConfigType const *config);
  104. static void ResetGenctrl1Ctrl(Clock_Ip_SelectorConfigType const *config);
  105. static void ConfigureResetGenCtrl1(void);
  106. static void ConfigureSetGenCtrl1(void);
  107. #endif
  108. #ifdef SIM_RTC_SEL
  109. static void ResetSimRtcSel(Clock_Ip_SelectorConfigType const *config);
  110. static void SetSimRtcSel(Clock_Ip_SelectorConfigType const *config);
  111. #endif
  112. #ifdef SIM_LPO_SEL
  113. static void ResetSimLpoSel(Clock_Ip_SelectorConfigType const *config);
  114. static void SetSimLpoSel(Clock_Ip_SelectorConfigType const *config);
  115. #endif
  116. #ifdef SCG_CLKOUT_SEL
  117. static void ResetScgClkoutSel(Clock_Ip_SelectorConfigType const *config);
  118. static void SetScgClkoutSel(Clock_Ip_SelectorConfigType const *config);
  119. #endif
  120. #ifdef SCG_SCS_RUN_SEL
  121. static void ResetScgRunSel(Clock_Ip_SelectorConfigType const *config);
  122. static void SetScgRunSel(Clock_Ip_SelectorConfigType const *config);
  123. #endif
  124. #ifdef SCG_SCS_VLPR_SEL
  125. static void SetScgVlprSel(Clock_Ip_SelectorConfigType const *config);
  126. #endif
  127. #ifdef SCG_SCS_HSRUN_SEL
  128. static void ResetScgHsrunSel(Clock_Ip_SelectorConfigType const *config);
  129. static void SetScgHsrunSel(Clock_Ip_SelectorConfigType const *config);
  130. #endif
  131. #ifdef SIM_FTMOPT_SEL
  132. static void ResetSimFtmoptSel(Clock_Ip_SelectorConfigType const *config);
  133. static void SetSimFtmoptSel(Clock_Ip_SelectorConfigType const *config);
  134. #endif
  135. #ifdef SIM_CLKOUT_SEL
  136. static void ResetSimClkoutSel(Clock_Ip_SelectorConfigType const *config);
  137. static void SetSimClkoutSel(Clock_Ip_SelectorConfigType const *config);
  138. #endif
  139. #ifdef PCC_PCS_SELECT
  140. static void ResetPccPcsSelect(Clock_Ip_SelectorConfigType const *config);
  141. static void SetPccPcsSelect(Clock_Ip_SelectorConfigType const *config);
  142. #endif
  143. #ifdef SIM_TRACE_SEL
  144. static void ResetSimTraceSel(Clock_Ip_SelectorConfigType const *config);
  145. static void SetSimTraceSel(Clock_Ip_SelectorConfigType const *config);
  146. #endif
  147. /* Clock stop section code */
  148. #define MCU_STOP_SEC_CODE
  149. #include "Mcu_MemMap.h"
  150. /* Clock start constant section data */
  151. #define MCU_START_SEC_CONST_UNSPECIFIED
  152. #include "Mcu_MemMap.h"
  153. const selectorCallback selectorCallbacks[SELECTOR_CALLBACKS_COUNT] =
  154. {
  155. {
  156. Callback_SelectorEmpty, /* Reset */
  157. Callback_SelectorEmpty, /* Set */
  158. },
  159. #ifdef CGM_X_CSC_CSS_CLK_SW_SWIP
  160. {
  161. ResetCgmXCscCssClkswSwip, /* Reset */
  162. SetCgmXCscCssClkswSwip, /* Set */
  163. },
  164. #endif
  165. #ifdef CGM_X_CSC_CSS_CLK_SW_RAMPDOWN_RAMPUP_SWIP
  166. {
  167. ResetCgmXCscCssClkswRampupRampdownSwip, /* Reset */
  168. SetCgmXCscCssClkswRampupRampdownSwip, /* Set */
  169. },
  170. #endif
  171. #ifdef CGM_X_CSC_CSS_CS_GRIP
  172. {
  173. ResetCgmXCscCssCsGrip, /* Reset */
  174. SetCgmXCscCssCsGrip, /* Set */
  175. },
  176. #endif
  177. #ifdef GENCTRL1_CTRL_SUPPORT
  178. {
  179. ResetGenctrl1Ctrl, /* Reset */
  180. SetGenctrl1Ctrl, /* Set */
  181. },
  182. #endif
  183. #ifdef SCG_SCS_RUN_SEL
  184. {
  185. ResetScgRunSel, /* Reset */
  186. SetScgRunSel, /* Set */
  187. },
  188. #endif
  189. #ifdef SCG_SCS_VLPR_SEL
  190. {
  191. Callback_SelectorEmpty, /* Reset */
  192. SetScgVlprSel, /* Set */
  193. },
  194. #endif
  195. #ifdef SCG_SCS_HSRUN_SEL
  196. {
  197. ResetScgHsrunSel, /* Reset */
  198. SetScgHsrunSel, /* Set */
  199. },
  200. #endif
  201. #ifdef SIM_RTC_SEL
  202. {
  203. ResetSimRtcSel, /* Reset */
  204. SetSimRtcSel, /* Set */
  205. },
  206. #endif
  207. #ifdef SIM_LPO_SEL
  208. {
  209. ResetSimLpoSel, /* Reset */
  210. SetSimLpoSel, /* Set */
  211. },
  212. #endif
  213. #ifdef SCG_CLKOUT_SEL
  214. {
  215. ResetScgClkoutSel, /* Reset */
  216. SetScgClkoutSel, /* Set */
  217. },
  218. #endif
  219. #ifdef SIM_FTMOPT_SEL
  220. {
  221. ResetSimFtmoptSel, /* Reset */
  222. SetSimFtmoptSel, /* Set */
  223. },
  224. #endif
  225. #ifdef SIM_CLKOUT_SEL
  226. {
  227. ResetSimClkoutSel, /* Reset */
  228. SetSimClkoutSel, /* Set */
  229. },
  230. #endif
  231. #ifdef PCC_PCS_SELECT
  232. {
  233. ResetPccPcsSelect, /* Reset */
  234. SetPccPcsSelect, /* Set */
  235. },
  236. #endif
  237. #ifdef SIM_TRACE_SEL
  238. {
  239. ResetSimTraceSel, /* Reset */
  240. SetSimTraceSel, /* Set */
  241. },
  242. #endif
  243. };
  244. /* Clock stop constant section data */
  245. #define MCU_STOP_SEC_CONST_UNSPECIFIED
  246. #include "Mcu_MemMap.h"
  247. /* Clock start section code */
  248. #define MCU_START_SEC_CODE
  249. #include "Mcu_MemMap.h"
  250. static void Callback_SelectorEmpty(Clock_Ip_SelectorConfigType const* config)
  251. {
  252. (void)config;
  253. /* No implementation */
  254. }
  255. #ifdef CGM_X_CSC_CSS_CLK_SW_SWIP
  256. static void ResetCgmXCscCssClkswSwip(Clock_Ip_SelectorConfigType const *config)
  257. {
  258. uint32 instance = clockFeatures[config->name][CLOCK_MODULE_INSTANCE];
  259. uint32 selectorIndex = clockFeatures[config->name][SELECTOR_INDEX];
  260. cgm[instance][selectorIndex]->CSC |= MC_CGM_MUX_CSC_SAFE_SW_MASK;
  261. }
  262. static void SetCgmXCscCssClkswSwip(Clock_Ip_SelectorConfigType const *config)
  263. {
  264. uint32 instance = clockFeatures[config->name][CLOCK_MODULE_INSTANCE];
  265. uint32 selectorIndex = clockFeatures[config->name][SELECTOR_INDEX];
  266. uint32 selectorValue = selectorEntry_hardwareValue[config->value]; /* Hw value corresponding to selector entry. Translate input clock source to hardware value. */
  267. uint32 SELECTOR_VALUE_MASK = clockFeatureExtensions[clockFeatures[config->name][EXTENSION_INDEX]].SELECTOR_VALUE_MASK;
  268. uint32 SELECTOR_VALUE_SHIFT = clockFeatureExtensions[clockFeatures[config->name][EXTENSION_INDEX]].SELECTOR_VALUE_SHIFT;
  269. uint32 regValue;
  270. boolean TimeoutOccurred = FALSE;
  271. uint32 StartTime;
  272. uint32 ElapsedTime;
  273. uint32 TimeoutTicks;
  274. /* Do not configure mux if it is already set to the selector value from configuration.*/
  275. if (selectorValue != ((cgm[instance][selectorIndex]->CSS & SELECTOR_VALUE_MASK) >> SELECTOR_VALUE_SHIFT))
  276. {
  277. ClockStartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_TIMEOUT_VALUE_US);
  278. do
  279. {
  280. TimeoutOccurred = ClockTimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
  281. }
  282. while(((cgm[instance][selectorIndex]->CSS & MC_CGM_MUX_CSS_SWIP_MASK) == MC_CGM_MUX_CSS_SWIP_IN_PROGRESS) && (FALSE == TimeoutOccurred));
  283. if (FALSE == TimeoutOccurred)
  284. {
  285. regValue = cgm[instance][selectorIndex]->CSC;
  286. regValue &= ~SELECTOR_VALUE_MASK;
  287. regValue |= (selectorValue << SELECTOR_VALUE_SHIFT) & SELECTOR_VALUE_MASK;
  288. regValue |= (MC_CGM_MUX_CSC_CLK_SW_MASK); /* Clock switch operation is requested */
  289. cgm[instance][selectorIndex]->CSC = regValue;
  290. ClockStartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_TIMEOUT_VALUE_US);
  291. /* Wait for CLK_SW to auto-clear */
  292. do
  293. {
  294. TimeoutOccurred = ClockTimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
  295. } /* No safe clock switch operation was requested. */
  296. while(((cgm[instance][selectorIndex]->CSS & MC_CGM_MUX_CSS_CLK_SW_MASK) == MC_CGM_MUX_CSS_CLK_SW_NOT_REQUESTED) && (FALSE == TimeoutOccurred));
  297. if (FALSE == TimeoutOccurred)
  298. {
  299. ClockStartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_TIMEOUT_VALUE_US);
  300. /* Wait for acknowledge to be cleared. */
  301. do
  302. {
  303. TimeoutOccurred = ClockTimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
  304. }
  305. while(((cgm[instance][selectorIndex]->CSS & MC_CGM_MUX_CSS_SWIP_MASK) == MC_CGM_MUX_CSS_SWIP_IN_PROGRESS) && (FALSE == TimeoutOccurred) );
  306. if (FALSE == TimeoutOccurred)
  307. {
  308. /* Check the switch status. */
  309. if (MC_CGM_MUX_CSS_SWTRG_SUCCEEDED != ((cgm[instance][selectorIndex]->CSS & MC_CGM_MUX_CSS_SWTRG_MASK) >> MC_CGM_MUX_0_CSS_SWTRG_SHIFT))
  310. {
  311. ReportClockErrors(CLOCK_IP_REPORT_CLOCK_MUX_SWITCH_ERROR, config->name);
  312. }
  313. }
  314. else
  315. {
  316. /* Report timeout error */
  317. ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, config->name);
  318. }
  319. }
  320. else
  321. {
  322. /* Report timeout error */
  323. ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, config->name);
  324. }
  325. }
  326. else {
  327. /* Report timeout error */
  328. ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, config->name);
  329. }
  330. }
  331. }
  332. #endif
  333. #ifdef CGM_X_CSC_CSS_CLK_SW_RAMPDOWN_RAMPUP_SWIP
  334. static void ResetCgmXCscCssClkswRampupRampdownSwip(Clock_Ip_SelectorConfigType const *config)
  335. {
  336. uint32 instance = clockFeatures[config->name][CLOCK_MODULE_INSTANCE];
  337. uint32 selectorIndex = clockFeatures[config->name][SELECTOR_INDEX];
  338. cgm[instance][selectorIndex]->CSC |= MC_CGM_MUX_CSC_SAFE_SW_MASK;
  339. }
  340. static void SetCgmXCscCssClkswRampupRampdownSwip(Clock_Ip_SelectorConfigType const *config)
  341. {
  342. uint32 instance = clockFeatures[config->name][CLOCK_MODULE_INSTANCE];
  343. uint32 selectorIndex = clockFeatures[config->name][SELECTOR_INDEX];
  344. uint32 selectorValue = selectorEntry_hardwareValue[config->value]; /* Hw value corresponding to selector entry. Translate input clock source to hardware value. */
  345. uint32 SELECTOR_VALUE_MASK = clockFeatureExtensions[clockFeatures[config->name][EXTENSION_INDEX]].SELECTOR_VALUE_MASK;
  346. uint32 SELECTOR_VALUE_SHIFT = clockFeatureExtensions[clockFeatures[config->name][EXTENSION_INDEX]].SELECTOR_VALUE_SHIFT;
  347. uint32 regValue;
  348. boolean TimeoutOccurred = FALSE;
  349. uint32 StartTime;
  350. uint32 ElapsedTime;
  351. uint32 TimeoutTicks;
  352. /* Do not configure mux if it is already set to the selector value from configuration.*/
  353. if (selectorValue != ((cgm[instance][selectorIndex]->CSS & SELECTOR_VALUE_MASK) >> SELECTOR_VALUE_SHIFT))
  354. {
  355. ClockStartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_TIMEOUT_VALUE_US);
  356. do
  357. {
  358. TimeoutOccurred = ClockTimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
  359. }
  360. while (((cgm[instance][selectorIndex]->CSS & MC_CGM_MUX_CSS_SWIP_MASK) == MC_CGM_MUX_CSS_SWIP_IN_PROGRESS) && (FALSE == TimeoutOccurred));
  361. if (FALSE == TimeoutOccurred)
  362. {
  363. regValue = cgm[instance][selectorIndex]->CSC;
  364. regValue &= ~SELECTOR_VALUE_MASK;
  365. regValue |= (selectorValue << SELECTOR_VALUE_SHIFT) & SELECTOR_VALUE_MASK;
  366. /* All the PCFS commands should be atomic in nature (i.e. a single register write should provide a complete PCFS sequence
  367. * to be executed, that is ramp-down, clock switch, and ramp-up. It is necessary to set both RAMPUP and RAMPDOWN bits
  368. * together even if you want to trigger either RAMPUP or RAMPDOWN process, otherwise the PCFS effect will not manifest. */
  369. regValue |= (MC_CGM_MUX_CSC_CLK_SW_MASK | MC_CGM_MUX_CSC_RAMPUP_MASK | MC_CGM_MUX_CSC_RAMPDOWN_MASK);
  370. cgm[instance][selectorIndex]->CSC = regValue;
  371. ClockStartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_TIMEOUT_VALUE_US);
  372. /* Wait for CLK_SW to auto-clear */
  373. do
  374. {
  375. TimeoutOccurred = ClockTimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
  376. } /* No safe clock switch operation was requested. */
  377. while(((cgm[instance][selectorIndex]->CSS & MC_CGM_MUX_CSS_CLK_SW_MASK) == MC_CGM_MUX_CSS_CLK_SW_NOT_REQUESTED) && (FALSE == TimeoutOccurred));
  378. if (FALSE == TimeoutOccurred)
  379. {
  380. ClockStartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_TIMEOUT_VALUE_US);
  381. /* Wait for acknowledge to be cleared. */
  382. do
  383. {
  384. TimeoutOccurred = ClockTimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
  385. }
  386. while (((cgm[instance][selectorIndex]->CSS & MC_CGM_MUX_CSS_SWIP_MASK) == MC_CGM_MUX_CSS_SWIP_IN_PROGRESS) && (FALSE == TimeoutOccurred) );
  387. if (FALSE == TimeoutOccurred)
  388. {
  389. /* Check the switch status. */
  390. if (MC_CGM_MUX_CSS_SWTRG_SUCCEEDED != ((cgm[instance][selectorIndex]->CSS & MC_CGM_MUX_CSS_SWTRG_MASK) >> MC_CGM_MUX_CSS_SWTRG_SHIFT))
  391. {
  392. ReportClockErrors(CLOCK_IP_REPORT_CLOCK_MUX_SWITCH_ERROR, config->name);
  393. }
  394. }
  395. else
  396. {
  397. /* Report timeout error */
  398. ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, config->name);
  399. }
  400. }
  401. else
  402. {
  403. /* Report timeout error */
  404. ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, config->name);
  405. }
  406. }
  407. else
  408. {
  409. /* Report timeout error */
  410. ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, config->name);
  411. }
  412. }
  413. }
  414. #endif
  415. #ifdef CGM_X_CSC_CSS_CS_GRIP
  416. static void ResetCgmXCscCssCsGrip(Clock_Ip_SelectorConfigType const *config)
  417. {
  418. (void)config;
  419. /* Software muxes can't be reset. They don't have SAFE_CLK as selector entry. */
  420. }
  421. static void SetCgmXCscCssCsGrip(Clock_Ip_SelectorConfigType const *config)
  422. {
  423. uint32 instance = clockFeatures[config->name][CLOCK_MODULE_INSTANCE];
  424. uint32 selectorIndex = clockFeatures[config->name][SELECTOR_INDEX];
  425. uint32 selectorValue = selectorEntry_hardwareValue[config->value]; /* Hw value corresponding to selector entry. Translate input clock source to hardware value. */
  426. uint32 SELECTOR_VALUE_MASK = clockFeatureExtensions[clockFeatures[config->name][EXTENSION_INDEX]].SELECTOR_VALUE_MASK;
  427. uint32 SELECTOR_VALUE_SHIFT = clockFeatureExtensions[clockFeatures[config->name][EXTENSION_INDEX]].SELECTOR_VALUE_SHIFT;
  428. uint32 regValue;
  429. boolean TimeoutOccurred = FALSE;
  430. uint32 StartTime;
  431. uint32 ElapsedTime;
  432. uint32 TimeoutTicks;
  433. /* Do not configure mux if it is already set to the selector value from configuration.*/
  434. if (selectorValue != ((cgm[instance][selectorIndex]->CSS & SELECTOR_VALUE_MASK) >> SELECTOR_VALUE_SHIFT))
  435. {
  436. cgm[instance][selectorIndex]->CSC |= (MC_CGM_MUX_CSC_CG_MASK | MC_CGM_MUX_CSC_FCG_MASK);
  437. ClockStartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_TIMEOUT_VALUE_US);
  438. do
  439. {
  440. TimeoutOccurred = ClockTimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
  441. }
  442. while (((cgm[instance][selectorIndex]->CSS & MC_CGM_MUX_CSS_CS_MASK) == MC_CGM_MUX_CSS_CS_TRANSPARENT) && (FALSE == TimeoutOccurred));
  443. if (FALSE == TimeoutOccurred)
  444. {
  445. /* Configure clock source. */
  446. regValue = cgm[instance][selectorIndex]->CSC;
  447. regValue &= ~SELECTOR_VALUE_MASK;
  448. regValue |= (selectorValue << SELECTOR_VALUE_SHIFT) & SELECTOR_VALUE_MASK;
  449. cgm[instance][selectorIndex]->CSC = regValue;
  450. /* Clear CG and FCG bit after set the SELCTL bit */
  451. cgm[instance][selectorIndex]->CSC &= ~(MC_CGM_MUX_CSC_FCG_MASK | MC_CGM_MUX_CSC_CG_MASK);
  452. ClockStartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_TIMEOUT_VALUE_US);
  453. /* Wait until the output clock is ungated. */
  454. do
  455. {
  456. TimeoutOccurred = ClockTimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
  457. }
  458. while (((cgm[instance][selectorIndex]->CSS & MC_CGM_MUX_CSS_CS_MASK) != MC_CGM_MUX_CSS_CS_TRANSPARENT) && (FALSE == TimeoutOccurred));
  459. if (TRUE == TimeoutOccurred)
  460. {
  461. ReportClockErrors(CLOCK_IP_REPORT_CLOCK_MUX_SWITCH_ERROR, config->name);
  462. }
  463. }
  464. else
  465. {
  466. /* Report timeout error */
  467. ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, config->name);
  468. }
  469. }
  470. }
  471. #endif
  472. #ifdef GENCTRL1_CTRL_SUPPORT
  473. static void ResetGenctrl1Ctrl(Clock_Ip_SelectorConfigType const *config)
  474. {
  475. (void)config;
  476. /* Clear GENCTRL1 register */
  477. Call_ConfigureResetGenCtrl1();
  478. }
  479. static void SetGenctrl1Ctrl(Clock_Ip_SelectorConfigType const *config)
  480. {
  481. if(PFEMAC0_TX_DIV_CLK != config->value)
  482. {
  483. /* Set GENCTRL1 register */
  484. Call_ConfigureSetGenCtrl1();
  485. }
  486. else
  487. {
  488. /* Clear GENCTRL1 register */
  489. Call_ConfigureResetGenCtrl1();
  490. }
  491. }
  492. static void ConfigureResetGenCtrl1(void)
  493. {
  494. /* Reset GENCTRL1 register */
  495. IP_S32G_GPR->GENCTRL1 &= ~S32G_GPR_GENCTRL1_CTRL_MASK;
  496. }
  497. static void ConfigureSetGenCtrl1(void)
  498. {
  499. /* Set GENCTRL1 register */
  500. IP_S32G_GPR->GENCTRL1 |= S32G_GPR_GENCTRL1_CTRL_MASK;
  501. }
  502. #endif
  503. #ifdef SCG_SCS_RUN_SEL
  504. static void ResetScgRunSel_TrustedCall(Clock_Ip_SelectorConfigType const *config)
  505. {
  506. uint32 regValue;
  507. uint32 selectorValue = selectorEntrySCS_hardwareValue[FIRC_CLK]; /* Hw value corresponding to selector entry. Translate input clock source to hardware value. */
  508. (void)config;
  509. regValue = IP_SCG->RCCR;
  510. regValue &= ~SCG_RCCR_SCS_MASK;
  511. regValue |= SCG_RCCR_SCS(selectorValue);
  512. IP_SCG->RCCR = regValue;
  513. }
  514. static void ResetScgRunSel(Clock_Ip_SelectorConfigType const *config)
  515. {
  516. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  517. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  518. OsIf_Trusted_Call1param(ResetScgRunSel_TrustedCall,(config));
  519. #else
  520. ResetScgRunSel_TrustedCall(config);
  521. #endif
  522. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  523. }
  524. static void SetScgRunSel_TrustedCall(Clock_Ip_SelectorConfigType const *config)
  525. {
  526. uint32 regValue;
  527. uint32 selectorValue = selectorEntrySCS_hardwareValue[config->value]; /* Hw value corresponding to selector entry. Translate input clock source to hardware value. */
  528. regValue = IP_SCG->RCCR;
  529. regValue &= ~SCG_RCCR_SCS_MASK;
  530. regValue |= SCG_RCCR_SCS(selectorValue);
  531. IP_SCG->RCCR = regValue;
  532. }
  533. static void SetScgRunSel(Clock_Ip_SelectorConfigType const *config)
  534. {
  535. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  536. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  537. OsIf_Trusted_Call1param(SetScgRunSel_TrustedCall,(config));
  538. #else
  539. SetScgRunSel_TrustedCall(config);
  540. #endif
  541. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  542. }
  543. #endif
  544. #ifdef SCG_SCS_VLPR_SEL
  545. static void SetScgVlprSel_TrustedCall(Clock_Ip_SelectorConfigType const *config)
  546. {
  547. uint32 regValue;
  548. uint32 selectorValue = selectorEntrySCS_hardwareValue[config->value]; /* Hw value corresponding to selector entry. Translate input clock source to hardware value. */
  549. regValue = IP_SCG->VCCR;
  550. regValue &= ~SCG_VCCR_SCS_MASK;
  551. regValue |= SCG_VCCR_SCS(selectorValue);
  552. IP_SCG->VCCR = regValue;
  553. }
  554. static void SetScgVlprSel(Clock_Ip_SelectorConfigType const *config)
  555. {
  556. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  557. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  558. OsIf_Trusted_Call1param(SetScgVlprSel_TrustedCall,(config));
  559. #else
  560. SetScgVlprSel_TrustedCall(config);
  561. #endif
  562. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  563. }
  564. #endif
  565. #ifdef SCG_SCS_HSRUN_SEL
  566. static void ResetScgHsrunSel_TrustedCall(Clock_Ip_SelectorConfigType const *config)
  567. {
  568. uint32 regValue;
  569. uint32 selectorValue = selectorEntrySCS_hardwareValue[FIRC_CLK]; /* Hw value corresponding to selector entry. Translate input clock source to hardware value. */
  570. (void)config;
  571. regValue = IP_SCG->HCCR;
  572. regValue &= ~SCG_HCCR_SCS_MASK;
  573. regValue |= SCG_HCCR_SCS(selectorValue);
  574. IP_SCG->HCCR = regValue;
  575. }
  576. static void ResetScgHsrunSel(Clock_Ip_SelectorConfigType const *config)
  577. {
  578. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  579. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  580. OsIf_Trusted_Call1param(ResetScgHsrunSel_TrustedCall,(config));
  581. #else
  582. ResetScgHsrunSel_TrustedCall(config);
  583. #endif
  584. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  585. }
  586. static void SetScgHsrunSel_TrustedCall(Clock_Ip_SelectorConfigType const *config)
  587. {
  588. uint32 regValue;
  589. uint32 selectorValue = selectorEntrySCS_hardwareValue[config->value]; /* Hw value corresponding to selector entry. Translate input clock source to hardware value. */
  590. regValue = IP_SCG->HCCR;
  591. regValue &= ~SCG_HCCR_SCS_MASK;
  592. regValue |= SCG_HCCR_SCS(selectorValue);
  593. IP_SCG->HCCR = regValue;
  594. }
  595. static void SetScgHsrunSel(Clock_Ip_SelectorConfigType const *config)
  596. {
  597. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  598. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  599. OsIf_Trusted_Call1param(SetScgHsrunSel_TrustedCall,(config));
  600. #else
  601. SetScgHsrunSel_TrustedCall(config);
  602. #endif
  603. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  604. }
  605. #endif
  606. #ifdef SIM_RTC_SEL
  607. static void ResetSimRtcSel_TrustedCall(Clock_Ip_SelectorConfigType const *config)
  608. {
  609. uint32 regValue;
  610. uint32 selectorValue = selectorEntry_hardwareValue[SOSCDIV1_CLK]; /* Hw value corresponding to selector entry. Translate input clock source to hardware value. */
  611. (void)config;
  612. regValue = IP_SIM->LPOCLKS;
  613. regValue &= ~SIM_LPOCLKS_RTCCLKSEL_MASK;
  614. regValue |= (selectorValue << SIM_LPOCLKS_RTCCLKSEL_SHIFT);
  615. IP_SIM->LPOCLKS = regValue;
  616. }
  617. static void ResetSimRtcSel(Clock_Ip_SelectorConfigType const *config)
  618. {
  619. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  620. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  621. OsIf_Trusted_Call1param(ResetSimRtcSel_TrustedCall,(config));
  622. #else
  623. ResetSimRtcSel_TrustedCall(config);
  624. #endif
  625. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  626. }
  627. static void SetSimRtcSel_TrustedCall(Clock_Ip_SelectorConfigType const *config)
  628. {
  629. uint32 regValue;
  630. uint32 selectorValue = selectorEntry_hardwareValue[config->value]; /* Hw value corresponding to selector entry. Translate input clock source to hardware value. */
  631. regValue = IP_SIM->LPOCLKS;
  632. regValue &= ~SIM_LPOCLKS_RTCCLKSEL_MASK;
  633. regValue |= (selectorValue << SIM_LPOCLKS_RTCCLKSEL_SHIFT);
  634. IP_SIM->LPOCLKS = regValue;
  635. }
  636. static void SetSimRtcSel(Clock_Ip_SelectorConfigType const *config)
  637. {
  638. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  639. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  640. OsIf_Trusted_Call1param(SetSimRtcSel_TrustedCall,(config));
  641. #else
  642. SetSimRtcSel_TrustedCall(config);
  643. #endif
  644. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  645. }
  646. #endif
  647. #ifdef SIM_LPO_SEL
  648. static void ResetSimLpoSel_TrustedCall(Clock_Ip_SelectorConfigType const *config)
  649. {
  650. uint32 regValue;
  651. uint32 selectorValue = selectorEntryPCS_hardwareValue[LPO_128K_CLK]; /* Hw value corresponding to selector entry. Translate input clock source to hardware value. */
  652. (void)config;
  653. regValue = IP_SIM->LPOCLKS;
  654. regValue &= ~SIM_LPOCLKS_LPOCLKSEL_MASK;
  655. regValue |= (selectorValue << SIM_LPOCLKS_LPOCLKSEL_SHIFT);
  656. IP_SIM->LPOCLKS = regValue;
  657. }
  658. static void ResetSimLpoSel(Clock_Ip_SelectorConfigType const *config)
  659. {
  660. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  661. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  662. OsIf_Trusted_Call1param(ResetSimLpoSel_TrustedCall,(config));
  663. #else
  664. ResetSimLpoSel_TrustedCall(config);
  665. #endif
  666. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  667. }
  668. static void SetSimLpoSel_TrustedCall(Clock_Ip_SelectorConfigType const *config)
  669. {
  670. uint32 regValue;
  671. /* LPO_CLK selector mapped to selectorEntryPCS_hardwareValue */
  672. uint32 selectorValue = selectorEntryPCS_hardwareValue[config->value]; /* Hw value corresponding to selector entry. Translate input clock source to hardware value. */
  673. (void)config;
  674. regValue = IP_SIM->LPOCLKS;
  675. regValue &= ~SIM_LPOCLKS_LPOCLKSEL_MASK;
  676. regValue |= (selectorValue << SIM_LPOCLKS_LPOCLKSEL_SHIFT);
  677. IP_SIM->LPOCLKS = regValue;
  678. }
  679. static void SetSimLpoSel(Clock_Ip_SelectorConfigType const *config)
  680. {
  681. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  682. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  683. OsIf_Trusted_Call1param(SetSimLpoSel_TrustedCall,(config));
  684. #else
  685. SetSimLpoSel_TrustedCall(config);
  686. #endif
  687. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  688. }
  689. #endif
  690. #ifdef SCG_CLKOUT_SEL
  691. static void ResetScgClkoutSel_TrustedCall(Clock_Ip_SelectorConfigType const *config)
  692. {
  693. uint32 regValue;
  694. /* LPO_CLK selector mapped to selectorEntryPCS_hardwareValue */
  695. uint32 selectorValue = selectorEntrySCS_hardwareValue[FIRC_CLK]; /* Hw value corresponding to selector entry. Translate input clock source to hardware value. */
  696. (void)config;
  697. regValue = IP_SCG->CLKOUTCNFG;
  698. regValue &= ~SCG_CLKOUTCNFG_CLKOUTSEL_MASK;
  699. regValue |= (selectorValue << SCG_CLKOUTCNFG_CLKOUTSEL_SHIFT);
  700. IP_SCG->CLKOUTCNFG = regValue;
  701. }
  702. static void ResetScgClkoutSel(Clock_Ip_SelectorConfigType const *config)
  703. {
  704. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  705. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  706. OsIf_Trusted_Call1param(ResetScgClkoutSel_TrustedCall,(config));
  707. #else
  708. ResetScgClkoutSel_TrustedCall(config);
  709. #endif
  710. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  711. }
  712. static void SetScgClkoutSel_TrustedCall(Clock_Ip_SelectorConfigType const *config)
  713. {
  714. uint32 regValue;
  715. uint32 selectorValue = selectorEntrySCS_hardwareValue[config->value]; /* Hw value corresponding to selector entry. Translate input clock source to hardware value. */
  716. regValue = IP_SCG->CLKOUTCNFG;
  717. regValue &= ~SCG_CLKOUTCNFG_CLKOUTSEL_MASK;
  718. regValue |= (selectorValue << SCG_CLKOUTCNFG_CLKOUTSEL_SHIFT);
  719. IP_SCG->CLKOUTCNFG = regValue;
  720. }
  721. static void SetScgClkoutSel(Clock_Ip_SelectorConfigType const *config)
  722. {
  723. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  724. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  725. OsIf_Trusted_Call1param(SetScgClkoutSel_TrustedCall,(config));
  726. #else
  727. SetScgClkoutSel_TrustedCall(config);
  728. #endif
  729. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  730. }
  731. #endif
  732. #ifdef SIM_FTMOPT_SEL
  733. #define SIM_FTMOPT0_FTM_0_3_CLKSEL_SHIFT(x) (24U + ((x) << 1U))
  734. #define SIM_FTMOPT0_FTM_0_3_CLKSEL_MASK(x) ((uint32)3U << SIM_FTMOPT0_FTM_0_3_CLKSEL_SHIFT(x))
  735. #define SIM_FTMOPT0_FTM_4_7_CLKSEL_SHIFT(x) (16U + (((x) - 4U) << 1U))
  736. #define SIM_FTMOPT0_FTM_4_7_CLKSEL_MASK(x) ((uint32)3U << SIM_FTMOPT0_FTM_4_7_CLKSEL_SHIFT(x))
  737. static void ResetSimFtmoptSel_TrustedCall(Clock_Ip_SelectorConfigType const *config)
  738. {
  739. uint32 regValue;
  740. uint32 selectorValue = selectorEntry_hardwareValue[FIRC_CLK]; /* Hw value corresponding to selector entry. Translate input clock source to hardware value. */
  741. uint32 instance = clockFeatures[config->name][CLOCK_MODULE_INSTANCE];
  742. regValue = IP_SIM->FTMOPT0;
  743. if(instance < 4U)
  744. {
  745. regValue &= ~(SIM_FTMOPT0_FTM_0_3_CLKSEL_MASK(instance));
  746. regValue |= (selectorValue << SIM_FTMOPT0_FTM_0_3_CLKSEL_SHIFT(instance));
  747. }
  748. else
  749. {
  750. regValue &= ~(SIM_FTMOPT0_FTM_4_7_CLKSEL_MASK(instance));
  751. regValue |= (selectorValue << SIM_FTMOPT0_FTM_4_7_CLKSEL_SHIFT(instance));
  752. }
  753. IP_SIM->FTMOPT0 = regValue;
  754. }
  755. static void ResetSimFtmoptSel(Clock_Ip_SelectorConfigType const *config)
  756. {
  757. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  758. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  759. OsIf_Trusted_Call1param(ResetSimFtmoptSel_TrustedCall,(config));
  760. #else
  761. ResetSimFtmoptSel_TrustedCall(config);
  762. #endif
  763. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  764. }
  765. static void SetSimFtmoptSel_TrustedCall(Clock_Ip_SelectorConfigType const *config)
  766. {
  767. uint32 regValue;
  768. uint32 selectorValue = selectorEntry_hardwareValue[config->value]; /* Hw value corresponding to selector entry. Translate input clock source to hardware value. */
  769. uint32 instance = clockFeatures[config->name][CLOCK_MODULE_INSTANCE];
  770. regValue = IP_SIM->FTMOPT0;
  771. if(instance < 4U)
  772. {
  773. regValue &= ~(SIM_FTMOPT0_FTM_0_3_CLKSEL_MASK(instance));
  774. regValue |= (selectorValue << SIM_FTMOPT0_FTM_0_3_CLKSEL_SHIFT(instance));
  775. }
  776. else
  777. {
  778. regValue &= ~(SIM_FTMOPT0_FTM_4_7_CLKSEL_MASK(instance));
  779. regValue |= (selectorValue << SIM_FTMOPT0_FTM_4_7_CLKSEL_SHIFT(instance));
  780. }
  781. IP_SIM->FTMOPT0 = regValue;
  782. }
  783. static void SetSimFtmoptSel(Clock_Ip_SelectorConfigType const *config)
  784. {
  785. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  786. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  787. OsIf_Trusted_Call1param(SetSimFtmoptSel_TrustedCall,(config));
  788. #else
  789. SetSimFtmoptSel_TrustedCall(config);
  790. #endif
  791. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  792. }
  793. #endif
  794. #ifdef SIM_CLKOUT_SEL
  795. /* Clear CLKOUTSEL and CLKOUTEN bit field in SIM_CHIPCTL register */
  796. static void ResetSimClkoutSel_TrustedCall(Clock_Ip_SelectorConfigType const *config)
  797. {
  798. uint32 regValue;
  799. (void)config;
  800. regValue = IP_SIM->CHIPCTL;
  801. regValue &= ~(SIM_CHIPCTL_CLKOUTSEL_MASK | SIM_CHIPCTL_CLKOUTEN_MASK);
  802. IP_SIM->CHIPCTL = regValue;
  803. }
  804. static void ResetSimClkoutSel(Clock_Ip_SelectorConfigType const *config)
  805. {
  806. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  807. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  808. OsIf_Trusted_Call1param(ResetSimClkoutSel_TrustedCall,(config));
  809. #else
  810. ResetSimClkoutSel_TrustedCall(config);
  811. #endif
  812. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  813. }
  814. static void SetSimClkoutSel_TrustedCall(Clock_Ip_SelectorConfigType const *config)
  815. {
  816. uint32 regValue;
  817. uint32 selectorValue = selectorEntry_hardwareValue[config->value]; /* Hw value corresponding to selector entry. Translate input clock source to hardware value. */
  818. regValue = IP_SIM->CHIPCTL;
  819. regValue &= ~SIM_CHIPCTL_CLKOUTSEL_MASK;
  820. regValue |= (selectorValue << SIM_CHIPCTL_CLKOUTSEL_SHIFT);
  821. IP_SIM->CHIPCTL = regValue;
  822. }
  823. static void SetSimClkoutSel(Clock_Ip_SelectorConfigType const *config)
  824. {
  825. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  826. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  827. OsIf_Trusted_Call1param(SetSimClkoutSel_TrustedCall,(config));
  828. #else
  829. SetSimClkoutSel_TrustedCall(config);
  830. #endif
  831. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  832. }
  833. #endif
  834. #ifdef PCC_PCS_SELECT
  835. /**
  836. * @brief This function will reset writable bit fields of PCC register
  837. */
  838. static void ResetPccPcsSelect_TrustedCall(Clock_Ip_SelectorConfigType const *config)
  839. {
  840. uint32 regValue;
  841. uint32 pccIndex = clockFeatures[config->name][SELECTOR_INDEX];
  842. regValue = IP_PCC->PCCn[pccIndex];
  843. regValue &= ~(PCC_PCCn_PCS_MASK | PCC_PCCn_CGC_MASK);
  844. IP_PCC->PCCn[pccIndex] = regValue;
  845. }
  846. static void ResetPccPcsSelect(Clock_Ip_SelectorConfigType const *config)
  847. {
  848. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  849. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  850. OsIf_Trusted_Call1param(ResetPccPcsSelect_TrustedCall,(config));
  851. #else
  852. ResetPccPcsSelect_TrustedCall(config);
  853. #endif
  854. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  855. }
  856. static void SetPccPcsSelect_TrustedCall(Clock_Ip_SelectorConfigType const *config)
  857. {
  858. uint32 regValue;
  859. uint32 pccIndex = clockFeatures[config->name][SELECTOR_INDEX];
  860. uint32 selectorValue = selectorEntryPCS_hardwareValue[config->value]; /* Hw value corresponding to selector entry. Translate input clock source to hardware value. */
  861. regValue = IP_PCC->PCCn[pccIndex];
  862. regValue &= ~PCC_PCCn_PCS_MASK;
  863. regValue |= PCC_PCCn_PCS(selectorValue);
  864. IP_PCC->PCCn[pccIndex] = regValue;
  865. }
  866. static void SetPccPcsSelect(Clock_Ip_SelectorConfigType const *config)
  867. {
  868. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  869. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  870. OsIf_Trusted_Call1param(SetPccPcsSelect_TrustedCall,(config));
  871. #else
  872. SetPccPcsSelect_TrustedCall(config);
  873. #endif
  874. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  875. }
  876. #endif
  877. #ifdef SIM_TRACE_SEL
  878. static void ResetSimTraceSel_TrustedCall(Clock_Ip_SelectorConfigType const *config)
  879. {
  880. uint32 regValue;
  881. /* TRACE_CLK selector mapped to selectorEntryPCS_hardwareValue */
  882. uint32 selectorValue = selectorEntryPCS_hardwareValue[CORE_CLK]; /* Hw value corresponding to selector entry. Translate input clock source to hardware value. */
  883. (void) config;
  884. regValue = (uint32)IP_SIM->CHIPCTL;
  885. regValue &= (~((uint32)SIM_CHIPCTL_TRACECLK_SEL_MASK));
  886. regValue |= SIM_CHIPCTL_TRACECLK_SEL(selectorValue);
  887. IP_SIM->CHIPCTL = (uint32)regValue;
  888. }
  889. static void ResetSimTraceSel(Clock_Ip_SelectorConfigType const *config)
  890. {
  891. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  892. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  893. OsIf_Trusted_Call1param(ResetSimTraceSel_TrustedCall,(config));
  894. #else
  895. ResetSimTraceSel_TrustedCall(config);
  896. #endif
  897. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  898. }
  899. static void SetSimTraceSel_TrustedCall(Clock_Ip_SelectorConfigType const *config)
  900. {
  901. uint32 regValue;
  902. /* TRACE_CLK selector mapped to selectorEntryPCS_hardwareValue */
  903. uint32 selectorValue = selectorEntryPCS_hardwareValue[config->value]; /* Hw value corresponding to selector entry. Translate input clock source to hardware value. */
  904. regValue = (uint32)IP_SIM->CHIPCTL;
  905. regValue &= (~((uint32)SIM_CHIPCTL_TRACECLK_SEL_MASK));
  906. regValue |= SIM_CHIPCTL_TRACECLK_SEL(selectorValue);
  907. IP_SIM->CHIPCTL = (uint32)regValue;
  908. }
  909. static void SetSimTraceSel(Clock_Ip_SelectorConfigType const *config)
  910. {
  911. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  912. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  913. OsIf_Trusted_Call1param(SetSimTraceSel_TrustedCall,(config));
  914. #else
  915. SetSimTraceSel_TrustedCall(config);
  916. #endif
  917. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  918. }
  919. #endif
  920. /* Clock stop section code */
  921. #define MCU_STOP_SEC_CODE
  922. #include "Mcu_MemMap.h"
  923. /*! @}*/
  924. /*******************************************************************************
  925. * EOF
  926. ******************************************************************************/