Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

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