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