1 /*
2 * Copyright 2020-2023 NXP
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6 /**
7 * @file Power_Ip_PMC.c
8 * @version 3.0.0
9 *
10 * @brief
11 * @brief POWER driver implementations.
12 * @details POWER driver implementations.
13 *
14 * @addtogroup POWER_DRIVER Power Ip Driver
15 * @{
16 */
17
18
19 #ifdef __cplusplus
20 extern "C"{
21 #endif
22
23
24
25
26
27 /*==================================================================================================
28 INCLUDE FILES
29 1) system and project includes
30 2) needed interfaces from external units
31 3) internal and external interfaces from this unit
32 ==================================================================================================*/
33 #include "Power_Ip_Private.h"
34 #include "Power_Ip_PMC.h"
35
36 #if (defined(POWER_IP_PMCAECONFIG_API) && (STD_ON == POWER_IP_PMCAECONFIG_API))
37 #include "Aec_Ip.h"
38 #endif
39
40 #if (defined(POWER_IP_ENABLE_USER_MODE_SUPPORT) && (STD_ON == POWER_IP_ENABLE_USER_MODE_SUPPORT))
41 #if (defined(MCAL_PMC_REG_PROT_AVAILABLE))
42 #if (STD_ON == MCAL_PMC_REG_PROT_AVAILABLE)
43 #define USER_MODE_REG_PROT_ENABLED (STD_ON)
44 #include "RegLockMacros.h"
45 #endif /* (STD_ON == MCAL_PMC_REG_PROT_AVAILABLE) */
46 #endif
47 #endif /* (STD_ON == POWER_IP_ENABLE_USER_MODE_SUPPORT) */
48
49
50 /*==================================================================================================
51 SOURCE FILE VERSION INFORMATION
52 ==================================================================================================*/
53 #define POWER_IP_PMC_VENDOR_ID_C 43
54 #define POWER_IP_PMC_AR_RELEASE_MAJOR_VERSION_C 4
55 #define POWER_IP_PMC_AR_RELEASE_MINOR_VERSION_C 7
56 #define POWER_IP_PMC_AR_RELEASE_REVISION_VERSION_C 0
57 #define POWER_IP_PMC_SW_MAJOR_VERSION_C 3
58 #define POWER_IP_PMC_SW_MINOR_VERSION_C 0
59 #define POWER_IP_PMC_SW_PATCH_VERSION_C 0
60
61 /*==================================================================================================
62 * FILE VERSION CHECKS
63 ==================================================================================================*/
64 #if (defined(POWER_IP_PMCAECONFIG_API) && (STD_ON == POWER_IP_PMCAECONFIG_API))
65 /* Check if Power_Ip_PMC.c file and Aec_Ip.h file are of the same vendor */
66 #if (POWER_IP_PMC_VENDOR_ID_C != AEC_IP_VENDOR_ID)
67 #error "Power_Ip_PMC.c and Aec_Ip.h have different vendor ids"
68 #endif
69
70 /* Check if Power_Ip_PMC.c file and Aec_Ip.h file are of the same Autosar version */
71 #if ((POWER_IP_PMC_AR_RELEASE_MAJOR_VERSION_C != AEC_IP_AR_RELEASE_MAJOR_VERSION) || \
72 (POWER_IP_PMC_AR_RELEASE_MINOR_VERSION_C != AEC_IP_AR_RELEASE_MINOR_VERSION) || \
73 (POWER_IP_PMC_AR_RELEASE_REVISION_VERSION_C != AEC_IP_AR_RELEASE_REVISION_VERSION) \
74 )
75 #error "AutoSar Version Numbers of Power_Ip_PMC.c and Aec_Ip.h are different"
76 #endif
77
78 /* Check if Power_Ip_PMC.c file and Aec_Ip.h file are of the same Software version */
79 #if ((POWER_IP_PMC_SW_MAJOR_VERSION_C != AEC_IP_SW_MAJOR_VERSION) || \
80 (POWER_IP_PMC_SW_MINOR_VERSION_C != AEC_IP_SW_MINOR_VERSION) || \
81 (POWER_IP_PMC_SW_PATCH_VERSION_C != AEC_IP_SW_PATCH_VERSION) \
82 )
83 #error "Software Version Numbers of Power_Ip_PMC.c and Aec_Ip.h are different"
84 #endif
85 #endif
86
87 /* Check if Power_Ip_PMC.c file and Power_Ip_Private.h file are of the same vendor */
88 #if (POWER_IP_PMC_VENDOR_ID_C != POWER_IP_PRIVATE_VENDOR_ID)
89 #error "Power_Ip_PMC.c and Power_Ip_Private.h have different vendor ids"
90 #endif
91
92 /* Check if Power_Ip_PMC.c file and Power_Ip_Private.h file are of the same Autosar version */
93 #if ((POWER_IP_PMC_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_PRIVATE_AR_RELEASE_MAJOR_VERSION) || \
94 (POWER_IP_PMC_AR_RELEASE_MINOR_VERSION_C != POWER_IP_PRIVATE_AR_RELEASE_MINOR_VERSION) || \
95 (POWER_IP_PMC_AR_RELEASE_REVISION_VERSION_C != POWER_IP_PRIVATE_AR_RELEASE_REVISION_VERSION) \
96 )
97 #error "AutoSar Version Numbers of Power_Ip_PMC.c and Power_Ip_Private.h are different"
98 #endif
99
100 /* Check if Power_Ip_PMC.c file and Power_Ip_Private.h file are of the same Software version */
101 #if ((POWER_IP_PMC_SW_MAJOR_VERSION_C != POWER_IP_PRIVATE_SW_MAJOR_VERSION) || \
102 (POWER_IP_PMC_SW_MINOR_VERSION_C != POWER_IP_PRIVATE_SW_MINOR_VERSION) || \
103 (POWER_IP_PMC_SW_PATCH_VERSION_C != POWER_IP_PRIVATE_SW_PATCH_VERSION) \
104 )
105 #error "Software Version Numbers of Power_Ip_PMC.c and Power_Ip_Private.h are different"
106 #endif
107
108 /* Check if Power_Ip_PMC.c file and Power_Ip_PMC.h file are of the same vendor */
109 #if (POWER_IP_PMC_VENDOR_ID_C != POWER_IP_PMC_VENDOR_ID)
110 #error "Power_Ip_PMC.c and Power_Ip_PMC.h have different vendor ids"
111 #endif
112
113 /* Check if Power_Ip_PMC.c file and Power_Ip_PMC.h file are of the same Autosar version */
114 #if ((POWER_IP_PMC_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_PMC_AR_RELEASE_MAJOR_VERSION) || \
115 (POWER_IP_PMC_AR_RELEASE_MINOR_VERSION_C != POWER_IP_PMC_AR_RELEASE_MINOR_VERSION) || \
116 (POWER_IP_PMC_AR_RELEASE_REVISION_VERSION_C != POWER_IP_PMC_AR_RELEASE_REVISION_VERSION) \
117 )
118 #error "AutoSar Version Numbers of Power_Ip_PMC.c and Power_Ip_PMC.h are different"
119 #endif
120
121 /* Check if Power_Ip_PMC.c file and Power_Ip_PMC.h file are of the same Software version */
122 #if ((POWER_IP_PMC_SW_MAJOR_VERSION_C != POWER_IP_PMC_SW_MAJOR_VERSION) || \
123 (POWER_IP_PMC_SW_MINOR_VERSION_C != POWER_IP_PMC_SW_MINOR_VERSION) || \
124 (POWER_IP_PMC_SW_PATCH_VERSION_C != POWER_IP_PMC_SW_PATCH_VERSION) \
125 )
126 #error "Software Version Numbers of Power_Ip_PMC.c and Power_Ip_PMC.h are different"
127 #endif
128
129 #if (defined(POWER_IP_ENABLE_USER_MODE_SUPPORT) && (STD_ON == POWER_IP_ENABLE_USER_MODE_SUPPORT))
130 #if (defined(MCAL_PMC_REG_PROT_AVAILABLE))
131 #if (STD_ON == MCAL_PMC_REG_PROT_AVAILABLE)
132 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
133 /* Check if Power_Ip_PMC.c file and RegLockMacros.h file are of the same Autosar version */
134 #if ((POWER_IP_PMC_AR_RELEASE_MAJOR_VERSION_C != REGLOCKMACROS_AR_RELEASE_MAJOR_VERSION) || \
135 (POWER_IP_PMC_AR_RELEASE_MINOR_VERSION_C != REGLOCKMACROS_AR_RELEASE_MINOR_VERSION))
136 #error "AutoSar Version Numbers of Power_Ip_PMC.c and RegLockMacros.h are different"
137 #endif
138 #endif
139 #endif /* (STD_ON == MCAL_PMC_REG_PROT_AVAILABLE) */
140 #endif
141 #endif /* (STD_ON == POWER_IP_ENABLE_USER_MODE_SUPPORT) */
142 /*==================================================================================================
143 LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
144 ==================================================================================================*/
145
146
147 /*==================================================================================================
148 LOCAL MACROS
149 ==================================================================================================*/
150
151
152 /*==================================================================================================
153 LOCAL CONSTANTS
154 ==================================================================================================*/
155
156
157 /*==================================================================================================
158 LOCAL VARIABLES
159 ==================================================================================================*/
160
161
162 /*==================================================================================================
163 GLOBAL CONSTANTS
164 ==================================================================================================*/
165
166
167 /*==================================================================================================
168 GLOBAL VARIABLES
169 ==================================================================================================*/
170 #if (defined(POWER_IP_VOLTAGE_ERROR_ISR_USED))
171 #if (POWER_IP_VOLTAGE_ERROR_ISR_USED == STD_ON)
172
173 #define MCU_START_SEC_VAR_INIT_UNSPECIFIED
174 #include "Mcu_MemMap.h"
175
176 static volatile Power_Ip_PMC_StatusType Power_Ip_ePMCStatus = PMC_UNINIT;
177
178 #if (defined(POWER_IP_PMCAECONFIG_API) && (STD_ON == POWER_IP_PMCAECONFIG_API))
179 static volatile Power_Ip_PMC_StatusType Power_Ip_ePMCAeStatus = PMC_UNINIT;
180 #endif
181
182 #define MCU_STOP_SEC_VAR_INIT_UNSPECIFIED
183 #include "Mcu_MemMap.h"
184
185 #endif
186 #endif
187 /*==================================================================================================
188 LOCAL FUNCTION PROTOTYPES
189 ==================================================================================================*/
190
191
192 /*==================================================================================================
193 LOCAL FUNCTIONS
194 ==================================================================================================*/
195 #define MCU_START_SEC_CODE
196
197 #include "Mcu_MemMap.h"
198
199
200 /*==================================================================================================
201 GLOBAL FUNCTIONS
202 ==================================================================================================*/
203 #if (defined(POWER_IP_ENABLE_USER_MODE_SUPPORT) && (STD_ON == POWER_IP_ENABLE_USER_MODE_SUPPORT))
204 #if (defined(MCAL_PMC_REG_PROT_AVAILABLE))
205 #if (STD_ON == MCAL_PMC_REG_PROT_AVAILABLE)
206 /**
207 * @brief This function will enable writing in User mode by configuring REG_PROT
208 */
Power_Ip_PMC_SetUserAccessAllowed(void)209 void Power_Ip_PMC_SetUserAccessAllowed(void)
210 {
211 #if (defined(IP_PMC_BASE))
212 SET_USER_ACCESS_ALLOWED(IP_PMC_BASE, PMC_PROT_MEM_U32);
213 #endif
214 }
215 #endif
216 #endif /* MCAL_PMC_REG_PROT_AVAILABLE */
217 #endif /* POWER_IP_ENABLE_USER_MODE_SUPPORT */
218
219
220 /**
221 * @brief This function configure the Power Management Controller
222 * @details The operating voltages are monitored by a set of on-chip supervisory circuits
223 * to ensure that this device works within the correct voltage range.
224 *
225 * @param[in] ConfigPtr Pointer to PMC configuration structure.
226 *
227 * @return void
228 *
229 */
Power_Ip_PMC_PowerInit(const Power_Ip_PMC_ConfigType * ConfigPtr)230 void Power_Ip_PMC_PowerInit(const Power_Ip_PMC_ConfigType * ConfigPtr)
231 {
232 #if !(defined(POWER_IP_DERIVATIVE_001) || defined(POWER_IP_DERIVATIVE_002) || defined(POWER_IP_DERIVATIVE_006) || defined(POWER_IP_DERIVATIVE_009) || defined(POWER_IP_DERIVATIVE_008))
233 uint32 StartTime;
234 uint32 ElapsedTime;
235 uint32 TimeoutTicks;
236 boolean TimeoutOccurred = FALSE;
237 uint32 LvscValue;
238 uint32 LastMileRegValue;
239 #endif
240 uint32 ConfigValue = 0;
241 (void)ConfigPtr;
242 (void)ConfigValue;
243
244 /* After the initial power ramp-up of the MCU, in PMC_LVSC register the POR flag
245 * and the LVR flags are all set to 1. The GNG flags will have an arbitrary value.
246 * Therefore, after the initial power ramp-up, all flags in PMC_LVSC must be
247 * cleared by writing 0xFFFF_FFFF */
248
249 if (PMC_LVSC_RAMP_UP_RESET_FLAGS_RWBITS_MASK == (IP_PMC->LVSC & PMC_LVSC_RAMP_UP_RESET_FLAGS_RWBITS_MASK))
250 {
251 IP_PMC->LVSC = PMC_LVSC_RWBITS_MASK;
252 }
253 #if defined(POWER_IP_DERIVATIVE_001) || defined(POWER_IP_DERIVATIVE_002) || defined(POWER_IP_DERIVATIVE_006) || defined(POWER_IP_DERIVATIVE_009) || defined(POWER_IP_DERIVATIVE_008)
254 /* Initialize the rest of the PMC module */
255 ConfigValue = IP_PMC->CONFIG;
256 ConfigValue &= (~(uint32)PMC_CONFIG_RWBITS_MASK);
257 ConfigValue |= (ConfigPtr->ConfigRegister & (uint32)PMC_CONFIG_RWBITS_MASK);
258 IP_PMC->CONFIG = ConfigValue;
259 #else
260 /* Initialize the rest of the PMC module */
261 if (PMC_CONFIG_LAST_MILE_REG_ENABLE == (ConfigPtr->ConfigRegister & PMC_CONFIG_LMEN_MASK))
262 {
263 IP_PMC->CONFIG = (uint32)(ConfigPtr->ConfigRegister & (~(uint32)PMC_CONFIG_LMEN_MASK));
264
265 /* If external BJT is using on the PCB board, the program needs to wait for the LVD15S bit to be cleared, then LMEN is enabled */
266 if(PMC_CONFIG_LM_BASE_CONTROL_ENABLE == (ConfigPtr->ConfigRegister & PMC_CONFIG_LMBCTLEN_MASK))
267 {
268 Power_Ip_StartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, POWER_IP_TIMEOUT_VALUE_US);
269 do
270 {
271 TimeoutOccurred = Power_Ip_TimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
272
273 LvscValue = IP_PMC->LVSC;
274 } while ( (PMC_LVSC_V15_ABOVE_LV != (LvscValue & PMC_LVSC_LVD15S_MASK)) && (!TimeoutOccurred) );
275
276 if (!TimeoutOccurred)
277 {
278 ConfigValue = IP_PMC->CONFIG;
279 ConfigValue = (uint32)(ConfigValue & (~(uint32)PMC_CONFIG_LMEN_MASK));
280 ConfigValue = (uint32)(ConfigValue | (uint32)(PMC_CONFIG_LAST_MILE_REG_ENABLE & PMC_CONFIG_LMEN_MASK));
281 IP_PMC->CONFIG = ConfigValue;
282 }
283 else
284 {
285 Power_Ip_ReportPowerErrors(POWER_IP_REPORT_TIMEOUT_ERROR, POWER_IP_ERR_CODE_RESERVED);
286 }
287 }
288 else
289 {
290 ConfigValue = IP_PMC->CONFIG;
291 ConfigValue = (uint32)(ConfigValue & (~(uint32)PMC_CONFIG_LMEN_MASK));
292 ConfigValue = (uint32)(ConfigValue | (uint32)(PMC_CONFIG_LAST_MILE_REG_ENABLE & PMC_CONFIG_LMEN_MASK));
293 IP_PMC->CONFIG = ConfigValue;
294 }
295 }
296 else
297 {
298 IP_PMC->CONFIG = ConfigPtr->ConfigRegister;
299
300 if (PMC_CONFIG_LAST_MILE_REG_AUTO_ENABLE == (ConfigPtr->ConfigRegister & PMC_CONFIG_LMAUTOEN_MASK))
301 {
302 Power_Ip_StartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, POWER_IP_TIMEOUT_VALUE_US);
303 do
304 {
305 TimeoutOccurred = Power_Ip_TimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
306
307 LastMileRegValue = (IP_PMC->CONFIG & PMC_CONFIG_LMSTAT_MASK);
308 } while ((PMC_CONFIG_LAST_MILE_REG_ON != LastMileRegValue) && (!TimeoutOccurred));
309
310 if (TimeoutOccurred)
311 {
312 Power_Ip_ReportPowerErrors(POWER_IP_REPORT_TIMEOUT_ERROR, POWER_IP_ERR_CODE_RESERVED);
313 }
314 else
315 {
316 /* do nothing */
317 }
318 }
319 }
320 #endif
321 #if (defined(POWER_IP_VOLTAGE_ERROR_ISR_USED))
322 #if (POWER_IP_VOLTAGE_ERROR_ISR_USED == STD_ON)
323 /* make Status of PMC to initialized to check in the interrupt function */
324 Power_Ip_ePMCStatus = PMC_INIT;
325 #endif
326 #endif
327 #if (defined(POWER_IP_DERIVATIVE_006) || defined(POWER_IP_DERIVATIVE_009) || defined(POWER_IP_DERIVATIVE_008))
328 ConfigValue = ConfigPtr->SMPSRegister;
329 if (PMC_SMPSCONFIG_DITHEREN_MASK == (ConfigValue & PMC_SMPSCONFIG_DITHEREN_MASK))
330 {
331 /* Write 0 to bit DITHEREN */
332 IP_PMC->SMPSCONFIG = 0U;
333 /* Write new configurtion to SMPS */
334 ConfigValue &= (~(uint32)PMC_SMPSCONFIG_DITHEREN_MASK);
335 IP_PMC->SMPSCONFIG = ConfigValue;
336 /* Set bit DITHEREN */
337 ConfigValue |= PMC_SMPSCONFIG_DITHEREN_MASK;
338 IP_PMC->SMPSCONFIG = ConfigValue;
339 }
340 else
341 {
342 IP_PMC->SMPSCONFIG = ConfigValue;
343 }
344 #endif
345 }
346
347 #if (defined(POWER_IP_PMCAECONFIG_API) && (STD_ON == POWER_IP_PMCAECONFIG_API))
348 /**
349 * @brief This function configure the Power Management Controller AE
350 * @details The operating voltages are monitored by a set of on-chip supervisory circuits
351 * to ensure that this device works within the correct voltage range.
352 *
353 * @param[in] ConfigPtr Pointer to PMC configuration structure.
354 *
355 * @return void
356 *
357 */
Power_Ip_PMC_AE_PowerInit(const Power_Ip_PMC_ConfigType * ConfigPtr)358 void Power_Ip_PMC_AE_PowerInit(const Power_Ip_PMC_ConfigType * ConfigPtr)
359 {
360 uint32 TmpAe;
361
362 Aec_Ip_SpiRead((uint32)(&(IP_PMC_AE->CONFIG)),POWER_IP_DATAWIDTH_32,&TmpAe);
363 TmpAe = (uint32)(TmpAe & (uint32)(~PMC_AE_CONFIG_RWBITS_MASK32));
364 TmpAe = (uint32)(TmpAe | (uint32)(ConfigPtr->PmcAeConfig));
365 Aec_Ip_SpiWrite((uint32)(&(IP_PMC_AE->CONFIG)),POWER_IP_DATAWIDTH_32,TmpAe);
366
367 Aec_Ip_SpiRead((uint32)(&(IP_PMC_AE->MONITOR)),POWER_IP_DATAWIDTH_32,&TmpAe);
368 TmpAe = (uint32)(TmpAe & (uint32)(~PMC_AE_MONITOR_RWBITS_MASK32));
369 TmpAe = (uint32)(TmpAe | (uint32)(ConfigPtr->PmcAeMonitor));
370 Aec_Ip_SpiWrite((uint32)(&(IP_PMC_AE->MONITOR)),POWER_IP_DATAWIDTH_32,TmpAe);
371
372 #if (defined(POWER_IP_VOLTAGE_ERROR_ISR_USED))
373 #if (POWER_IP_VOLTAGE_ERROR_ISR_USED == STD_ON)
374 /* make Status of PMC to initialized to check in the interrupt function */
375 Power_Ip_ePMCAeStatus = PMC_INIT;
376 #endif
377 #endif
378 }
379 #endif
380
381 #if (defined(POWER_IP_ENTER_LOW_POWER_MODE) && (POWER_IP_ENTER_LOW_POWER_MODE == STD_ON))
382 /**
383 * @brief This function prepares the PMC module for Standby/Low Power entry.
384 * @details If the Lastmile Regulator is enabled, clear both PMC_LVSC[LMEN]
385 * and PMC_LSVC[LMBCTLEN] simultaneously and notify the application
386 * of the regulator disablement. The LVD/HVD Interrupts are also
387 * disabled.
388 *
389 * @param[in] void
390 *
391 * @return void
392 *
393 */
Power_Ip_PMC_PrepareLowPowerEntry(void)394 void Power_Ip_PMC_PrepareLowPowerEntry(void)
395 {
396 uint32 TempValue = 0U;
397
398 /* Disable LVD/HVD Interrupts */
399 TempValue = IP_PMC->CONFIG;
400 TempValue = (uint32)(TempValue & (uint32)( ~(PMC_CONFIG_LVDIE_MASK | PMC_CONFIG_HVDIE_MASK) ) );
401 TempValue = (uint32)(TempValue | (uint32)(PMC_CONFIG_LVD_INTERRUPTS_DISABLE | PMC_CONFIG_HVD_INTERRUPTS_DISABLE));
402 IP_PMC->CONFIG = TempValue;
403
404 #if !(defined(POWER_IP_DERIVATIVE_001) || defined(POWER_IP_DERIVATIVE_002) || defined(POWER_IP_DERIVATIVE_006) || defined(POWER_IP_DERIVATIVE_009) || defined(POWER_IP_DERIVATIVE_008))
405 /* Disable LM Regulator, if enabled, and notify the application */
406 if ((PMC_CONFIG_LAST_MILE_REG_ENABLE == ((uint32)(IP_PMC->CONFIG & PMC_CONFIG_LMEN_MASK))) || \
407 (PMC_CONFIG_LAST_MILE_REG_AUTO_ENABLE == ((uint32)(IP_PMC->CONFIG & PMC_CONFIG_LMAUTOEN_MASK))))
408 {
409 TempValue = IP_PMC->CONFIG;
410 TempValue = (uint32)(TempValue & (uint32)( ~(PMC_CONFIG_LMBCTLEN_MASK | PMC_CONFIG_LMEN_MASK | PMC_CONFIG_LMAUTOEN_MASK) ) );
411 TempValue = (uint32)(TempValue | (uint32)(PMC_CONFIG_LM_BASE_CONTROL_DISABLE | PMC_CONFIG_LAST_MILE_REG_DISABLE | PMC_CONFIG_LAST_MILE_REG_AUTO_DISABLE));
412 IP_PMC->CONFIG = TempValue;
413
414 /* Notify the application of the regulator disablement to further signal the SBC, if needed */
415 #ifdef POWER_IP_PMC_NOTIFICATION
416 POWER_IP_PMC_NOTIFICATION(POWER_IP_LAST_MILE_REGULATOR_DISABLED);
417 #else
418 Power_Ip_ReportPowerErrors(POWER_IP_PMC_ERROR, POWER_IP_LAST_MILE_REGULATOR_DISABLED);
419 #endif
420 }
421 #endif
422 }
423 #endif /* (POWER_IP_ENTER_LOW_POWER_MODE == STD_ON) */
424
425 #if (defined(POWER_IP_VOLTAGE_ERROR_ISR_USED))
426 #if (POWER_IP_VOLTAGE_ERROR_ISR_USED == STD_ON)
427 /**
428 * @brief This function handles the voltage error detection.
429 *
430 * @return void
431 *
432 * @isr
433 * @implements Power_Ip_PMC_VoltageErrorIsr_Activity
434 */
Power_Ip_PMC_VoltageErrorIsr(void)435 void Power_Ip_PMC_VoltageErrorIsr(void)
436 {
437 uint32 RegValue;
438 uint32 VoltageIsrEnabled;
439 uint32 VoltageIsrStatus;
440 uint32 EventReport;
441 RegValue = IP_PMC->LVSC;
442
443 VoltageIsrEnabled = RegValue & PMC_LVSC_OV_UV_IRQ_FLAGS_MASK32;
444
445 if (PMC_UNINIT != Power_Ip_ePMCStatus)
446 {
447
448 VoltageIsrStatus = RegValue & PMC_LVSC_OV_UV_STATUS_FLAGS_MASK32;
449
450 RegValue = IP_PMC->CONFIG;
451
452 if (PMC_CONFIG_LVD_INTERRUPTS_DISABLE == (RegValue & PMC_CONFIG_LVDIE_MASK))
453 {
454 VoltageIsrEnabled = (VoltageIsrEnabled & (uint32)(~PMC_LVSC_UV_IRQ_FLAGS_MASK32));
455 }
456 else
457 {
458 IP_PMC->LVSC &= (uint32)(~PMC_LVSC_UV_IRQ_FLAGS_MASK32);
459 }
460
461 if (PMC_CONFIG_HVD_INTERRUPTS_DISABLE == (RegValue & PMC_CONFIG_HVDIE_MASK))
462 {
463 VoltageIsrEnabled = (VoltageIsrEnabled & (uint32)(~PMC_LVSC_OV_IRQ_FLAGS_MASK32));
464 }
465 else
466 {
467 IP_PMC->LVSC &= (uint32)(~PMC_LVSC_OV_IRQ_FLAGS_MASK32);
468 }
469
470 /* Align IRQ Flags with Status flags */
471 VoltageIsrStatus = (VoltageIsrStatus >> 8U);
472 EventReport = (VoltageIsrStatus & VoltageIsrEnabled);
473
474 /* Check if there is any event to report */
475 if ((uint32)0U != EventReport)
476 {
477 if (((EventReport & PMC_LVSC_UV_IRQ_FLAGS_MASK32) != (uint32)0U) && \
478 ((EventReport & PMC_LVSC_OV_IRQ_FLAGS_MASK32) != (uint32)0U))
479 {
480 #ifdef POWER_IP_ERROR_ISR_NOTIFICATION
481 POWER_IP_ERROR_ISR_NOTIFICATION(POWER_IP_E_ISR_VOLTAGE_ERROR);
482 #else
483 Power_Ip_ReportPowerErrors(POWER_IP_ISR_ERROR, POWER_IP_E_ISR_VOLTAGE_ERROR);
484 #endif
485 }
486 else if ((EventReport & PMC_LVSC_UV_IRQ_FLAGS_MASK32) != (uint32)0U)
487 {
488 #ifdef POWER_IP_ERROR_ISR_NOTIFICATION
489 POWER_IP_ERROR_ISR_NOTIFICATION(POWER_IP_E_ISR_LOW_VOLTAGE_ERROR);
490 #else
491 Power_Ip_ReportPowerErrors(POWER_IP_ISR_ERROR, POWER_IP_E_ISR_LOW_VOLTAGE_ERROR);
492 #endif
493 }
494 else
495 {
496 #ifdef POWER_IP_ERROR_ISR_NOTIFICATION
497 POWER_IP_ERROR_ISR_NOTIFICATION(POWER_IP_E_ISR_HIGH_VOLTAGE_ERROR);
498 #else
499 Power_Ip_ReportPowerErrors(POWER_IP_ISR_ERROR, POWER_IP_E_ISR_HIGH_VOLTAGE_ERROR);
500 #endif
501 }
502
503 }
504 }
505 else
506 {
507 /* Clear ISR flag */
508 IP_PMC->LVSC = VoltageIsrEnabled;
509 }
510 }
511
512 #if (defined(POWER_IP_PMCAECONFIG_API) && (STD_ON == POWER_IP_PMCAECONFIG_API))
513
514 /**
515 * @brief This function handle the high voltage detection on VDDINT or VDD15.
516 *
517 * @return void
518 *
519 * @isr
520 *
521 */
Power_Ip_PMC_AE_VoltageDetectHvdOnVddintVdd15Isr(void)522 void Power_Ip_PMC_AE_VoltageDetectHvdOnVddintVdd15Isr(void)
523 {
524 uint32 TmpAe;
525 uint32 VoltageDetectFlags;
526 uint32 VoltageDetectStatus;
527 uint32 EventReport;
528
529 /* Read Voltage Detect Flag */
530 Aec_Ip_SpiRead((uint32)(&(IP_PMC_AE->MONITOR)),POWER_IP_DATAWIDTH_32,&TmpAe);
531
532 VoltageDetectFlags = (TmpAe & (PMC_AE_MONITOR_HVDINTF_MASK | PMC_AE_MONITOR_HVD15F_MASK));
533
534 if(PMC_UNINIT != Power_Ip_ePMCAeStatus)
535 {
536 VoltageDetectStatus = (TmpAe & (PMC_AE_MONITOR_HVDINTS_MASK | PMC_AE_MONITOR_HVD15S_MASK));
537 if ((uint32)0U == (TmpAe & PMC_AE_MONITOR_HVDINT15IE_MASK))
538 {
539 VoltageDetectFlags = (VoltageDetectFlags & (uint32)(~(PMC_AE_MONITOR_HVDINTF_MASK | PMC_AE_MONITOR_HVD15F_MASK)));
540 }
541 /* Align IRQ Flags with Status flags */
542 VoltageDetectStatus = (VoltageDetectStatus >> 16U);
543 EventReport = (VoltageDetectStatus & VoltageDetectFlags);
544
545 /* Check if there is any event to report */
546 if ((uint32)0U != EventReport)
547 {
548 /* clear IRQ flags */
549 Aec_Ip_SpiWrite((uint32)(&(IP_PMC_AE->MONITOR)),POWER_IP_DATAWIDTH_32,VoltageDetectFlags);
550
551 if((uint32)0x0U != (EventReport & PMC_AE_MONITOR_HVDINTF_MASK))
552 {
553 #ifdef POWER_IP_DETECT_ISR_NOTIFICATION
554 POWER_IP_DETECT_ISR_NOTIFICATION(POWER_IP_VOLTAGE_HVD_VDDINT,POWER_IP_E_ISR_HIGH_VOLTAGE_ERROR);
555 #else
556 Power_Ip_ReportPowerErrors(POWER_IP_ISR_VOLTAGE_HVD_VDDINT_DETECT, POWER_IP_E_ISR_HIGH_VOLTAGE_ERROR);
557 #endif
558 }
559
560 if((uint32)0x0U != (EventReport & PMC_AE_MONITOR_HVD15F_MASK))
561 {
562 #ifdef POWER_IP_DETECT_ISR_NOTIFICATION
563 POWER_IP_DETECT_ISR_NOTIFICATION(POWER_IP_VOLTAGE_HVD_15,POWER_IP_E_ISR_HIGH_VOLTAGE_ERROR);
564 #else
565 Power_Ip_ReportPowerErrors(POWER_IP_ISR_VOLTAGE_HVD_15_DETECT, POWER_IP_E_ISR_HIGH_VOLTAGE_ERROR);
566 #endif
567 }
568 }
569 }
570 else
571 {
572 /* clear IRQ flags */
573 Aec_Ip_SpiWrite((uint32)(&(IP_PMC_AE->MONITOR)),POWER_IP_DATAWIDTH_32,VoltageDetectFlags);
574 }
575 }
576
577 /**
578 * @brief This function handle the high voltage detection on VDD.
579 *
580 * @return void
581 *
582 * @isr
583 *
584 */
Power_Ip_PMC_AE_VoltageDetectHvdOnVddIsr(void)585 void Power_Ip_PMC_AE_VoltageDetectHvdOnVddIsr(void)
586 {
587 uint32 TmpAe;
588 uint32 VoltageDetectStatus;
589 uint32 VoltageDetectFlags;
590 uint32 EventReport;
591
592 /* Read Voltage Detect Flag */
593 Aec_Ip_SpiRead((uint32)(&(IP_PMC_AE->MONITOR)),POWER_IP_DATAWIDTH_32,&TmpAe);
594 VoltageDetectFlags = (TmpAe & PMC_AE_MONITOR_HVDVDDF_MASK);
595
596 if(PMC_UNINIT != Power_Ip_ePMCAeStatus)
597 {
598 VoltageDetectStatus = (TmpAe & PMC_AE_MONITOR_HVDVDDS_MASK);
599 if ((uint32)0U == (TmpAe & PMC_AE_MONITOR_HVDVDDIE_MASK))
600 {
601 VoltageDetectFlags = (VoltageDetectFlags & (uint32)(~PMC_AE_MONITOR_HVDVDDF_MASK));
602 }
603 /* Align IRQ Flags with Status flags */
604 VoltageDetectStatus = (VoltageDetectStatus >> 16U);
605 EventReport = (VoltageDetectStatus & VoltageDetectFlags);
606
607 /* Check if there is any event to report */
608 if ((uint32)0U != EventReport)
609 {
610 /* clear IRQ flags */
611 Aec_Ip_SpiWrite((uint32)(&(IP_PMC_AE->MONITOR)),POWER_IP_DATAWIDTH_32,VoltageDetectFlags);
612
613 if((uint32)0x0U != (EventReport & PMC_AE_MONITOR_HVDVDDF_MASK))
614 {
615 #ifdef POWER_IP_DETECT_ISR_NOTIFICATION
616 POWER_IP_DETECT_ISR_NOTIFICATION(POWER_IP_VOLTAGE_HVD_VDD,POWER_IP_E_ISR_HIGH_VOLTAGE_ERROR);
617 #else
618 Power_Ip_ReportPowerErrors(POWER_IP_ISR_VOLTAGE_HVD_VDD_DETECT, POWER_IP_E_ISR_HIGH_VOLTAGE_ERROR);
619 #endif
620 }
621 }
622 }
623 else
624 {
625 /* clear IRQ flags */
626 Aec_Ip_SpiWrite((uint32)(&(IP_PMC_AE->MONITOR)),POWER_IP_DATAWIDTH_32,VoltageDetectFlags);
627 }
628 }
629
630 /**
631 * @brief This function handle the low voltage detection on VDDC.
632 *
633 * @return void
634 *
635 * @isr
636 *
637 */
Power_Ip_PMC_AE_VoltageDetectLvdOnVddcIsr(void)638 void Power_Ip_PMC_AE_VoltageDetectLvdOnVddcIsr(void)
639 {
640 uint32 TmpAe;
641 uint32 VoltageDetectStatus;
642 uint32 VoltageDetectFlags;
643 uint32 EventReport;
644
645 /* Read Voltage Detect Flag */
646 Aec_Ip_SpiRead((uint32)(&(IP_PMC_AE->MONITOR)),POWER_IP_DATAWIDTH_32,&TmpAe);
647 VoltageDetectFlags = (TmpAe & PMC_AE_MONITOR_LVDCF_MASK);
648
649 if(PMC_UNINIT != Power_Ip_ePMCAeStatus)
650 {
651 VoltageDetectStatus = (TmpAe & PMC_AE_MONITOR_LVDCS_MASK);
652 if ((uint32)0U == (TmpAe & PMC_AE_MONITOR_LVDCIE_MASK))
653 {
654 VoltageDetectFlags = (VoltageDetectFlags & (uint32)(~PMC_AE_MONITOR_LVDCF_MASK));
655 }
656 /* Align IRQ Flags with Status flags */
657 VoltageDetectStatus = (VoltageDetectStatus >> 16U);
658 EventReport = (VoltageDetectStatus & VoltageDetectFlags);
659
660 /* Check if there is any event to report */
661 if ((uint32)0U != EventReport)
662 {
663 /* clear IRQ flags */
664 Aec_Ip_SpiWrite((uint32)(&(IP_PMC_AE->MONITOR)),POWER_IP_DATAWIDTH_32,VoltageDetectFlags);
665
666 if((uint32)0x0U != (EventReport & PMC_AE_MONITOR_LVDCF_MASK))
667 {
668 #ifdef POWER_IP_DETECT_ISR_NOTIFICATION
669 POWER_IP_DETECT_ISR_NOTIFICATION(POWER_IP_VOLTAGE_HVD_VDD,POWER_IP_E_ISR_LOW_VOLTAGE_ERROR);
670 #else
671 Power_Ip_ReportPowerErrors(POWER_IP_ISR_VOLTAGE_HVD_VDD_DETECT, POWER_IP_E_ISR_LOW_VOLTAGE_ERROR);
672 #endif
673 }
674 }
675 }
676 else
677 {
678 /* clear IRQ flags */
679 Aec_Ip_SpiWrite((uint32)(&(IP_PMC_AE->MONITOR)),POWER_IP_DATAWIDTH_32,VoltageDetectFlags);
680 }
681 }
682
683 /**
684 * @brief This function handle the low voltage detection on VLS.
685 *
686 * @return void
687 *
688 * @isr
689 *
690 */
Power_Ip_PMC_AE_VoltageDetectLvdOnVlsIsr(void)691 void Power_Ip_PMC_AE_VoltageDetectLvdOnVlsIsr(void)
692 {
693
694
695 uint32 TmpAe;
696 uint32 VoltageDetectStatus;
697 uint32 VoltageDetectFlags;
698 uint32 EventReport;
699
700 /* Read Voltage Detect Flag */
701 Aec_Ip_SpiRead((uint32)(&(IP_PMC_AE->MONITOR)),POWER_IP_DATAWIDTH_32,&TmpAe);
702 VoltageDetectFlags = (TmpAe & PMC_AE_MONITOR_LVDVLSF_MASK);
703
704 if(PMC_UNINIT != Power_Ip_ePMCAeStatus)
705 {
706 VoltageDetectStatus = (TmpAe & PMC_AE_MONITOR_LVDVLSS_MASK);
707 if ((uint32)0U == (TmpAe & PMC_AE_MONITOR_LVDVLSIE_MASK))
708 {
709 VoltageDetectFlags = (VoltageDetectFlags & (uint32)(~PMC_AE_MONITOR_LVDVLSF_MASK));
710 }
711 /* Align IRQ Flags with Status flags */
712 VoltageDetectStatus = (VoltageDetectStatus >> 16U);
713 EventReport = (VoltageDetectStatus & VoltageDetectFlags);
714
715 /* Check if there is any event to report */
716 if ((uint32)0U != EventReport)
717 {
718 /* clear IRQ flags */
719 Aec_Ip_SpiWrite((uint32)(&(IP_PMC_AE->MONITOR)),POWER_IP_DATAWIDTH_32,VoltageDetectFlags);
720
721 if((uint32)0x0U != (EventReport & PMC_AE_MONITOR_LVDVLSF_MASK))
722 {
723 #ifdef POWER_IP_DETECT_ISR_NOTIFICATION
724 POWER_IP_DETECT_ISR_NOTIFICATION(POWER_IP_VOLTAGE_HVD_VDD,POWER_IP_E_ISR_LOW_VOLTAGE_ERROR);
725 #else
726 Power_Ip_ReportPowerErrors(POWER_IP_ISR_VOLTAGE_HVD_VDD_DETECT, POWER_IP_E_ISR_LOW_VOLTAGE_ERROR);
727 #endif
728 }
729 }
730 }
731 else
732 {
733 /* clear IRQ flags */
734 Aec_Ip_SpiWrite((uint32)(&(IP_PMC_AE->MONITOR)),POWER_IP_DATAWIDTH_32,VoltageDetectFlags);
735 }
736 }
737 #endif
738
739 #endif
740 #endif /* (POWER_IP_VOLTAGE_ERROR_ISR_USED == STD_ON) */
741
742 #define MCU_STOP_SEC_CODE
743
744 #include "Mcu_MemMap.h"
745
746
747 #ifdef __cplusplus
748 }
749 #endif
750
751 /** @} */
752