fsl_pmc.c 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include "fsl_pmc.h"
  35. #if (defined(FSL_FEATURE_PMC_HAS_PARAM) && FSL_FEATURE_PMC_HAS_PARAM)
  36. void PMC_GetParam(PMC_Type *base, pmc_param_t *param)
  37. {
  38. uint32_t reg = base->PARAM;
  39. ;
  40. param->vlpoEnable = (bool)(reg & PMC_PARAM_VLPOE_MASK);
  41. param->hvdEnable = (bool)(reg & PMC_PARAM_HVDE_MASK);
  42. }
  43. #endif /* FSL_FEATURE_PMC_HAS_PARAM */
  44. void PMC_ConfigureLowVoltDetect(PMC_Type *base, const pmc_low_volt_detect_config_t *config)
  45. {
  46. base->LVDSC1 = (0U |
  47. #if (defined(FSL_FEATURE_PMC_HAS_LVDV) && FSL_FEATURE_PMC_HAS_LVDV)
  48. ((uint32_t)config->voltSelect << PMC_LVDSC1_LVDV_SHIFT) |
  49. #endif
  50. ((uint32_t)config->enableInt << PMC_LVDSC1_LVDIE_SHIFT) |
  51. ((uint32_t)config->enableReset << PMC_LVDSC1_LVDRE_SHIFT)
  52. /* Clear the Low Voltage Detect Flag with previouse power detect setting */
  53. | PMC_LVDSC1_LVDACK_MASK);
  54. }
  55. void PMC_ConfigureLowVoltWarning(PMC_Type *base, const pmc_low_volt_warning_config_t *config)
  56. {
  57. base->LVDSC2 = (0U |
  58. #if (defined(FSL_FEATURE_PMC_HAS_LVWV) && FSL_FEATURE_PMC_HAS_LVWV)
  59. ((uint32_t)config->voltSelect << PMC_LVDSC2_LVWV_SHIFT) |
  60. #endif
  61. ((uint32_t)config->enableInt << PMC_LVDSC2_LVWIE_SHIFT)
  62. /* Clear the Low Voltage Warning Flag with previouse power detect setting */
  63. | PMC_LVDSC2_LVWACK_MASK);
  64. }
  65. #if (defined(FSL_FEATURE_PMC_HAS_HVDSC1) && FSL_FEATURE_PMC_HAS_HVDSC1)
  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. #if ((defined(FSL_FEATURE_PMC_HAS_BGBE) && FSL_FEATURE_PMC_HAS_BGBE) || \
  76. (defined(FSL_FEATURE_PMC_HAS_BGEN) && FSL_FEATURE_PMC_HAS_BGEN) || \
  77. (defined(FSL_FEATURE_PMC_HAS_BGBDS) && FSL_FEATURE_PMC_HAS_BGBDS))
  78. void PMC_ConfigureBandgapBuffer(PMC_Type *base, const pmc_bandgap_buffer_config_t *config)
  79. {
  80. base->REGSC = (0U
  81. #if (defined(FSL_FEATURE_PMC_HAS_BGBE) && FSL_FEATURE_PMC_HAS_BGBE)
  82. | ((uint32_t)config->enable << PMC_REGSC_BGBE_SHIFT)
  83. #endif /* FSL_FEATURE_PMC_HAS_BGBE */
  84. #if (defined(FSL_FEATURE_PMC_HAS_BGEN) && FSL_FEATURE_PMC_HAS_BGEN)
  85. | (((uint32_t)config->enableInLowPowerMode << PMC_REGSC_BGEN_SHIFT))
  86. #endif /* FSL_FEATURE_PMC_HAS_BGEN */
  87. #if (defined(FSL_FEATURE_PMC_HAS_BGBDS) && FSL_FEATURE_PMC_HAS_BGBDS)
  88. | ((uint32_t)config->drive << PMC_REGSC_BGBDS_SHIFT)
  89. #endif /* FSL_FEATURE_PMC_HAS_BGBDS */
  90. );
  91. }
  92. #endif