Power_Ip_PMC.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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_PMC.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_PMC.h"
  45. #include "Power_Ip_Private.h"
  46. #if (defined(POWER_IP_ENABLE_USER_MODE_SUPPORT) && (STD_ON == POWER_IP_ENABLE_USER_MODE_SUPPORT))
  47. #if (defined(MCAL_PMC_REG_PROT_AVAILABLE))
  48. #if (STD_ON == MCAL_PMC_REG_PROT_AVAILABLE)
  49. #define USER_MODE_REG_PROT_ENABLED (STD_ON)
  50. #include "RegLockMacros.h"
  51. #endif /* (STD_ON == MCAL_PMC_REG_PROT_AVAILABLE) */
  52. #endif
  53. #endif /* (STD_ON == POWER_IP_ENABLE_USER_MODE_SUPPORT) */
  54. /*==================================================================================================
  55. SOURCE FILE VERSION INFORMATION
  56. ==================================================================================================*/
  57. #define POWER_IP_PMC_VENDOR_ID_C 43
  58. #define POWER_IP_PMC_AR_RELEASE_MAJOR_VERSION_C 4
  59. #define POWER_IP_PMC_AR_RELEASE_MINOR_VERSION_C 4
  60. #define POWER_IP_PMC_AR_RELEASE_REVISION_VERSION_C 0
  61. #define POWER_IP_PMC_SW_MAJOR_VERSION_C 1
  62. #define POWER_IP_PMC_SW_MINOR_VERSION_C 0
  63. #define POWER_IP_PMC_SW_PATCH_VERSION_C 0
  64. /*==================================================================================================
  65. * FILE VERSION CHECKS
  66. ==================================================================================================*/
  67. /* Check if Power_Ip_PMC.c file and Power_Ip_PMC.h file are of the same vendor */
  68. #if (POWER_IP_PMC_VENDOR_ID_C != POWER_IP_PMC_VENDOR_ID)
  69. #error "Power_Ip_PMC.c and Power_Ip_PMC.h have different vendor ids"
  70. #endif
  71. /* Check if Power_Ip_PMC.c file and Power_Ip_PMC.h file are of the same Autosar version */
  72. #if ((POWER_IP_PMC_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_PMC_AR_RELEASE_MAJOR_VERSION) || \
  73. (POWER_IP_PMC_AR_RELEASE_MINOR_VERSION_C != POWER_IP_PMC_AR_RELEASE_MINOR_VERSION) || \
  74. (POWER_IP_PMC_AR_RELEASE_REVISION_VERSION_C != POWER_IP_PMC_AR_RELEASE_REVISION_VERSION) \
  75. )
  76. #error "AutoSar Version Numbers of Power_Ip_PMC.c and Power_Ip_PMC.h are different"
  77. #endif
  78. /* Check if Power_Ip_PMC.c file and Power_Ip_PMC.h file are of the same Software version */
  79. #if ((POWER_IP_PMC_SW_MAJOR_VERSION_C != POWER_IP_PMC_SW_MAJOR_VERSION) || \
  80. (POWER_IP_PMC_SW_MINOR_VERSION_C != POWER_IP_PMC_SW_MINOR_VERSION) || \
  81. (POWER_IP_PMC_SW_PATCH_VERSION_C != POWER_IP_PMC_SW_PATCH_VERSION) \
  82. )
  83. #error "Software Version Numbers of Power_Ip_PMC.c and Power_Ip_PMC.h are different"
  84. #endif
  85. /* Check if Power_Ip_PMC.c file and Power_Ip_Private.h file are of the same vendor */
  86. #if (POWER_IP_PMC_VENDOR_ID_C != POWER_IP_PRIVATE_VENDOR_ID)
  87. #error "Power_Ip_PMC.c and Power_Ip_Private.h have different vendor ids"
  88. #endif
  89. /* Check if Power_Ip_PMC.c file and Power_Ip_Private.h file are of the same Autosar version */
  90. #if ((POWER_IP_PMC_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_PRIVATE_AR_RELEASE_MAJOR_VERSION) || \
  91. (POWER_IP_PMC_AR_RELEASE_MINOR_VERSION_C != POWER_IP_PRIVATE_AR_RELEASE_MINOR_VERSION) || \
  92. (POWER_IP_PMC_AR_RELEASE_REVISION_VERSION_C != POWER_IP_PRIVATE_AR_RELEASE_REVISION_VERSION) \
  93. )
  94. #error "AutoSar Version Numbers of Power_Ip_PMC.c and Power_Ip_Private.h are different"
  95. #endif
  96. /* Check if Power_Ip_PMC.c file and Power_Ip_Private.h file are of the same Software version */
  97. #if ((POWER_IP_PMC_SW_MAJOR_VERSION_C != POWER_IP_PRIVATE_SW_MAJOR_VERSION) || \
  98. (POWER_IP_PMC_SW_MINOR_VERSION_C != POWER_IP_PRIVATE_SW_MINOR_VERSION) || \
  99. (POWER_IP_PMC_SW_PATCH_VERSION_C != POWER_IP_PRIVATE_SW_PATCH_VERSION) \
  100. )
  101. #error "Software Version Numbers of Power_Ip_PMC.c and Power_Ip_Private.h are different"
  102. #endif
  103. #if (defined(POWER_IP_ENABLE_USER_MODE_SUPPORT) && (STD_ON == POWER_IP_ENABLE_USER_MODE_SUPPORT))
  104. #if (defined(MCAL_PMC_REG_PROT_AVAILABLE))
  105. #if (STD_ON == MCAL_PMC_REG_PROT_AVAILABLE)
  106. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  107. /* Check if Power_Ip_PMC.c file and RegLockMacros.h file are of the same Autosar version */
  108. #if ((POWER_IP_PMC_AR_RELEASE_MAJOR_VERSION_C != REGLOCKMACROS_AR_RELEASE_MAJOR_VERSION) || \
  109. (POWER_IP_PMC_AR_RELEASE_MINOR_VERSION_C != REGLOCKMACROS_AR_RELEASE_MINOR_VERSION))
  110. #error "AutoSar Version Numbers of Power_Ip_PMC.c and RegLockMacros.h are different"
  111. #endif
  112. #endif
  113. #endif /* (STD_ON == MCAL_PMC_REG_PROT_AVAILABLE) */
  114. #endif
  115. #endif /* (STD_ON == POWER_IP_ENABLE_USER_MODE_SUPPORT) */
  116. /*==================================================================================================
  117. LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
  118. ==================================================================================================*/
  119. /*==================================================================================================
  120. LOCAL MACROS
  121. ==================================================================================================*/
  122. /*==================================================================================================
  123. LOCAL CONSTANTS
  124. ==================================================================================================*/
  125. /*==================================================================================================
  126. LOCAL VARIABLES
  127. ==================================================================================================*/
  128. /*==================================================================================================
  129. GLOBAL CONSTANTS
  130. ==================================================================================================*/
  131. /*==================================================================================================
  132. GLOBAL VARIABLES
  133. ==================================================================================================*/
  134. #if (defined(POWER_IP_VOLTAGE_ERROR_ISR_USED))
  135. #if (POWER_IP_VOLTAGE_ERROR_ISR_USED == STD_ON)
  136. #define MCU_START_SEC_VAR_INIT_UNSPECIFIED
  137. #include "Mcu_MemMap.h"
  138. static volatile PMC_StatusType PMC_Status = PMC_UNINIT;
  139. #define MCU_STOP_SEC_VAR_INIT_UNSPECIFIED
  140. #include "Mcu_MemMap.h"
  141. #endif
  142. #endif
  143. /*==================================================================================================
  144. LOCAL FUNCTION PROTOTYPES
  145. ==================================================================================================*/
  146. /*==================================================================================================
  147. LOCAL FUNCTIONS
  148. ==================================================================================================*/
  149. #define MCU_START_SEC_CODE
  150. #include "Mcu_MemMap.h"
  151. /*==================================================================================================
  152. GLOBAL FUNCTIONS
  153. ==================================================================================================*/
  154. #if (defined(POWER_IP_DISABLE_PMC_INIT) && (STD_OFF == POWER_IP_DISABLE_PMC_INIT))
  155. /**
  156. * @brief This function configure the Power Management Controller
  157. * @details The operating voltages are monitored by a set of on-chip supervisory circuits
  158. * to ensure that this device works within the correct voltage range.
  159. *
  160. * @param[in] pConfigPtr Pointer to PMC configuration structure.
  161. *
  162. * @return void
  163. *
  164. */
  165. void Power_Ip_PMC_PowerInit(const Power_Ip_PMC_ConfigType * pConfigPtr)
  166. {
  167. uint8 u8Tmp;
  168. #if(STD_ON == POWER_IP_PMC_LVDSC1_SUPPORT)
  169. u8Tmp = (uint8)IP_PMC->LVDSC1;
  170. u8Tmp = (uint8)(u8Tmp & (uint8)(~PMC_LVDSC1_RWBITS_MASK8));
  171. u8Tmp = (uint8)(u8Tmp | (uint8)(pConfigPtr->u8Lvdsc1));
  172. IP_PMC->LVDSC1 = u8Tmp;
  173. #endif
  174. u8Tmp = (uint8)IP_PMC->LVDSC2;
  175. u8Tmp = (uint8)(u8Tmp & (uint8)(~PMC_LVDSC2_RWBITS_MASK8));
  176. u8Tmp = (uint8)(u8Tmp | (uint8)(pConfigPtr->u8Lvdsc2));
  177. IP_PMC->LVDSC2 = u8Tmp;
  178. u8Tmp = (uint8)IP_PMC->REGSC;
  179. u8Tmp = (uint8)(u8Tmp & (uint8)(~PMC_REGSC_RWBITS_MASK8));
  180. u8Tmp = (uint8)(u8Tmp | (uint8)(pConfigPtr->u8Regsc));
  181. IP_PMC->REGSC = u8Tmp;
  182. #if (defined(POWER_IP_VOLTAGE_ERROR_ISR_USED))
  183. #if (POWER_IP_VOLTAGE_ERROR_ISR_USED == STD_ON)
  184. /* make Status of PMC to initialized to check in the interrupt function */
  185. PMC_Status = PMC_INIT;
  186. #endif
  187. #endif
  188. }
  189. #endif
  190. #if (POWER_IP_VOLTAGE_ERROR_ISR_USED == STD_ON)
  191. /**
  192. * @brief This function get status voltage error
  193. *
  194. * @return uint8
  195. *
  196. */
  197. uint8 Power_Ip_PMC_GetInterruptStatus(void)
  198. {
  199. uint8 u8VoltageStatus = 0U;
  200. #if(STD_ON == POWER_IP_PMC_LVDSC1_SUPPORT)
  201. /* Read Low Voltage Detect Flag */
  202. u8VoltageStatus = ((IP_PMC->LVDSC1) & PMC_LVDSC1_LVDF_MASK);
  203. #endif
  204. /* Read Low Voltage Warning Flag */
  205. u8VoltageStatus |= ((IP_PMC->LVDSC2) & PMC_LVDSC2_LVWF_MASK);
  206. return u8VoltageStatus;
  207. }
  208. /**
  209. * @brief This function handle the voltage error detection.
  210. *
  211. * @return void
  212. *
  213. * @isr
  214. * @implements Power_Ip_PMC_VoltageErrorIsr_Activity
  215. */
  216. void Power_Ip_PMC_VoltageErrorIsr(void)
  217. {
  218. #if(STD_ON == POWER_IP_PMC_LVDSC1_SUPPORT)
  219. uint8 u8VoltageDetectStatus;
  220. uint8 u8VoltageDetectEnable;
  221. #endif
  222. uint8 u8VoltageWarningStatus;
  223. uint8 u8VoltageWarningEnable;
  224. #if(STD_ON == POWER_IP_PMC_LVDSC1_SUPPORT)
  225. /* Read Low Voltage Detect Flag */
  226. u8VoltageDetectStatus = ((IP_PMC->LVDSC1) & PMC_LVDSC1_LVDF_MASK);
  227. /* clear IRQ flags */
  228. IP_PMC->LVDSC1 |= (u8VoltageDetectStatus & PMC_LVDSC1_LVDF_MASK);
  229. #endif
  230. /* Read Low Voltage Warning Flag */
  231. u8VoltageWarningStatus = ((IP_PMC->LVDSC2) & PMC_LVDSC2_LVWF_MASK);
  232. /* clear IRQ flags */
  233. IP_PMC->LVDSC2 |= (u8VoltageWarningStatus & PMC_LVDSC2_LVWF_MASK);
  234. if(PMC_UNINIT != PMC_Status)
  235. {
  236. #if(STD_ON == POWER_IP_PMC_LVDSC1_SUPPORT)
  237. /* Read Low Voltage Detect Reset Enable */
  238. u8VoltageDetectEnable = ((IP_PMC->LVDSC1) & PMC_LVDSC1_LVDIE_MASK);
  239. #endif
  240. /* Read Low-Voltage Warning Interrupt Enable */
  241. u8VoltageWarningEnable = ((IP_PMC->LVDSC2) & PMC_LVDSC2_LVWIE_MASK);
  242. /* check if there is an event to report */
  243. #if(STD_ON == POWER_IP_PMC_LVDSC1_SUPPORT)
  244. if((((uint8)0x00U != u8VoltageDetectStatus) && ((uint8)0x00U != u8VoltageDetectEnable)) ||
  245. (((uint8)0x00U != u8VoltageWarningStatus) && ((uint8)0x00U != u8VoltageWarningEnable)))
  246. #else
  247. if(((uint8)0x00U != u8VoltageWarningStatus) && ((uint8)0x00U != u8VoltageWarningEnable))
  248. #endif
  249. {
  250. ReportPowerErrors(POWER_IP_ERROR_ISR_NOTIFICATION, POWER_E_ISR_VOLTAGE_ERROR);
  251. }
  252. }
  253. }
  254. #endif
  255. #define MCU_STOP_SEC_CODE
  256. #include "Mcu_MemMap.h"
  257. #ifdef __cplusplus
  258. }
  259. #endif
  260. /** @} */