Clock_Ip_Specific.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  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_Specific.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. #if (defined(CLOCK_IP_ENABLE_USER_MODE_SUPPORT))
  36. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  37. #define USER_MODE_REG_PROT_ENABLED (STD_ON)
  38. #include "RegLockMacros.h"
  39. #endif
  40. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  41. /*==================================================================================================
  42. SOURCE FILE VERSION INFORMATION
  43. ==================================================================================================*/
  44. #define CLOCK_IP_SPECIFIC_VENDOR_ID_C 43
  45. #define CLOCK_IP_SPECIFIC_AR_RELEASE_MAJOR_VERSION_C 4
  46. #define CLOCK_IP_SPECIFIC_AR_RELEASE_MINOR_VERSION_C 4
  47. #define CLOCK_IP_SPECIFIC_AR_RELEASE_REVISION_VERSION_C 0
  48. #define CLOCK_IP_SPECIFIC_SW_MAJOR_VERSION_C 1
  49. #define CLOCK_IP_SPECIFIC_SW_MINOR_VERSION_C 0
  50. #define CLOCK_IP_SPECIFIC_SW_PATCH_VERSION_C 0
  51. /*==================================================================================================
  52. * FILE VERSION CHECKS
  53. ==================================================================================================*/
  54. /* Check if Clock_Ip_Specific.c file and Clock_Ip_Private.h file are of the same vendor */
  55. #if (CLOCK_IP_SPECIFIC_VENDOR_ID_C != CLOCK_IP_PRIVATE_VENDOR_ID)
  56. #error "Clock_Ip_Specific.c and Clock_Ip_Private.h have different vendor ids"
  57. #endif
  58. /* Check if Clock_Ip_Specific.c file and Clock_Ip_Private.h file are of the same Autosar version */
  59. #if ((CLOCK_IP_SPECIFIC_AR_RELEASE_MAJOR_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_MAJOR_VERSION) || \
  60. (CLOCK_IP_SPECIFIC_AR_RELEASE_MINOR_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_MINOR_VERSION) || \
  61. (CLOCK_IP_SPECIFIC_AR_RELEASE_REVISION_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_REVISION_VERSION) \
  62. )
  63. #error "AutoSar Version Numbers of Clock_Ip_Specific.c and Clock_Ip_Private.h are different"
  64. #endif
  65. /* Check if Clock_Ip_Specific.c file and Clock_Ip_Private.h file are of the same Software version */
  66. #if ((CLOCK_IP_SPECIFIC_SW_MAJOR_VERSION_C != CLOCK_IP_PRIVATE_SW_MAJOR_VERSION) || \
  67. (CLOCK_IP_SPECIFIC_SW_MINOR_VERSION_C != CLOCK_IP_PRIVATE_SW_MINOR_VERSION) || \
  68. (CLOCK_IP_SPECIFIC_SW_PATCH_VERSION_C != CLOCK_IP_PRIVATE_SW_PATCH_VERSION) \
  69. )
  70. #error "Software Version Numbers of Clock_Ip_Specific.c and Clock_Ip_Private.h are different"
  71. #endif
  72. #if (defined(CLOCK_IP_ENABLE_USER_MODE_SUPPORT))
  73. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  74. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  75. /* Check if Clock_Ip_Specific.c file and RegLockMacros.h file are of the same Autosar version */
  76. #if ((CLOCK_IP_SPECIFIC_AR_RELEASE_MAJOR_VERSION_C != REGLOCKMACROS_AR_RELEASE_MAJOR_VERSION) || \
  77. (CLOCK_IP_SPECIFIC_AR_RELEASE_MINOR_VERSION_C != REGLOCKMACROS_AR_RELEASE_MINOR_VERSION))
  78. #error "AutoSar Version Numbers of Clock_Ip_Specific.c and RegLockMacros.h are different"
  79. #endif
  80. #endif
  81. #endif
  82. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  83. /*==================================================================================================
  84. LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
  85. ==================================================================================================*/
  86. /*==================================================================================================
  87. * LOCAL MACROS
  88. ==================================================================================================*/
  89. #define SCS_SELECTOR_HARDWARE_VALUES_NO 7U
  90. #define RUN_POWER_MODE_STATUS 1U
  91. #if (defined (CLOCK_IP_S32K118) || defined(CLOCK_IP_S32K116))
  92. #define SYS_OSC 1U
  93. #define CMU 1U
  94. #define SCS_RUN 4U
  95. #define FIRCOSC 4U
  96. #define DIVCORE_RUN 5U
  97. #define DIVBUS_RUN 7U
  98. #define DIVSLOW_RUN 9U
  99. #elif (defined (CLOCK_IP_S32K142W) || defined(CLOCK_IP_S32K144W))
  100. #define SYS_OSC 1U
  101. #define SYS_PLL 1U
  102. #define FIRCOSC 4U
  103. #define SCS_RUN 5U
  104. #define DIVCORE_RUN 6U
  105. #define DIVBUS_RUN 8U
  106. #define DIVSLOW_RUN 10U
  107. #elif (defined (CLOCK_IP_S32K142) || defined(CLOCK_IP_S32K144) || defined(CLOCK_IP_S32K146) || defined(CLOCK_IP_S32K148))
  108. #define SYS_OSC 1U
  109. #define SYS_PLL 1U
  110. #define FIRCOSC 4U
  111. #define SCS_RUN 5U
  112. #define DIVCORE_RUN 6U
  113. #define SCS_HSRUN 7U
  114. #define DIVCORE_HSRUN 8U
  115. #define DIVBUS_RUN 9U
  116. #define DIVBUS_HSRUN 11U
  117. #define DIVSLOW_RUN 12U
  118. #define DIVSLOW_HSRUN 14U
  119. #endif
  120. /*==================================================================================================
  121. LOCAL CONSTANTS
  122. ==================================================================================================*/
  123. /*==================================================================================================
  124. LOCAL VARIABLES
  125. ==================================================================================================*/
  126. /*==================================================================================================
  127. GLOBAL CONSTANTS
  128. ==================================================================================================*/
  129. /*==================================================================================================
  130. GLOBAL VARIABLES
  131. ==================================================================================================*/
  132. #ifdef FEATURE_CLOCK_IP_HAS_FLASH_WAIT_STATES
  133. /* Clock start ram section code */
  134. #define MCU_START_SEC_RAMCODE
  135. #include "Mcu_MemMap.h"
  136. static void CodeInRam_SetFlashWaitStates(void);
  137. /* Clock start ram section code */
  138. #define MCU_STOP_SEC_RAMCODE
  139. #include "Mcu_MemMap.h"
  140. #endif /* FEATURE_CLOCK_IP_HAS_FLASH_WAIT_STATES */
  141. /* Clock start initialized section data */
  142. #define MCU_START_SEC_VAR_CLEARED_BOOLEAN
  143. #include "Mcu_MemMap.h"
  144. static boolean fircWasEnabledBeforeMcuInit; /* Firc clock was enabled before MCU initialization */
  145. /* Clock stop initialized section data */
  146. #define MCU_STOP_SEC_VAR_CLEARED_BOOLEAN
  147. #include "Mcu_MemMap.h"
  148. /* Clock start initialized section data */
  149. #define MCU_START_SEC_VAR_CLEARED_UNSPECIFIED
  150. #include "Mcu_MemMap.h"
  151. static const Clock_Ip_ClockConfigType *config_clock;
  152. #if defined(FEATURE_CLOCK_IP_HAS_SPLL_CLK)
  153. static const pllCallback * spllClock;
  154. #endif
  155. static const extOscCallback *soscClock;
  156. static const intOscCallback *fircClock;
  157. #if defined(FEATURE_CLOCK_IP_HAS_FIRC_MON1_CLK) || defined(FEATURE_CLOCK_IP_HAS_FIRC_MON2_CLK)
  158. static const clockMonitorCallback *cmuFircMonitor;
  159. #endif
  160. static const selectorCallback *scsRunClockSelector;
  161. static const dividerCallback *coreRunClockDivider;
  162. static const dividerCallback *busRunClockDivider;
  163. static const dividerCallback *slowRunClockDivider;
  164. static const Clock_Ip_IrcoscConfigType *fircConfig;
  165. static const Clock_Ip_XoscConfigType *soscConfig;
  166. #if defined(FEATURE_CLOCK_IP_HAS_SPLL_CLK)
  167. static const Clock_Ip_PllConfigType *spllConfig;
  168. #endif
  169. #if defined(FEATURE_CLOCK_IP_HAS_FIRC_MON1_CLK) || defined(FEATURE_CLOCK_IP_HAS_FIRC_MON2_CLK)
  170. const Clock_Ip_CmuConfigType *cmuFircMon1Config,*cmuFircMon2Config;
  171. #endif
  172. static const Clock_Ip_SelectorConfigType *scsConfig_Run_Mode, *scsConfig_Vlpr_Mode;
  173. static const Clock_Ip_DividerConfigType *coreConfig_Run_Mode, *coreConfig_Vlpr_Mode, *busConfig_Run_Mode, *busConfig_Vlpr_Mode, *slowConfig_Run_Mode, *slowConfig_Vlpr_Mode;
  174. #if defined(FEATURE_CLOCK_IP_HAS_SLOW_HSRUN_CLK)
  175. static const selectorCallback *scsHsrunClockSelector;
  176. static const dividerCallback *coreHsrunClockDivider;
  177. static const dividerCallback *busHsrunClockDivider;
  178. static const dividerCallback *slowHsrunClockDivider;
  179. static const Clock_Ip_SelectorConfigType *scsConfig_Hsrun_Mode;
  180. static const Clock_Ip_DividerConfigType *coreConfig_Hsrun_Mode, *busConfig_Hsrun_Mode, *slowConfig_Hsrun_Mode;
  181. #endif
  182. /* Clock stop initialized section data */
  183. #define MCU_STOP_SEC_VAR_CLEARED_UNSPECIFIED
  184. #include "Mcu_MemMap.h"
  185. /*==================================================================================================
  186. * LOCAL FUNCTION PROTOTYPES
  187. ==================================================================================================*/
  188. #define MCU_START_SEC_CODE
  189. #include "Mcu_MemMap.h"
  190. static const Clock_Ip_IrcoscConfigType *getFircConfig(void);
  191. static const Clock_Ip_XoscConfigType *getSoscConfig(void);
  192. static const Clock_Ip_XoscConfigType *getSoscConfig(void);
  193. #if defined(FEATURE_CLOCK_IP_HAS_SPLL_CLK)
  194. static const Clock_Ip_PllConfigType *getSpllConfig(void);
  195. #endif
  196. #if defined(FEATURE_CLOCK_IP_HAS_FIRC_MON1_CLK) || defined(FEATURE_CLOCK_IP_HAS_FIRC_MON2_CLK)
  197. static const Clock_Ip_CmuConfigType *getCmuFircConfig(Clock_Ip_NameType name);
  198. #endif
  199. static const Clock_Ip_SelectorConfigType *getSelectorConfig(Clock_Ip_NameType name);
  200. static const Clock_Ip_DividerConfigType *getCoreDividerConfig(Clock_Ip_NameType name);
  201. static const Clock_Ip_DividerConfigType *getBusDividerConfig(Clock_Ip_NameType name);
  202. static const Clock_Ip_DividerConfigType *getSlowDividerConfig(Clock_Ip_NameType name);
  203. static void SetSimLpoclksRegister_TrustedCall(Clock_Ip_ClockConfigType const *config);
  204. #if defined(FEATURE_CLOCK_IP_HAS_FIRC_MON1_CLK) || defined(FEATURE_CLOCK_IP_HAS_FIRC_MON2_CLK)
  205. static void EnableCmuGate_TrustedCall(void);
  206. #endif
  207. #define MCU_STOP_SEC_CODE
  208. #include "Mcu_MemMap.h"
  209. /*==================================================================================================
  210. * LOCAL FUNCTIONS
  211. ==================================================================================================*/
  212. /*==================================================================================================
  213. * GLOBAL FUNCTIONS
  214. ==================================================================================================*/
  215. #ifdef FEATURE_CLOCK_IP_HAS_RAM_WAIT_STATES
  216. #define MCU_START_SEC_CODE_AC
  217. #include "Mcu_MemMap.h"
  218. static void PRAMC_SetRamIWS(void);
  219. #define MCU_STOP_SEC_CODE_AC
  220. #include "Mcu_MemMap.h"
  221. #endif
  222. #define MCU_START_SEC_CODE
  223. #include "Mcu_MemMap.h"
  224. #ifdef FEATURE_CLOCK_IP_HAS_RAM_WAIT_STATES
  225. void SetRamWaitStates(void)
  226. {
  227. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  228. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  229. OsIf_Trusted_Call(PRAMC_SetRamIWS);
  230. #else
  231. PRAMC_SetRamIWS();
  232. #endif
  233. #else
  234. PRAMC_SetRamIWS();
  235. #endif
  236. }
  237. #endif
  238. #ifdef FEATURE_CLOCK_IP_HAS_FLASH_WAIT_STATES
  239. void FLASH_SetFlashIWS(void);
  240. void SetFlashWaitStates(void)
  241. {
  242. FLASH_SetFlashIWS();
  243. }
  244. #endif
  245. /* Configure the specific modules like eMios */
  246. void SpecificPeripheralClockInitialization(Clock_IP_SpecificPeriphConfigType const * config)
  247. {
  248. (void)config;
  249. }
  250. void DisableSafeClock(Clock_Ip_ClockConfigType const * config)
  251. {
  252. uint32 i;
  253. boolean fircConfigFound = FALSE;
  254. if (config != NULL_PTR)
  255. {
  256. for (i = 0U; i < config_clock->ircoscsCount; i++)
  257. {
  258. if (config_clock->ircoscs[i].name == FIRC_CLK)
  259. {
  260. fircConfigFound = TRUE;
  261. if (config_clock->ircoscs[i].enable == FALSE)
  262. {
  263. /* Disable FIRC according to configuration */
  264. intOscCallbacks[ircoscCallbackIndex[FIRCOSC]].Disable(FIRC_CLK);
  265. }
  266. break;
  267. }
  268. }
  269. }
  270. if ((fircConfigFound == FALSE) && (fircWasEnabledBeforeMcuInit == FALSE))
  271. {
  272. /* Disable FIRC according to configuration */
  273. intOscCallbacks[ircoscCallbackIndex[FIRCOSC]].Disable(FIRC_CLK);
  274. }
  275. }
  276. static void SetFircToResetValue_TrustedCall(void)
  277. {
  278. /* Range is 48Mhz. */
  279. IP_SCG->FIRCCFG = SCG_FIRCCFG_RANGE(0U);
  280. /* Enable clock, regulator is enabled. */
  281. IP_SCG->FIRCCSR |= (SCG_FIRCCSR_FIRCEN(1U) | SCG_FIRCCSR_FIRCREGOFF(0U));
  282. }
  283. static void SetSimLpoclksRegister_TrustedCall(Clock_Ip_ClockConfigType const *config)
  284. {
  285. uint32 SimLpoValue = 3U; /* Reset value of SIM_LPOCLKS register */
  286. uint32 i;
  287. /* The LPOCLKS register is a write-once register so configuration will be written here*/
  288. for (i = 0U; i < config->selectorsCount; i++)
  289. {
  290. /* Selector for RTC_CLK */
  291. if (RTC_CLK == config->selectors[i].name)
  292. {
  293. SimLpoValue |= ((uint32)(selectorEntry_hardwareValue[config->selectors[i].value]) << SIM_LPOCLKS_RTCCLKSEL_SHIFT);
  294. }
  295. /* Selector for LPO_CLK */
  296. if (LPO_CLK == config->selectors[i].name)
  297. {
  298. SimLpoValue |= ((uint32)(selectorEntryPCS_hardwareValue[config->selectors[i].value]) << SIM_LPOCLKS_LPOCLKSEL_SHIFT);
  299. }
  300. }
  301. for (i = 0U; i < config->gatesCount; i++) /* Set clock gates that are under clock control. */
  302. {
  303. /* Gate for LPO_32K_CLK */
  304. if (LPO_32K_CLK == config->gates[i].name)
  305. {
  306. SimLpoValue |= ((uint32)(config->gates[i].enable) << SIM_LPOCLKS_LPO32KCLKEN_SHIFT);
  307. }
  308. /* Gate for LPO_1K_CLK */
  309. if (LPO_1K_CLK == config->gates[i].name)
  310. {
  311. SimLpoValue |= ((uint32)(config->gates[i].enable) << SIM_LPOCLKS_LPO1KCLKEN_SHIFT);
  312. }
  313. }
  314. IP_SIM->LPOCLKS = SimLpoValue;
  315. }
  316. #if defined(FEATURE_CLOCK_IP_HAS_FIRC_MON1_CLK) || defined(FEATURE_CLOCK_IP_HAS_FIRC_MON2_CLK)
  317. static void EnableCmuGate_TrustedCall(void)
  318. {
  319. uint32 regValue;
  320. regValue = IP_PCC->PCCn[clockFeatures[CMU0_CLK][GATE_INDEX]];
  321. regValue &= ~PCC_PCCn_CGC_MASK;
  322. regValue |= PCC_PCCn_CGC_MASK;
  323. IP_PCC->PCCn[clockFeatures[CMU0_CLK][GATE_INDEX]] = regValue;
  324. regValue = IP_PCC->PCCn[clockFeatures[CMU1_CLK][GATE_INDEX]];
  325. regValue &= ~PCC_PCCn_CGC_MASK;
  326. regValue |= PCC_PCCn_CGC_MASK;
  327. IP_PCC->PCCn[clockFeatures[CMU1_CLK][GATE_INDEX]] = regValue;
  328. }
  329. #endif
  330. void SpecificPlatformInitClock(Clock_Ip_ClockConfigType const * config)
  331. {
  332. boolean TimeoutOccurred = FALSE;
  333. uint32 StartTime;
  334. uint32 ElapsedTime;
  335. uint32 TimeoutTicks;
  336. uint32 IrcoscStatus;
  337. config_clock = config;
  338. (void)RUN_POWER_MODE_STATUS;
  339. /* Clocks cannot be configured while the chip is in other mode than RUN_MODE */
  340. CLOCK_DEV_ASSERT(RUN_POWER_MODE_STATUS == ((IP_SMC->PMSTAT & SMC_PMSTAT_PMSTAT_MASK) >> SMC_PMSTAT_PMSTAT_SHIFT));
  341. /* Check whether FIRC is disabled, enable it in this case. */
  342. if ((IP_SCG->FIRCCSR & SCG_FIRCCSR_FIRCEN_MASK) == 0U)
  343. {
  344. fircWasEnabledBeforeMcuInit = FALSE;
  345. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  346. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  347. OsIf_Trusted_Call(SetFircToResetValue_TrustedCall);
  348. #else
  349. SetFircToResetValue_TrustedCall();
  350. #endif
  351. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  352. ClockStartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_TIMEOUT_VALUE_US);
  353. /* Wait until ircosc is locked */
  354. do
  355. {
  356. IrcoscStatus = (((IP_SCG->FIRCCSR & SCG_FIRCCSR_FIRCVLD_MASK) >> SCG_FIRCCSR_FIRCVLD_SHIFT));
  357. TimeoutOccurred = ClockTimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
  358. }
  359. while ((IrcoscStatus == 0U) && (FALSE == TimeoutOccurred));
  360. if (FALSE != TimeoutOccurred)
  361. {
  362. /* Report timeout error */
  363. ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, FIRC_CLK);
  364. }
  365. }
  366. else
  367. {
  368. fircWasEnabledBeforeMcuInit = TRUE;
  369. }
  370. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  371. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  372. OsIf_Trusted_Call1param(SetSimLpoclksRegister_TrustedCall,(config));
  373. #else
  374. SetSimLpoclksRegister_TrustedCall(config);
  375. #endif
  376. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  377. #if defined(FEATURE_CLOCK_IP_HAS_FIRC_MON1_CLK) || defined(FEATURE_CLOCK_IP_HAS_FIRC_MON2_CLK)
  378. #ifdef CLOCK_IP_ENABLE_USER_MODE_SUPPORT
  379. #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
  380. OsIf_Trusted_Call(EnableCmuGate_TrustedCall);
  381. #else
  382. EnableCmuGate_TrustedCall();
  383. #endif
  384. #endif /* CLOCK_IP_ENABLE_USER_MODE_SUPPORT */
  385. #endif
  386. }
  387. /**
  388. * @brief This function will get current configuration of FIRC.
  389. */
  390. static const Clock_Ip_IrcoscConfigType *getFircConfig(void)
  391. {
  392. uint32 i;
  393. const Clock_Ip_IrcoscConfigType *returnValue = NULL_PTR;
  394. static Clock_Ip_IrcoscConfigType fircConfiguration;
  395. if (config_clock != NULL_PTR)
  396. {
  397. for (i = 0U; i < config_clock->ircoscsCount; i++)
  398. {
  399. if (config_clock->ircoscs[i].name == FIRC_CLK)
  400. {
  401. returnValue = &config_clock->ircoscs[i];
  402. break;
  403. }
  404. }
  405. }
  406. /* Element is not under mcu control */
  407. if (returnValue == NULL_PTR)
  408. {
  409. returnValue = &fircConfiguration;
  410. fircConfiguration.name = FIRC_CLK;
  411. fircConfiguration.enable = (uint16)(IP_SCG->FIRCCSR & SCG_FIRCCSR_FIRCEN_MASK) >> SCG_FIRCCSR_FIRCEN_SHIFT;
  412. fircConfiguration.range = (uint8)(IP_SCG->FIRCCFG & SCG_FIRCCFG_RANGE_MASK) >> SCG_FIRCCFG_RANGE_SHIFT;
  413. fircConfiguration.regulator = (uint8)(IP_SCG->FIRCCSR & SCG_FIRCCSR_FIRCREGOFF_MASK) >> SCG_FIRCCSR_FIRCREGOFF_SHIFT;
  414. }
  415. return returnValue;
  416. }
  417. /**
  418. * @brief This function will get current configuration of SOSC.
  419. */
  420. static const Clock_Ip_XoscConfigType *getSoscConfig(void)
  421. {
  422. uint32 i;
  423. const Clock_Ip_XoscConfigType *returnValue = NULL_PTR;
  424. static Clock_Ip_XoscConfigType soscConfiguration;
  425. if (config_clock != NULL_PTR)
  426. {
  427. for (i = 0U; i < config_clock->xoscsCount; i++)
  428. {
  429. if (config_clock->xoscs[i].name == SOSC_CLK)
  430. {
  431. returnValue = &config_clock->xoscs[i];
  432. break;
  433. }
  434. }
  435. }
  436. /* Element is not under mcu control */
  437. if (returnValue == NULL_PTR)
  438. {
  439. returnValue = &soscConfiguration;
  440. soscConfiguration.name = SOSC_CLK;
  441. soscConfiguration.enable = (uint16)(IP_SCG->SOSCCSR & SCG_SOSCCSR_SOSCEN_MASK) >> SCG_SOSCCSR_SOSCEN_SHIFT;
  442. soscConfiguration.freq = FEATURE_CLOCK_IP_DEFAULT_SOSC_FREQUENCY;
  443. }
  444. return returnValue;
  445. }
  446. #if defined(FEATURE_CLOCK_IP_HAS_SPLL_CLK)
  447. /**
  448. * @brief This function will get current configuration of SPLL.
  449. */
  450. static const Clock_Ip_PllConfigType *getSpllConfig(void)
  451. {
  452. uint32 i;
  453. const Clock_Ip_PllConfigType *returnValue = NULL_PTR;
  454. static Clock_Ip_PllConfigType spllConfiguration;
  455. if (config_clock != NULL_PTR)
  456. {
  457. for (i = 0U; i < config_clock->pllsCount; i++)
  458. {
  459. if (config_clock->plls[i].name == SPLL_CLK)
  460. {
  461. returnValue = &config_clock->plls[i];
  462. break;
  463. }
  464. }
  465. }
  466. /* Element is not under mcu control */
  467. if (returnValue == NULL_PTR)
  468. {
  469. returnValue = &spllConfiguration;
  470. spllConfiguration.name = SPLL_CLK;
  471. spllConfiguration.enable = (uint16)(IP_SCG->SPLLCSR & SCG_SPLLCSR_SPLLEN_MASK) >> SCG_SPLLCSR_SPLLEN_SHIFT;
  472. spllConfiguration.predivider = (uint8)((IP_SCG->SPLLCFG & SCG_SPLLCFG_PREDIV_MASK) >> SCG_SPLLCFG_PREDIV_SHIFT);
  473. spllConfiguration.mulFactorDiv = (uint8)((IP_SCG->SPLLCFG & SCG_SPLLCFG_MULT_MASK) >> SCG_SPLLCFG_MULT_SHIFT);
  474. }
  475. return returnValue;
  476. }
  477. #endif
  478. #if defined(FEATURE_CLOCK_IP_HAS_FIRC_MON1_CLK) || defined(FEATURE_CLOCK_IP_HAS_FIRC_MON2_CLK)
  479. static const Clock_Ip_CmuConfigType *getCmuFircConfig(Clock_Ip_NameType name)
  480. {
  481. uint32 i;
  482. const Clock_Ip_CmuConfigType *returnValue = NULL_PTR;
  483. static Clock_Ip_CmuConfigType cmuConfiguration;
  484. if (config_clock != NULL_PTR)
  485. {
  486. for (i = 0U; i < config_clock->cmusCount; i++)
  487. {
  488. if (config_clock->cmus[i].name == name)
  489. {
  490. returnValue = &config_clock->cmus[i];
  491. break;
  492. }
  493. }
  494. }
  495. /* Element is not under mcu control */
  496. if (returnValue == NULL_PTR)
  497. {
  498. returnValue = &cmuConfiguration;
  499. cmuConfiguration.name = FIRC_CLK;
  500. cmuConfiguration.enable = (cmu[0U]->GCR & CMU_FC_GCR_FCE_MASK) >> CMU_FC_GCR_FCE_SHIFT;
  501. }
  502. return returnValue;
  503. }
  504. #endif
  505. static const Clock_Ip_SelectorConfigType *getSelectorConfig(Clock_Ip_NameType name)
  506. {
  507. const Clock_Ip_SelectorConfigType *returnValue = NULL_PTR;
  508. static Clock_Ip_SelectorConfigType selectorConfigurations[3U];
  509. uint32 selectorConfigIndex, i;
  510. static const Clock_Ip_NameType clockSource[SCS_SELECTOR_HARDWARE_VALUES_NO] = {
  511. CLOCK_IS_OFF, /* clock name for 0 hardware value */
  512. SOSC_CLK, /* clock name for 1 hardware value */
  513. SIRC_CLK, /* clock name for 2 hardware value */
  514. FIRC_CLK, /* clock name for 3 hardware value */
  515. CLOCK_IS_OFF, /* clock name for 4 hardware value */
  516. CLOCK_IS_OFF, /* clock name for 5 hardware value */
  517. #if defined(FEATURE_CLOCK_IP_HAS_SPLL_CLK)
  518. SPLL_CLK, /* clock name for 6 hardware value */
  519. #else
  520. CLOCK_IS_OFF, /* clock name for 6 hardware value */
  521. #endif
  522. };
  523. switch(name)
  524. {
  525. case SCS_RUN_CLK:
  526. selectorConfigIndex = 0U;
  527. break;
  528. case SCS_VLPR_CLK:
  529. selectorConfigIndex = 1U;
  530. break;
  531. #if defined(FEATURE_CLOCK_IP_HAS_SCS_HSRUN_CLK)
  532. case SCS_HSRUN_CLK:
  533. selectorConfigIndex = 2U;
  534. break;
  535. #endif
  536. default:
  537. selectorConfigIndex = 0U;
  538. break;
  539. }
  540. if (config_clock != NULL_PTR)
  541. {
  542. for (i = 0U; i < config_clock->selectorsCount; i++)
  543. {
  544. if (config_clock->selectors[i].name == name)
  545. {
  546. returnValue = &config_clock->selectors[i];
  547. break;
  548. }
  549. }
  550. }
  551. /* Element is not under mcu control */
  552. if (returnValue == NULL_PTR)
  553. {
  554. returnValue = &selectorConfigurations[selectorConfigIndex];
  555. selectorConfigurations[selectorConfigIndex].name = name;
  556. switch(name)
  557. {
  558. case SCS_RUN_CLK:
  559. selectorConfigurations[selectorConfigIndex].value = clockSource[(IP_SCG->RCCR & SCG_RCCR_SCS_MASK) >> SCG_RCCR_SCS_SHIFT];
  560. break;
  561. case SCS_VLPR_CLK:
  562. selectorConfigurations[selectorConfigIndex].value = clockSource[(IP_SCG->VCCR & SCG_VCCR_SCS_MASK) >> SCG_VCCR_SCS_SHIFT];
  563. break;
  564. #if defined(FEATURE_CLOCK_IP_HAS_SCS_HSRUN_CLK)
  565. case SCS_HSRUN_CLK:
  566. selectorConfigurations[selectorConfigIndex].value = clockSource[(IP_SCG->HCCR & SCG_HCCR_SCS_MASK) >> SCG_HCCR_SCS_SHIFT];
  567. break;
  568. #endif
  569. default:
  570. /* Invalid clock name */
  571. break;
  572. }
  573. }
  574. return returnValue;
  575. }
  576. static const Clock_Ip_DividerConfigType *getCoreDividerConfig(Clock_Ip_NameType name)
  577. {
  578. const Clock_Ip_DividerConfigType *returnValue = NULL_PTR;
  579. static Clock_Ip_DividerConfigType dividerConfigurations[3U];
  580. uint32 dividerConfigIndex = 0U;
  581. uint32 i;
  582. switch(name)
  583. {
  584. case CORE_RUN_CLK:
  585. dividerConfigIndex = 0U;
  586. break;
  587. case CORE_VLPR_CLK:
  588. dividerConfigIndex = 1U;
  589. break;
  590. #if defined(FEATURE_CLOCK_IP_HAS_CORE_HSRUN_CLK)
  591. case CORE_HSRUN_CLK:
  592. dividerConfigIndex = 2U;
  593. break;
  594. #endif
  595. default:
  596. /* Invalid clock name */
  597. break;
  598. }
  599. if (config_clock != NULL_PTR)
  600. {
  601. for (i = 0U; i < config_clock->dividersCount; i++)
  602. {
  603. if (config_clock->dividers[i].name == name)
  604. {
  605. returnValue = &config_clock->dividers[i];
  606. break;
  607. }
  608. }
  609. }
  610. /* Element is not under mcu control */
  611. if (returnValue == NULL_PTR)
  612. {
  613. returnValue = &dividerConfigurations[dividerConfigIndex];
  614. dividerConfigurations[dividerConfigIndex].name = name;
  615. switch(name)
  616. {
  617. case CORE_RUN_CLK:
  618. dividerConfigurations[dividerConfigIndex].value = ((IP_SCG->RCCR & SCG_RCCR_DIVCORE_MASK) >> SCG_RCCR_DIVCORE_SHIFT) + 1U;
  619. break;
  620. case CORE_VLPR_CLK:
  621. dividerConfigurations[dividerConfigIndex].value = ((IP_SCG->VCCR & SCG_VCCR_DIVCORE_MASK) >> SCG_VCCR_DIVCORE_SHIFT) + 1U;
  622. break;
  623. #if defined(FEATURE_CLOCK_IP_HAS_CORE_HSRUN_CLK)
  624. case CORE_HSRUN_CLK:
  625. dividerConfigurations[dividerConfigIndex].value = ((IP_SCG->HCCR & SCG_HCCR_DIVCORE_MASK) >> SCG_HCCR_DIVCORE_SHIFT) + 1U;
  626. break;
  627. #endif
  628. default:
  629. /* Invalid clock name */
  630. break;
  631. }
  632. }
  633. return returnValue;
  634. }
  635. static const Clock_Ip_DividerConfigType *getBusDividerConfig(Clock_Ip_NameType name)
  636. {
  637. const Clock_Ip_DividerConfigType *returnValue = NULL_PTR;
  638. static Clock_Ip_DividerConfigType dividerConfigurations[3U];
  639. uint32 dividerConfigIndex = 0U;
  640. uint32 i;
  641. switch(name)
  642. {
  643. case BUS_RUN_CLK:
  644. dividerConfigIndex = 0U;
  645. break;
  646. case BUS_VLPR_CLK:
  647. dividerConfigIndex = 1U;
  648. break;
  649. #if defined(FEATURE_CLOCK_IP_HAS_BUS_HSRUN_CLK)
  650. case BUS_HSRUN_CLK:
  651. dividerConfigIndex = 2U;
  652. break;
  653. #endif
  654. default:
  655. /* Invalid clock name */
  656. break;
  657. }
  658. if (config_clock != NULL_PTR)
  659. {
  660. for (i = 0U; i < config_clock->dividersCount; i++)
  661. {
  662. if (config_clock->dividers[i].name == name)
  663. {
  664. returnValue = &config_clock->dividers[i];
  665. break;
  666. }
  667. }
  668. }
  669. /* Element is not under mcu control */
  670. if (returnValue == NULL_PTR)
  671. {
  672. returnValue = &dividerConfigurations[dividerConfigIndex];
  673. dividerConfigurations[dividerConfigIndex].name = name;
  674. switch(name)
  675. {
  676. case BUS_RUN_CLK:
  677. dividerConfigurations[dividerConfigIndex].value = ((IP_SCG->RCCR & SCG_RCCR_DIVBUS_MASK) >> SCG_RCCR_DIVBUS_SHIFT) + 1U;
  678. break;
  679. case BUS_VLPR_CLK:
  680. dividerConfigurations[dividerConfigIndex].value = ((IP_SCG->VCCR & SCG_VCCR_DIVBUS_MASK) >> SCG_VCCR_DIVBUS_SHIFT) + 1U;
  681. break;
  682. #if defined(FEATURE_CLOCK_IP_HAS_BUS_HSRUN_CLK)
  683. case BUS_HSRUN_CLK:
  684. dividerConfigurations[dividerConfigIndex].value = ((IP_SCG->HCCR & SCG_HCCR_DIVBUS_MASK) >> SCG_HCCR_DIVBUS_SHIFT) + 1U;
  685. break;
  686. #endif
  687. default:
  688. /* Invalid clock name */
  689. break;
  690. }
  691. }
  692. return returnValue;
  693. }
  694. static const Clock_Ip_DividerConfigType *getSlowDividerConfig(Clock_Ip_NameType name)
  695. {
  696. const Clock_Ip_DividerConfigType *returnValue = NULL_PTR;
  697. static Clock_Ip_DividerConfigType dividerConfigurations[3U];
  698. uint32 dividerConfigIndex = 0U;
  699. uint32 i;
  700. switch(name)
  701. {
  702. case SLOW_RUN_CLK:
  703. dividerConfigIndex = 0U;
  704. break;
  705. case SLOW_VLPR_CLK:
  706. dividerConfigIndex = 1U;
  707. break;
  708. #if defined(FEATURE_CLOCK_IP_HAS_SLOW_HSRUN_CLK)
  709. case SLOW_HSRUN_CLK:
  710. dividerConfigIndex = 2U;
  711. break;
  712. #endif
  713. default:
  714. /* Invalid clock name */
  715. break;
  716. }
  717. if (config_clock != NULL_PTR)
  718. {
  719. for (i = 0U; i < config_clock->dividersCount; i++)
  720. {
  721. if (config_clock->dividers[i].name == name)
  722. {
  723. returnValue = &config_clock->dividers[i];
  724. break;
  725. }
  726. }
  727. }
  728. /* Element is not under mcu control */
  729. if (returnValue == NULL_PTR)
  730. {
  731. returnValue = &dividerConfigurations[dividerConfigIndex];
  732. dividerConfigurations[dividerConfigIndex].name = name;
  733. switch(name)
  734. {
  735. case SLOW_RUN_CLK:
  736. dividerConfigurations[dividerConfigIndex].value = ((IP_SCG->RCCR & SCG_RCCR_DIVSLOW_MASK) >> SCG_RCCR_DIVSLOW_SHIFT) + 1U;
  737. break;
  738. case SLOW_VLPR_CLK:
  739. dividerConfigurations[dividerConfigIndex].value = ((IP_SCG->VCCR & SCG_VCCR_DIVSLOW_MASK) >> SCG_VCCR_DIVSLOW_SHIFT) + 1U;
  740. break;
  741. #if defined(FEATURE_CLOCK_IP_HAS_SLOW_HSRUN_CLK)
  742. case SLOW_HSRUN_CLK:
  743. dividerConfigurations[dividerConfigIndex].value = ((IP_SCG->HCCR & SCG_HCCR_DIVSLOW_MASK) >> SCG_HCCR_DIVSLOW_SHIFT) + 1U;
  744. break;
  745. #endif
  746. default:
  747. /* Invalid clock name */
  748. break;
  749. }
  750. }
  751. return returnValue;
  752. }
  753. /* Initialize objects for clock */
  754. void ClockInitializeObjects(void)
  755. {
  756. #if defined(FEATURE_CLOCK_IP_HAS_SPLL_CLK)
  757. spllClock = &pllCallbacks[pllCallbackIndex[SYS_PLL]];
  758. #endif
  759. soscClock = &extOscCallbacks[xoscCallbackIndex[SYS_OSC]];
  760. fircClock = &intOscCallbacks[ircoscCallbackIndex[FIRCOSC]];
  761. #if defined(FEATURE_CLOCK_IP_HAS_FIRC_MON1_CLK) || defined(FEATURE_CLOCK_IP_HAS_FIRC_MON2_CLK)
  762. cmuFircMonitor = &cmuCallbacks[cmuCallbackIndex[CMU]];
  763. #endif
  764. scsRunClockSelector = &selectorCallbacks[selectorCallbackIndex[SCS_RUN]];
  765. #if defined(FEATURE_CLOCK_IP_HAS_SCS_HSRUN_CLK)
  766. scsHsrunClockSelector = &selectorCallbacks[selectorCallbackIndex[SCS_HSRUN]];
  767. #endif
  768. coreRunClockDivider = &dividerCallbacks[dividerCallbackIndex[DIVCORE_RUN]];
  769. #if defined(FEATURE_CLOCK_IP_HAS_CORE_HSRUN_CLK)
  770. coreHsrunClockDivider = &dividerCallbacks[dividerCallbackIndex[DIVCORE_HSRUN]];
  771. #endif
  772. busRunClockDivider = &dividerCallbacks[dividerCallbackIndex[DIVBUS_RUN]];
  773. #if defined(FEATURE_CLOCK_IP_HAS_BUS_HSRUN_CLK)
  774. busHsrunClockDivider = &dividerCallbacks[dividerCallbackIndex[DIVBUS_HSRUN]];
  775. #endif
  776. slowRunClockDivider = &dividerCallbacks[dividerCallbackIndex[DIVSLOW_RUN]];
  777. #if defined(FEATURE_CLOCK_IP_HAS_SLOW_HSRUN_CLK)
  778. slowHsrunClockDivider = &dividerCallbacks[dividerCallbackIndex[DIVSLOW_HSRUN]];
  779. #endif
  780. fircConfig = getFircConfig();
  781. soscConfig = getSoscConfig();
  782. #if defined(FEATURE_CLOCK_IP_HAS_SPLL_CLK)
  783. spllConfig = getSpllConfig();
  784. #endif
  785. #if defined(FEATURE_CLOCK_IP_HAS_FIRC_MON1_CLK)
  786. cmuFircMon1Config = getCmuFircConfig(FIRC_MON1_CLK);
  787. #endif
  788. #if defined(FEATURE_CLOCK_IP_HAS_FIRC_MON2_CLK)
  789. cmuFircMon2Config = getCmuFircConfig(FIRC_MON2_CLK);
  790. #endif
  791. scsConfig_Run_Mode = getSelectorConfig(SCS_RUN_CLK);
  792. scsConfig_Vlpr_Mode = getSelectorConfig(SCS_VLPR_CLK);
  793. #if defined(FEATURE_CLOCK_IP_HAS_SCS_HSRUN_CLK)
  794. scsConfig_Hsrun_Mode = getSelectorConfig(SCS_HSRUN_CLK);
  795. #endif
  796. coreConfig_Run_Mode = getCoreDividerConfig(CORE_RUN_CLK);
  797. coreConfig_Vlpr_Mode = getCoreDividerConfig(CORE_VLPR_CLK);
  798. #if defined(FEATURE_CLOCK_IP_HAS_CORE_HSRUN_CLK)
  799. coreConfig_Hsrun_Mode = getCoreDividerConfig(CORE_HSRUN_CLK);
  800. #endif
  801. busConfig_Run_Mode = getBusDividerConfig(BUS_RUN_CLK);
  802. busConfig_Vlpr_Mode = getBusDividerConfig(BUS_VLPR_CLK);
  803. #if defined(FEATURE_CLOCK_IP_HAS_BUS_HSRUN_CLK)
  804. busConfig_Hsrun_Mode = getBusDividerConfig(BUS_HSRUN_CLK);
  805. #endif
  806. slowConfig_Run_Mode = getSlowDividerConfig(SLOW_RUN_CLK);
  807. slowConfig_Vlpr_Mode = getSlowDividerConfig(SLOW_VLPR_CLK);
  808. #if defined(FEATURE_CLOCK_IP_HAS_SLOW_HSRUN_CLK)
  809. slowConfig_Hsrun_Mode = getSlowDividerConfig(SLOW_HSRUN_CLK);
  810. #endif
  811. }
  812. void ClockPowerModeChangeNotification(power_modes_t powerMode, power_notification_t notification)
  813. {
  814. switch(powerMode)
  815. {
  816. case VLPR_MODE:
  817. case VLPS_MODE:
  818. {
  819. if(BEFORE_POWER_MODE_CHANGE == notification)
  820. {
  821. /* Disable all cmus */
  822. #if defined(FEATURE_CLOCK_IP_HAS_FIRC_MON1_CLK)
  823. /* Check enable clock gate for CMU0 */
  824. if(((IP_PCC->PCCn[62] & PCC_PCCn_CGC_MASK) >> PCC_PCCn_CGC_SHIFT) == 1U)
  825. {
  826. cmuFircMonitor->Disable(FIRC_MON1_CLK);
  827. }
  828. #endif
  829. #if defined(FEATURE_CLOCK_IP_HAS_FIRC_MON2_CLK)
  830. /* Check enable clock gate for CMU1 */
  831. if(((IP_PCC->PCCn[63] & PCC_PCCn_CGC_MASK) >> PCC_PCCn_CGC_SHIFT) == 1U)
  832. {
  833. cmuFircMonitor->Disable(FIRC_MON2_CLK);
  834. }
  835. #endif
  836. /* Load system clock settings for VLPR mode */
  837. scsRunClockSelector->Set(scsConfig_Vlpr_Mode);
  838. coreRunClockDivider->Set(coreConfig_Vlpr_Mode);
  839. busRunClockDivider->Set(busConfig_Vlpr_Mode);
  840. slowRunClockDivider->Set(slowConfig_Vlpr_Mode);
  841. /* Disable all clock sources except SIRC */
  842. #if defined(FEATURE_CLOCK_IP_HAS_SPLL_CLK)
  843. spllClock->Disable(spllConfig->name);
  844. #endif
  845. soscClock->Disable(soscConfig->name);
  846. fircClock->Disable(fircConfig->name);
  847. }
  848. }
  849. break;
  850. case RUN_MODE:
  851. {
  852. if(POWER_MODE_CHANGED == notification)
  853. {
  854. /* Restore clock source settings */
  855. fircClock->Enable(fircConfig);
  856. soscClock->Enable(soscConfig); /* Enable */
  857. soscClock->Complete(soscConfig); /* Wait to lock */
  858. #if defined(FEATURE_CLOCK_IP_HAS_SPLL_CLK)
  859. spllClock->Enable(spllConfig); /* Enable */
  860. (void)(spllClock->Complete(spllConfig->name)); /* Wait to lock */
  861. #endif
  862. /* Restore system clock settings */
  863. scsRunClockSelector->Set(scsConfig_Run_Mode);
  864. coreRunClockDivider->Set(coreConfig_Run_Mode);
  865. busRunClockDivider->Set(busConfig_Run_Mode);
  866. slowRunClockDivider->Set(slowConfig_Run_Mode);
  867. /* Restore all cmus */
  868. #if defined(FEATURE_CLOCK_IP_HAS_FIRC_MON1_CLK)
  869. /* Check enable clock gate for CMU0 */
  870. if(((IP_PCC->PCCn[62] & PCC_PCCn_CGC_MASK) >> PCC_PCCn_CGC_SHIFT) == 1U)
  871. {
  872. cmuFircMonitor->Enable(cmuFircMon1Config);
  873. }
  874. #endif
  875. #if defined(FEATURE_CLOCK_IP_HAS_FIRC_MON2_CLK)
  876. /* Check enable clock gate for CMU1 */
  877. if(((IP_PCC->PCCn[63] & PCC_PCCn_CGC_MASK) >> PCC_PCCn_CGC_SHIFT) == 1U)
  878. {
  879. cmuFircMonitor->Enable(cmuFircMon2Config);
  880. }
  881. #endif
  882. }
  883. }
  884. break;
  885. case HSRUN_MODE:
  886. {
  887. if(POWER_MODE_CHANGED == notification)
  888. {
  889. /* Restore clock source settings */
  890. fircClock->Enable(fircConfig);
  891. soscClock->Enable(soscConfig); /* Enable */
  892. soscClock->Complete(soscConfig); /* Wait to lock */
  893. #if defined(FEATURE_CLOCK_IP_HAS_SPLL_CLK)
  894. spllClock->Enable(spllConfig); /* Enable */
  895. (void)(spllClock->Complete(spllConfig->name)); /* Wait to lock */
  896. #endif
  897. /* Restore system clock settings */
  898. #if defined(FEATURE_CLOCK_IP_HAS_SCS_HSRUN_CLK)
  899. scsHsrunClockSelector->Set(scsConfig_Hsrun_Mode);
  900. #endif
  901. #if defined(FEATURE_CLOCK_IP_HAS_CORE_HSRUN_CLK)
  902. coreHsrunClockDivider->Set(coreConfig_Hsrun_Mode);
  903. #endif
  904. #if defined(FEATURE_CLOCK_IP_HAS_BUS_HSRUN_CLK)
  905. busHsrunClockDivider->Set(busConfig_Hsrun_Mode);
  906. #endif
  907. #if defined(FEATURE_CLOCK_IP_HAS_SLOW_HSRUN_CLK)
  908. slowHsrunClockDivider->Set(slowConfig_Hsrun_Mode);
  909. #endif
  910. /* Restore all cmus */
  911. #if defined(FEATURE_CLOCK_IP_HAS_FIRC_MON1_CLK)
  912. /* Check enable clock gate for CMU0 */
  913. if(((IP_PCC->PCCn[62] & PCC_PCCn_CGC_MASK) >> PCC_PCCn_CGC_SHIFT) == 1U)
  914. {
  915. cmuFircMonitor->Enable(cmuFircMon1Config);
  916. }
  917. #endif
  918. #if defined(FEATURE_CLOCK_IP_HAS_FIRC_MON2_CLK)
  919. /* Check enable clock gate for CMU1 */
  920. if(((IP_PCC->PCCn[63] & PCC_PCCn_CGC_MASK) >> PCC_PCCn_CGC_SHIFT) == 1U)
  921. {
  922. cmuFircMonitor->Enable(cmuFircMon2Config);
  923. }
  924. #endif
  925. }
  926. }
  927. break;
  928. default:
  929. {
  930. /* Invalid power mode */
  931. }
  932. break;
  933. }
  934. }
  935. /* Clock stop section code */
  936. #define MCU_STOP_SEC_CODE
  937. #include "Mcu_MemMap.h"
  938. #ifdef FEATURE_CLOCK_IP_HAS_RAM_WAIT_STATES
  939. /* Clock start rom section code */
  940. #define MCU_START_SEC_CODE_AC
  941. #include "Mcu_MemMap.h"
  942. static void PRAMC_SetRamIWS(void)
  943. {
  944. /* CORE_CLK frequency is greater than 80MHz or CORE_CLK and AIPS_PLAT_CLK have the same frequency */
  945. if ((configuredCoreClock > 80000000U) || (configuredCoreClock == configuredAipsPlatClock))
  946. {
  947. /* Enable RAM WS */
  948. PRAMC_0->PRCR1 |= PRAMC_PRCR1_FT_DIS_MASK;
  949. PRAMC_1->PRCR1 |= PRAMC_PRCR1_FT_DIS_MASK;
  950. }
  951. else
  952. {
  953. /* Disable RAM WS */
  954. PRAMC_0->PRCR1 &= ~PRAMC_PRCR1_FT_DIS_MASK;
  955. PRAMC_1->PRCR1 &= ~PRAMC_PRCR1_FT_DIS_MASK;
  956. }
  957. }
  958. /* Clock stop rom section code */
  959. #define MCU_STOP_SEC_CODE_AC
  960. #include "Mcu_MemMap.h"
  961. #endif
  962. #ifdef FEATURE_CLOCK_IP_HAS_FLASH_WAIT_STATES
  963. /* Clock start ram section code */
  964. #define MCU_START_SEC_RAMCODE
  965. #include "Mcu_MemMap.h"
  966. static void CodeInRam_SetFlashWaitStates(void)
  967. {
  968. uint32 rwsc_setting = 0U;
  969. if (configuredCoreClock <= 167000000U)
  970. {
  971. if (configuredCoreClock <= 66000000U)
  972. {
  973. rwsc_setting = 1U;
  974. }
  975. else if (configuredCoreClock <= 100000000U)
  976. {
  977. rwsc_setting = 2U;
  978. }
  979. else if (configuredCoreClock <= 133000000U)
  980. {
  981. rwsc_setting = 3U;
  982. }
  983. else
  984. {
  985. rwsc_setting = 4U;
  986. }
  987. }
  988. else
  989. {
  990. if (configuredCoreClock <= 200000000U)
  991. {
  992. rwsc_setting = 5U;
  993. }
  994. else if (configuredCoreClock <= 233000000U)
  995. {
  996. rwsc_setting = 6U;
  997. }
  998. else if (configuredCoreClock <= 250000000U)
  999. {
  1000. rwsc_setting = 7U;
  1001. }
  1002. else
  1003. {
  1004. rwsc_setting = 7U;
  1005. }
  1006. }
  1007. FLASH->CTL &= ~FLASH_CTL_RWSL_MASK;
  1008. FLASH->CTL &= ~FLASH_CTL_RWSC_MASK;
  1009. FLASH->CTL |= FLASH_CTL_RWSC(rwsc_setting);
  1010. }
  1011. /* Clock stop ram section code */
  1012. #define MCU_STOP_SEC_RAMCODE
  1013. #include "Mcu_MemMap.h"
  1014. /* Clock start initialized section data */
  1015. #define MCU_START_SEC_VAR_INIT_UNSPECIFIED
  1016. #include "Mcu_MemMap.h"
  1017. typedef void (*SetFlashWaitStatesCallbackType)(void);
  1018. SetFlashWaitStatesCallbackType SetFlashWaitStatesCallback = CodeInRam_SetFlashWaitStates; /* Set Flash Wait States callback */
  1019. /* Clock stop initialized section data */
  1020. #define MCU_STOP_SEC_VAR_INIT_UNSPECIFIED
  1021. #include "Mcu_MemMap.h"
  1022. /* Clock start section code */
  1023. #define MCU_START_SEC_CODE
  1024. #include "Mcu_MemMap.h"
  1025. void FLASH_SetFlashIWS(void)
  1026. {
  1027. SetFlashWaitStatesCallback();
  1028. }
  1029. /* Clock stop section code */
  1030. #define MCU_STOP_SEC_CODE
  1031. #include "Mcu_MemMap.h"
  1032. #endif
  1033. /*! @}*/
  1034. /*******************************************************************************
  1035. * EOF
  1036. ******************************************************************************/