fsl_pmc.c 4.7 KB

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