fsl_power.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  4. * Copyright (c) 2016, NXP
  5. * All rights reserved.
  6. *
  7. *
  8. * Redistribution and use in source and binary forms, with or without modification,
  9. * are permitted (subject to the limitations in the disclaimer below) provided
  10. * that the following conditions are met:
  11. *
  12. * o Redistributions of source code must retain the above copyright notice, this list
  13. * of conditions and the following disclaimer.
  14. *
  15. * o Redistributions in binary form must reproduce the above copyright notice, this
  16. * list of conditions and the following disclaimer in the documentation and/or
  17. * other materials provided with the distribution.
  18. *
  19. * o Neither the name of copyright holder nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  25. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  26. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  28. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  29. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  30. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  31. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #ifndef _FSL_POWER_H_
  36. #define _FSL_POWER_H_
  37. #include "fsl_common.h"
  38. /*! @addtogroup power */
  39. /*! @{ */
  40. /*! @file */
  41. /*******************************************************************************
  42. * Definitions
  43. ******************************************************************************/
  44. /*! @name Driver version */
  45. /*@{*/
  46. /*! @brief power driver version 2.0.0. */
  47. #define FSL_POWER_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
  48. /*@}*/
  49. #define MAKE_PD_BITS(reg, slot) (((reg) << 8) | (slot))
  50. #define PDRCFG0 0x0U
  51. #define PDRCFG1 0x1U
  52. typedef enum pd_bits
  53. {
  54. kPDRUNCFG_PD_FRO_EN = MAKE_PD_BITS(PDRCFG0, 4U),
  55. kPDRUNCFG_PD_FLASH = MAKE_PD_BITS(PDRCFG0, 5U),
  56. kPDRUNCFG_PD_TEMPS = MAKE_PD_BITS(PDRCFG0, 6U),
  57. kPDRUNCFG_PD_BOD_RESET = MAKE_PD_BITS(PDRCFG0, 7U),
  58. kPDRUNCFG_PD_BOD_INTR = MAKE_PD_BITS(PDRCFG0, 8U),
  59. kPDRUNCFG_PD_ADC0 = MAKE_PD_BITS(PDRCFG0, 10U),
  60. kPDRUNCFG_PD_VDDFLASH = MAKE_PD_BITS(PDRCFG0, 11U),
  61. kPDRUNCFG_LP_VDDFLASH = MAKE_PD_BITS(PDRCFG0, 12U),
  62. kPDRUNCFG_PD_RAM0 = MAKE_PD_BITS(PDRCFG0, 13U),
  63. kPDRUNCFG_PD_RAM1 = MAKE_PD_BITS(PDRCFG0, 14U),
  64. kPDRUNCFG_PD_RAM2 = MAKE_PD_BITS(PDRCFG0, 15U),
  65. kPDRUNCFG_PD_RAMX = MAKE_PD_BITS(PDRCFG0, 16U),
  66. kPDRUNCFG_PD_ROM = MAKE_PD_BITS(PDRCFG0, 17U),
  67. kPDRUNCFG_PD_VDDHV_ENA = MAKE_PD_BITS(PDRCFG0, 18U),
  68. kPDRUNCFG_PD_VD7_ENA = MAKE_PD_BITS(PDRCFG0, 19U),
  69. kPDRUNCFG_PD_WDT_OSC = MAKE_PD_BITS(PDRCFG0, 20U),
  70. kPDRUNCFG_PD_USB0_PHY = MAKE_PD_BITS(PDRCFG0, 21U),
  71. kPDRUNCFG_PD_SYS_PLL0 = MAKE_PD_BITS(PDRCFG0, 22U),
  72. kPDRUNCFG_PD_VREFP_SW = MAKE_PD_BITS(PDRCFG0, 23U),
  73. kPDRUNCFG_PD_FLASH_BG = MAKE_PD_BITS(PDRCFG0, 25U),
  74. kPDRUNCFG_PD_ALT_FLASH_IBG = MAKE_PD_BITS(PDRCFG1, 28U),
  75. kPDRUNCFG_SEL_ALT_FLASH_IBG = MAKE_PD_BITS(PDRCFG1, 29U),
  76. /*
  77. This enum member has no practical meaning,it is used to avoid MISRA issue,
  78. user should not trying to use it.
  79. */
  80. kPDRUNCFG_ForceUnsigned = 0x80000000U
  81. } pd_bit_t;
  82. /* Power mode configuration API parameter */
  83. typedef enum _power_mode_config
  84. {
  85. kPmu_Sleep = 0U,
  86. kPmu_Deep_Sleep = 1U,
  87. kPmu_Deep_PowerDown = 2U,
  88. } power_mode_cfg_t;
  89. /*******************************************************************************
  90. * API
  91. ******************************************************************************/
  92. #ifdef __cplusplus
  93. extern "C" {
  94. #endif
  95. /*!
  96. * @name Power Configuration
  97. * @{
  98. */
  99. /*!
  100. * @brief API to enable PDRUNCFG bit in the Syscon. Note that enabling the bit powers down the peripheral
  101. *
  102. * @param en peripheral for which to enable the PDRUNCFG bit
  103. * @return none
  104. */
  105. static inline void POWER_EnablePD(pd_bit_t en)
  106. {
  107. /* PDRUNCFGSET */
  108. SYSCON->PDRUNCFGSET[(en >> 8UL)] = (1UL << (en & 0xffU));
  109. }
  110. /*!
  111. * @brief API to disable PDRUNCFG bit in the Syscon. Note that disabling the bit powers up the peripheral
  112. *
  113. * @param en peripheral for which to disable the PDRUNCFG bit
  114. * @return none
  115. */
  116. static inline void POWER_DisablePD(pd_bit_t en)
  117. {
  118. /* PDRUNCFGCLR */
  119. SYSCON->PDRUNCFGCLR[(en >> 8UL)] = (1UL << (en & 0xffU));
  120. }
  121. /*!
  122. * @brief API to enable deep sleep bit in the ARM Core.
  123. *
  124. * @return none
  125. */
  126. static inline void POWER_EnableDeepSleep(void)
  127. {
  128. SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
  129. }
  130. /*!
  131. * @brief API to disable deep sleep bit in the ARM Core.
  132. *
  133. * @return none
  134. */
  135. static inline void POWER_DisableDeepSleep(void)
  136. {
  137. SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
  138. }
  139. /*!
  140. * @brief API to power down flash controller.
  141. *
  142. * @return none
  143. */
  144. static inline void POWER_PowerDownFlash(void)
  145. {
  146. /* note, we retain flash trim to make waking back up faster */
  147. SYSCON->PDRUNCFGSET[0] =
  148. SYSCON_PDRUNCFG_LP_VDDFLASH_MASK | SYSCON_PDRUNCFG_PD_VDDHV_ENA_MASK | SYSCON_PDRUNCFG_PD_FLASH_BG_MASK;
  149. /* TURN OFF clock for Flash Controller (only needed for FLASH programming, will be turned on by ROM API) */
  150. CLOCK_DisableClock(kCLOCK_Flash);
  151. /* TURN OFF clock for Flash Accelerator */
  152. CLOCK_DisableClock(kCLOCK_Fmc);
  153. }
  154. /*!
  155. * @brief API to power up flash controller.
  156. *
  157. * @return none
  158. */
  159. static inline void POWER_PowerUpFlash(void)
  160. {
  161. SYSCON->PDRUNCFGCLR[0] = SYSCON_PDRUNCFG_LP_VDDFLASH_MASK | SYSCON_PDRUNCFG_PD_VDDHV_ENA_MASK;
  162. /* TURN ON clock for flash Accelerator */
  163. CLOCK_EnableClock(kCLOCK_Fmc);
  164. /* TURN ON clock for flash Controller */
  165. CLOCK_EnableClock(kCLOCK_Flash);
  166. }
  167. /*!
  168. * @brief Power Library API to enter different power mode.
  169. *
  170. * @param exclude_from_pd Bit mask of the PDRUNCFG bits that needs to be powered on during deep sleep
  171. * @return none
  172. */
  173. void POWER_EnterPowerMode(power_mode_cfg_t mode, uint64_t exclude_from_pd);
  174. /*!
  175. * @brief Power Library API to enter sleep mode.
  176. *
  177. * @return none
  178. */
  179. void POWER_EnterSleep(void);
  180. /*!
  181. * @brief Power Library API to enter deep sleep mode.
  182. *
  183. * @param exclude_from_pd Bit mask of the PDRUNCFG bits that needs to be powered on during deep sleep
  184. * @return none
  185. */
  186. void POWER_EnterDeepSleep(uint64_t exclude_from_pd);
  187. /*!
  188. * @brief Power Library API to enter deep power down mode.
  189. *
  190. * @param exclude_from_pd Bit mask of the PDRUNCFG bits that needs to be powered on during deep power down mode,
  191. * but this is has no effect as the voltages are cut off.
  192. * @return none
  193. */
  194. void POWER_EnterDeepPowerDown(uint64_t exclude_from_pd);
  195. /*!
  196. * @brief Power Library API to choose normal regulation and set the voltage for the desired operating frequency.
  197. *
  198. * @param freq - The desired frequency at which the part would like to operate,
  199. * note that the voltage and flash wait states should be set before changing frequency
  200. * @return none
  201. */
  202. void POWER_SetVoltageForFreq(uint32_t freq);
  203. /*!
  204. * @brief Power Library API to choose low power regulation and set the voltage for the desired operating frequency.
  205. *
  206. * @param freq - The desired frequency at which the part would like to operate,
  207. * note only 12MHz and 48Mhz are supported
  208. * @return none
  209. */
  210. void POWER_SetLowPowerVoltageForFreq(uint32_t freq);
  211. /*!
  212. * @brief Power Library API to return the library version.
  213. *
  214. * @return version number of the power library
  215. */
  216. uint32_t POWER_GetLibVersion(void);
  217. /* @} */
  218. #ifdef __cplusplus
  219. }
  220. #endif
  221. /*! @} */
  222. #endif /* _FSL_POWER_H_ */