1 /*
2  * Copyright 2020-2023 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 /**
7 *   @file       Power_Ip_DCM_GPR.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_DCM_GPR.h"
35 
36 #if (defined(POWER_IP_ENABLE_USER_MODE_SUPPORT) && (STD_ON == POWER_IP_ENABLE_USER_MODE_SUPPORT))
37   #if (defined(MCAL_DCM_REG_PROT_AVAILABLE))
38     #if (STD_ON == MCAL_DCM_REG_PROT_AVAILABLE)
39       #define USER_MODE_REG_PROT_ENABLED      (STD_ON)
40       #include "RegLockMacros.h"
41     #endif /* (STD_ON == MCAL_DCM_REG_PROT_AVAILABLE) */
42   #endif
43 #endif /* (STD_ON == POWER_IP_ENABLE_USER_MODE_SUPPORT) */
44 
45 
46 /*==================================================================================================
47                                SOURCE FILE VERSION INFORMATION
48 ==================================================================================================*/
49 #define POWER_IP_DCM_GPR_VENDOR_ID_C                      43
50 #define POWER_IP_DCM_GPR_AR_RELEASE_MAJOR_VERSION_C       4
51 #define POWER_IP_DCM_GPR_AR_RELEASE_MINOR_VERSION_C       7
52 #define POWER_IP_DCM_GPR_AR_RELEASE_REVISION_VERSION_C    0
53 #define POWER_IP_DCM_GPR_SW_MAJOR_VERSION_C               3
54 #define POWER_IP_DCM_GPR_SW_MINOR_VERSION_C               0
55 #define POWER_IP_DCM_GPR_SW_PATCH_VERSION_C               0
56 
57 /*==================================================================================================
58 *                                     FILE VERSION CHECKS
59 ==================================================================================================*/
60 /* Check if Power_Ip_DCM_GPR.c file and Power_Ip_Private.h file are of the same vendor */
61 #if (POWER_IP_DCM_GPR_VENDOR_ID_C != POWER_IP_PRIVATE_VENDOR_ID)
62     #error "Power_Ip_DCM_GPR.c and Power_Ip_Private.h have different vendor ids"
63 #endif
64 
65 /* Check if Power_Ip_DCM_GPR.c file and Power_Ip_Private.h file are of the same Autosar version */
66 #if ((POWER_IP_DCM_GPR_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_PRIVATE_AR_RELEASE_MAJOR_VERSION) || \
67      (POWER_IP_DCM_GPR_AR_RELEASE_MINOR_VERSION_C != POWER_IP_PRIVATE_AR_RELEASE_MINOR_VERSION) || \
68      (POWER_IP_DCM_GPR_AR_RELEASE_REVISION_VERSION_C != POWER_IP_PRIVATE_AR_RELEASE_REVISION_VERSION) \
69     )
70     #error "AutoSar Version Numbers of Power_Ip_DCM_GPR.c and Power_Ip_Private.h are different"
71 #endif
72 
73 /* Check if Power_Ip_DCM_GPR.c file and Power_Ip_Private.h file are of the same Software version */
74 #if ((POWER_IP_DCM_GPR_SW_MAJOR_VERSION_C != POWER_IP_PRIVATE_SW_MAJOR_VERSION) || \
75      (POWER_IP_DCM_GPR_SW_MINOR_VERSION_C != POWER_IP_PRIVATE_SW_MINOR_VERSION) || \
76      (POWER_IP_DCM_GPR_SW_PATCH_VERSION_C != POWER_IP_PRIVATE_SW_PATCH_VERSION) \
77     )
78     #error "Software Version Numbers of Power_Ip_DCM_GPR.c and Power_Ip_Private.h are different"
79 #endif
80 
81 /* Check if Power_Ip_DCM_GPR.c file and Power_Ip_DCM_GPR.h file are of the same vendor */
82 #if (POWER_IP_DCM_GPR_VENDOR_ID_C != POWER_IP_DCM_GPR_VENDOR_ID)
83     #error "Power_Ip_DCM_GPR.c and Power_Ip_DCM_GPR.h have different vendor ids"
84 #endif
85 
86 /* Check if Power_Ip_DCM_GPR.c file and Power_Ip_DCM_GPR.h file are of the same Autosar version */
87 #if ((POWER_IP_DCM_GPR_AR_RELEASE_MAJOR_VERSION_C != POWER_IP_DCM_GPR_AR_RELEASE_MAJOR_VERSION) || \
88      (POWER_IP_DCM_GPR_AR_RELEASE_MINOR_VERSION_C != POWER_IP_DCM_GPR_AR_RELEASE_MINOR_VERSION) || \
89      (POWER_IP_DCM_GPR_AR_RELEASE_REVISION_VERSION_C != POWER_IP_DCM_GPR_AR_RELEASE_REVISION_VERSION) \
90     )
91     #error "AutoSar Version Numbers of Power_Ip_DCM_GPR.c and Power_Ip_DCM_GPR.h are different"
92 #endif
93 
94 /* Check if Power_Ip_DCM_GPR.c file and Power_Ip_DCM_GPR.h file are of the same Software version */
95 #if ((POWER_IP_DCM_GPR_SW_MAJOR_VERSION_C != POWER_IP_DCM_GPR_SW_MAJOR_VERSION) || \
96      (POWER_IP_DCM_GPR_SW_MINOR_VERSION_C != POWER_IP_DCM_GPR_SW_MINOR_VERSION) || \
97      (POWER_IP_DCM_GPR_SW_PATCH_VERSION_C != POWER_IP_DCM_GPR_SW_PATCH_VERSION) \
98     )
99     #error "Software Version Numbers of Power_Ip_DCM_GPR.c and Power_Ip_DCM_GPR.h are different"
100 #endif
101 
102 #if (defined(POWER_IP_ENABLE_USER_MODE_SUPPORT) && (STD_ON == POWER_IP_ENABLE_USER_MODE_SUPPORT))
103   #if (defined(MCAL_DCM_REG_PROT_AVAILABLE))
104     #if (STD_ON == MCAL_DCM_REG_PROT_AVAILABLE)
105         #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
106         /* Check if Power_Ip_DCM_GPR.c file and RegLockMacros.h file are of the same Autosar version */
107             #if ((POWER_IP_DCM_GPR_AR_RELEASE_MAJOR_VERSION_C    != REGLOCKMACROS_AR_RELEASE_MAJOR_VERSION) || \
108                 (POWER_IP_DCM_GPR_AR_RELEASE_MINOR_VERSION_C    != REGLOCKMACROS_AR_RELEASE_MINOR_VERSION))
109                 #error "AutoSar Version Numbers of Power_Ip_DCM_GPR.c and RegLockMacros.h are different"
110             #endif
111         #endif
112     #endif /* (STD_ON == MCAL_DCM_REG_PROT_AVAILABLE) */
113   #endif
114 #endif /* (STD_ON == POWER_IP_ENABLE_USER_MODE_SUPPORT) */
115 /*==================================================================================================
116                           LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
117 ==================================================================================================*/
118 
119 
120 /*==================================================================================================
121                                        LOCAL MACROS
122 ==================================================================================================*/
123 
124 
125 /*==================================================================================================
126                                        LOCAL CONSTANTS
127 ==================================================================================================*/
128 
129 
130 /*==================================================================================================
131                                        LOCAL VARIABLES
132 ==================================================================================================*/
133 
134 
135 /*==================================================================================================
136                                        GLOBAL CONSTANTS
137 ==================================================================================================*/
138 
139 
140 /*==================================================================================================
141                                        GLOBAL VARIABLES
142 ==================================================================================================*/
143 
144 /*==================================================================================================
145                                    LOCAL FUNCTION PROTOTYPES
146 ==================================================================================================*/
147 
148 
149 /*==================================================================================================
150                                        LOCAL FUNCTIONS
151 ==================================================================================================*/
152 #define MCU_START_SEC_CODE
153 
154 #include "Mcu_MemMap.h"
155 
156 
157 /*==================================================================================================
158                                        GLOBAL FUNCTIONS
159 ==================================================================================================*/
160 #if (defined(POWER_IP_ENABLE_USER_MODE_SUPPORT) && (STD_ON == POWER_IP_ENABLE_USER_MODE_SUPPORT))
161   #if (defined(MCAL_DCM_REG_PROT_AVAILABLE))
162     #if (STD_ON == MCAL_DCM_REG_PROT_AVAILABLE)
163 /**
164 * @brief            This function will enable writing in User mode by configuring REG_PROT
165 */
Power_Ip_DCM_GPR_SetUserAccessAllowed(void)166 void Power_Ip_DCM_GPR_SetUserAccessAllowed(void)
167 {
168 #if (defined(IP_DCM_GPR_BASE))
169     SET_USER_ACCESS_ALLOWED(IP_DCM_GPR_BASE, DCM_PROT_MEM_U32);
170 #endif
171 }
172     #endif
173   #endif /* MCAL_DCM_REG_PROT_AVAILABLE */
174 #endif /* POWER_IP_ENABLE_USER_MODE_SUPPORT */
175 
176 
177 /**
178 * @brief            This function configure the Device Configuration Module General-Purpose Registers
179 * @details          Control to bypass the SIRC trimming, PMC trimming and RGM DCF loading, FIRC trimming
180 *                   DCM scanning on standby exit.
181 *
182 * @param[in]        ConfigPtr   Pointer to DCM_GPR configuration structure.
183 *
184 * @return           void
185 *
186 */
Power_Ip_DCM_GPR_Config(const Power_Ip_DCM_GPR_ConfigType * ConfigPtr)187 void Power_Ip_DCM_GPR_Config(const Power_Ip_DCM_GPR_ConfigType * ConfigPtr)
188 {
189     (void)ConfigPtr;
190     uint32 TempValue = 0U;
191 
192     if (TRUE == ConfigPtr->DcmGprUnderMcuControl)
193     {
194         /* Check the boot mode is Fast Standby */
195         if (1U == ConfigPtr->BootMode)
196         {
197             /* Set Vector table address and Enable Fast Standby Exit */
198             IP_DCM_GPR->DCMRWF5 = (ConfigPtr->BootAddress) | (uint32)(ConfigPtr->BootMode);
199         }
200         else
201         {
202             /* Reset value of the field Boot_Address and Boot Mode is Normal selected */
203             IP_DCM_GPR->DCMRWF5 = 0U;
204         }
205 
206         /* Set bypassed or not bypassed for the SIRC trimming, PMC trimming and RGM DCF loading, FIRC trimming DCM scanning */
207         TempValue = IP_DCM_GPR->DCMRWF2;
208         TempValue &= ~((uint32)((uint32)DCM_GPR_DCMRWF2_SIRC_TRIM_BYP_STDBY_EXT_MASK | (uint32)DCM_GPR_DCMRWF2_PMC_TRIM_RGM_DCF_BYP_STDBY_EXT_MASK | (uint32)DCM_GPR_DCMRWF2_FIRC_TRIM_BYP_STDBY_EXT_MASK | (uint32)DCM_GPR_DCMRWF2_DCM_SCAN_BYP_STDBY_EXT_MASK));
209         TempValue |= (ConfigPtr->ConfigRegister);
210         IP_DCM_GPR->DCMRWF2 = TempValue;
211     }
212 }
213 
214 /**
215 * @brief            This function configures The global padkeeping
216 * @details          Control global padkeeping before entering low power mode
217 *
218 * @param[in]        config   Value which writing to STANDBY_IO_CONFIG bitfield.
219 *
220 * @return           void
221 *
222 */
Power_Ip_DCM_GPR_GlobalPadkeepingConfig(uint8 Config)223 void Power_Ip_DCM_GPR_GlobalPadkeepingConfig(uint8 Config)
224 {
225     uint32 TempValue = 0U;
226 
227     TempValue = IP_DCM_GPR->DCMRWF1;
228     TempValue &= ~((uint32)DCM_GPR_DCMRWF1_STANDBY_IO_CONFIG_MASK);
229     TempValue |= DCM_GPR_DCMRWF1_STANDBY_IO_CONFIG(Config);
230     IP_DCM_GPR->DCMRWF1 = TempValue;
231 }
232 #define MCU_STOP_SEC_CODE
233 
234 #include "Mcu_MemMap.h"
235 
236 
237 #ifdef __cplusplus
238 }
239 #endif
240 
241 /** @} */
242