Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

121 rader
4.8 KiB

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