fsl_pmc.h 15 KB

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