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 #include "fsl_pmc.h"
9
10 /* Component ID definition, used by tools. */
11 #ifndef FSL_COMPONENT_ID
12 #define FSL_COMPONENT_ID "platform.drivers.pmc"
13 #endif
14
15 #if (defined(FSL_FEATURE_PMC_HAS_PARAM) && FSL_FEATURE_PMC_HAS_PARAM)
16 /*!
17 * brief Gets the PMC parameter.
18 *
19 * This function gets the PMC parameter including the VLPO enable and the HVD enable.
20 *
21 * param base PMC peripheral base address.
22 * param param Pointer to PMC param structure.
23 */
PMC_GetParam(PMC_Type * base,pmc_param_t * param)24 void PMC_GetParam(PMC_Type *base, pmc_param_t *param)
25 {
26 uint32_t reg = base->PARAM;
27 ;
28 param->vlpoEnable = (bool)(reg & PMC_PARAM_VLPOE_MASK);
29 param->hvdEnable = (bool)(reg & PMC_PARAM_HVDE_MASK);
30 }
31 #endif /* FSL_FEATURE_PMC_HAS_PARAM */
32
33 /*!
34 * brief Configures the low-voltage detect setting.
35 *
36 * This function configures the low-voltage detect setting, including the trip
37 * point voltage setting, enables or disables the interrupt, enables or disables the system reset.
38 *
39 * param base PMC peripheral base address.
40 * param config Low-voltage detect configuration structure.
41 */
PMC_ConfigureLowVoltDetect(PMC_Type * base,const pmc_low_volt_detect_config_t * config)42 void PMC_ConfigureLowVoltDetect(PMC_Type *base, const pmc_low_volt_detect_config_t *config)
43 {
44 base->LVDSC1 = (uint8_t)((0U |
45 #if (defined(FSL_FEATURE_PMC_HAS_LVDV) && FSL_FEATURE_PMC_HAS_LVDV)
46 ((uint32_t)config->voltSelect << PMC_LVDSC1_LVDV_SHIFT) |
47 #endif
48 ((uint32_t)config->enableInt << PMC_LVDSC1_LVDIE_SHIFT) |
49 ((uint32_t)config->enableReset << PMC_LVDSC1_LVDRE_SHIFT)
50 /* Clear the Low Voltage Detect Flag with previous power detect setting */
51 | PMC_LVDSC1_LVDACK_MASK));
52 }
53
54 /*!
55 * brief Configures the low-voltage warning setting.
56 *
57 * This function configures the low-voltage warning setting, including the trip
58 * point voltage setting and enabling or disabling the interrupt.
59 *
60 * param base PMC peripheral base address.
61 * param config Low-voltage warning configuration structure.
62 */
PMC_ConfigureLowVoltWarning(PMC_Type * base,const pmc_low_volt_warning_config_t * config)63 void PMC_ConfigureLowVoltWarning(PMC_Type *base, const pmc_low_volt_warning_config_t *config)
64 {
65 base->LVDSC2 = (uint8_t)((0U |
66 #if (defined(FSL_FEATURE_PMC_HAS_LVWV) && FSL_FEATURE_PMC_HAS_LVWV)
67 ((uint32_t)config->voltSelect << PMC_LVDSC2_LVWV_SHIFT) |
68 #endif
69 ((uint32_t)config->enableInt << PMC_LVDSC2_LVWIE_SHIFT)
70 /* Clear the Low Voltage Warning Flag with previous power detect setting */
71 | PMC_LVDSC2_LVWACK_MASK));
72 }
73
74 #if (defined(FSL_FEATURE_PMC_HAS_HVDSC1) && FSL_FEATURE_PMC_HAS_HVDSC1)
75 /*!
76 * brief Configures the high-voltage detect setting.
77 *
78 * This function configures the high-voltage detect setting, including the trip
79 * point voltage setting, enabling or disabling the interrupt, enabling or disabling the system reset.
80 *
81 * param base PMC peripheral base address.
82 * param config High-voltage detect configuration structure.
83 */
PMC_ConfigureHighVoltDetect(PMC_Type * base,const pmc_high_volt_detect_config_t * config)84 void PMC_ConfigureHighVoltDetect(PMC_Type *base, const pmc_high_volt_detect_config_t *config)
85 {
86 base->HVDSC1 = (uint8_t)(((uint32_t)config->voltSelect << PMC_HVDSC1_HVDV_SHIFT) |
87 ((uint32_t)config->enableInt << PMC_HVDSC1_HVDIE_SHIFT) |
88 ((uint32_t)config->enableReset << PMC_HVDSC1_HVDRE_SHIFT)
89 /* Clear the High Voltage Detect Flag with previous power detect setting */
90 | PMC_HVDSC1_HVDACK_MASK);
91 }
92 #endif /* FSL_FEATURE_PMC_HAS_HVDSC1 */
93
94 #if ((defined(FSL_FEATURE_PMC_HAS_BGBE) && FSL_FEATURE_PMC_HAS_BGBE) || \
95 (defined(FSL_FEATURE_PMC_HAS_BGEN) && FSL_FEATURE_PMC_HAS_BGEN) || \
96 (defined(FSL_FEATURE_PMC_HAS_BGBDS) && FSL_FEATURE_PMC_HAS_BGBDS))
97 /*!
98 * brief Configures the PMC bandgap.
99 *
100 * This function configures the PMC bandgap, including the drive select and
101 * behavior in low-power mode.
102 *
103 * param base PMC peripheral base address.
104 * param config Pointer to the configuration structure
105 */
PMC_ConfigureBandgapBuffer(PMC_Type * base,const pmc_bandgap_buffer_config_t * config)106 void PMC_ConfigureBandgapBuffer(PMC_Type *base, const pmc_bandgap_buffer_config_t *config)
107 {
108 base->REGSC = (uint8_t)(0U
109 #if (defined(FSL_FEATURE_PMC_HAS_BGBE) && FSL_FEATURE_PMC_HAS_BGBE)
110 | ((uint32_t)config->enable << PMC_REGSC_BGBE_SHIFT)
111 #endif /* FSL_FEATURE_PMC_HAS_BGBE */
112 #if (defined(FSL_FEATURE_PMC_HAS_BGEN) && FSL_FEATURE_PMC_HAS_BGEN)
113 | (((uint32_t)config->enableInLowPowerMode << PMC_REGSC_BGEN_SHIFT))
114 #endif /* FSL_FEATURE_PMC_HAS_BGEN */
115 #if (defined(FSL_FEATURE_PMC_HAS_BGBDS) && FSL_FEATURE_PMC_HAS_BGBDS)
116 | ((uint32_t)config->drive << PMC_REGSC_BGBDS_SHIFT)
117 #endif /* FSL_FEATURE_PMC_HAS_BGBDS */
118 );
119 }
120 #endif
121