fsl_pmc.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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. #ifndef _FSL_PMC_H_
  35. #define _FSL_PMC_H_
  36. #include "fsl_common.h"
  37. /*! @addtogroup pmc */
  38. /*! @{ */
  39. /*******************************************************************************
  40. * Definitions
  41. ******************************************************************************/
  42. /*! @name Driver version */
  43. /*@{*/
  44. /*! @brief PMC driver version */
  45. #define FSL_PMC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0. */
  46. /*@}*/
  47. #if (defined(FSL_FEATURE_PMC_HAS_LVDV) && FSL_FEATURE_PMC_HAS_LVDV)
  48. /*!
  49. * @brief Low-voltage Detect Voltage Select
  50. */
  51. typedef enum _pmc_low_volt_detect_volt_select
  52. {
  53. kPMC_LowVoltDetectLowTrip = 0U, /*!< Low-trip point selected (VLVD = VLVDL )*/
  54. kPMC_LowVoltDetectHighTrip = 1U /*!< High-trip point selected (VLVD = VLVDH )*/
  55. } pmc_low_volt_detect_volt_select_t;
  56. #endif
  57. #if (defined(FSL_FEATURE_PMC_HAS_LVWV) && FSL_FEATURE_PMC_HAS_LVWV)
  58. /*!
  59. * @brief Low-voltage Warning Voltage Select
  60. */
  61. typedef enum _pmc_low_volt_warning_volt_select
  62. {
  63. kPMC_LowVoltWarningLowTrip = 0U, /*!< Low-trip point selected (VLVW = VLVW1)*/
  64. kPMC_LowVoltWarningMid1Trip = 1U, /*!< Mid 1 trip point selected (VLVW = VLVW2)*/
  65. kPMC_LowVoltWarningMid2Trip = 2U, /*!< Mid 2 trip point selected (VLVW = VLVW3)*/
  66. kPMC_LowVoltWarningHighTrip = 3U /*!< High-trip point selected (VLVW = VLVW4)*/
  67. } pmc_low_volt_warning_volt_select_t;
  68. #endif
  69. #if (defined(FSL_FEATURE_PMC_HAS_HVDSC1) && FSL_FEATURE_PMC_HAS_HVDSC1)
  70. /*!
  71. * @brief High-voltage Detect Voltage Select
  72. */
  73. typedef enum _pmc_high_volt_detect_volt_select
  74. {
  75. kPMC_HighVoltDetectLowTrip = 0U, /*!< Low-trip point selected (VHVD = VHVDL )*/
  76. kPMC_HighVoltDetectHighTrip = 1U /*!< High-trip point selected (VHVD = VHVDH )*/
  77. } pmc_high_volt_detect_volt_select_t;
  78. #endif /* FSL_FEATURE_PMC_HAS_HVDSC1 */
  79. #if (defined(FSL_FEATURE_PMC_HAS_BGBDS) && FSL_FEATURE_PMC_HAS_BGBDS)
  80. /*!
  81. * @brief Bandgap Buffer Drive Select.
  82. */
  83. typedef enum _pmc_bandgap_buffer_drive_select
  84. {
  85. kPMC_BandgapBufferDriveLow = 0U, /*!< Low-drive. */
  86. kPMC_BandgapBufferDriveHigh = 1U /*!< High-drive. */
  87. } pmc_bandgap_buffer_drive_select_t;
  88. #endif /* FSL_FEATURE_PMC_HAS_BGBDS */
  89. #if (defined(FSL_FEATURE_PMC_HAS_VLPO) && FSL_FEATURE_PMC_HAS_VLPO)
  90. /*!
  91. * @brief VLPx Option
  92. */
  93. typedef enum _pmc_vlp_freq_option
  94. {
  95. kPMC_FreqRestrict = 0U, /*!< Frequency is restricted in VLPx mode. */
  96. kPMC_FreqUnrestrict = 1U /*!< Frequency is unrestricted in VLPx mode. */
  97. } pmc_vlp_freq_mode_t;
  98. #endif /* FSL_FEATURE_PMC_HAS_VLPO */
  99. #if (defined(FSL_FEATURE_PMC_HAS_VERID) && FSL_FEATURE_PMC_HAS_VERID)
  100. /*!
  101. @brief IP version ID definition.
  102. */
  103. typedef struct _pmc_version_id
  104. {
  105. uint16_t feature; /*!< Feature Specification Number. */
  106. uint8_t minor; /*!< Minor version number. */
  107. uint8_t major; /*!< Major version number. */
  108. } pmc_version_id_t;
  109. #endif /* FSL_FEATURE_PMC_HAS_VERID */
  110. #if (defined(FSL_FEATURE_PMC_HAS_PARAM) && FSL_FEATURE_PMC_HAS_PARAM)
  111. /*! @brief IP parameter definition. */
  112. typedef struct _pmc_param
  113. {
  114. bool vlpoEnable; /*!< VLPO enable. */
  115. bool hvdEnable; /*!< HVD enable. */
  116. } pmc_param_t;
  117. #endif /* FSL_FEATURE_PMC_HAS_PARAM */
  118. /*!
  119. * @brief Low-voltage Detect Configuration Structure
  120. */
  121. typedef struct _pmc_low_volt_detect_config
  122. {
  123. bool enableInt; /*!< Enable interrupt when Low-voltage detect*/
  124. bool enableReset; /*!< Enable system reset when Low-voltage detect*/
  125. #if (defined(FSL_FEATURE_PMC_HAS_LVDV) && FSL_FEATURE_PMC_HAS_LVDV)
  126. pmc_low_volt_detect_volt_select_t voltSelect; /*!< Low-voltage detect trip point voltage selection*/
  127. #endif
  128. } pmc_low_volt_detect_config_t;
  129. /*!
  130. * @brief Low-voltage Warning Configuration Structure
  131. */
  132. typedef struct _pmc_low_volt_warning_config
  133. {
  134. bool enableInt; /*!< Enable interrupt when low-voltage warning*/
  135. #if (defined(FSL_FEATURE_PMC_HAS_LVWV) && FSL_FEATURE_PMC_HAS_LVWV)
  136. pmc_low_volt_warning_volt_select_t voltSelect; /*!< Low-voltage warning trip point voltage selection*/
  137. #endif
  138. } pmc_low_volt_warning_config_t;
  139. #if (defined(FSL_FEATURE_PMC_HAS_HVDSC1) && FSL_FEATURE_PMC_HAS_HVDSC1)
  140. /*!
  141. * @brief High-voltage Detect Configuration Structure
  142. */
  143. typedef struct _pmc_high_volt_detect_config
  144. {
  145. bool enableInt; /*!< Enable interrupt when high-voltage detect*/
  146. bool enableReset; /*!< Enable system reset when high-voltage detect*/
  147. pmc_high_volt_detect_volt_select_t voltSelect; /*!< High-voltage detect trip point voltage selection*/
  148. } pmc_high_volt_detect_config_t;
  149. #endif /* FSL_FEATURE_PMC_HAS_HVDSC1 */
  150. #if ((defined(FSL_FEATURE_PMC_HAS_BGBE) && FSL_FEATURE_PMC_HAS_BGBE) || \
  151. (defined(FSL_FEATURE_PMC_HAS_BGEN) && FSL_FEATURE_PMC_HAS_BGEN) || \
  152. (defined(FSL_FEATURE_PMC_HAS_BGBDS) && FSL_FEATURE_PMC_HAS_BGBDS))
  153. /*!
  154. * @brief Bandgap Buffer configuration.
  155. */
  156. typedef struct _pmc_bandgap_buffer_config
  157. {
  158. #if (defined(FSL_FEATURE_PMC_HAS_BGBE) && FSL_FEATURE_PMC_HAS_BGBE)
  159. bool enable; /*!< Enable bandgap buffer. */
  160. #endif
  161. #if (defined(FSL_FEATURE_PMC_HAS_BGEN) && FSL_FEATURE_PMC_HAS_BGEN)
  162. bool enableInLowPowerMode; /*!< Enable bandgap buffer in low-power mode. */
  163. #endif /* FSL_FEATURE_PMC_HAS_BGEN */
  164. #if (defined(FSL_FEATURE_PMC_HAS_BGBDS) && FSL_FEATURE_PMC_HAS_BGBDS)
  165. pmc_bandgap_buffer_drive_select_t drive; /*!< Bandgap buffer drive select. */
  166. #endif /* FSL_FEATURE_PMC_HAS_BGBDS */
  167. } pmc_bandgap_buffer_config_t;
  168. #endif
  169. /*******************************************************************************
  170. * API
  171. ******************************************************************************/
  172. #if defined(__cplusplus)
  173. extern "C" {
  174. #endif /* __cplusplus*/
  175. /*! @name Power Management Controller Control APIs*/
  176. /*@{*/
  177. #if (defined(FSL_FEATURE_PMC_HAS_VERID) && FSL_FEATURE_PMC_HAS_VERID)
  178. /*!
  179. * @brief Gets the PMC version ID.
  180. *
  181. * This function gets the PMC version ID, including major version number,
  182. * minor version number, and a feature specification number.
  183. *
  184. * @param base PMC peripheral base address.
  185. * @param versionId Pointer to version ID structure.
  186. */
  187. static inline void PMC_GetVersionId(PMC_Type *base, pmc_version_id_t *versionId)
  188. {
  189. *((uint32_t *)versionId) = base->VERID;
  190. }
  191. #endif /* FSL_FEATURE_PMC_HAS_VERID */
  192. #if (defined(FSL_FEATURE_PMC_HAS_PARAM) && FSL_FEATURE_PMC_HAS_PARAM)
  193. /*!
  194. * @brief Gets the PMC parameter.
  195. *
  196. * This function gets the PMC parameter including the VLPO enable and the HVD enable.
  197. *
  198. * @param base PMC peripheral base address.
  199. * @param param Pointer to PMC param structure.
  200. */
  201. void PMC_GetParam(PMC_Type *base, pmc_param_t *param);
  202. #endif
  203. /*!
  204. * @brief Configures the low-voltage detect setting.
  205. *
  206. * This function configures the low-voltage detect setting, including the trip
  207. * point voltage setting, enables or disables the interrupt, enables or disables the system reset.
  208. *
  209. * @param base PMC peripheral base address.
  210. * @param config Low-voltage detect configuration structure.
  211. */
  212. void PMC_ConfigureLowVoltDetect(PMC_Type *base, const pmc_low_volt_detect_config_t *config);
  213. /*!
  214. * @brief Gets the Low-voltage Detect Flag status.
  215. *
  216. * This function reads the current LVDF status. If it returns 1, a low-voltage event is detected.
  217. *
  218. * @param base PMC peripheral base address.
  219. * @return Current low-voltage detect flag
  220. * - true: Low-voltage detected
  221. * - false: Low-voltage not detected
  222. */
  223. static inline bool PMC_GetLowVoltDetectFlag(PMC_Type *base)
  224. {
  225. return (bool)(base->LVDSC1 & PMC_LVDSC1_LVDF_MASK);
  226. }
  227. /*!
  228. * @brief Acknowledges clearing the Low-voltage Detect flag.
  229. *
  230. * This function acknowledges the low-voltage detection errors (write 1 to
  231. * clear LVDF).
  232. *
  233. * @param base PMC peripheral base address.
  234. */
  235. static inline void PMC_ClearLowVoltDetectFlag(PMC_Type *base)
  236. {
  237. base->LVDSC1 |= PMC_LVDSC1_LVDACK_MASK;
  238. }
  239. /*!
  240. * @brief Configures the low-voltage warning setting.
  241. *
  242. * This function configures the low-voltage warning setting, including the trip
  243. * point voltage setting and enabling or disabling the interrupt.
  244. *
  245. * @param base PMC peripheral base address.
  246. * @param config Low-voltage warning configuration structure.
  247. */
  248. void PMC_ConfigureLowVoltWarning(PMC_Type *base, const pmc_low_volt_warning_config_t *config);
  249. /*!
  250. * @brief Gets the Low-voltage Warning Flag status.
  251. *
  252. * This function polls the current LVWF status. When 1 is returned, it
  253. * indicates a low-voltage warning event. LVWF is set when V Supply transitions
  254. * below the trip point or after reset and V Supply is already below the V LVW.
  255. *
  256. * @param base PMC peripheral base address.
  257. * @return Current LVWF status
  258. * - true: Low-voltage Warning Flag is set.
  259. * - false: the Low-voltage Warning does not happen.
  260. */
  261. static inline bool PMC_GetLowVoltWarningFlag(PMC_Type *base)
  262. {
  263. return (bool)(base->LVDSC2 & PMC_LVDSC2_LVWF_MASK);
  264. }
  265. /*!
  266. * @brief Acknowledges the Low-voltage Warning flag.
  267. *
  268. * This function acknowledges the low voltage warning errors (write 1 to
  269. * clear LVWF).
  270. *
  271. * @param base PMC peripheral base address.
  272. */
  273. static inline void PMC_ClearLowVoltWarningFlag(PMC_Type *base)
  274. {
  275. base->LVDSC2 |= PMC_LVDSC2_LVWACK_MASK;
  276. }
  277. #if (defined(FSL_FEATURE_PMC_HAS_HVDSC1) && FSL_FEATURE_PMC_HAS_HVDSC1)
  278. /*!
  279. * @brief Configures the high-voltage detect setting.
  280. *
  281. * This function configures the high-voltage detect setting, including the trip
  282. * point voltage setting, enabling or disabling the interrupt, enabling or disabling the system reset.
  283. *
  284. * @param base PMC peripheral base address.
  285. * @param config High-voltage detect configuration structure.
  286. */
  287. void PMC_ConfigureHighVoltDetect(PMC_Type *base, const pmc_high_volt_detect_config_t *config);
  288. /*!
  289. * @brief Gets the High-voltage Detect Flag status.
  290. *
  291. * This function reads the current HVDF status. If it returns 1, a low
  292. * voltage event is detected.
  293. *
  294. * @param base PMC peripheral base address.
  295. * @return Current high-voltage detect flag
  296. * - true: High-voltage detected
  297. * - false: High-voltage not detected
  298. */
  299. static inline bool PMC_GetHighVoltDetectFlag(PMC_Type *base)
  300. {
  301. return (bool)(base->HVDSC1 & PMC_HVDSC1_HVDF_MASK);
  302. }
  303. /*!
  304. * @brief Acknowledges clearing the High-voltage Detect flag.
  305. *
  306. * This function acknowledges the high-voltage detection errors (write 1 to
  307. * clear HVDF).
  308. *
  309. * @param base PMC peripheral base address.
  310. */
  311. static inline void PMC_ClearHighVoltDetectFlag(PMC_Type *base)
  312. {
  313. base->HVDSC1 |= PMC_HVDSC1_HVDACK_MASK;
  314. }
  315. #endif /* FSL_FEATURE_PMC_HAS_HVDSC1 */
  316. #if ((defined(FSL_FEATURE_PMC_HAS_BGBE) && FSL_FEATURE_PMC_HAS_BGBE) || \
  317. (defined(FSL_FEATURE_PMC_HAS_BGEN) && FSL_FEATURE_PMC_HAS_BGEN) || \
  318. (defined(FSL_FEATURE_PMC_HAS_BGBDS) && FSL_FEATURE_PMC_HAS_BGBDS))
  319. /*!
  320. * @brief Configures the PMC bandgap.
  321. *
  322. * This function configures the PMC bandgap, including the drive select and
  323. * behavior in low-power mode.
  324. *
  325. * @param base PMC peripheral base address.
  326. * @param config Pointer to the configuration structure
  327. */
  328. void PMC_ConfigureBandgapBuffer(PMC_Type *base, const pmc_bandgap_buffer_config_t *config);
  329. #endif
  330. #if (defined(FSL_FEATURE_PMC_HAS_ACKISO) && FSL_FEATURE_PMC_HAS_ACKISO)
  331. /*!
  332. * @brief Gets the acknowledge Peripherals and I/O pads isolation flag.
  333. *
  334. * This function reads the Acknowledge Isolation setting that indicates
  335. * whether certain peripherals and the I/O pads are in a latched state as
  336. * a result of having been in the VLLS mode.
  337. *
  338. * @param base PMC peripheral base address.
  339. * @param base Base address for current PMC instance.
  340. * @return ACK isolation
  341. * 0 - Peripherals and I/O pads are in a normal run state.
  342. * 1 - Certain peripherals and I/O pads are in an isolated and
  343. * latched state.
  344. */
  345. static inline bool PMC_GetPeriphIOIsolationFlag(PMC_Type *base)
  346. {
  347. return (bool)(base->REGSC & PMC_REGSC_ACKISO_MASK);
  348. }
  349. /*!
  350. * @brief Acknowledges the isolation flag to Peripherals and I/O pads.
  351. *
  352. * This function clears the ACK Isolation flag. Writing one to this setting
  353. * when it is set releases the I/O pads and certain peripherals to their normal
  354. * run mode state.
  355. *
  356. * @param base PMC peripheral base address.
  357. */
  358. static inline void PMC_ClearPeriphIOIsolationFlag(PMC_Type *base)
  359. {
  360. base->REGSC |= PMC_REGSC_ACKISO_MASK;
  361. }
  362. #endif /* FSL_FEATURE_PMC_HAS_ACKISO */
  363. #if (defined(FSL_FEATURE_PMC_HAS_REGONS) && FSL_FEATURE_PMC_HAS_REGONS)
  364. /*!
  365. * @brief Gets the regulator regulation status.
  366. *
  367. * This function returns the regulator to run a regulation status. It provides
  368. * the current status of the internal voltage regulator.
  369. *
  370. * @param base PMC peripheral base address.
  371. * @param base Base address for current PMC instance.
  372. * @return Regulation status
  373. * 0 - Regulator is in a stop regulation or in transition to/from the regulation.
  374. * 1 - Regulator is in a run regulation.
  375. *
  376. */
  377. static inline bool PMC_IsRegulatorInRunRegulation(PMC_Type *base)
  378. {
  379. return (bool)(base->REGSC & PMC_REGSC_REGONS_MASK);
  380. }
  381. #endif /* FSL_FEATURE_PMC_HAS_REGONS */
  382. /*@}*/
  383. #if defined(__cplusplus)
  384. }
  385. #endif /* __cplusplus*/
  386. /*! @}*/
  387. #endif /* _FSL_PMC_H_*/