Power_Ip.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  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 Power_Ip.c
  26. * @version 1.0.0
  27. *
  28. * @brief
  29. * @brief POWER driver implementations.
  30. * @details POWER driver implementations.
  31. *
  32. * @addtogroup POWER_DRIVER Power Ip Driver
  33. * @{
  34. */
  35. #ifdef __cplusplus
  36. extern "C"{
  37. #endif
  38. /*==================================================================================================
  39. * INCLUDE FILES
  40. * 1) system and project includes
  41. * 2) needed interfaces from external units
  42. * 3) internal and external interfaces from this unit
  43. ==================================================================================================*/
  44. #include "Power_Ip.h"
  45. #include "Power_Ip_Private.h"
  46. #include "Power_Ip_PMC.h"
  47. #include "Power_Ip_RCM.h"
  48. #include "Power_Ip_SCG.h"
  49. #include "Power_Ip_SMC.h"
  50. #include "Power_Ip_PCC.h"
  51. #include "Power_Ip_CMU.h"
  52. #include "Power_Ip_CortexM4.h"
  53. #include "Power_Ip_SIM.h"
  54. #if (POWER_MODE_CHANGE_NOTIFICATION == STD_ON)
  55. #include "Clock_Ip.h"
  56. #endif
  57. /*==================================================================================================
  58. SOURCE FILE VERSION INFORMATION
  59. ==================================================================================================*/
  60. #define POWER_IP_VENDOR_ID_C 43
  61. #define POWER_IP_AR_RELEASE_MAJOR_VERSION_C 4
  62. #define POWER_IP_AR_RELEASE_MINOR_VERSION_C 4
  63. #define POWER_IP_AR_RELEASE_REVISION_VERSION_C 0
  64. #define POWER_IP_SW_MAJOR_VERSION_C 1
  65. #define POWER_IP_SW_MINOR_VERSION_C 0
  66. #define POWER_IP_SW_PATCH_VERSION_C 0
  67. /*==================================================================================================
  68. * FILE VERSION CHECKS
  69. ==================================================================================================*/
  70. /* Check if Power_Ip.c file and Power_Ip.h file are of the same vendor */
  71. #if (POWER_IP_VENDOR_ID_C != POWER_IP_VENDOR_ID)
  72. #error "Power_Ip.c and Power_Ip.h have different vendor ids"
  73. #endif
  74. /* Check if Power_Ip.c file and Power_Ip.h file are of the same Autosar version */
  75. #if ((POWER_IP_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_AR_RELEASE_MAJOR_VERSION) || \
  76. (POWER_IP_AR_RELEASE_MINOR_VERSION_C != POWER_IP_AR_RELEASE_MINOR_VERSION) || \
  77. (POWER_IP_AR_RELEASE_REVISION_VERSION_C != POWER_IP_AR_RELEASE_REVISION_VERSION) \
  78. )
  79. #error "AutoSar Version Numbers of Power_Ip.c and Power_Ip.h are different"
  80. #endif
  81. /* Check if Power_Ip.c file and Power_Ip.h file are of the same Software version */
  82. #if ((POWER_IP_SW_MAJOR_VERSION_C != POWER_IP_SW_MAJOR_VERSION) || \
  83. (POWER_IP_SW_MINOR_VERSION_C != POWER_IP_SW_MINOR_VERSION) || \
  84. (POWER_IP_SW_PATCH_VERSION_C != POWER_IP_SW_PATCH_VERSION) \
  85. )
  86. #error "Software Version Numbers of Power_Ip.c and Power_Ip.h are different"
  87. #endif
  88. /* Check if Power_Ip.c file and Power_Ip_Private.h file are of the same vendor */
  89. #if (POWER_IP_VENDOR_ID_C != POWER_IP_PRIVATE_VENDOR_ID)
  90. #error "Power_Ip.c and Power_Ip_Private.h have different vendor ids"
  91. #endif
  92. /* Check if Power_Ip.c file and Power_Ip_Private.h file are of the same Autosar version */
  93. #if ((POWER_IP_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_PRIVATE_AR_RELEASE_MAJOR_VERSION) || \
  94. (POWER_IP_AR_RELEASE_MINOR_VERSION_C != POWER_IP_PRIVATE_AR_RELEASE_MINOR_VERSION) || \
  95. (POWER_IP_AR_RELEASE_REVISION_VERSION_C != POWER_IP_PRIVATE_AR_RELEASE_REVISION_VERSION) \
  96. )
  97. #error "AutoSar Version Numbers of Power_Ip.c and Power_Ip_Private.h are different"
  98. #endif
  99. /* Check if Power_Ip.c file and Power_Ip_Private.h file are of the same Software version */
  100. #if ((POWER_IP_SW_MAJOR_VERSION_C != POWER_IP_PRIVATE_SW_MAJOR_VERSION) || \
  101. (POWER_IP_SW_MINOR_VERSION_C != POWER_IP_PRIVATE_SW_MINOR_VERSION) || \
  102. (POWER_IP_SW_PATCH_VERSION_C != POWER_IP_PRIVATE_SW_PATCH_VERSION) \
  103. )
  104. #error "Software Version Numbers of Power_Ip.c and Power_Ip_Private.h are different"
  105. #endif
  106. /* Check if Power_Ip.c file and Power_Ip_PMC.h file are of the same vendor */
  107. #if (POWER_IP_VENDOR_ID_C != POWER_IP_PMC_VENDOR_ID)
  108. #error "Power_Ip.c and Power_Ip_PMC.h have different vendor ids"
  109. #endif
  110. /* Check if Power_Ip.c file and Power_Ip_PMC.h file are of the same Autosar version */
  111. #if ((POWER_IP_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_PMC_AR_RELEASE_MAJOR_VERSION) || \
  112. (POWER_IP_AR_RELEASE_MINOR_VERSION_C != POWER_IP_PMC_AR_RELEASE_MINOR_VERSION) || \
  113. (POWER_IP_AR_RELEASE_REVISION_VERSION_C != POWER_IP_PMC_AR_RELEASE_REVISION_VERSION) \
  114. )
  115. #error "AutoSar Version Numbers of Power_Ip.c and Power_Ip_PMC.h are different"
  116. #endif
  117. /* Check if Power_Ip.c file and Power_Ip_PMC.h file are of the same Software version */
  118. #if ((POWER_IP_SW_MAJOR_VERSION_C != POWER_IP_PMC_SW_MAJOR_VERSION) || \
  119. (POWER_IP_SW_MINOR_VERSION_C != POWER_IP_PMC_SW_MINOR_VERSION) || \
  120. (POWER_IP_SW_PATCH_VERSION_C != POWER_IP_PMC_SW_PATCH_VERSION) \
  121. )
  122. #error "Software Version Numbers of Power_Ip.c and Power_Ip_PMC.h are different"
  123. #endif
  124. /* Check if Power_Ip.c file and Power_Ip_RCM.h file are of the same vendor */
  125. #if (POWER_IP_VENDOR_ID_C != POWER_IP_RCM_VENDOR_ID)
  126. #error "Power_Ip.c and Power_Ip_RCM.h have different vendor ids"
  127. #endif
  128. /* Check if Power_Ip.c file and Power_Ip_RCM.h file are of the same Autosar version */
  129. #if ((POWER_IP_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_RCM_AR_RELEASE_MAJOR_VERSION) || \
  130. (POWER_IP_AR_RELEASE_MINOR_VERSION_C != POWER_IP_RCM_AR_RELEASE_MINOR_VERSION) || \
  131. (POWER_IP_AR_RELEASE_REVISION_VERSION_C != POWER_IP_RCM_AR_RELEASE_REVISION_VERSION) \
  132. )
  133. #error "AutoSar Version Numbers of Power_Ip.c and Power_Ip_RCM.h are different"
  134. #endif
  135. /* Check if Power_Ip.c file and Power_Ip_RCM.h file are of the same Software version */
  136. #if ((POWER_IP_SW_MAJOR_VERSION_C != POWER_IP_RCM_SW_MAJOR_VERSION) || \
  137. (POWER_IP_SW_MINOR_VERSION_C != POWER_IP_RCM_SW_MINOR_VERSION) || \
  138. (POWER_IP_SW_PATCH_VERSION_C != POWER_IP_RCM_SW_PATCH_VERSION) \
  139. )
  140. #error "Software Version Numbers of Power_Ip.c and Power_Ip_RCM.h are different"
  141. #endif
  142. /* Check if Power_Ip.c file and Power_Ip_SCG.h file are of the same vendor */
  143. #if (POWER_IP_VENDOR_ID_C != POWER_IP_SCG_VENDOR_ID)
  144. #error "Power_Ip.c and Power_Ip_SCG.h have different vendor ids"
  145. #endif
  146. /* Check if Power_Ip.c file and Power_Ip_SCG.h file are of the same Autosar version */
  147. #if ((POWER_IP_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_SCG_AR_RELEASE_MAJOR_VERSION) || \
  148. (POWER_IP_AR_RELEASE_MINOR_VERSION_C != POWER_IP_SCG_AR_RELEASE_MINOR_VERSION) || \
  149. (POWER_IP_AR_RELEASE_REVISION_VERSION_C != POWER_IP_SCG_AR_RELEASE_REVISION_VERSION) \
  150. )
  151. #error "AutoSar Version Numbers of Power_Ip.c and Power_Ip_SCG.h are different"
  152. #endif
  153. /* Check if Power_Ip.c file and Power_Ip_SCG.h file are of the same Software version */
  154. #if ((POWER_IP_SW_MAJOR_VERSION_C != POWER_IP_SCG_SW_MAJOR_VERSION) || \
  155. (POWER_IP_SW_MINOR_VERSION_C != POWER_IP_SCG_SW_MINOR_VERSION) || \
  156. (POWER_IP_SW_PATCH_VERSION_C != POWER_IP_SCG_SW_PATCH_VERSION) \
  157. )
  158. #error "Software Version Numbers of Power_Ip.c and Power_Ip_SCG.h are different"
  159. #endif
  160. /* Check if Power_Ip.c file and Power_Ip_SMC.h file are of the same vendor */
  161. #if (POWER_IP_VENDOR_ID_C != POWER_IP_SMC_VENDOR_ID)
  162. #error "Power_Ip.c and Power_Ip_SMC.h have different vendor ids"
  163. #endif
  164. /* Check if Power_Ip.c file and Power_Ip_SMC.h file are of the same Autosar version */
  165. #if ((POWER_IP_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_SMC_AR_RELEASE_MAJOR_VERSION) || \
  166. (POWER_IP_AR_RELEASE_MINOR_VERSION_C != POWER_IP_SMC_AR_RELEASE_MINOR_VERSION) || \
  167. (POWER_IP_AR_RELEASE_REVISION_VERSION_C != POWER_IP_SMC_AR_RELEASE_REVISION_VERSION) \
  168. )
  169. #error "AutoSar Version Numbers of Power_Ip.c and Power_Ip_SMC.h are different"
  170. #endif
  171. /* Check if Power_Ip.c file and Power_Ip_SMC.h file are of the same Software version */
  172. #if ((POWER_IP_SW_MAJOR_VERSION_C != POWER_IP_SMC_SW_MAJOR_VERSION) || \
  173. (POWER_IP_SW_MINOR_VERSION_C != POWER_IP_SMC_SW_MINOR_VERSION) || \
  174. (POWER_IP_SW_PATCH_VERSION_C != POWER_IP_SMC_SW_PATCH_VERSION) \
  175. )
  176. #error "Software Version Numbers of Power_Ip.c and Power_Ip_SMC.h are different"
  177. #endif
  178. /* Check if Power_Ip.c file and Power_Ip_PCC.h file are of the same vendor */
  179. #if (POWER_IP_VENDOR_ID_C != POWER_IP_PCC_VENDOR_ID)
  180. #error "Power_Ip.c and Power_Ip_PCC.h have different vendor ids"
  181. #endif
  182. /* Check if Power_Ip.c file and Power_Ip_PCC.h file are of the same Autosar version */
  183. #if ((POWER_IP_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_PCC_AR_RELEASE_MAJOR_VERSION) || \
  184. (POWER_IP_AR_RELEASE_MINOR_VERSION_C != POWER_IP_PCC_AR_RELEASE_MINOR_VERSION) || \
  185. (POWER_IP_AR_RELEASE_REVISION_VERSION_C != POWER_IP_PCC_AR_RELEASE_REVISION_VERSION) \
  186. )
  187. #error "AutoSar Version Numbers of Power_Ip.c and Power_Ip_PCC.h are different"
  188. #endif
  189. /* Check if Power_Ip.c file and Power_Ip_PCC.h file are of the same Software version */
  190. #if ((POWER_IP_SW_MAJOR_VERSION_C != POWER_IP_PCC_SW_MAJOR_VERSION) || \
  191. (POWER_IP_SW_MINOR_VERSION_C != POWER_IP_PCC_SW_MINOR_VERSION) || \
  192. (POWER_IP_SW_PATCH_VERSION_C != POWER_IP_PCC_SW_PATCH_VERSION) \
  193. )
  194. #error "Software Version Numbers of Power_Ip.c and Power_Ip_PCC.h are different"
  195. #endif
  196. /* Check if Power_Ip.c file and Power_Ip_CMU.h file are of the same vendor */
  197. #if (POWER_IP_VENDOR_ID_C != POWER_IP_CMU_VENDOR_ID)
  198. #error "Power_Ip.c and Power_Ip_CMU.h have different vendor ids"
  199. #endif
  200. /* Check if Power_Ip.c file and Power_Ip_CMU.h file are of the same Autosar version */
  201. #if ((POWER_IP_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_CMU_AR_RELEASE_MAJOR_VERSION) || \
  202. (POWER_IP_AR_RELEASE_MINOR_VERSION_C != POWER_IP_CMU_AR_RELEASE_MINOR_VERSION) || \
  203. (POWER_IP_AR_RELEASE_REVISION_VERSION_C != POWER_IP_CMU_AR_RELEASE_REVISION_VERSION) \
  204. )
  205. #error "AutoSar Version Numbers of Power_Ip.c and Power_Ip_CMU.h are different"
  206. #endif
  207. /* Check if Power_Ip.c file and Power_Ip_CMU.h file are of the same Software version */
  208. #if ((POWER_IP_SW_MAJOR_VERSION_C != POWER_IP_CMU_SW_MAJOR_VERSION) || \
  209. (POWER_IP_SW_MINOR_VERSION_C != POWER_IP_CMU_SW_MINOR_VERSION) || \
  210. (POWER_IP_SW_PATCH_VERSION_C != POWER_IP_CMU_SW_PATCH_VERSION) \
  211. )
  212. #error "Software Version Numbers of Power_Ip.c and Power_Ip_CMU.h are different"
  213. #endif
  214. /* Check if Power_Ip.c file and Power_Ip_CortexM4.h file are of the same vendor */
  215. #if (POWER_IP_VENDOR_ID_C != POWER_IP_CORTEXM4_VENDOR_ID)
  216. #error "Power_Ip.c and Power_Ip_CortexM4.h have different vendor ids"
  217. #endif
  218. /* Check if Power_Ip.c file and Power_Ip_CortexM4.h file are of the same Autosar version */
  219. #if ((POWER_IP_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_CORTEXM4_AR_RELEASE_MAJOR_VERSION) || \
  220. (POWER_IP_AR_RELEASE_MINOR_VERSION_C != POWER_IP_CORTEXM4_AR_RELEASE_MINOR_VERSION) || \
  221. (POWER_IP_AR_RELEASE_REVISION_VERSION_C != POWER_IP_CORTEXM4_AR_RELEASE_REVISION_VERSION) \
  222. )
  223. #error "AutoSar Version Numbers of Power_Ip.c and Power_Ip_CortexM4.h are different"
  224. #endif
  225. /* Check if Power_Ip.c file and Power_Ip_CortexM4.h file are of the same Software version */
  226. #if ((POWER_IP_SW_MAJOR_VERSION_C != POWER_IP_CORTEXM4_SW_MAJOR_VERSION) || \
  227. (POWER_IP_SW_MINOR_VERSION_C != POWER_IP_CORTEXM4_SW_MINOR_VERSION) || \
  228. (POWER_IP_SW_PATCH_VERSION_C != POWER_IP_CORTEXM4_SW_PATCH_VERSION) \
  229. )
  230. #error "Software Version Numbers of Power_Ip.c and Power_Ip_CortexM4.h are different"
  231. #endif
  232. /* Check if Power_Ip.c file and Power_Ip_SIM.h file are of the same vendor */
  233. #if (POWER_IP_VENDOR_ID_C != POWER_IP_SIM_VENDOR_ID)
  234. #error "Power_Ip.c and Power_Ip_SIM.h have different vendor ids"
  235. #endif
  236. /* Check if Power_Ip.c file and Power_Ip_SIM.h file are of the same Autosar version */
  237. #if ((POWER_IP_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_SIM_AR_RELEASE_MAJOR_VERSION) || \
  238. (POWER_IP_AR_RELEASE_MINOR_VERSION_C != POWER_IP_SIM_AR_RELEASE_MINOR_VERSION) || \
  239. (POWER_IP_AR_RELEASE_REVISION_VERSION_C != POWER_IP_SIM_AR_RELEASE_REVISION_VERSION) \
  240. )
  241. #error "AutoSar Version Numbers of Power_Ip.c and Power_Ip_SIM.h are different"
  242. #endif
  243. /* Check if Power_Ip.c file and Power_Ip_SIM.h file are of the same Software version */
  244. #if ((POWER_IP_SW_MAJOR_VERSION_C != POWER_IP_SIM_SW_MAJOR_VERSION) || \
  245. (POWER_IP_SW_MINOR_VERSION_C != POWER_IP_SIM_SW_MINOR_VERSION) || \
  246. (POWER_IP_SW_PATCH_VERSION_C != POWER_IP_SIM_SW_PATCH_VERSION) \
  247. )
  248. #error "Software Version Numbers of Power_Ip.c and Power_Ip_SIM.h are different"
  249. #endif
  250. #if (POWER_MODE_CHANGE_NOTIFICATION == STD_ON)
  251. /* Check if Power_Ip.c file and Clock_Ip.h file are of the same vendor */
  252. #if (POWER_IP_VENDOR_ID_C != CLOCK_IP_VENDOR_ID)
  253. #error "Power_Ip.c and Clock_Ip.h have different vendor ids"
  254. #endif
  255. /* Check if Power_Ip.c file and Clock_Ip.h file are of the same Autosar version */
  256. #if ((POWER_IP_AR_RELEASE_MAJOR_VERSION_C != CLOCK_IP_AR_RELEASE_MAJOR_VERSION) || \
  257. (POWER_IP_AR_RELEASE_MINOR_VERSION_C != CLOCK_IP_AR_RELEASE_MINOR_VERSION) || \
  258. (POWER_IP_AR_RELEASE_REVISION_VERSION_C != CLOCK_IP_AR_RELEASE_REVISION_VERSION) \
  259. )
  260. #error "AutoSar Version Numbers of Power_Ip.c and Clock_Ip.h are different"
  261. #endif
  262. /* Check if Power_Ip.c file and Clock_Ip.h file are of the same Software version */
  263. #if ((POWER_IP_SW_MAJOR_VERSION_C != CLOCK_IP_SW_MAJOR_VERSION) || \
  264. (POWER_IP_SW_MINOR_VERSION_C != CLOCK_IP_SW_MINOR_VERSION) || \
  265. (POWER_IP_SW_PATCH_VERSION_C != CLOCK_IP_SW_PATCH_VERSION) \
  266. )
  267. #error "Software Version Numbers of Power_Ip.c and Clock_Ip.h are different"
  268. #endif
  269. #endif
  270. /*==================================================================================================
  271. LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
  272. ==================================================================================================*/
  273. /*==================================================================================================
  274. LOCAL MACROS
  275. ==================================================================================================*/
  276. /*==================================================================================================
  277. LOCAL CONSTANTS
  278. ==================================================================================================*/
  279. /*==================================================================================================
  280. LOCAL VARIABLES
  281. ==================================================================================================*/
  282. #define MCU_START_SEC_VAR_INIT_UNSPECIFIED
  283. #include "Mcu_MemMap.h"
  284. /* Power Report Error Callback */
  285. Power_Ip_ReportErrorsCallbackType powerReportErrorsCallback = ReportPowerErrorsEmptyCallback;
  286. #define MCU_STOP_SEC_VAR_INIT_UNSPECIFIED
  287. #include "Mcu_MemMap.h"
  288. /*==================================================================================================
  289. GLOBAL CONSTANTS
  290. ==================================================================================================*/
  291. /*==================================================================================================
  292. GLOBAL VARIABLES
  293. ==================================================================================================*/
  294. /*==================================================================================================
  295. LOCAL FUNCTION PROTOTYPES
  296. ==================================================================================================*/
  297. #define MCU_START_SEC_CODE
  298. #include "Mcu_MemMap.h"
  299. #if (MCU_ENTER_LOW_POWER_MODE == STD_ON)
  300. static void Power_Ip_DisableFircClock(void);
  301. static void Power_Ip_DisableSoscClock(void);
  302. static void Power_Ip_PrepareLowPowerMode(Power_Ip_PowerModeType ePowerMode);
  303. #endif
  304. #if (POWER_MODE_CHANGE_NOTIFICATION == STD_ON)
  305. static power_modes_t Power_Ip_ModeConvert(Power_Ip_PowerModeType ePowerMode);
  306. #endif
  307. static Power_Ip_ResetType Power_Ip_ConvertIntergeToResetType(uint32 resetReasonIndex);
  308. /*==================================================================================================
  309. LOCAL FUNCTIONS
  310. ==================================================================================================*/
  311. #if (MCU_ENTER_LOW_POWER_MODE == STD_ON)
  312. /**
  313. * @brief This function will disable Firc clock
  314. */
  315. static void Power_Ip_DisableFircClock(void)
  316. {
  317. uint32 u32SystemResetIsrConfig;
  318. /* Configurable SIRC as system clock */
  319. Call_Power_Ip_SCG_DropSysClkToSircInRunMode();
  320. /* get the current System Reset Interrupt Enable settings */
  321. u32SystemResetIsrConfig = Power_Ip_RCM_GetCurrentSystemResetIsrSettings();
  322. /* Configure all reset sources to be 'Reset' */
  323. Call_Power_Ip_RCM_SystemResetIsrConfig();
  324. /* Disable Firc Clock */
  325. Call_Power_Ip_SCG_DisableFircClock();
  326. /* Restore System Reset Interrupt Config */
  327. Call_Power_Ip_RCM_RestoreSystemResetIsrConfig(u32SystemResetIsrConfig);
  328. }
  329. /**
  330. * @brief This function will disable SOSC clock
  331. */
  332. static void Power_Ip_DisableSoscClock(void)
  333. {
  334. VAR (uint32, AUTOMATIC) u32SystemResetIsrConfig;
  335. /* Configurable SIRC as system clock */
  336. Call_Power_Ip_SCG_DropSysClkToSircInRunMode();
  337. /* get the current System Reset Interrupt Enable settings */
  338. u32SystemResetIsrConfig = Power_Ip_RCM_GetCurrentSystemResetIsrSettings();
  339. /* Configure all reset sources to be 'Reset' */
  340. Call_Power_Ip_RCM_SystemResetIsrConfig();
  341. /* Disable SOSC Clock */
  342. Call_Power_Ip_SCG_DisableSoscClock();
  343. /* Restore System Reset Interrupt Config */
  344. Call_Power_Ip_RCM_RestoreSystemResetIsrConfig(u32SystemResetIsrConfig);
  345. }
  346. static void Power_Ip_PrepareLowPowerMode(Power_Ip_PowerModeType ePowerMode)
  347. {
  348. if ((POWER_IP_VLPS_MODE == ePowerMode) || (POWER_IP_VLPR_MODE == ePowerMode))
  349. {
  350. /*
  351. * All clock monitors are always disabled when chip in a low power mode.
  352. * However, to prevent unexpected loss of clock reset events, we should
  353. * disable them before entering any low power modes, including VLPR and VLPS. */
  354. Call_Power_Ip_SCG_DisableClockMonitors();
  355. #ifdef MCU_ENABLE_CMU_PERIPHERAL
  356. #if(MCU_ENABLE_CMU_PERIPHERAL == STD_ON)
  357. /* Disable CMU before Disable FIRC. */
  358. /* CMU is gated by its PCC.CGC before entering STOP/VLPS/CPO mode */
  359. if(Power_Ip_PCC_GetStatus(PCC_CMU0_INDEX) & PCC_PCCn_CGC_MASK)
  360. {
  361. Power_Ip_CMU_Disable_CMU(CMU0_CHANNEL);
  362. Call_Power_Ip_PCC_DisableCMUGate(PCC_CMU0_INDEX);
  363. }
  364. if(Power_Ip_PCC_GetStatus(PCC_CMU1_INDEX) & PCC_PCCn_CGC_MASK)
  365. {
  366. Power_Ip_CMU_Disable_CMU(CMU1_CHANNEL);
  367. Call_Power_Ip_PCC_DisableCMUGate(PCC_CMU1_INDEX);
  368. }
  369. #endif
  370. #endif
  371. /* Disable FIRC in RUN mode before initiating a mode transition request to any low power mode. */
  372. Power_Ip_DisableFircClock();
  373. /* Disable SOSC in RUN mode before initiating a mode transition request to any low power mode. */
  374. Power_Ip_DisableSoscClock();
  375. #if (POWER_IP_NO_PLL == STD_OFF)
  376. /* Disable PLL in RUN mode before initiating a mode transition request to any low power mode. */
  377. Call_Power_Ip_SCG_DisableSpllClock();
  378. #endif /* (POWER_IP_NO_PLL == STD_OFF) */
  379. if (POWER_IP_VLPS_MODE == ePowerMode)
  380. {
  381. /*This enable chip go into deep sleep mode by setting bit SLEEPDEEP */
  382. Call_Power_Ip_CM4_EnableDeepSleep();
  383. }
  384. }
  385. if ((POWER_IP_STOP1_MODE == ePowerMode) || (POWER_IP_STOP2_MODE == ePowerMode))
  386. {
  387. /*This enable chip go into deep sleep mode by setting bit SLEEPDEEP */
  388. Call_Power_Ip_CM4_EnableDeepSleep();
  389. }
  390. }
  391. #endif
  392. #if (POWER_MODE_CHANGE_NOTIFICATION == STD_ON)
  393. static power_modes_t Power_Ip_ModeConvert(Power_Ip_PowerModeType ePowerMode)
  394. {
  395. power_modes_t ePowerModeChanged = RUN_MODE;
  396. switch(ePowerMode)
  397. {
  398. case (POWER_IP_RUN_MODE):
  399. ePowerModeChanged = RUN_MODE;
  400. break;
  401. case (POWER_IP_HSRUN_MODE):
  402. ePowerModeChanged = HSRUN_MODE;
  403. break;
  404. case (POWER_IP_VLPR_MODE):
  405. ePowerModeChanged = VLPR_MODE;
  406. break;
  407. case (POWER_IP_VLPS_MODE):
  408. ePowerModeChanged = VLPS_MODE;
  409. break;
  410. default:
  411. /* Do nothing */
  412. break;
  413. }
  414. return ePowerModeChanged;
  415. }
  416. #endif
  417. /*==================================================================================================
  418. GLOBAL FUNCTIONS
  419. ==================================================================================================*/
  420. /**
  421. * @brief This function initializes the mode structure.
  422. * @details This function initializes the mode structure by configuring the MC_ME module.
  423. *
  424. * @param[in] Power_Ip_pModeConfigPtr Pointer to mode configuration structure.
  425. *
  426. * @return void
  427. *
  428. * @implements Power_Ip_SetMode_Activity
  429. *
  430. */
  431. void Power_Ip_SetMode(const Power_Ip_ModeConfigType * Power_Ip_pModeConfigPtr)
  432. {
  433. uint32 ePowerSwitchMode;
  434. #if (POWER_MODE_CHANGE_NOTIFICATION == STD_ON)
  435. power_modes_t ePowerModeChanged;
  436. power_notification_t eModeChangeStatus;
  437. #endif
  438. Power_Ip_PowerModeType ePowerMode = Power_Ip_pModeConfigPtr->Power_Ip_ePowerMode;
  439. if (POWER_IP_MODE_OK != Power_Ip_SMC_ModeCheckEntry(ePowerMode))
  440. {
  441. ePowerSwitchMode = POWER_IP_SWITCH_MODE_FAIL;
  442. }
  443. else
  444. {
  445. #if (MCU_ENTER_LOW_POWER_MODE == STD_ON)
  446. Power_Ip_PrepareLowPowerMode(ePowerMode);
  447. #endif /* (MCU_ENTER_LOW_POWER_MODE == STD_ON) */
  448. /* Request new mode transition to SMC. */
  449. ePowerSwitchMode = Call_Power_Ip_SMC_ModeConfig(Power_Ip_pModeConfigPtr);
  450. #if (MCU_ENTER_LOW_POWER_MODE == STD_ON)
  451. if ((POWER_IP_VLPS_MODE == ePowerMode) ||
  452. (POWER_IP_STOP1_MODE == ePowerMode) || (POWER_IP_STOP2_MODE == ePowerMode)
  453. )
  454. {
  455. /*This will clear SLEEPDEEP bit after wake-up */
  456. Call_Power_Ip_CM4_DisableDeepSleep();
  457. }
  458. #endif
  459. }
  460. if (POWER_IP_SWITCH_MODE_FAIL == ePowerSwitchMode)
  461. {
  462. ReportPowerErrors(POWER_IP_REPORT_SWITCH_MODE_ERROR, POWER_IP_ERR_CODE_RESERVED);
  463. }
  464. else
  465. {
  466. #if (POWER_MODE_CHANGE_NOTIFICATION == STD_ON)
  467. eModeChangeStatus = POWER_MODE_CHANGED;
  468. /* Convert mode from PowerModeType to power_modes_t */
  469. ePowerModeChanged = Power_Ip_ModeConvert(ePowerMode);
  470. /* Callback Clock Ip Notification. */
  471. Clock_Ip_PowerModeChangeNotification(ePowerModeChanged,eModeChangeStatus);
  472. #endif
  473. }
  474. }
  475. #ifdef POWER_IP_POWERMODE_STATE_API
  476. #if (STD_ON == POWER_IP_POWERMODE_STATE_API)
  477. /**
  478. * @brief This function return current power mode.
  479. * @details Return value:
  480. * 0000_0001b = RUN
  481. * 0000_0100b = VLPR
  482. * 0001_0000b = VLPS
  483. * 1000_0000b = HSRUN
  484. *
  485. * @param[in] None
  486. *
  487. * @return Power_Ip_PowerModeStateType
  488. */
  489. Power_Ip_PowerModeStateType Power_Ip_GetPowerModeState(void)
  490. {
  491. Power_Ip_PowerModeStateType State ;
  492. State = Power_Ip_SMC_GetPowerModeState();
  493. return State;
  494. }
  495. #endif
  496. #endif
  497. #if (MCU_PERFORM_RESET_API == STD_ON)
  498. /**
  499. * @brief This function performs a microcontroller reset.
  500. * @details This function performs a microcontroller reset by using the hardware feature of
  501. * the microcontroller.
  502. * Called by:
  503. * - Mcu_PerformReset() from HLD.
  504. *
  505. * @param[in] Power_Ip_pHwIPsConfigPtr Pointer to LLD configuration structure (member of
  506. * 'Mcu_ConfigType' struct).
  507. *
  508. * @return void
  509. *
  510. * @implements Power_Ip_PerformReset_Activity
  511. *
  512. */
  513. void Power_Ip_PerformReset(const Power_Ip_HwIPsConfigType * Power_Ip_pHwIPsConfigPtr)
  514. {
  515. (void)(Power_Ip_pHwIPsConfigPtr);
  516. /* Performs a micro controller reset. */
  517. Call_Power_Ip_CM4_SystemReset();
  518. }
  519. #endif /* (MCU_PERFORM_RESET_API == STD_ON) */
  520. #define EMPTY_RESET_REASON ((uint32)33U)
  521. /**
  522. * @brief This function convert a number (uint32) to Power_Ip_ResetType.
  523. *
  524. * @details This function convert a number (uint32) to Power_Ip_ResetType.
  525. *
  526. * @param[in] resetReasonIndex Reset reason index.
  527. *
  528. * @return Power_Ip_ResetType
  529. */
  530. static Power_Ip_ResetType Power_Ip_ConvertIntergeToResetType(uint32 resetReasonIndex)
  531. {
  532. Power_Ip_ResetType eResetReason = MCU_NO_RESET_REASON;
  533. /* If the value of macro reset reason is not continuous, EMPTY_RESET_REASON is used to fill missing index */
  534. static const Power_Ip_ResetType resetReasonArray[(uint8)MCU_RESET_UNDEFINED + 1U] = {MCU_STOP_ACKNOWLEDGE_ERROR_RESET,MCU_MDM_AP_SYSTEM_RESET,MCU_SW_RESET,MCU_CORE_LOCKUP_RESET,MCU_JTAG_RESET,MCU_POWER_ON_RESET,MCU_EXTERNAL_PIN_RESET,MCU_WATCHDOG_RESET,MCU_CMU_LOSS_OF_CLOCK_RESET,MCU_LOSS_OF_LOCK_RESET,MCU_LOSS_OF_CLOCK_RESET,MCU_LOW_OR_HIGH_VOLTAGE_DETECT_RESET,MCU_NO_RESET_REASON,MCU_MULTIPLE_RESET_REASON,MCU_RESET_UNDEFINED};
  535. if ( (resetReasonArray[resetReasonIndex] <= MCU_RESET_UNDEFINED) && ((uint32)resetReasonArray[resetReasonIndex] != EMPTY_RESET_REASON) )
  536. {
  537. eResetReason = resetReasonArray[resetReasonIndex];
  538. }
  539. else
  540. {
  541. eResetReason = MCU_NO_RESET_REASON;
  542. }
  543. return eResetReason;
  544. }
  545. /**
  546. * @brief This function returns the reset reason.
  547. * @details This routine returns the Reset reason that is read from the hardware.
  548. *
  549. * @param[in] None
  550. *
  551. * @return void
  552. *
  553. * @implements Power_Ip_GetResetReason_Activity
  554. *
  555. */
  556. Power_Ip_ResetType Power_Ip_GetResetReason(void)
  557. {
  558. Power_Ip_ResetType eResetReason = MCU_RESET_UNDEFINED;
  559. uint32 resetVal;
  560. resetVal = Call_Power_Ip_RCM_GetResetReason();
  561. /* Use function Power_Ip_ConvertIntergeToResetType to avoid MISRA violation 10.5 : cast from uint32 to enum */
  562. eResetReason = Power_Ip_ConvertIntergeToResetType(resetVal);
  563. return (Power_Ip_ResetType) eResetReason;
  564. }
  565. /**
  566. * @brief This function returns the reset reason.
  567. * @details This routine returns the Reset reason that is read from the hardware.
  568. * Called by:
  569. * - Mcu_GetResetReason() from HLD.
  570. *
  571. * @param[in] None
  572. *
  573. * @return void
  574. *
  575. * @implements Power_Ip_GetResetRawValue_Activity
  576. *
  577. */
  578. Power_Ip_RawResetType Power_Ip_GetResetRawValue(void)
  579. {
  580. Power_Ip_RawResetType ResetReason;
  581. ResetReason = (Power_Ip_RawResetType)Call_Power_Ip_RCM_GetResetRawValue();
  582. return (Power_Ip_RawResetType) ResetReason;
  583. }
  584. #if (defined(POWER_IP_DISABLE_RCM_INIT) && (STD_OFF == POWER_IP_DISABLE_RCM_INIT))
  585. /**
  586. * @brief This function initializes the reset module.
  587. * @details
  588. *
  589. * @param[in] Power_Ip_pHwIPsConfigPtr Pointer to LLD configuration structure.
  590. *
  591. * @return void
  592. *
  593. * @implements Power_Ip_InitReset_Activity
  594. *
  595. */
  596. void Power_Ip_InitReset (const Power_Ip_HwIPsConfigType * Power_Ip_pHwIPsConfigPtr)
  597. {
  598. POWER_DEV_ASSERT(NULL_PTR != Power_Ip_pHwIPsConfigPtr);
  599. Call_Power_Ip_RCM_ResetInit(Power_Ip_pHwIPsConfigPtr->RCM_pConfig);
  600. }
  601. #endif
  602. /**
  603. * @brief This function initializes the power module.
  604. * @details
  605. *
  606. * @param[in] Power_Ip_pHwIPsConfigPtr Pointer to LLD configuration structure.
  607. *
  608. * @return void
  609. *
  610. * @implements Power_Ip_InitPower_Activity
  611. *
  612. */
  613. void Power_Ip_InitPower (const Power_Ip_HwIPsConfigType * Power_Ip_pHwIPsConfigPtr)
  614. {
  615. POWER_DEV_ASSERT(NULL_PTR != Power_Ip_pHwIPsConfigPtr);
  616. (void)(Power_Ip_pHwIPsConfigPtr);
  617. #if (defined(POWER_IP_DISABLE_PMC_INIT) && (STD_OFF == POWER_IP_DISABLE_PMC_INIT))
  618. Call_Power_Ip_PMC_PowerInit(Power_Ip_pHwIPsConfigPtr->PMC_pConfig);
  619. #endif
  620. #if (defined(POWER_IP_DISABLE_SMC_INIT) && (STD_OFF == POWER_IP_DISABLE_SMC_INIT))
  621. Call_Power_Ip_SMC_AllowedModesConfig(Power_Ip_pHwIPsConfigPtr->SMC_pConfig);
  622. #endif
  623. }
  624. #ifdef POWER_IP_SLEEPONEXIT_SUPPORT
  625. #if (POWER_IP_SLEEPONEXIT_SUPPORT == STD_ON)
  626. /**
  627. * @brief The function disable SLEEPONEXIT bit.
  628. * @details The function disable SLEEPONEXIT bit.
  629. *
  630. * @param[in] none
  631. *
  632. * @return void
  633. */
  634. void Power_Ip_DisableSleepOnExit(void)
  635. {
  636. Call_Power_Ip_CM4_DisableSleepOnExit();
  637. }
  638. /**
  639. * @brief The function enable SLEEPONEXIT bit.
  640. * @details The function enable SLEEPONEXIT bit.
  641. *
  642. * @param[in] none
  643. *
  644. * @return void
  645. */
  646. void Power_Ip_EnableSleepOnExit(void)
  647. {
  648. Call_Power_Ip_CM4_EnableSleepOnExit();
  649. }
  650. #endif
  651. #endif
  652. #ifdef POWER_IP_SRAM_RETEN_CONFIG_API
  653. #if (POWER_IP_SRAM_RETEN_CONFIG_API == STD_ON)
  654. /**
  655. * @brief Configuration for SRAM retention.
  656. * @details This function configure for both SRAML_RETEN and SRAMU_RETEN bits.
  657. * Called by:
  658. * - Mcu_Ipw_SRAMRetentionConfig() from IPW
  659. * @param[in] eSRAMRetenConfig The value will be configured to SRAML_RETEN and SRAMU_RETEN bits.
  660. * MCU_SRAML_RETEN - SRAML will be retain only.
  661. * MCU_SRAMU_RETEN - SRAMU will be retain only.
  662. * MCU_SRAMLU_RETEN - Both SRAML and SRAMU will be retain.
  663. * MCU_NO_SRAMLU_RETEN - Both SRAML and SRAMU will not be retain.
  664. *
  665. * @return void
  666. *
  667. */
  668. void Power_Ip_SRAMRetentionConfig(Power_Ip_SRAMRetenConfigType eSRAMRetenConfig)
  669. {
  670. Call_Power_Ip_SIM_SRAMRetentionConfig(eSRAMRetenConfig);
  671. }
  672. #endif
  673. #endif
  674. /**
  675. * @brief This function installs a callback for reporting errors from power driver.
  676. * @details
  677. *
  678. * @param[in] reportErrorsCallback Callback to be installed.
  679. *
  680. * @return void
  681. *
  682. * @implements Power_Ip_InstallNotificationsCallback_Activity
  683. */
  684. void Power_Ip_InstallNotificationsCallback(Power_Ip_ReportErrorsCallbackType reportErrorsCallback)
  685. {
  686. POWER_DEV_ASSERT(NULL_PTR != reportErrorsCallback);
  687. powerReportErrorsCallback = reportErrorsCallback;
  688. }
  689. #define MCU_STOP_SEC_CODE
  690. #include "Mcu_MemMap.h"
  691. #ifdef __cplusplus
  692. }
  693. #endif
  694. /** @} */