Clock_Ip_IntOsc.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  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_IntOsc.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_INTOSC_VENDOR_ID_C 43
  39. #define CLOCK_IP_INTOSC_AR_RELEASE_MAJOR_VERSION_C 4
  40. #define CLOCK_IP_INTOSC_AR_RELEASE_MINOR_VERSION_C 4
  41. #define CLOCK_IP_INTOSC_AR_RELEASE_REVISION_VERSION_C 0
  42. #define CLOCK_IP_INTOSC_SW_MAJOR_VERSION_C 1
  43. #define CLOCK_IP_INTOSC_SW_MINOR_VERSION_C 0
  44. #define CLOCK_IP_INTOSC_SW_PATCH_VERSION_C 0
  45. /*==================================================================================================
  46. * FILE VERSION CHECKS
  47. ==================================================================================================*/
  48. /* Check if Clock_Ip_IntOsc.c file and Clock_Ip_Private.h file are of the same vendor */
  49. #if (CLOCK_IP_INTOSC_VENDOR_ID_C != CLOCK_IP_PRIVATE_VENDOR_ID)
  50. #error "Clock_Ip_IntOsc.c and Clock_Ip_Private.h have different vendor ids"
  51. #endif
  52. /* Check if Clock_Ip_IntOsc.c file and Clock_Ip_Private.h file are of the same Autosar version */
  53. #if ((CLOCK_IP_INTOSC_AR_RELEASE_MAJOR_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_MAJOR_VERSION) || \
  54. (CLOCK_IP_INTOSC_AR_RELEASE_MINOR_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_MINOR_VERSION) || \
  55. (CLOCK_IP_INTOSC_AR_RELEASE_REVISION_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_REVISION_VERSION) \
  56. )
  57. #error "AutoSar Version Numbers of Clock_Ip_IntOsc.c and Clock_Ip_Private.h are different"
  58. #endif
  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. /* Clock start section code */
  67. #define MCU_START_SEC_CODE
  68. #include "Mcu_MemMap.h"
  69. static void InternalOscillatorEmpty(Clock_Ip_IrcoscConfigType const* config);
  70. static void InternalOscillatorEmpty_Disable(Clock_Ip_NameType name);
  71. #ifdef FIRC_STDBY_ENABLE
  72. static void SetFircStdby(Clock_Ip_IrcoscConfigType const* config);
  73. static void EnableFircStdby(Clock_Ip_IrcoscConfigType const* config);
  74. static void DisableFircStdby(Clock_Ip_NameType name);
  75. #endif
  76. #ifdef SIRC_STDBY_ENABLE
  77. static void SetSircStdby(Clock_Ip_IrcoscConfigType const* config);
  78. static void EnableSircStdby(Clock_Ip_IrcoscConfigType const* config);
  79. static void DisableSircStdby(Clock_Ip_NameType name);
  80. #endif
  81. #ifdef SIRC_ENABLE
  82. static void SetSirc(Clock_Ip_IrcoscConfigType const* config);
  83. static void EnableSirc(Clock_Ip_IrcoscConfigType const* config);
  84. static void DisableSirc(Clock_Ip_NameType name);
  85. #endif
  86. #ifdef SIRC_VLP_ENABLE
  87. static void SetSircVlp(Clock_Ip_IrcoscConfigType const* config);
  88. static void EnableSircVlp(Clock_Ip_IrcoscConfigType const* config);
  89. static void DisableSircVlp(Clock_Ip_NameType name);
  90. #endif
  91. #ifdef SIRC_STOP_ENABLE
  92. static void SetSircStop(Clock_Ip_IrcoscConfigType const* config);
  93. static void EnableSircStop(Clock_Ip_IrcoscConfigType const* config);
  94. static void DisableSircStop(Clock_Ip_NameType name);
  95. #endif
  96. #ifdef FIRC_ENABLE
  97. static void SetFirc(Clock_Ip_IrcoscConfigType const* config);
  98. static void EnableFirc(Clock_Ip_IrcoscConfigType const* config);
  99. static void DisableFirc(Clock_Ip_NameType name);
  100. #endif
  101. /* Clock stop section code */
  102. #define MCU_STOP_SEC_CODE
  103. #include "Mcu_MemMap.h"
  104. /* Clock start constant section data */
  105. #define MCU_START_SEC_CONST_UNSPECIFIED
  106. #include "Mcu_MemMap.h"
  107. const intOscCallback intOscCallbacks[IRCOSC_CALLBACKS_COUNT] =
  108. {
  109. {
  110. InternalOscillatorEmpty, /* Set */
  111. InternalOscillatorEmpty, /* Enable */
  112. InternalOscillatorEmpty_Disable, /* Disable */
  113. },
  114. #ifdef FIRC_STDBY_ENABLE
  115. {
  116. SetFircStdby, /* Set */
  117. EnableFircStdby, /* Enable */
  118. DisableFircStdby, /* Disable */
  119. },
  120. #endif
  121. #ifdef SIRC_STDBY_ENABLE
  122. {
  123. SetSircStdby, /* Set */
  124. EnableSircStdby, /* Enable */
  125. DisableSircStdby, /* Disable */
  126. },
  127. #endif
  128. #ifdef SIRC_ENABLE
  129. {
  130. SetSirc, /* Set */
  131. EnableSirc, /* Enable */
  132. DisableSirc, /* Disable */
  133. },
  134. #endif
  135. #ifdef SIRC_VLP_ENABLE
  136. {
  137. SetSircVlp, /* Set */
  138. EnableSircVlp, /* Enable */
  139. DisableSircVlp, /* Disable */
  140. },
  141. #endif
  142. #ifdef SIRC_STOP_ENABLE
  143. {
  144. SetSircStop, /* Set */
  145. EnableSircStop, /* Enable */
  146. DisableSircStop, /* Disable */
  147. },
  148. #endif
  149. #ifdef FIRC_ENABLE
  150. {
  151. SetFirc, /* Set */
  152. EnableFirc, /* Enable */
  153. DisableFirc, /* Disable */
  154. },
  155. #endif
  156. };
  157. /* Clock stop constant section data */
  158. #define MCU_STOP_SEC_CONST_UNSPECIFIED
  159. #include "Mcu_MemMap.h"
  160. /* Clock start section code */
  161. #define MCU_START_SEC_CODE
  162. #include "Mcu_MemMap.h"
  163. static void InternalOscillatorEmpty(Clock_Ip_IrcoscConfigType const* config)
  164. {
  165. (void)config;
  166. /* No implementation */
  167. }
  168. static void InternalOscillatorEmpty_Disable(Clock_Ip_NameType name)
  169. {
  170. (void)name;
  171. /* No implementation */
  172. }
  173. #ifdef FIRC_STDBY_ENABLE
  174. static void SetFircStdby(Clock_Ip_IrcoscConfigType const* config)
  175. {
  176. if (config->enable != 0U)
  177. {
  178. IP_FIRC->STDBY_ENABLE |= FIRC_STDBY_ENABLE_STDBY_EN_MASK;
  179. }
  180. else
  181. {
  182. IP_FIRC->STDBY_ENABLE &= ~FIRC_STDBY_ENABLE_STDBY_EN_MASK;
  183. }
  184. }
  185. static void EnableFircStdby(Clock_Ip_IrcoscConfigType const* config)
  186. {
  187. (void)config;
  188. IP_FIRC->STDBY_ENABLE |= FIRC_STDBY_ENABLE_STDBY_EN_MASK;
  189. }
  190. static void DisableFircStdby(Clock_Ip_NameType name)
  191. {
  192. (void)name;
  193. IP_FIRC->STDBY_ENABLE &= ~FIRC_STDBY_ENABLE_STDBY_EN_MASK;
  194. }
  195. #endif
  196. #ifdef SIRC_STDBY_ENABLE
  197. static void SetSircStdby(Clock_Ip_IrcoscConfigType const* config)
  198. {
  199. if (config->enable != 0U)
  200. {
  201. IP_SIRC->MISCELLANEOUS_IN |= SIRC_MISCELLANEOUS_IN_STANDBY_ENABLE_MASK;
  202. }
  203. else
  204. {
  205. IP_SIRC->MISCELLANEOUS_IN &= ~SIRC_MISCELLANEOUS_IN_STANDBY_ENABLE_MASK;
  206. }
  207. }
  208. static void EnableSircStdby(Clock_Ip_IrcoscConfigType const* config)
  209. {
  210. (void)config;
  211. IP_SIRC->MISCELLANEOUS_IN |= SIRC_MISCELLANEOUS_IN_STANDBY_ENABLE_MASK;
  212. }
  213. static void DisableSircStdby(Clock_Ip_NameType name)
  214. {
  215. (void)name;
  216. IP_SIRC->MISCELLANEOUS_IN &= ~SIRC_MISCELLANEOUS_IN_STANDBY_ENABLE_MASK;
  217. }
  218. #endif
  219. #ifdef SIRC_ENABLE
  220. static void SetSirc_TrustedCall(Clock_Ip_IrcoscConfigType const* config)
  221. {
  222. boolean TimeoutOccurred = FALSE;
  223. uint32 StartTime;
  224. uint32 ElapsedTime;
  225. uint32 TimeoutTicks;
  226. uint32 IrcoscStatus;
  227. Clock_Ip_IrcoscConfigType sircConfig;
  228. if (config == NULL_PTR)
  229. {
  230. sircConfig.name = FIRC_CLK;
  231. sircConfig.range = 1U; /* 8MHz */
  232. sircConfig.enable = 1U; /* enabled */
  233. sircConfig.lowPowerModeEnable =1U;
  234. }
  235. else
  236. {
  237. sircConfig.name = config->name;
  238. sircConfig.range = config->range;
  239. sircConfig.enable = config->enable;
  240. sircConfig.lowPowerModeEnable = config->lowPowerModeEnable;
  241. }
  242. /* Clear LK bit field */
  243. IP_SCG->SIRCCSR &= (~((uint32)SCG_SIRCCSR_LK_MASK));
  244. /* Disable clock */
  245. IP_SCG->SIRCCSR &= (~((uint32)SCG_SIRCCSR_SIRCEN_MASK));
  246. /* Disable SIRC Low Power */
  247. IP_SCG->SIRCCSR &= (~((uint32)SCG_SIRCCSR_SIRCLPEN_MASK));
  248. /* Configure SIRC. */
  249. if (sircConfig.enable == 1U)
  250. {
  251. /* Step frequency range. */
  252. IP_SCG->SIRCCFG = SCG_SIRCCFG_RANGE(sircConfig.range);
  253. /* Enable clock. */
  254. IP_SCG->SIRCCSR |= SCG_SIRCCSR_SIRCEN(1U);
  255. /* Set SIRC in VLP modes */
  256. IP_SCG->SIRCCSR |= SCG_SIRCCSR_SIRCLPEN(sircConfig.lowPowerModeEnable);
  257. ClockStartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_TIMEOUT_VALUE_US);
  258. /* Wait until ircosc is locked */
  259. do
  260. {
  261. IrcoscStatus = (((IP_SCG->SIRCCSR & SCG_SIRCCSR_SIRCVLD_MASK) >> SCG_SIRCCSR_SIRCVLD_SHIFT));
  262. TimeoutOccurred = ClockTimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
  263. }
  264. while ((IrcoscStatus == 0U) && (FALSE == TimeoutOccurred));
  265. if (FALSE != TimeoutOccurred)
  266. {
  267. /* Report timeout error */
  268. ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, sircConfig.name);
  269. }
  270. }
  271. }
  272. static void SetSirc(Clock_Ip_IrcoscConfigType const* config)
  273. {
  274. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  275. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  276. OsIf_Trusted_Call1param(SetSirc_TrustedCall,(config));
  277. #else
  278. SetSirc_TrustedCall(config);
  279. #endif
  280. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  281. }
  282. static void EnableSirc_TrustedCall(Clock_Ip_IrcoscConfigType const* config)
  283. {
  284. boolean TimeoutOccurred = FALSE;
  285. uint32 StartTime;
  286. uint32 ElapsedTime;
  287. uint32 TimeoutTicks;
  288. uint32 IrcoscStatus;
  289. /* Enable clock. */
  290. IP_SCG->SIRCCSR |= SCG_SIRCCSR_SIRCEN(1U);
  291. /* Enable SIRC Low Power */
  292. IP_SCG->SIRCCSR |= SCG_SIRCCSR_SIRCLPEN(1UL);
  293. ClockStartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_TIMEOUT_VALUE_US);
  294. /* Wait until ircosc is locked */
  295. do
  296. {
  297. IrcoscStatus = (((IP_SCG->SIRCCSR & SCG_SIRCCSR_SIRCVLD_MASK) >> SCG_SIRCCSR_SIRCVLD_SHIFT));
  298. TimeoutOccurred = ClockTimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
  299. }
  300. while ((IrcoscStatus == 0U) && (FALSE == TimeoutOccurred));
  301. if (FALSE != TimeoutOccurred)
  302. {
  303. /* Report timeout error */
  304. ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, config->name);
  305. }
  306. }
  307. static void EnableSirc(Clock_Ip_IrcoscConfigType const* config)
  308. {
  309. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  310. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  311. OsIf_Trusted_Call1param(EnableSirc_TrustedCall,(config));
  312. #else
  313. EnableSirc_TrustedCall(config);
  314. #endif
  315. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  316. }
  317. static void DisableSirc_TrustedCall(Clock_Ip_NameType name)
  318. {
  319. (void)name;
  320. /* Disable clock. */
  321. IP_SCG->SIRCCSR &= ~SCG_SIRCCSR_SIRCEN_MASK;
  322. /* Disable SIRC Low Power */
  323. IP_SCG->SIRCCSR &= (~((uint32)SCG_SIRCCSR_SIRCLPEN_MASK));
  324. }
  325. static void DisableSirc(Clock_Ip_NameType name)
  326. {
  327. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  328. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  329. OsIf_Trusted_Call1param(DisableSirc_TrustedCall,(name));
  330. #else
  331. DisableSirc_TrustedCall(name);
  332. #endif
  333. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  334. }
  335. #endif
  336. #ifdef SIRC_VLP_ENABLE
  337. static void SetSircVlp_TrustedCall(Clock_Ip_IrcoscConfigType const* config)
  338. {
  339. /* Clear LK bit field */
  340. IP_SCG->SIRCCSR &= (~((uint32)SCG_SIRCCSR_LK_MASK));
  341. IP_SCG->SIRCCSR &= (~((uint32)SCG_SIRCCSR_SIRCLPEN_MASK));
  342. /* Configure SIRC in VLP mode */
  343. IP_SCG->SIRCCSR |= SCG_SIRCCSR_SIRCLPEN(config->lowPowerModeEnable);
  344. }
  345. static void SetSircVlp(Clock_Ip_IrcoscConfigType const* config)
  346. {
  347. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  348. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  349. OsIf_Trusted_Call1param(SetSircVlp_TrustedCall,(config));
  350. #else
  351. SetSircVlp_TrustedCall(config);
  352. #endif
  353. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  354. }
  355. static void EnableSircVlp_TrustedCall(Clock_Ip_IrcoscConfigType const* config)
  356. {
  357. if (config->enable == 1U)
  358. {
  359. /* Enable clock in VLP mode */
  360. IP_SCG->SIRCCSR |= SCG_SIRCCSR_SIRCLPEN(1U);
  361. }
  362. }
  363. static void EnableSircVlp(Clock_Ip_IrcoscConfigType const* config)
  364. {
  365. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  366. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  367. OsIf_Trusted_Call1param(EnableSircVlp_TrustedCall,(config));
  368. #else
  369. EnableSircVlp_TrustedCall(config);
  370. #endif
  371. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  372. }
  373. static void DisableSircVlp_TrustedCall(Clock_Ip_NameType name)
  374. {
  375. (void)name;
  376. /* Disable clock */
  377. IP_SCG->SIRCCSR &= (~((uint32)SCG_SIRCCSR_SIRCLPEN_MASK));
  378. }
  379. static void DisableSircVlp(Clock_Ip_NameType name)
  380. {
  381. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  382. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  383. OsIf_Trusted_Call1param(DisableSircVlp_TrustedCall,(name));
  384. #else
  385. DisableSircVlp_TrustedCall(name);
  386. #endif
  387. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  388. }
  389. #endif
  390. #ifdef SIRC_STOP_ENABLE
  391. static void SetSircStop_TrustedCall(Clock_Ip_IrcoscConfigType const* config)
  392. {
  393. (void)config;
  394. /* Clear LK bit field */
  395. IP_SCG->SIRCCSR &= (~((uint32)SCG_SIRCCSR_LK_MASK));
  396. IP_SCG->SIRCCSR &= (~((uint32)SCG_SIRCCSR_SIRCSTEN_MASK));
  397. /* Configure SIRC in STOP mode */
  398. IP_SCG->SIRCCSR |= SCG_SIRCCSR_SIRCSTEN(config->stopModeEnable);
  399. }
  400. static void SetSircStop(Clock_Ip_IrcoscConfigType const* config)
  401. {
  402. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  403. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  404. OsIf_Trusted_Call1param(SetSircStop_TrustedCall,(config));
  405. #else
  406. SetSircStop_TrustedCall(config);
  407. #endif
  408. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  409. }
  410. static void EnableSircStop_TrustedCall(Clock_Ip_IrcoscConfigType const* config)
  411. {
  412. if (config->enable == 1U)
  413. {
  414. /* Enable clock in VLP mode */
  415. IP_SCG->SIRCCSR |= SCG_SIRCCSR_SIRCSTEN(1U);
  416. }
  417. }
  418. static void EnableSircStop(Clock_Ip_IrcoscConfigType const* config)
  419. {
  420. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  421. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  422. OsIf_Trusted_Call1param(EnableSircStop_TrustedCall,(config));
  423. #else
  424. EnableSircStop_TrustedCall(config);
  425. #endif
  426. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  427. }
  428. static void DisableSircStop_TrustedCall(Clock_Ip_NameType name)
  429. {
  430. (void)name;
  431. /* Disable clock */
  432. IP_SCG->SIRCCSR &= (~((uint32)SCG_SIRCCSR_SIRCSTEN_MASK));
  433. }
  434. static void DisableSircStop(Clock_Ip_NameType name)
  435. {
  436. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  437. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  438. OsIf_Trusted_Call1param(DisableSircStop_TrustedCall,(name));
  439. #else
  440. DisableSircStop_TrustedCall(name);
  441. #endif
  442. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  443. }
  444. #endif
  445. #ifdef FIRC_ENABLE
  446. #define SIRC_CLK_SOURCE 2U
  447. #define FIRC_CLK_SOURCE 3U
  448. static void SetInputSouceSytemClock(uint32 sourceClock)
  449. {
  450. uint32 regValue;
  451. boolean TimeoutOccurred = FALSE;
  452. uint32 StartTime;
  453. uint32 ElapsedTime;
  454. uint32 TimeoutTicks;
  455. uint32 ScsStatus;
  456. regValue = IP_SCG->RCCR;
  457. regValue &= ~SCG_RCCR_SCS_MASK;
  458. regValue |= (sourceClock << SCG_RCCR_SCS_SHIFT);
  459. IP_SCG->RCCR = regValue;
  460. ClockStartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_TIMEOUT_VALUE_US);
  461. do
  462. {
  463. ScsStatus = (((IP_SCG->CSR & SCG_CSR_SCS_MASK) >> SCG_CSR_SCS_SHIFT) != (sourceClock))?1U:0U;
  464. TimeoutOccurred = ClockTimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
  465. }
  466. while ((ScsStatus == 0U) && (FALSE == TimeoutOccurred));
  467. if (FALSE != TimeoutOccurred)
  468. {
  469. /* Report timeout error */
  470. ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, FIRC_CLK);
  471. }
  472. }
  473. static void SetFirc_TrustedCall(Clock_Ip_IrcoscConfigType const* config)
  474. {
  475. uint32 instance = clockFeatures[config->name][CLOCK_MODULE_INSTANCE];
  476. boolean TimeoutOccurred = FALSE, SircWasDisabled = FALSE;
  477. uint32 StartTime;
  478. uint32 ElapsedTime;
  479. uint32 TimeoutTicks;
  480. uint32 IrcoscStatus;
  481. (void)instance;
  482. /* Clear LK bit field */
  483. IP_SCG->FIRCCSR &= (uint32)(~(SCG_FIRCCSR_LK_MASK));
  484. /* Check that FIRC is used by system clock) */
  485. if ((IP_SCG->FIRCCSR & SCG_FIRCCSR_FIRCSEL_MASK) != 0U)
  486. {
  487. /* Check whether FIRC is already configured as required */
  488. if ( (config->range != ((IP_SCG->FIRCCFG & SCG_FIRCCFG_RANGE_MASK) >> SCG_FIRCCFG_RANGE_SHIFT)) ||
  489. (config->regulator != ((IP_SCG->FIRCCSR & SCG_FIRCCSR_FIRCREGOFF_MASK) >> SCG_FIRCCSR_FIRCREGOFF_SHIFT)) )
  490. {
  491. /* Enable SIRC if it is disabled. */
  492. if ((IP_SCG->SIRCCSR & SCG_SIRCCSR_SIRCEN_MASK) == 0U)
  493. {
  494. SircWasDisabled = TRUE;
  495. SetSirc(NULL_PTR);
  496. }
  497. /* Switch to SIRC */
  498. SetInputSouceSytemClock(SIRC_CLK_SOURCE);
  499. /* Disable clock */
  500. IP_SCG->FIRCCSR &= (~((uint32)SCG_FIRCCSR_FIRCEN_MASK));
  501. /* Configure FIRC. */
  502. if (config->enable == 1U)
  503. {
  504. /* Step frequency range. */
  505. IP_SCG->FIRCCFG = SCG_FIRCCFG_RANGE(config->range);
  506. /* Enable clock. */
  507. IP_SCG->FIRCCSR |= (SCG_FIRCCSR_FIRCEN(1U) | SCG_FIRCCSR_FIRCREGOFF(config->regulator));
  508. ClockStartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_TIMEOUT_VALUE_US);
  509. /* Wait until ircosc is locked */
  510. do
  511. {
  512. IrcoscStatus = (((IP_SCG->FIRCCSR & SCG_FIRCCSR_FIRCVLD_MASK) >> SCG_FIRCCSR_FIRCVLD_SHIFT));
  513. TimeoutOccurred = ClockTimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
  514. }
  515. while ((IrcoscStatus == 0U) && (FALSE == TimeoutOccurred));
  516. if (FALSE != TimeoutOccurred)
  517. {
  518. /* Report timeout error */
  519. ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, config->name);
  520. }
  521. /* Switch back to FIRC */
  522. SetInputSouceSytemClock(FIRC_CLK_SOURCE);
  523. if (SircWasDisabled)
  524. {
  525. DisableSirc(SIRC_CLK);
  526. }
  527. }
  528. }
  529. }
  530. else
  531. {
  532. /* Configure FIRC. */
  533. /* Disable clock */
  534. IP_SCG->FIRCCSR &= (~((uint32)SCG_FIRCCSR_FIRCEN_MASK));
  535. if (config->enable == 1U)
  536. {
  537. /* Step frequency range. */
  538. IP_SCG->FIRCCFG = SCG_FIRCCFG_RANGE(config->range);
  539. /* Enable clock. */
  540. IP_SCG->FIRCCSR |= (SCG_FIRCCSR_FIRCEN(1U) | SCG_FIRCCSR_FIRCREGOFF(config->regulator));
  541. ClockStartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_TIMEOUT_VALUE_US);
  542. /* Wait until ircosc is locked */
  543. do
  544. {
  545. IrcoscStatus = (((IP_SCG->FIRCCSR & SCG_FIRCCSR_FIRCVLD_MASK) >> SCG_FIRCCSR_FIRCVLD_SHIFT));
  546. TimeoutOccurred = ClockTimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
  547. }
  548. while ((IrcoscStatus == 0U) && (FALSE == TimeoutOccurred));
  549. if (FALSE != TimeoutOccurred)
  550. {
  551. /* Report timeout error */
  552. ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, config->name);
  553. }
  554. }
  555. }
  556. }
  557. static void SetFirc(Clock_Ip_IrcoscConfigType const* config)
  558. {
  559. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  560. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  561. OsIf_Trusted_Call1param(SetFirc_TrustedCall,(config));
  562. #else
  563. SetFirc_TrustedCall(config);
  564. #endif
  565. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  566. }
  567. static void EnableFirc_TrustedCall(Clock_Ip_IrcoscConfigType const* config)
  568. {
  569. boolean TimeoutOccurred = FALSE;
  570. uint32 StartTime;
  571. uint32 ElapsedTime;
  572. uint32 TimeoutTicks;
  573. uint32 IrcoscStatus;
  574. if (config->enable == 1U)
  575. {
  576. /* Enable clock. */
  577. IP_SCG->FIRCCSR |= SCG_FIRCCSR_FIRCEN(1U);
  578. ClockStartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_TIMEOUT_VALUE_US);
  579. /* Wait until ircosc is locked */
  580. do
  581. {
  582. IrcoscStatus = (((IP_SCG->FIRCCSR & SCG_FIRCCSR_FIRCVLD_MASK) >> SCG_FIRCCSR_FIRCVLD_SHIFT));
  583. TimeoutOccurred = ClockTimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
  584. }
  585. while ((IrcoscStatus == 0U) && (FALSE == TimeoutOccurred));
  586. if (FALSE != TimeoutOccurred)
  587. {
  588. /* Report timeout error */
  589. ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, config->name);
  590. }
  591. }
  592. }
  593. static void EnableFirc(Clock_Ip_IrcoscConfigType const* config)
  594. {
  595. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  596. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  597. OsIf_Trusted_Call1param(EnableFirc_TrustedCall,(config));
  598. #else
  599. EnableFirc_TrustedCall(config);
  600. #endif
  601. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  602. }
  603. static void DisableFirc_TrustedCall(Clock_Ip_NameType name)
  604. {
  605. (void) name;
  606. /* Disable clock. */
  607. IP_SCG->FIRCCSR &= ~SCG_FIRCCSR_FIRCEN_MASK;
  608. }
  609. static void DisableFirc(Clock_Ip_NameType name)
  610. {
  611. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  612. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  613. OsIf_Trusted_Call1param(DisableFirc_TrustedCall,(name));
  614. #else
  615. DisableFirc_TrustedCall(name);
  616. #endif
  617. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  618. }
  619. #endif
  620. /* Clock stop section code */
  621. #define MCU_STOP_SEC_CODE
  622. #include "Mcu_MemMap.h"
  623. /*! @}*/
  624. /*******************************************************************************
  625. * EOF
  626. ******************************************************************************/