1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * Copyright 2016-2019 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 #ifndef _FSL_PMC_H_
9 #define _FSL_PMC_H_
10 
11 #include "fsl_common.h"
12 
13 /*! @addtogroup pmc */
14 /*! @{ */
15 
16 /*******************************************************************************
17  * Definitions
18  ******************************************************************************/
19 
20 /*! @name Driver version */
21 /*@{*/
22 /*! @brief PMC driver version */
23 #define FSL_PMC_DRIVER_VERSION (MAKE_VERSION(2, 0, 3)) /*!< Version 2.0.3. */
24 /*@}*/
25 
26 #if (defined(FSL_FEATURE_PMC_HAS_LVDV) && FSL_FEATURE_PMC_HAS_LVDV)
27 /*!
28  * @brief Low-voltage Detect Voltage Select
29  */
30 typedef enum _pmc_low_volt_detect_volt_select
31 {
32     kPMC_LowVoltDetectLowTrip  = 0U, /*!< Low-trip point selected (VLVD = VLVDL )*/
33     kPMC_LowVoltDetectHighTrip = 1U  /*!< High-trip point selected (VLVD = VLVDH )*/
34 } pmc_low_volt_detect_volt_select_t;
35 #endif
36 
37 #if (defined(FSL_FEATURE_PMC_HAS_LVWV) && FSL_FEATURE_PMC_HAS_LVWV)
38 /*!
39  * @brief Low-voltage Warning Voltage Select
40  */
41 typedef enum _pmc_low_volt_warning_volt_select
42 {
43     kPMC_LowVoltWarningLowTrip  = 0U, /*!< Low-trip point selected (VLVW = VLVW1)*/
44     kPMC_LowVoltWarningMid1Trip = 1U, /*!< Mid 1 trip point selected (VLVW = VLVW2)*/
45     kPMC_LowVoltWarningMid2Trip = 2U, /*!< Mid 2 trip point selected (VLVW = VLVW3)*/
46     kPMC_LowVoltWarningHighTrip = 3U  /*!< High-trip point selected (VLVW = VLVW4)*/
47 } pmc_low_volt_warning_volt_select_t;
48 #endif
49 
50 #if (defined(FSL_FEATURE_PMC_HAS_HVDSC1) && FSL_FEATURE_PMC_HAS_HVDSC1)
51 /*!
52  * @brief High-voltage Detect Voltage Select
53  */
54 typedef enum _pmc_high_volt_detect_volt_select
55 {
56     kPMC_HighVoltDetectLowTrip  = 0U, /*!< Low-trip point selected (VHVD = VHVDL )*/
57     kPMC_HighVoltDetectHighTrip = 1U  /*!< High-trip point selected (VHVD = VHVDH )*/
58 } pmc_high_volt_detect_volt_select_t;
59 #endif /* FSL_FEATURE_PMC_HAS_HVDSC1 */
60 
61 #if (defined(FSL_FEATURE_PMC_HAS_BGBDS) && FSL_FEATURE_PMC_HAS_BGBDS)
62 /*!
63  * @brief Bandgap Buffer Drive Select.
64  */
65 typedef enum _pmc_bandgap_buffer_drive_select
66 {
67     kPMC_BandgapBufferDriveLow  = 0U, /*!< Low-drive.  */
68     kPMC_BandgapBufferDriveHigh = 1U  /*!< High-drive. */
69 } pmc_bandgap_buffer_drive_select_t;
70 #endif /* FSL_FEATURE_PMC_HAS_BGBDS */
71 
72 #if (defined(FSL_FEATURE_PMC_HAS_VLPO) && FSL_FEATURE_PMC_HAS_VLPO)
73 /*!
74  * @brief VLPx Option
75  */
76 typedef enum _pmc_vlp_freq_option
77 {
78     kPMC_FreqRestrict   = 0U, /*!< Frequency is restricted in VLPx mode. */
79     kPMC_FreqUnrestrict = 1U  /*!< Frequency is unrestricted in VLPx mode. */
80 } pmc_vlp_freq_mode_t;
81 #endif /* FSL_FEATURE_PMC_HAS_VLPO */
82 
83 #if (defined(FSL_FEATURE_PMC_HAS_VERID) && FSL_FEATURE_PMC_HAS_VERID)
84 /*!
85  @brief IP version ID definition.
86  */
87 typedef struct _pmc_version_id
88 {
89     uint16_t feature; /*!< Feature Specification Number. */
90     uint8_t minor;    /*!< Minor version number.         */
91     uint8_t major;    /*!< Major version number.         */
92 } pmc_version_id_t;
93 #endif /* FSL_FEATURE_PMC_HAS_VERID */
94 
95 #if (defined(FSL_FEATURE_PMC_HAS_PARAM) && FSL_FEATURE_PMC_HAS_PARAM)
96 /*! @brief IP parameter definition. */
97 typedef struct _pmc_param
98 {
99     bool vlpoEnable; /*!< VLPO enable. */
100     bool hvdEnable;  /*!< HVD enable.  */
101 } pmc_param_t;
102 #endif /* FSL_FEATURE_PMC_HAS_PARAM */
103 
104 /*!
105  * @brief Low-voltage Detect Configuration Structure
106  */
107 typedef struct _pmc_low_volt_detect_config
108 {
109     bool enableInt;   /*!< Enable interrupt when Low-voltage detect*/
110     bool enableReset; /*!< Enable system reset when Low-voltage detect*/
111 #if (defined(FSL_FEATURE_PMC_HAS_LVDV) && FSL_FEATURE_PMC_HAS_LVDV)
112     pmc_low_volt_detect_volt_select_t voltSelect; /*!< Low-voltage detect trip point voltage selection*/
113 #endif
114 } pmc_low_volt_detect_config_t;
115 
116 /*!
117  * @brief Low-voltage Warning Configuration Structure
118  */
119 typedef struct _pmc_low_volt_warning_config
120 {
121     bool enableInt; /*!< Enable interrupt when low-voltage warning*/
122 #if (defined(FSL_FEATURE_PMC_HAS_LVWV) && FSL_FEATURE_PMC_HAS_LVWV)
123     pmc_low_volt_warning_volt_select_t voltSelect; /*!< Low-voltage warning trip point voltage selection*/
124 #endif
125 } pmc_low_volt_warning_config_t;
126 
127 #if (defined(FSL_FEATURE_PMC_HAS_HVDSC1) && FSL_FEATURE_PMC_HAS_HVDSC1)
128 /*!
129  * @brief High-voltage Detect Configuration Structure
130  */
131 typedef struct _pmc_high_volt_detect_config
132 {
133     bool enableInt;                                /*!< Enable interrupt when high-voltage detect*/
134     bool enableReset;                              /*!< Enable system reset when high-voltage detect*/
135     pmc_high_volt_detect_volt_select_t voltSelect; /*!< High-voltage detect trip point voltage selection*/
136 } pmc_high_volt_detect_config_t;
137 #endif /* FSL_FEATURE_PMC_HAS_HVDSC1 */
138 
139 #if ((defined(FSL_FEATURE_PMC_HAS_BGBE) && FSL_FEATURE_PMC_HAS_BGBE) || \
140      (defined(FSL_FEATURE_PMC_HAS_BGEN) && FSL_FEATURE_PMC_HAS_BGEN) || \
141      (defined(FSL_FEATURE_PMC_HAS_BGBDS) && FSL_FEATURE_PMC_HAS_BGBDS))
142 /*!
143  * @brief Bandgap Buffer configuration.
144  */
145 typedef struct _pmc_bandgap_buffer_config
146 {
147 #if (defined(FSL_FEATURE_PMC_HAS_BGBE) && FSL_FEATURE_PMC_HAS_BGBE)
148     bool enable; /*!< Enable bandgap buffer.                   */
149 #endif
150 #if (defined(FSL_FEATURE_PMC_HAS_BGEN) && FSL_FEATURE_PMC_HAS_BGEN)
151     bool enableInLowPowerMode; /*!< Enable bandgap buffer in low-power mode. */
152 #endif                         /* FSL_FEATURE_PMC_HAS_BGEN */
153 #if (defined(FSL_FEATURE_PMC_HAS_BGBDS) && FSL_FEATURE_PMC_HAS_BGBDS)
154     pmc_bandgap_buffer_drive_select_t drive; /*!< Bandgap buffer drive select.             */
155 #endif                                       /* FSL_FEATURE_PMC_HAS_BGBDS */
156 } pmc_bandgap_buffer_config_t;
157 #endif
158 
159 /*******************************************************************************
160  * API
161  ******************************************************************************/
162 
163 #if defined(__cplusplus)
164 extern "C" {
165 #endif /* __cplusplus*/
166 
167 /*! @name Power Management Controller Control APIs*/
168 /*@{*/
169 
170 #if (defined(FSL_FEATURE_PMC_HAS_VERID) && FSL_FEATURE_PMC_HAS_VERID)
171 /*!
172  * @brief Gets the PMC version ID.
173  *
174  * This function gets the PMC version ID, including major version number,
175  * minor version number, and a feature specification number.
176  *
177  * @param base PMC peripheral base address.
178  * @param versionId     Pointer to version ID structure.
179  */
PMC_GetVersionId(PMC_Type * base,pmc_version_id_t * versionId)180 static inline void PMC_GetVersionId(PMC_Type *base, pmc_version_id_t *versionId)
181 {
182     union
183     {
184         pmc_version_id_t vid;
185         uint32_t u32;
186     } pmcVID;
187 
188     pmcVID.u32 = base->VERID;
189     *versionId = pmcVID.vid;
190 }
191 #endif /* FSL_FEATURE_PMC_HAS_VERID */
192 
193 #if (defined(FSL_FEATURE_PMC_HAS_PARAM) && FSL_FEATURE_PMC_HAS_PARAM)
194 /*!
195  * @brief Gets the PMC parameter.
196  *
197  * This function gets the PMC parameter including the VLPO enable and the HVD enable.
198  *
199  * @param base PMC peripheral base address.
200  * @param param         Pointer to PMC param structure.
201  */
202 void PMC_GetParam(PMC_Type *base, pmc_param_t *param);
203 #endif
204 
205 /*!
206  * @brief Configures the low-voltage detect setting.
207  *
208  * This function configures the low-voltage detect setting, including the trip
209  * point voltage setting, enables or disables the interrupt, enables or disables the system reset.
210  *
211  * @param base PMC peripheral base address.
212  * @param config  Low-voltage detect configuration structure.
213  */
214 void PMC_ConfigureLowVoltDetect(PMC_Type *base, const pmc_low_volt_detect_config_t *config);
215 
216 /*!
217  * @brief Gets the Low-voltage Detect Flag status.
218  *
219  * This function  reads the current LVDF status. If it returns 1, a low-voltage event is detected.
220  *
221  * @param base PMC peripheral base address.
222  * @return Current low-voltage detect flag
223  *                - true: Low-voltage detected
224  *                - false: Low-voltage not detected
225  */
PMC_GetLowVoltDetectFlag(PMC_Type * base)226 static inline bool PMC_GetLowVoltDetectFlag(PMC_Type *base)
227 {
228     if (0U != (base->LVDSC1 & PMC_LVDSC1_LVDF_MASK))
229     {
230         return true;
231     }
232     else
233     {
234         return false;
235     }
236 }
237 
238 /*!
239  * @brief Acknowledges clearing the Low-voltage Detect flag.
240  *
241  * This function acknowledges the low-voltage detection errors (write 1 to
242  * clear LVDF).
243  *
244  * @param base PMC peripheral base address.
245  */
PMC_ClearLowVoltDetectFlag(PMC_Type * base)246 static inline void PMC_ClearLowVoltDetectFlag(PMC_Type *base)
247 {
248     base->LVDSC1 |= PMC_LVDSC1_LVDACK_MASK;
249 }
250 
251 /*!
252  * @brief Configures the low-voltage warning setting.
253  *
254  * This function configures the low-voltage warning setting, including the trip
255  * point voltage setting and enabling or disabling the interrupt.
256  *
257  * @param base PMC peripheral base address.
258  * @param config  Low-voltage warning configuration structure.
259  */
260 void PMC_ConfigureLowVoltWarning(PMC_Type *base, const pmc_low_volt_warning_config_t *config);
261 
262 /*!
263  * @brief Gets the Low-voltage Warning Flag status.
264  *
265  * This function polls the current LVWF status. When 1 is returned, it
266  * indicates a low-voltage warning event. LVWF is set when V Supply transitions
267  * below the trip point or after reset and V Supply is already below the V LVW.
268  *
269  * @param base PMC peripheral base address.
270  * @return Current LVWF status
271  *                  - true: Low-voltage Warning Flag is set.
272  *                  - false: the  Low-voltage Warning does not happen.
273  */
PMC_GetLowVoltWarningFlag(PMC_Type * base)274 static inline bool PMC_GetLowVoltWarningFlag(PMC_Type *base)
275 {
276     if (0U != (base->LVDSC2 & PMC_LVDSC2_LVWF_MASK))
277     {
278         return true;
279     }
280     else
281     {
282         return false;
283     }
284 }
285 
286 /*!
287  * @brief Acknowledges the Low-voltage Warning flag.
288  *
289  * This function acknowledges the low voltage warning errors (write 1 to
290  * clear LVWF).
291  *
292  * @param base PMC peripheral base address.
293  */
PMC_ClearLowVoltWarningFlag(PMC_Type * base)294 static inline void PMC_ClearLowVoltWarningFlag(PMC_Type *base)
295 {
296     base->LVDSC2 |= PMC_LVDSC2_LVWACK_MASK;
297 }
298 
299 #if (defined(FSL_FEATURE_PMC_HAS_HVDSC1) && FSL_FEATURE_PMC_HAS_HVDSC1)
300 /*!
301  * @brief Configures the high-voltage detect setting.
302  *
303  * This function configures the high-voltage detect setting, including the trip
304  * point voltage setting, enabling or disabling the interrupt, enabling or disabling the system reset.
305  *
306  * @param base PMC peripheral base address.
307  * @param config  High-voltage detect configuration structure.
308  */
309 void PMC_ConfigureHighVoltDetect(PMC_Type *base, const pmc_high_volt_detect_config_t *config);
310 
311 /*!
312  * @brief Gets the High-voltage Detect Flag status.
313  *
314  * This function  reads the current HVDF status. If it returns 1, a low
315  * voltage event is detected.
316  *
317  * @param base PMC peripheral base address.
318  * @return Current high-voltage detect flag
319  *                - true: High-voltage detected
320  *                - false: High-voltage not detected
321  */
PMC_GetHighVoltDetectFlag(PMC_Type * base)322 static inline bool PMC_GetHighVoltDetectFlag(PMC_Type *base)
323 {
324     return (bool)(base->HVDSC1 & PMC_HVDSC1_HVDF_MASK);
325 }
326 
327 /*!
328  * @brief Acknowledges clearing the High-voltage Detect flag.
329  *
330  * This function acknowledges the high-voltage detection errors (write 1 to
331  * clear HVDF).
332  *
333  * @param base PMC peripheral base address.
334  */
PMC_ClearHighVoltDetectFlag(PMC_Type * base)335 static inline void PMC_ClearHighVoltDetectFlag(PMC_Type *base)
336 {
337     base->HVDSC1 |= PMC_HVDSC1_HVDACK_MASK;
338 }
339 #endif /* FSL_FEATURE_PMC_HAS_HVDSC1 */
340 
341 #if ((defined(FSL_FEATURE_PMC_HAS_BGBE) && FSL_FEATURE_PMC_HAS_BGBE) || \
342      (defined(FSL_FEATURE_PMC_HAS_BGEN) && FSL_FEATURE_PMC_HAS_BGEN) || \
343      (defined(FSL_FEATURE_PMC_HAS_BGBDS) && FSL_FEATURE_PMC_HAS_BGBDS))
344 /*!
345  * @brief Configures the PMC bandgap.
346  *
347  * This function configures the PMC bandgap, including the drive select and
348  * behavior in low-power mode.
349  *
350  * @param base PMC peripheral base address.
351  * @param config Pointer to the configuration structure
352  */
353 void PMC_ConfigureBandgapBuffer(PMC_Type *base, const pmc_bandgap_buffer_config_t *config);
354 #endif
355 
356 #if (defined(FSL_FEATURE_PMC_HAS_ACKISO) && FSL_FEATURE_PMC_HAS_ACKISO)
357 /*!
358  * @brief Gets the acknowledge Peripherals and I/O pads isolation flag.
359  *
360  * This function  reads the Acknowledge Isolation setting that indicates
361  * whether certain peripherals and the I/O pads are in a latched state as
362  * a result of having been in the VLLS mode.
363  *
364  * @param base PMC peripheral base address.
365  * @param base  Base address for current PMC instance.
366  * @return ACK isolation
367  *               0 - Peripherals and I/O pads are in a normal run state.
368  *               1 - Certain peripherals and I/O pads are in an isolated and
369  *                   latched state.
370  */
PMC_GetPeriphIOIsolationFlag(PMC_Type * base)371 static inline bool PMC_GetPeriphIOIsolationFlag(PMC_Type *base)
372 {
373     return (0U != (base->REGSC & PMC_REGSC_ACKISO_MASK)) ? true : false;
374 }
375 
376 /*!
377  * @brief Acknowledges the isolation flag to Peripherals and I/O pads.
378  *
379  * This function  clears the ACK Isolation flag. Writing one to this setting
380  * when it is set releases the I/O pads and certain peripherals to their normal
381  * run mode state.
382  *
383  * @param base PMC peripheral base address.
384  */
PMC_ClearPeriphIOIsolationFlag(PMC_Type * base)385 static inline void PMC_ClearPeriphIOIsolationFlag(PMC_Type *base)
386 {
387     base->REGSC |= PMC_REGSC_ACKISO_MASK;
388 }
389 #endif /* FSL_FEATURE_PMC_HAS_ACKISO */
390 
391 #if (defined(FSL_FEATURE_PMC_HAS_REGONS) && FSL_FEATURE_PMC_HAS_REGONS)
392 /*!
393  * @brief Gets the regulator regulation status.
394  *
395  * This function  returns the regulator to run a regulation status. It provides
396  * the current status of the internal voltage regulator.
397  *
398  * @param base PMC peripheral base address.
399  * @param base  Base address for current PMC instance.
400  * @return Regulation status
401  *               0 - Regulator is in a stop regulation or in transition to/from the regulation.
402  *               1 - Regulator is in a run regulation.
403  *
404  */
PMC_IsRegulatorInRunRegulation(PMC_Type * base)405 static inline bool PMC_IsRegulatorInRunRegulation(PMC_Type *base)
406 {
407     if (0U != (base->REGSC & PMC_REGSC_REGONS_MASK))
408     {
409         return true;
410     }
411     else
412     {
413         return false;
414     }
415 }
416 #endif /* FSL_FEATURE_PMC_HAS_REGONS */
417 
418 /*@}*/
419 
420 #if defined(__cplusplus)
421 }
422 #endif /* __cplusplus*/
423 
424 /*! @}*/
425 
426 #endif /* _FSL_PMC_H_*/
427