Power_Ip_SCG.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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_SCG.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_SCG.h"
  46. #include "Power_Ip_Private.h"
  47. #if (defined(POWER_IP_ENABLE_USER_MODE_SUPPORT) && (STD_ON == POWER_IP_ENABLE_USER_MODE_SUPPORT))
  48. #if (defined(MCAL_SMC_REG_PROT_AVAILABLE))
  49. #if (STD_ON == MCAL_SMC_REG_PROT_AVAILABLE)
  50. #define USER_MODE_REG_PROT_ENABLED (STD_ON)
  51. #include "RegLockMacros.h"
  52. #endif /* (STD_ON == MCAL_PMC_REG_PROT_AVAILABLE) */
  53. #endif
  54. #endif /* (STD_ON == POWER_IP_ENABLE_USER_MODE_SUPPORT) */
  55. /*==================================================================================================
  56. SOURCE FILE VERSION INFORMATION
  57. ==================================================================================================*/
  58. #define POWER_IP_SCG_VENDOR_ID_C 43
  59. #define POWER_IP_SCG_AR_RELEASE_MAJOR_VERSION_C 4
  60. #define POWER_IP_SCG_AR_RELEASE_MINOR_VERSION_C 4
  61. #define POWER_IP_SCG_AR_RELEASE_REVISION_VERSION_C 0
  62. #define POWER_IP_SCG_SW_MAJOR_VERSION_C 1
  63. #define POWER_IP_SCG_SW_MINOR_VERSION_C 0
  64. #define POWER_IP_SCG_SW_PATCH_VERSION_C 0
  65. /*==================================================================================================
  66. * FILE VERSION CHECKS
  67. ==================================================================================================*/
  68. /* Check if Power_Ip_SCG.c file and Power_Ip.h file are of the same vendor */
  69. #if (POWER_IP_SCG_VENDOR_ID_C != POWER_IP_VENDOR_ID)
  70. #error "Power_Ip_SCG.c and Power_Ip.h have different vendor ids"
  71. #endif
  72. /* Check if Power_Ip_SCG.c file and Power_Ip.h file are of the same Autosar version */
  73. #if ((POWER_IP_SCG_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_AR_RELEASE_MAJOR_VERSION) || \
  74. (POWER_IP_SCG_AR_RELEASE_MINOR_VERSION_C != POWER_IP_AR_RELEASE_MINOR_VERSION) || \
  75. (POWER_IP_SCG_AR_RELEASE_REVISION_VERSION_C != POWER_IP_AR_RELEASE_REVISION_VERSION) \
  76. )
  77. #error "AutoSar Version Numbers of Power_Ip_SCG.c and Power_Ip.h are different"
  78. #endif
  79. /* Check if Power_Ip_SCG.c file and Power_Ip.h file are of the same Software version */
  80. #if ((POWER_IP_SCG_SW_MAJOR_VERSION_C != POWER_IP_SW_MAJOR_VERSION) || \
  81. (POWER_IP_SCG_SW_MINOR_VERSION_C != POWER_IP_SW_MINOR_VERSION) || \
  82. (POWER_IP_SCG_SW_PATCH_VERSION_C != POWER_IP_SW_PATCH_VERSION) \
  83. )
  84. #error "Software Version Numbers of Power_Ip_SCG.c and Power_Ip.h are different"
  85. #endif
  86. /* Check if Power_Ip_SCG.c file and Power_Ip_SCG.h file are of the same vendor */
  87. #if (POWER_IP_SCG_VENDOR_ID_C != POWER_IP_SCG_VENDOR_ID)
  88. #error "Power_Ip_SCG.c and Power_Ip_SCG.h have different vendor ids"
  89. #endif
  90. /* Check if Power_Ip_SCG.c file and Power_Ip_SCG.h file are of the same Autosar version */
  91. #if ((POWER_IP_SCG_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_SCG_AR_RELEASE_MAJOR_VERSION) || \
  92. (POWER_IP_SCG_AR_RELEASE_MINOR_VERSION_C != POWER_IP_SCG_AR_RELEASE_MINOR_VERSION) || \
  93. (POWER_IP_SCG_AR_RELEASE_REVISION_VERSION_C != POWER_IP_SCG_AR_RELEASE_REVISION_VERSION) \
  94. )
  95. #error "AutoSar Version Numbers of Power_Ip_SCG.c and Power_Ip_SCG.h are different"
  96. #endif
  97. /* Check if Power_Ip_SCG.c file and Power_Ip_SCG.h file are of the same Software version */
  98. #if ((POWER_IP_SCG_SW_MAJOR_VERSION_C != POWER_IP_SCG_SW_MAJOR_VERSION) || \
  99. (POWER_IP_SCG_SW_MINOR_VERSION_C != POWER_IP_SCG_SW_MINOR_VERSION) || \
  100. (POWER_IP_SCG_SW_PATCH_VERSION_C != POWER_IP_SCG_SW_PATCH_VERSION) \
  101. )
  102. #error "Software Version Numbers of Power_Ip_SCG.c and Power_Ip_SCG.h are different"
  103. #endif
  104. /* Check if Power_Ip_SCG.c file and Power_Ip_Private.h file are of the same vendor */
  105. #if (POWER_IP_SCG_VENDOR_ID_C != POWER_IP_PRIVATE_VENDOR_ID)
  106. #error "Power_Ip_SCG.c and Power_Ip_Private.h have different vendor ids"
  107. #endif
  108. /* Check if Power_Ip_SCG.c file and Power_Ip_Private.h file are of the same Autosar version */
  109. #if ((POWER_IP_SCG_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_PRIVATE_AR_RELEASE_MAJOR_VERSION) || \
  110. (POWER_IP_SCG_AR_RELEASE_MINOR_VERSION_C != POWER_IP_PRIVATE_AR_RELEASE_MINOR_VERSION) || \
  111. (POWER_IP_SCG_AR_RELEASE_REVISION_VERSION_C != POWER_IP_PRIVATE_AR_RELEASE_REVISION_VERSION) \
  112. )
  113. #error "AutoSar Version Numbers of Power_Ip_SCG.c and Power_Ip_Private.h are different"
  114. #endif
  115. /* Check if Power_Ip_SCG.c file and Power_Ip_Private.h file are of the same Software version */
  116. #if ((POWER_IP_SCG_SW_MAJOR_VERSION_C != POWER_IP_PRIVATE_SW_MAJOR_VERSION) || \
  117. (POWER_IP_SCG_SW_MINOR_VERSION_C != POWER_IP_PRIVATE_SW_MINOR_VERSION) || \
  118. (POWER_IP_SCG_SW_PATCH_VERSION_C != POWER_IP_PRIVATE_SW_PATCH_VERSION) \
  119. )
  120. #error "Software Version Numbers of Power_Ip_SCG.c and Power_Ip_Private.h are different"
  121. #endif
  122. /*==================================================================================================
  123. LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
  124. ==================================================================================================*/
  125. /*==================================================================================================
  126. LOCAL CONSTANTS
  127. ==================================================================================================*/
  128. /*==================================================================================================
  129. LOCAL VARIABLES
  130. ==================================================================================================*/
  131. /*==================================================================================================
  132. GLOBAL CONSTANTS
  133. ==================================================================================================*/
  134. /*==================================================================================================
  135. GLOBAL VARIABLES
  136. ==================================================================================================*/
  137. /*==================================================================================================
  138. LOCAL FUNCTION PROTOTYPES
  139. ==================================================================================================*/
  140. #define MCU_START_SEC_CODE
  141. #include "Mcu_MemMap.h"
  142. /**
  143. * @brief This function will disable all clock monitors
  144. */
  145. void Power_Ip_SCG_DisableClockMonitors(void)
  146. {
  147. IP_SCG->SOSCCSR &= (~(SCG_SOSCCSR_SOSCCM_MASK));
  148. #if (POWER_IP_NO_PLL == STD_OFF)
  149. IP_SCG->SPLLCSR &= (~(SCG_SPLLCSR_SPLLCM_MASK));
  150. #endif /* POWER_IP_NO_PLL */
  151. }
  152. #if (POWER_IP_NO_PLL == STD_OFF)
  153. /**
  154. * @brief This function will disable PLL clock
  155. */
  156. void Power_Ip_SCG_DisableSpllClock(void)
  157. {
  158. IP_SCG->SPLLCSR &= (~(SCG_SPLLCSR_SPLLEN_MASK));
  159. }
  160. #endif /* POWER_IP_NO_PLL */
  161. #if (MCU_ENTER_LOW_POWER_MODE == STD_ON)
  162. /**
  163. * @brief This function will configurable SIRC as system clock.
  164. */
  165. void Power_Ip_SCG_DropSysClkToSircInRunMode(void)
  166. {
  167. uint32 u32RegValue = 0U;
  168. uint32 u32TmpValue = 0U;
  169. uint32 StartTime;
  170. uint32 ElapsedTime;
  171. uint32 TimeoutTicks;
  172. boolean TimeoutOccurred = FALSE;
  173. /* Set SIRC as system clock in Run mode */
  174. u32TmpValue = IP_SCG->RCCR;
  175. u32TmpValue &= (uint32)(~SCG_RCCR_SCS_MASK);
  176. u32TmpValue |= (uint32)(SCG_RCCR_SCS(SCG_SCS_SIRC_U32));
  177. IP_SCG->RCCR = u32TmpValue;
  178. /* Wait for switching system clock source done. */
  179. #ifdef ERR_IPV_SCG_ERR010777
  180. #if (ERR_IPV_SCG_ERR010777 == STD_ON)
  181. /* Support for e10777 errata: SCG_RCCR[SCS] and SCG_HCCR[SCS] should be read twice by software to get correctly value */
  182. u32RegValue = ((IP_SCG->RCCR & SCG_RCCR_SCS_MASK) >> SCG_RCCR_SCS_SHIFT);
  183. #endif
  184. #endif
  185. PowerStartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, POWER_TIMEOUT_VALUE_US);
  186. do
  187. {
  188. TimeoutOccurred = PowerTimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
  189. u32RegValue = ((IP_SCG->RCCR & SCG_RCCR_SCS_MASK) >> SCG_RCCR_SCS_SHIFT);
  190. }
  191. while ((SCG_SCS_SIRC_U32 != u32RegValue) && (!TimeoutOccurred));
  192. /* Raise an error report if the timeout is expired */
  193. if(TimeoutOccurred)
  194. {
  195. ReportPowerErrors(POWER_IP_REPORT_TIMEOUT_ERROR, POWER_IP_ERR_CODE_RESERVED);
  196. }
  197. }
  198. /**
  199. * @brief This function will disable FIRC clock.
  200. */
  201. void Power_Ip_SCG_DisableFircClock(void)
  202. {
  203. /* Disable FIRC clock */
  204. IP_SCG->FIRCCSR &= (~(SCG_FIRCCSR_FIRCEN_MASK));
  205. }
  206. /**
  207. * @brief This function will disable SOSC clock.
  208. */
  209. void Power_Ip_SCG_DisableSoscClock(void)
  210. {
  211. /* Disable SOSC clock */
  212. IP_SCG->SOSCCSR &= (~(SCG_SOSCCSR_SOSCEN_MASK));
  213. }
  214. #endif
  215. #define MCU_STOP_SEC_CODE
  216. #include "Mcu_MemMap.h"
  217. #ifdef __cplusplus
  218. }
  219. #endif
  220. /** @} */