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 #include "fsl_pmc.h"
31 
32 #if (defined(FSL_FEATURE_PMC_HAS_PARAM) && FSL_FEATURE_PMC_HAS_PARAM)
PMC_GetParam(PMC_Type * base,pmc_param_t * param)33 void PMC_GetParam(PMC_Type *base, pmc_param_t *param)
34 {
35     uint32_t reg = base->PARAM;
36     ;
37     param->vlpoEnable = (bool)(reg & PMC_PARAM_VLPOE_MASK);
38     param->hvdEnable = (bool)(reg & PMC_PARAM_HVDE_MASK);
39 }
40 #endif /* FSL_FEATURE_PMC_HAS_PARAM */
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 = (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 previouse power detect setting */
51                     | PMC_LVDSC1_LVDACK_MASK);
52 }
53 
PMC_ConfigureLowVoltWarning(PMC_Type * base,const pmc_low_volt_warning_config_t * config)54 void PMC_ConfigureLowVoltWarning(PMC_Type *base, const pmc_low_volt_warning_config_t *config)
55 {
56     base->LVDSC2 = (0U |
57 #if (defined(FSL_FEATURE_PMC_HAS_LVWV) && FSL_FEATURE_PMC_HAS_LVWV)
58                     ((uint32_t)config->voltSelect << PMC_LVDSC2_LVWV_SHIFT) |
59 #endif
60                     ((uint32_t)config->enableInt << PMC_LVDSC2_LVWIE_SHIFT)
61                     /* Clear the Low Voltage Warning Flag with previouse power detect setting */
62                     | PMC_LVDSC2_LVWACK_MASK);
63 }
64 
65 #if (defined(FSL_FEATURE_PMC_HAS_HVDSC1) && FSL_FEATURE_PMC_HAS_HVDSC1)
PMC_ConfigureHighVoltDetect(PMC_Type * base,const pmc_high_volt_detect_config_t * config)66 void PMC_ConfigureHighVoltDetect(PMC_Type *base, const pmc_high_volt_detect_config_t *config)
67 {
68     base->HVDSC1 = (((uint32_t)config->voltSelect << PMC_HVDSC1_HVDV_SHIFT) |
69                     ((uint32_t)config->enableInt << PMC_HVDSC1_HVDIE_SHIFT) |
70                     ((uint32_t)config->enableReset << PMC_HVDSC1_HVDRE_SHIFT)
71                     /* Clear the High Voltage Detect Flag with previouse power detect setting */
72                     | PMC_HVDSC1_HVDACK_MASK);
73 }
74 #endif /* FSL_FEATURE_PMC_HAS_HVDSC1 */
75 
76 #if ((defined(FSL_FEATURE_PMC_HAS_BGBE) && FSL_FEATURE_PMC_HAS_BGBE) || \
77      (defined(FSL_FEATURE_PMC_HAS_BGEN) && FSL_FEATURE_PMC_HAS_BGEN) || \
78      (defined(FSL_FEATURE_PMC_HAS_BGBDS) && FSL_FEATURE_PMC_HAS_BGBDS))
PMC_ConfigureBandgapBuffer(PMC_Type * base,const pmc_bandgap_buffer_config_t * config)79 void PMC_ConfigureBandgapBuffer(PMC_Type *base, const pmc_bandgap_buffer_config_t *config)
80 {
81     base->REGSC = (0U
82 #if (defined(FSL_FEATURE_PMC_HAS_BGBE) && FSL_FEATURE_PMC_HAS_BGBE)
83                    | ((uint32_t)config->enable << PMC_REGSC_BGBE_SHIFT)
84 #endif /* FSL_FEATURE_PMC_HAS_BGBE */
85 #if (defined(FSL_FEATURE_PMC_HAS_BGEN) && FSL_FEATURE_PMC_HAS_BGEN)
86                    | (((uint32_t)config->enableInLowPowerMode << PMC_REGSC_BGEN_SHIFT))
87 #endif /* FSL_FEATURE_PMC_HAS_BGEN */
88 #if (defined(FSL_FEATURE_PMC_HAS_BGBDS) && FSL_FEATURE_PMC_HAS_BGBDS)
89                    | ((uint32_t)config->drive << PMC_REGSC_BGBDS_SHIFT)
90 #endif /* FSL_FEATURE_PMC_HAS_BGBDS */
91                        );
92 }
93 #endif
94