1 /*
2  * Copyright 2020-2023 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 /**
7 *   @file       Power_Ip.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 *                                        INCLUDE FILES
25 * 1) system and project includes
26 * 2) needed interfaces from external units
27 * 3) internal and external interfaces from this unit
28 ==================================================================================================*/
29 #include "Power_Ip_Private.h"
30 #include "Power_Ip.h"
31 #include "Power_Ip_MC_ME.h"
32 #include "Power_Ip_MC_RGM.h"
33 #include "Power_Ip_PMC.h"
34 #include "Power_Ip_FLASH.h"
35 #include "Power_Ip_CortexM7.h"
36 #include "Power_Ip_DCM_GPR.h"
37 
38 #ifdef POWER_IP_AECRESETCONFIG_API
39 #if (POWER_IP_AECRESETCONFIG_API == STD_ON)
40 #include "Power_Ip_AEC.h"
41 #endif
42 #endif
43 /*==================================================================================================
44                                SOURCE FILE VERSION INFORMATION
45 ==================================================================================================*/
46 #define POWER_IP_VENDOR_ID_C                      43
47 #define POWER_IP_AR_RELEASE_MAJOR_VERSION_C       4
48 #define POWER_IP_AR_RELEASE_MINOR_VERSION_C       7
49 #define POWER_IP_AR_RELEASE_REVISION_VERSION_C    0
50 #define POWER_IP_SW_MAJOR_VERSION_C               3
51 #define POWER_IP_SW_MINOR_VERSION_C               0
52 #define POWER_IP_SW_PATCH_VERSION_C               0
53 
54 /*==================================================================================================
55 *                                     FILE VERSION CHECKS
56 ==================================================================================================*/
57 /* Check if Power_Ip.c file and Power_Ip_Private.h file are of the same vendor */
58 #if (POWER_IP_VENDOR_ID_C != POWER_IP_PRIVATE_VENDOR_ID)
59     #error "Power_Ip.c and Power_Ip_Private.h have different vendor ids"
60 #endif
61 
62 /* Check if Power_Ip.c file and Power_Ip_Private.h file are of the same Autosar version */
63 #if ((POWER_IP_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_PRIVATE_AR_RELEASE_MAJOR_VERSION) || \
64      (POWER_IP_AR_RELEASE_MINOR_VERSION_C != POWER_IP_PRIVATE_AR_RELEASE_MINOR_VERSION) || \
65      (POWER_IP_AR_RELEASE_REVISION_VERSION_C != POWER_IP_PRIVATE_AR_RELEASE_REVISION_VERSION) \
66     )
67     #error "AutoSar Version Numbers of Power_Ip.c and Power_Ip_Private.h are different"
68 #endif
69 
70 /* Check if Power_Ip.c file and Power_Ip_Private.h file are of the same Software version */
71 #if ((POWER_IP_SW_MAJOR_VERSION_C != POWER_IP_PRIVATE_SW_MAJOR_VERSION) || \
72      (POWER_IP_SW_MINOR_VERSION_C != POWER_IP_PRIVATE_SW_MINOR_VERSION) || \
73      (POWER_IP_SW_PATCH_VERSION_C != POWER_IP_PRIVATE_SW_PATCH_VERSION) \
74     )
75     #error "Software Version Numbers of Power_Ip.c and Power_Ip_Private.h are different"
76 #endif
77 
78 /* Check if Power_Ip.c file and Power_Ip.h file are of the same vendor */
79 #if (POWER_IP_VENDOR_ID_C != POWER_IP_VENDOR_ID)
80     #error "Power_Ip.c and Power_Ip.h have different vendor ids"
81 #endif
82 
83 /* Check if Power_Ip.c file and Power_Ip.h file are of the same Autosar version */
84 #if ((POWER_IP_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_AR_RELEASE_MAJOR_VERSION) || \
85      (POWER_IP_AR_RELEASE_MINOR_VERSION_C != POWER_IP_AR_RELEASE_MINOR_VERSION) || \
86      (POWER_IP_AR_RELEASE_REVISION_VERSION_C != POWER_IP_AR_RELEASE_REVISION_VERSION) \
87     )
88     #error "AutoSar Version Numbers of Power_Ip.c and Power_Ip.h are different"
89 #endif
90 
91 /* Check if Power_Ip.c file and Power_Ip.h file are of the same Software version */
92 #if ((POWER_IP_SW_MAJOR_VERSION_C != POWER_IP_SW_MAJOR_VERSION) || \
93      (POWER_IP_SW_MINOR_VERSION_C != POWER_IP_SW_MINOR_VERSION) || \
94      (POWER_IP_SW_PATCH_VERSION_C != POWER_IP_SW_PATCH_VERSION) \
95     )
96     #error "Software Version Numbers of Power_Ip.c and Power_Ip.h are different"
97 #endif
98 
99 /* Check if Power_Ip.c file and Power_Ip_MC_ME.h file are of the same vendor */
100 #if (POWER_IP_VENDOR_ID_C != POWER_IP_MC_ME_VENDOR_ID)
101     #error "Power_Ip.c and Power_Ip_MC_ME.h have different vendor ids"
102 #endif
103 
104 /* Check if Power_Ip.c file and Power_Ip_MC_ME.h file are of the same Autosar version */
105 #if ((POWER_IP_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_MC_ME_AR_RELEASE_MAJOR_VERSION) || \
106      (POWER_IP_AR_RELEASE_MINOR_VERSION_C != POWER_IP_MC_ME_AR_RELEASE_MINOR_VERSION) || \
107      (POWER_IP_AR_RELEASE_REVISION_VERSION_C != POWER_IP_MC_ME_AR_RELEASE_REVISION_VERSION) \
108     )
109     #error "AutoSar Version Numbers of Power_Ip.c and Power_Ip_MC_ME.h are different"
110 #endif
111 
112 /* Check if Power_Ip.c file and Power_Ip_MC_ME.h file are of the same Software version */
113 #if ((POWER_IP_SW_MAJOR_VERSION_C != POWER_IP_MC_ME_SW_MAJOR_VERSION) || \
114      (POWER_IP_SW_MINOR_VERSION_C != POWER_IP_MC_ME_SW_MINOR_VERSION) || \
115      (POWER_IP_SW_PATCH_VERSION_C != POWER_IP_MC_ME_SW_PATCH_VERSION) \
116     )
117     #error "Software Version Numbers of Power_Ip.c and Power_Ip_MC_ME.h are different"
118 #endif
119 
120 /* Check if Power_Ip.c file and Power_Ip_MC_RGM.h file are of the same vendor */
121 #if (POWER_IP_VENDOR_ID_C != POWER_IP_MC_RGM_VENDOR_ID)
122     #error "Power_Ip.c and Power_Ip_MC_RGM.h have different vendor ids"
123 #endif
124 
125 /* Check if Power_Ip.c file and Power_Ip_MC_RGM.h file are of the same Autosar version */
126 #if ((POWER_IP_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_MC_RGM_AR_RELEASE_MAJOR_VERSION) || \
127      (POWER_IP_AR_RELEASE_MINOR_VERSION_C != POWER_IP_MC_RGM_AR_RELEASE_MINOR_VERSION) || \
128      (POWER_IP_AR_RELEASE_REVISION_VERSION_C != POWER_IP_MC_RGM_AR_RELEASE_REVISION_VERSION) \
129     )
130     #error "AutoSar Version Numbers of Power_Ip.c and Power_Ip_MC_RGM.h are different"
131 #endif
132 
133 /* Check if Power_Ip.c file and Power_Ip_MC_RGM.h file are of the same Software version */
134 #if ((POWER_IP_SW_MAJOR_VERSION_C != POWER_IP_MC_RGM_SW_MAJOR_VERSION) || \
135      (POWER_IP_SW_MINOR_VERSION_C != POWER_IP_MC_RGM_SW_MINOR_VERSION) || \
136      (POWER_IP_SW_PATCH_VERSION_C != POWER_IP_MC_RGM_SW_PATCH_VERSION) \
137     )
138     #error "Software Version Numbers of Power_Ip.c and Power_Ip_MC_RGM.h are different"
139 #endif
140 
141 /* Check if Power_Ip.c file and Power_Ip_PMC.h file are of the same vendor */
142 #if (POWER_IP_VENDOR_ID_C != POWER_IP_PMC_VENDOR_ID)
143     #error "Power_Ip.c and Power_Ip_PMC.h have different vendor ids"
144 #endif
145 
146 /* Check if Power_Ip.c file and Power_Ip_PMC.h file are of the same Autosar version */
147 #if ((POWER_IP_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_PMC_AR_RELEASE_MAJOR_VERSION) || \
148      (POWER_IP_AR_RELEASE_MINOR_VERSION_C != POWER_IP_PMC_AR_RELEASE_MINOR_VERSION) || \
149      (POWER_IP_AR_RELEASE_REVISION_VERSION_C != POWER_IP_PMC_AR_RELEASE_REVISION_VERSION) \
150     )
151     #error "AutoSar Version Numbers of Power_Ip.c and Power_Ip_PMC.h are different"
152 #endif
153 
154 /* Check if Power_Ip.c file and Power_Ip_PMC.h file are of the same Software version */
155 #if ((POWER_IP_SW_MAJOR_VERSION_C != POWER_IP_PMC_SW_MAJOR_VERSION) || \
156      (POWER_IP_SW_MINOR_VERSION_C != POWER_IP_PMC_SW_MINOR_VERSION) || \
157      (POWER_IP_SW_PATCH_VERSION_C != POWER_IP_PMC_SW_PATCH_VERSION) \
158     )
159     #error "Software Version Numbers of Power_Ip.c and Power_Ip_PMC.h are different"
160 #endif
161 
162 /* Check if Power_Ip.c file and Power_Ip_FLASH.h file are of the same vendor */
163 #if (POWER_IP_VENDOR_ID_C != POWER_IP_FLASH_VENDOR_ID)
164     #error "Power_Ip.c and Power_Ip_FLASH.h have different vendor ids"
165 #endif
166 
167 /* Check if Power_Ip.c file and Power_Ip_FLASH.h file are of the same Autosar version */
168 #if ((POWER_IP_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_FLASH_AR_RELEASE_MAJOR_VERSION) || \
169      (POWER_IP_AR_RELEASE_MINOR_VERSION_C != POWER_IP_FLASH_AR_RELEASE_MINOR_VERSION) || \
170      (POWER_IP_AR_RELEASE_REVISION_VERSION_C != POWER_IP_FLASH_AR_RELEASE_REVISION_VERSION) \
171     )
172     #error "AutoSar Version Numbers of Power_Ip.c and Power_Ip_FLASH.h are different"
173 #endif
174 
175 /* Check if Power_Ip.c file and Power_Ip_FLASH.h file are of the same Software version */
176 #if ((POWER_IP_SW_MAJOR_VERSION_C != POWER_IP_FLASH_SW_MAJOR_VERSION) || \
177      (POWER_IP_SW_MINOR_VERSION_C != POWER_IP_FLASH_SW_MINOR_VERSION) || \
178      (POWER_IP_SW_PATCH_VERSION_C != POWER_IP_FLASH_SW_PATCH_VERSION) \
179     )
180     #error "Software Version Numbers of Power_Ip.c and Power_Ip_FLASH.h are different"
181 #endif
182 
183 /* Check if Power_Ip.c file and Power_Ip_CortexM7.h file are of the same vendor */
184 #if (POWER_IP_VENDOR_ID_C != POWER_IP_CORTEXM7_VENDOR_ID)
185     #error "Power_Ip.c and Power_Ip_CortexM7.h have different vendor ids"
186 #endif
187 
188 /* Check if Power_Ip.c file and Power_Ip_CortexM7.h file are of the same Autosar version */
189 #if ((POWER_IP_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_CORTEXM7_AR_RELEASE_MAJOR_VERSION) || \
190      (POWER_IP_AR_RELEASE_MINOR_VERSION_C != POWER_IP_CORTEXM7_AR_RELEASE_MINOR_VERSION) || \
191      (POWER_IP_AR_RELEASE_REVISION_VERSION_C != POWER_IP_CORTEXM7_AR_RELEASE_REVISION_VERSION) \
192     )
193     #error "AutoSar Version Numbers of Power_Ip.c and Power_Ip_CortexM7.h are different"
194 #endif
195 
196 /* Check if Power_Ip.c file and Power_Ip_CortexM7.h file are of the same Software version */
197 #if ((POWER_IP_SW_MAJOR_VERSION_C != POWER_IP_CORTEXM7_SW_MAJOR_VERSION) || \
198      (POWER_IP_SW_MINOR_VERSION_C != POWER_IP_CORTEXM7_SW_MINOR_VERSION) || \
199      (POWER_IP_SW_PATCH_VERSION_C != POWER_IP_CORTEXM7_SW_PATCH_VERSION) \
200     )
201     #error "Software Version Numbers of Power_Ip.c and Power_Ip_CortexM7.h are different"
202 #endif
203 /*==================================================================================================
204                           LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
205 ==================================================================================================*/
206 
207 
208 /*==================================================================================================
209                                         LOCAL MACROS
210 ==================================================================================================*/
211 
212 
213 /*==================================================================================================
214                                        LOCAL CONSTANTS
215 ==================================================================================================*/
216 
217 
218 /*==================================================================================================
219                                        LOCAL VARIABLES
220 ==================================================================================================*/
221 #define MCU_START_SEC_VAR_INIT_UNSPECIFIED
222 #include "Mcu_MemMap.h"
223 
224 /* Power Report Error Callback */
225 Power_Ip_ReportErrorsCallbackType Power_Ip_pfReportErrorsCallback = Power_Ip_ReportPowerErrorsEmptyCallback;
226 
227 #define MCU_STOP_SEC_VAR_INIT_UNSPECIFIED
228 #include "Mcu_MemMap.h"
229 
230 /*==================================================================================================
231                                        GLOBAL CONSTANTS
232 ==================================================================================================*/
233 
234 
235 /*==================================================================================================
236                                        GLOBAL VARIABLES
237 ==================================================================================================*/
238 
239 
240 /*==================================================================================================
241                                    LOCAL FUNCTION PROTOTYPES
242 ==================================================================================================*/
243 #define MCU_START_SEC_CODE
244 #include "Mcu_MemMap.h"
245 
246 #if (defined(POWER_IP_ENABLE_USER_MODE_SUPPORT) && (STD_ON == POWER_IP_ENABLE_USER_MODE_SUPPORT))
247 static void Power_Ip_SetUserAccessAllowed(void);
248 #endif
249 
250 
251 #if (defined(POWER_IP_ENTER_LOW_POWER_MODE) && (POWER_IP_ENTER_LOW_POWER_MODE == STD_ON))
252 
253 #ifdef POWER_IP_SOC_PREPARE_STANDBY_MODE_SUPPORT
254   #if (POWER_IP_SOC_PREPARE_STANDBY_MODE_SUPPORT == STD_ON)
255 static void Power_Ip_PrepareSocStandby(const Power_Ip_ModeConfigType * ModeConfigPtr);
256   #endif
257 #endif
258 
259 #endif
260 
261 /*==================================================================================================
262                                        LOCAL FUNCTIONS
263 ==================================================================================================*/
264 
265 #if (defined(POWER_IP_ENABLE_USER_MODE_SUPPORT) && (STD_ON == POWER_IP_ENABLE_USER_MODE_SUPPORT))
266 /* Set user access to power register allowed when run in Usermode */
Power_Ip_SetUserAccessAllowed(void)267 static void Power_Ip_SetUserAccessAllowed(void)
268 {
269 #if (defined(MCAL_MC_ME_REG_PROT_AVAILABLE))
270   #if (STD_ON == MCAL_MC_ME_REG_PROT_AVAILABLE)
271     OsIf_Trusted_Call(Power_Ip_MC_ME_SetUserAccessAllowed);
272   #endif
273 #endif
274 
275 #if (defined(MCAL_PMC_REG_PROT_AVAILABLE))
276   #if (STD_ON == MCAL_PMC_REG_PROT_AVAILABLE)
277     OsIf_Trusted_Call(Power_Ip_PMC_SetUserAccessAllowed);
278   #endif
279 #endif
280 
281 #if (defined(POWER_IP_ENTER_LOW_POWER_MODE) && (POWER_IP_ENTER_LOW_POWER_MODE == STD_ON))
282   #if (defined(MCAL_C40ASF_REG_PROT_AVAILABLE))
283     #if(STD_ON == MCAL_C40ASF_REG_PROT_AVAILABLE)
284     OsIf_Trusted_Call(Power_Ip_FLASH_C40ASF_SetUserAccessAllowed);
285     #endif
286   #endif
287 #endif
288 
289 #if (defined(MCAL_MC_RGM_REG_PROT_AVAILABLE))
290   #if (STD_ON == MCAL_MC_RGM_REG_PROT_AVAILABLE)
291     OsIf_Trusted_Call(Power_Ip_MC_RGM_SetUserAccessAllowed);
292   #endif
293 #endif
294 
295 #if (defined(MCAL_RDC_REG_PROT_AVAILABLE))
296   #if (STD_ON == MCAL_RDC_REG_PROT_AVAILABLE)
297     OsIf_Trusted_Call(Power_Ip_RDC_SetUserAccessAllowed);
298   #endif
299 #endif
300 
301 #if (defined(MCAL_DCM_REG_PROT_AVAILABLE))
302   #if (STD_ON == MCAL_DCM_REG_PROT_AVAILABLE)
303     OsIf_Trusted_Call(Power_Ip_DCM_GPR_SetUserAccessAllowed);
304   #endif
305 #endif
306 }
307 #endif /* (STD_ON == POWER_IP_ENABLE_USER_MODE_SUPPORT) */
308 
309 #if (defined(POWER_IP_ENTER_LOW_POWER_MODE) && (POWER_IP_ENTER_LOW_POWER_MODE == STD_ON))
310 
311 #ifdef POWER_IP_SOC_PREPARE_STANDBY_MODE_SUPPORT
312   #if (POWER_IP_SOC_PREPARE_STANDBY_MODE_SUPPORT == STD_ON)
313 /* Prepare soc standby */
Power_Ip_PrepareSocStandby(const Power_Ip_ModeConfigType * ModeConfigPtr)314 static void Power_Ip_PrepareSocStandby(const Power_Ip_ModeConfigType * ModeConfigPtr)
315 {
316     /* Init Device Configuration Module General-Purpose Registers */
317     Power_Ip_DCM_GPR_Config(ModeConfigPtr->DcmGprConfigPtr);
318 
319     if(((boolean)TRUE == ModeConfigPtr->DcmGprConfigPtr->GlobalPadkeeping) && \
320        ((boolean)TRUE == ModeConfigPtr->DcmGprConfigPtr->DcmGprUnderMcuControl))
321     {
322         Power_Ip_DCM_GPR_GlobalPadkeepingConfig(POWER_IP_GLOBAL_PADKEEPING_ENABLED);
323     }
324 
325     if (FALSE == Power_Ip_FLASH_HighVoltageOperationOngoing())
326     {
327         Call_Power_Ip_PMC_PrepareLowPowerEntry();
328     }
329     else
330     {
331 #ifdef POWER_IP_ERROR_ISR_NOTIFICATION
332         POWER_IP_ERROR_ISR_NOTIFICATION(POWER_IP_E_FLASH_HV_OPERATION_ONGOING);
333 #else
334         Power_Ip_ReportPowerErrors(POWER_IP_ISR_ERROR, POWER_IP_E_FLASH_HV_OPERATION_ONGOING);
335 #endif
336     }
337 }
338   #endif
339 #endif /* POWER_IP_SOC_PREPARE_STANDBY_MODE_SUPPORT */
340 
341 #endif /* ((POWER_IP_ENTER_LOW_POWER_MODE == STD_ON)) */
342 
343 
344 /*==================================================================================================
345                                        GLOBAL FUNCTIONS
346 ==================================================================================================*/
347 
348 
349 
350 /**
351 * @brief            This function initializes the mode structure.
352 * @details          This function initializes the mode structure by configuring the MC_ME module.
353 *
354 * @param[in]        ModeConfigPtr   Pointer to mode configuration structure.
355 *
356 * @return           void
357 *
358 * @implements Power_Ip_SetMode_Activity
359 *
360 */
Power_Ip_SetMode(const Power_Ip_ModeConfigType * ModeConfigPtr)361 void Power_Ip_SetMode(const Power_Ip_ModeConfigType * ModeConfigPtr)
362 {
363     Power_Ip_PowerModeType PowerMode;
364 
365     POWER_IP_DEV_ASSERT(NULL_PTR != ModeConfigPtr);
366 
367     PowerMode = ModeConfigPtr->PowerMode;
368 
369     /* Step 1: Enable Partitions clock base on configuration of McuPartitionClockEnable.  */
370     Power_Ip_MC_ME_EnablePartitionClock(ModeConfigPtr->McMeModeConfigPtr);
371 
372 #if (defined(POWER_IP_RESET_DOMAINS_SUPPORTED) && (POWER_IP_RESET_DOMAINS_SUPPORTED == STD_ON))
373     /* Step 2: Enable interconnect interface of Software Reset Domain base on configuration of McuPartitionResetEnable. */
374     Call_Power_Ip_MC_RGM_EnableResetDomain(ModeConfigPtr->McRgmModeConfigPtr);
375 #endif
376 
377 #if (defined(POWER_IP_HAS_OUTPUT_SAFE_STATE))
378   #if (POWER_IP_HAS_OUTPUT_SAFE_STATE == STD_ON)
379     /* Step 3: Disable Output safe stating base on configuration of McuPartitionClockEnable. */
380     Power_Ip_MC_ME_DisablePartitionOutputSafe(ModeConfigPtr->McMeModeConfigPtr);
381   #endif
382 #endif
383 
384     /* Step 4: Configure Cores address, Cores clock and COFB clock */
385     Power_Ip_MC_ME_ConfigCoreCOFBClock(ModeConfigPtr->McMeModeConfigPtr);
386 
387 #if (defined(POWER_IP_RESET_DOMAINS_SUPPORTED) && (POWER_IP_RESET_DOMAINS_SUPPORTED == STD_ON))
388     /* Step 5: Configure and check configure Core and COFB reset */
389     /* Request new mode configuration from MC_RGM. */
390     Call_Power_Ip_MC_RGM_ModeConfig(ModeConfigPtr->McRgmModeConfigPtr);
391     /* Check new mode configuration from MC_RGM. */
392     Call_Power_Ip_MC_RGM_CheckModeConfig(ModeConfigPtr->McRgmModeConfigPtr);
393 
394     /* Step 6: Disable interconnect interface of Software Reset Domain base on configuration of McuPartitionResetEnable. */
395     Call_Power_Ip_MC_RGM_DisableResetDomain(ModeConfigPtr->McRgmModeConfigPtr);
396 #endif /* (POWER_IP_RESET_DOMAINS_SUPPORTED == STD_ON) */
397 
398     /* Step 7: Disable Partitions clock base on configuration of McuPartitionClockEnable.  */
399     Power_Ip_MC_ME_DisablePartitionClock(ModeConfigPtr->McMeModeConfigPtr);
400 
401 #if (defined(POWER_IP_HAS_OUTPUT_SAFE_STATE))
402   #if (POWER_IP_HAS_OUTPUT_SAFE_STATE == STD_ON)
403     /* Step 8: Enable Output safe stating base on configuration of McuPartitionClockEnable. */
404     Power_Ip_MC_ME_EnablePartitionOutputSafe(ModeConfigPtr->McMeModeConfigPtr);
405   #endif
406 #endif
407 
408     if ( (POWER_IP_DEST_RESET_MODE == PowerMode) || (POWER_IP_FUNC_RESET_MODE == PowerMode) )
409     {
410         Power_Ip_MC_ME_SocTriggerResetEvent(PowerMode);
411     }
412 #if (defined(POWER_IP_ENTER_LOW_POWER_MODE) && (POWER_IP_ENTER_LOW_POWER_MODE == STD_ON))
413     else if (POWER_IP_CORE_STANDBY_MODE == PowerMode)
414     {
415         /* External assumption: The application will make sure that the core is prepared for standby entry. */
416         Power_Ip_MC_ME_CoreStandbyEntry(ModeConfigPtr);
417     }
418 #ifdef POWER_IP_SOC_PREPARE_STANDBY_MODE_SUPPORT
419   #if (POWER_IP_SOC_PREPARE_STANDBY_MODE_SUPPORT == STD_ON)
420     else if ( (POWER_IP_SOC_PREPARE_STANDBY_MODE == PowerMode) || (POWER_IP_SOC_PREPARE_FAST_STANDBY_MODE == PowerMode) )
421     {
422         /* External assumption: The application will disable the PLL (and optionally disable FIRC/SIRC/SXOSC/FXOSC
423          * as per power-consumption requirements in order to reduce power consumption in STANDBY mode) and ensure
424          * that no flash high-voltage operations are ongoing. */
425 
426         Power_Ip_PrepareSocStandby(ModeConfigPtr);
427     }
428   #endif
429 #endif
430     else if ( (POWER_IP_SOC_STANDBY_MODE == PowerMode) || (POWER_IP_SOC_FAST_STANDBY_MODE == PowerMode) )
431     {
432         /* External assumption: The application will program the necessary wakeup IP(s). */
433         Power_Ip_MC_ME_SocStandbyEntry(ModeConfigPtr);
434     }
435 #ifdef POWER_IP_SOC_PREPARE_STANDBY_MODE_SUPPORT
436   #if (POWER_IP_SOC_PREPARE_STANDBY_MODE_SUPPORT == STD_ON)
437     else if ( (POWER_IP_STANDBY_MODE == PowerMode) || (POWER_IP_FAST_STANDBY_MODE == PowerMode) )
438     {
439         /* Step 1: prepare soc standby */
440         Power_Ip_PrepareSocStandby(ModeConfigPtr);
441         /* External assumption: The application will program the necessary wakeup IP(s). */
442         /* Step 2: set soc standby */
443         Power_Ip_MC_ME_SocStandbyEntry(ModeConfigPtr);
444     }
445   #endif
446 #endif /* POWER_IP_SOC_PREPARE_STANDBY_MODE_SUPPORT */
447 #endif /* (POWER_IP_ENTER_LOW_POWER_MODE == STD_ON) */
448     else
449     {
450         /* Nothing else to be done. Ignore the power mode. */
451     }
452 }
453 
454 #if (defined(POWER_IP_ENTER_LOW_POWER_MODE) && (POWER_IP_ENTER_LOW_POWER_MODE == STD_ON))
455 /**
456 * @brief            This function returns the previous mode.
457 * @details          This function returns the previous mode.
458 *
459 * @return           Status of the previous mode.
460 *
461 * @implements Power_Ip_GetPreviousMode_Activity
462 *
463 */
Power_Ip_GetPreviousMode(void)464 Power_Ip_PowerModeType Power_Ip_GetPreviousMode(void)
465 {
466     Power_Ip_PowerModeType PowerPrevMode;
467 
468     PowerPrevMode = Power_Ip_MC_ME_GetPreviousMode();
469 
470     return PowerPrevMode;
471 }
472 #endif /* (POWER_IP_ENTER_LOW_POWER_MODE == STD_ON) */
473 
474 #if (POWER_IP_PERFORM_RESET_API == STD_ON)
475 /**
476 * @brief            This function performs a microcontroller reset.
477 * @details          This function performs a microcontroller reset by using the hardware feature of
478 *                   the microcontroller.
479 *
480 * @param[in]        HwIPsConfigPtr  Pointer to LLD configuration structure (member of
481 *                   'Mcu_ConfigType' struct).
482 *
483 * @return           void
484 *
485 * @implements Power_Ip_PerformReset_Activity
486 *
487 */
Power_Ip_PerformReset(const Power_Ip_HwIPsConfigType * HwIPsConfigPtr)488 void Power_Ip_PerformReset(const Power_Ip_HwIPsConfigType * HwIPsConfigPtr)
489 {
490 
491     POWER_IP_DEV_ASSERT(NULL_PTR != HwIPsConfigPtr);
492     /*
493      *  Performs a microcontroller reset.
494      *  A RESET mode requested via the ME_MCTL register is passed to the MC_RGM, which generates a
495      *  global system reset and initiates the reset sequence.
496      */
497 
498     Call_Power_Ip_MC_RGM_PerformReset(HwIPsConfigPtr->McRgmConfigPtr);
499 }
500 #endif /* (POWER_IP_PERFORM_RESET_API == STD_ON) */
501 
502 /**
503 * @brief            This function returns the reset reason.
504 * @details          This routine returns the Reset reason that is read from the hardware.
505 *
506 * @param[in]        None
507 *
508 * @return           void
509 *
510 * @implements Power_Ip_GetResetReason_Activity
511 *
512 */
Power_Ip_GetResetReason(void)513 Power_Ip_ResetType Power_Ip_GetResetReason(void)
514 {
515     Power_Ip_ResetType ResetReason = MCU_RESET_UNDEFINED;
516 #if (defined(POWER_IP_RESET_DURING_STANDBY_SUPPORTED))
517   #if (POWER_IP_RESET_DURING_STANDBY_SUPPORTED == STD_ON)
518     #if (defined(POWER_IP_ENTER_LOW_POWER_MODE) && (POWER_IP_ENTER_LOW_POWER_MODE == STD_ON))
519     Power_Ip_PowerModeType PreviousMode;
520     #endif /*(POWER_IP_ENTER_LOW_POWER_MODE == STD_ON) */
521   #endif
522 #endif
523 
524 #if (defined(POWER_IP_RESET_DURING_STANDBY_SUPPORTED))
525   #if (POWER_IP_RESET_DURING_STANDBY_SUPPORTED == STD_ON)
526     #if (defined(POWER_IP_ENTER_LOW_POWER_MODE) && (POWER_IP_ENTER_LOW_POWER_MODE == STD_ON))
527     if ( 0U != Call_Power_Ip_MC_RGM_ResetDuringStandby() )
528     {
529         ResetReason = MCU_WAKEUP_REASON;
530     }
531     else
532     {
533         PreviousMode = Power_Ip_MC_ME_GetPreviousMode();
534         if ( POWER_IP_SOC_STANDBY_MODE == PreviousMode )
535         {
536             ResetReason = MCU_WAKEUP_REASON;
537         }
538         else
539         {
540     #endif
541   #endif
542 #endif
543             ResetReason = (Power_Ip_ResetType)Call_Power_Ip_MC_RGM_GetResetReason();
544 #if (defined(POWER_IP_RESET_DURING_STANDBY_SUPPORTED))
545   #if (POWER_IP_RESET_DURING_STANDBY_SUPPORTED == STD_ON)
546     #if (defined(POWER_IP_ENTER_LOW_POWER_MODE) && (POWER_IP_ENTER_LOW_POWER_MODE == STD_ON))
547         }
548     }
549     #endif
550   #endif
551 #endif
552 
553     return ResetReason;
554 }
555 
556 /**
557 * @brief            This function returns the reset reason.
558 * @details          This routine returns the Reset reason that is read from the hardware.
559 *                   Called by:
560 *                       - Mcu_GetResetReason() from HLD.
561 *
562 * @param[in]        None
563 *
564 * @return           void
565 *
566 * @implements Power_Ip_GetResetRawValue_Activity
567 *
568 */
Power_Ip_GetResetRawValue(void)569 Power_Ip_RawResetType Power_Ip_GetResetRawValue(void)
570 {
571     Power_Ip_RawResetType ResetReason;
572 
573     /**  @violates @ref Mcu_IPW_c_REF_12 The comma operator shall not be used. */
574     ResetReason = Call_Power_Ip_MC_RGM_GetResetRawValue();
575     return ResetReason;
576 }
577 
578 /**
579 * @brief            This function initializes the power module.
580 * @details
581 *
582 * @param[in]        HwIPsConfigPtr  Pointer to LLD configuration structure.
583 *
584 * @return           void
585 *
586 * @implements Power_Ip_Init_Activity
587 *
588 */
Power_Ip_Init(const Power_Ip_HwIPsConfigType * HwIPsConfigPtr)589 void Power_Ip_Init(const Power_Ip_HwIPsConfigType * HwIPsConfigPtr)
590 {
591     POWER_IP_DEV_ASSERT(NULL_PTR != HwIPsConfigPtr);
592 
593 #if (defined(POWER_IP_ENABLE_USER_MODE_SUPPORT) && (STD_ON == POWER_IP_ENABLE_USER_MODE_SUPPORT))
594     /* Set user access allowed for Power */
595     Power_Ip_SetUserAccessAllowed();
596 #endif
597 
598 #if (defined(POWER_IP_DISABLE_RGM_INIT) && (STD_OFF == POWER_IP_DISABLE_RGM_INIT))
599     /* Init MCU MC_RGM part of the registers: MC_RGM_FERD, MC_RGM_FEAR, MC_RGM_FESS, MC_RGM_FBRE, clear FES & DES status registers. */
600     Call_Power_Ip_MC_RGM_ResetInit(HwIPsConfigPtr->McRgmConfigPtr);
601 #endif
602 
603 #if (defined(POWER_IP_DISABLE_PMC_INIT) && (STD_OFF == POWER_IP_DISABLE_PMC_INIT))
604     /* Init Power Management Controller digital interface */
605     Power_Ip_PMC_PowerInit(HwIPsConfigPtr->PMCConfigPtr);
606 #endif
607 
608     /* Disable the padkeeping for every Power Init */
609     Power_Ip_DCM_GPR_GlobalPadkeepingConfig(POWER_IP_GLOBAL_PADKEEPING_DISABLED);
610 
611     /* Avoid compiler warning */
612     (void)HwIPsConfigPtr;
613 }
614 
615 #ifdef POWER_IP_PMCAECONFIG_API
616 #if (POWER_IP_PMCAECONFIG_API == STD_ON)
617 /**
618 * @brief            This function performs a microcontroller reset.
619 * @details          This function performs a microcontroller reset by using the hardware feature of
620 *                   the microcontroller.
621 *                   Called by:
622 *                       - Mcu_PerformReset() from HLD.
623 *
624 * @param[in]        HwIPsConfigPtr  Pointer to LLD configuration structure (member of
625 *                   'Mcu_ConfigType' struct).
626 *
627 * @return           void
628 *
629 *
630 *
631 */
Power_Ip_PmcAeConfig(const Power_Ip_HwIPsConfigType * HwIPsConfigPtr)632 void Power_Ip_PmcAeConfig(const Power_Ip_HwIPsConfigType * HwIPsConfigPtr)
633 {
634     Power_Ip_PMC_AE_PowerInit(HwIPsConfigPtr->PMCConfigPtr);
635 }
636 #endif /* (POWER_IP_PMCAECONFIG_API == STD_ON) */
637 #endif
638 
639 #ifdef POWER_IP_AECRESETCONFIG_API
640 #if (POWER_IP_AECRESETCONFIG_API == STD_ON)
641 /**
642 * @brief            This function configure reset generator (AEC_AE)
643 * @details          This function configure reset generator (AEC_AE)
644 *                   Called by:
645 *                       - Mcu_AecResetConfig() from HLD.
646 *
647 * @param[in]        HwIPsConfigPtr  Pointer to LLD configuration structure (member of
648 *                   'Mcu_ConfigType' struct).
649 *
650 * @return           void
651 *
652 *
653 *
654 */
Power_Ip_AecResetConfig(const Power_Ip_HwIPsConfigType * HwIPsConfigPtr)655 void Power_Ip_AecResetConfig(const Power_Ip_HwIPsConfigType * HwIPsConfigPtr)
656 {
657     Power_Ip_AEC_Reset_Config(HwIPsConfigPtr->AECConfigPtr);
658 }
659 #endif /* (POWER_IP_AECRESETCONFIG_API == STD_ON) */
660 #endif
661 
662 /**
663 * @brief            This function installs a callback for reporting errors from power driver.
664 * @details
665 *
666 * @param[in]        ReportErrorsCallback    Callback to be installed.
667 *
668 * @return           void
669 *
670 * @implements Power_Ip_InstallNotificationsCallback_Activity
671 */
Power_Ip_InstallNotificationsCallback(Power_Ip_ReportErrorsCallbackType ReportErrorsCallback)672 void Power_Ip_InstallNotificationsCallback(Power_Ip_ReportErrorsCallbackType ReportErrorsCallback)
673 {
674     POWER_IP_DEV_ASSERT(NULL_PTR != ReportErrorsCallback);
675 
676     Power_Ip_pfReportErrorsCallback = ReportErrorsCallback;
677 }
678 
679 #ifdef POWER_IP_SLEEPONEXIT_SUPPORT
680   #if (POWER_IP_SLEEPONEXIT_SUPPORT == STD_ON)
681 /**
682 * @brief        The function enable SLEEPONEXIT bit.
683 * @details      The function enable SLEEPONEXIT bit.
684 *
685 * @return void
686 *
687 * @implements Power_Ip_EnableSleepOnExit_Activity
688 */
Power_Ip_EnableSleepOnExit(void)689 void Power_Ip_EnableSleepOnExit(void)
690 {
691     Call_Power_Ip_CM7_EnableSleepOnExit();
692 }
693 
694 /**
695 * @brief        The function disable SLEEPONEXIT bit.
696 * @details      The function disable SLEEPONEXIT bit.
697 *
698 * @return void
699 *
700 * @implements Power_Ip_DisableSleepOnExit_Activity
701 */
Power_Ip_DisableSleepOnExit(void)702 void Power_Ip_DisableSleepOnExit(void)
703 {
704     Call_Power_Ip_CM7_DisableSleepOnExit();
705 }
706   #endif
707 #endif
708 
709 #define MCU_STOP_SEC_CODE
710 #include "Mcu_MemMap.h"
711 
712 
713 #ifdef __cplusplus
714 }
715 #endif
716 
717 /** @} */
718