fsl_pmc.c 4.4 KB

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