fsl_dcdc.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2017, NXP
  4. * All rights reserved.
  5. *
  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 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_DCDC_H__
  35. #define __FSL_DCDC_H__
  36. #include "fsl_common.h"
  37. /*!
  38. * @addtogroup dcdc
  39. * @{
  40. */
  41. /*******************************************************************************
  42. * Definitions
  43. ******************************************************************************/
  44. /*! @brief DCDC driver version. */
  45. #define FSL_DCDC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0. */
  46. /*!
  47. * @brief DCDC status flags.
  48. */
  49. enum _dcdc_status_flags_t
  50. {
  51. kDCDC_LockedOKStatus = (1U << 0U), /*!< Indicate DCDC status. 1'b1: DCDC already settled 1'b0: DCDC is settling. */
  52. };
  53. /*!
  54. * @brief The current bias of low power comparator.
  55. */
  56. typedef enum _dcdc_comparator_current_bias
  57. {
  58. kDCDC_ComparatorCurrentBias50nA = 0U, /*!< The current bias of low power comparator is 50nA. */
  59. kDCDC_ComparatorCurrentBias100nA = 1U, /*!< The current bias of low power comparator is 100nA. */
  60. kDCDC_ComparatorCurrentBias200nA = 2U, /*!< The current bias of low power comparator is 200nA. */
  61. kDCDC_ComparatorCurrentBias400nA = 3U, /*!< The current bias of low power comparator is 400nA. */
  62. } dcdc_comparator_current_bias_t;
  63. /*!
  64. * @brief The threshold of over current detection.
  65. */
  66. typedef enum _dcdc_over_current_threshold
  67. {
  68. kDCDC_OverCurrentThresholdAlt0 = 0U, /*!< 1A in the run mode, 0.25A in the power save mode. */
  69. kDCDC_OverCurrentThresholdAlt1 = 1U, /*!< 2A in the run mode, 0.25A in the power save mode. */
  70. kDCDC_OverCurrentThresholdAlt2 = 2U, /*!< 1A in the run mode, 0.2A in the power save mode. */
  71. kDCDC_OverCurrentThresholdAlt3 = 3U, /*!< 2A in the run mode, 0.2A in the power save mode. */
  72. } dcdc_over_current_threshold_t;
  73. /*!
  74. * @brief The threshold if peak current detection.
  75. */
  76. typedef enum _dcdc_peak_current_threshold
  77. {
  78. kDCDC_PeakCurrentThresholdAlt0 = 0U, /*!< 150mA peak current threshold. */
  79. kDCDC_PeakCurrentThresholdAlt1 = 1U, /*!< 250mA peak current threshold. */
  80. kDCDC_PeakCurrentThresholdAlt2 = 2U, /*!< 350mA peak current threshold. */
  81. kDCDC_PeakCurrentThresholdAlt3 = 3U, /*!< 450mA peak current threshold. */
  82. kDCDC_PeakCurrentThresholdAlt4 = 4U, /*!< 550mA peak current threshold. */
  83. kDCDC_PeakCurrentThresholdAlt5 = 5U, /*!< 650mA peak current threshold. */
  84. } dcdc_peak_current_threshold_t;
  85. /*!
  86. * @brief The period of counting the charging times in power save mode.
  87. */
  88. typedef enum _dcdc_count_charging_time_period
  89. {
  90. kDCDC_CountChargingTimePeriod8Cycle = 0U, /*!< Eight 32k cycle. */
  91. kDCDC_CountChargingTimePeriod16Cycle = 1U, /*!< Sixteen 32k cycle. */
  92. } dcdc_count_charging_time_period_t;
  93. /*!
  94. * @brief The threshold of the counting number of charging times
  95. */
  96. typedef enum _dcdc_count_charging_time_threshold
  97. {
  98. kDCDC_CountChargingTimeThreshold32 = 0U, /*!< 0x0: 32. */
  99. kDCDC_CountChargingTimeThreshold64 = 1U, /*!< 0x1: 64. */
  100. kDCDC_CountChargingTimeThreshold16 = 2U, /*!< 0x2: 16. */
  101. kDCDC_CountChargingTimeThreshold8 = 3U, /*!< 0x3: 8. */
  102. } dcdc_count_charging_time_threshold_t;
  103. /*!
  104. * @brief Oscillator clock option.
  105. */
  106. typedef enum _dcdc_clock_source
  107. {
  108. kDCDC_ClockAutoSwitch = 0U, /*!< Automatic clock switch from internal oscillator to external clock. */
  109. kDCDC_ClockInternalOsc = 1U, /*!< Use internal oscillator. */
  110. kDCDC_ClockExternalOsc = 2U, /*!< Use external 24M crystal oscillator. */
  111. } dcdc_clock_source_t;
  112. /*!
  113. * @brief Configuration for DCDC detection.
  114. */
  115. typedef struct _dcdc_detection_config
  116. {
  117. bool enableXtalokDetection; /*!< Enable xtalok detection circuit. */
  118. bool powerDownOverVoltageDetection; /*!< Power down over-voltage detection comparator. */
  119. bool powerDownLowVlotageDetection; /*!< Power down low-voltage detection comparator. */
  120. bool powerDownOverCurrentDetection; /*!< Power down over-current detection. */
  121. bool powerDownPeakCurrentDetection; /*!< Power down peak-current detection. */
  122. bool powerDownZeroCrossDetection; /*!< Power down the zero cross detection function for discontinuous conductor
  123. mode. */
  124. dcdc_over_current_threshold_t OverCurrentThreshold; /*!< The threshold of over current detection. */
  125. dcdc_peak_current_threshold_t PeakCurrentThreshold; /*!< The threshold of peak current detection. */
  126. } dcdc_detection_config_t;
  127. /*!
  128. * @brief Configuration for the loop control.
  129. */
  130. typedef struct _dcdc_loop_control_config
  131. {
  132. bool enableCommonHysteresis; /*!< Enable hysteresis in switching converter common mode analog comparators.
  133. This feature will improve transient supply ripple and efficiency. */
  134. bool enableCommonThresholdDetection; /*!< Increase the threshold detection for common mode analog comparator. */
  135. bool enableInvertHysteresisSign; /*!< Invert the sign of the hysteresis in DC-DC analog comparators. */
  136. bool enableRCThresholdDetection; /*!< Increase the threshold detection for RC scale circuit. */
  137. uint32_t enableRCScaleCircuit; /*!< Available range is 0~7. Enable analog circuit of DC-DC converter to respond
  138. faster under transient load conditions. */
  139. uint32_t complementFeedForwardStep; /*!< Available range is 0~7. Two's complement feed forward step in duty cycle in
  140. the switching DC-DC converter. Each time this field makes a transition from
  141. 0x0, the loop filter of the DC-DC converter is stepped once by a value
  142. proportional to the change. This can be used to force a certain control loop
  143. behavior, such as improving response under known heavy load transients. */
  144. uint32_t controlParameterMagnitude; /*!< Available range is 0~15. Magnitude of proportional control parameter in the
  145. switching DC-DC converter control loop. */
  146. uint32_t integralProportionalRatio; /*!< Available range is 0~3.Ratio of integral control parameter to proportional
  147. control parameter in the switching DC-DC converter, and can be used to
  148. optimize efficiency and loop response. */
  149. } dcdc_loop_control_config_t;
  150. /*!
  151. * @brief Configuration for DCDC low power.
  152. */
  153. typedef struct _dcdc_low_power_config
  154. {
  155. bool enableOverloadDetection; /*!< Enable the overload detection in power save mode, if current is larger than the
  156. overloading threshold (typical value is 50 mA), DCDC will switch to the run mode
  157. automatically. */
  158. bool enableAdjustHystereticValue; /*!< Adjust hysteretic value in low power from 12.5mV to 25mV. */
  159. dcdc_count_charging_time_period_t
  160. countChargingTimePeriod; /*!< The period of counting the charging times in power save mode. */
  161. dcdc_count_charging_time_threshold_t
  162. countChargingTimeThreshold; /*!< the threshold of the counting number of charging times during
  163. the period that lp_overload_freq_sel sets in power save mode. */
  164. } dcdc_low_power_config_t;
  165. /*!
  166. * @brief Configuration for DCDC internal regulator.
  167. */
  168. typedef struct _dcdc_internal_regulator_config
  169. {
  170. bool enableLoadResistor; /*!< control the load resistor of the internal regulator of DCDC, the load resistor is
  171. connected as default "true", and need set to "false" to disconnect the load
  172. resistor. */
  173. uint32_t feedbackPoint; /*!< Available range is 0~3. Select the feedback point of the internal regulator. */
  174. } dcdc_internal_regulator_config_t;
  175. /*!
  176. * @brief Configuration for min power setting.
  177. */
  178. typedef struct _dcdc_min_power_config
  179. {
  180. bool enableUseHalfFreqForContinuous; /*!< Set DCDC clock to half frequency for the continuous mode. */
  181. } dcdc_min_power_config_t;
  182. #if defined(__cplusplus)
  183. extern "C" {
  184. #endif
  185. /*******************************************************************************
  186. * API
  187. ******************************************************************************/
  188. /*!
  189. * @name Initialization and deinitialization
  190. * @{
  191. */
  192. /*!
  193. * @brief Enable the access to DCDC registers.
  194. *
  195. * @param base DCDC peripheral base address.
  196. */
  197. void DCDC_Init(DCDC_Type *base);
  198. /*!
  199. * @brief Disable the access to DCDC registers.
  200. *
  201. * @param base DCDC peripheral base address.
  202. */
  203. void DCDC_Deinit(DCDC_Type *base);
  204. /* @} */
  205. /*!
  206. * @name Status
  207. * @{
  208. */
  209. /*!
  210. * @brief Get DCDC status flags.
  211. *
  212. * @param base peripheral base address.
  213. * @return Mask of asserted status flags. See to "_dcdc_status_flags_t".
  214. */
  215. uint32_t DCDC_GetstatusFlags(DCDC_Type *base);
  216. /* @} */
  217. /*!
  218. * @name Misc control.
  219. * @{
  220. */
  221. /*!
  222. * @brief Enable the output range comparator.
  223. *
  224. * The output range comparator is disabled by default.
  225. *
  226. * @param base DCDC peripheral base address.
  227. * @param enable Enable the feature or not.
  228. */
  229. static inline void DCDC_EnableOutputRangeComparator(DCDC_Type *base, bool enable)
  230. {
  231. if (enable)
  232. {
  233. base->REG0 &= ~DCDC_REG0_PWD_CMP_OFFSET_MASK;
  234. }
  235. else
  236. {
  237. base->REG0 |= DCDC_REG0_PWD_CMP_OFFSET_MASK;
  238. }
  239. }
  240. /*!
  241. * @brief Configure the DCDC clock source.
  242. *
  243. * @param base DCDC peripheral base address.
  244. * @param clockSource Clock source for DCDC. See to "dcdc_clock_source_t".
  245. */
  246. void DCDC_SetClockSource(DCDC_Type *base, dcdc_clock_source_t clockSource);
  247. /*!
  248. * @brief Get the default setting for detection configuration.
  249. *
  250. * The default configuration are set according to responding registers' setting when powered on.
  251. * They are:
  252. * @code
  253. * config->enableXtalokDetection = false;
  254. * config->powerDownOverVoltageDetection = true;
  255. * config->powerDownLowVlotageDetection = false;
  256. * config->powerDownOverCurrentDetection = true;
  257. * config->powerDownPeakCurrentDetection = true;
  258. * config->powerDownZeroCrossDetection = true;
  259. * config->OverCurrentThreshold = kDCDC_OverCurrentThresholdAlt0;
  260. * config->PeakCurrentThreshold = kDCDC_PeakCurrentThresholdAlt0;
  261. * @endcode
  262. *
  263. * @param config Pointer to configuration structure. See to "dcdc_detection_config_t"
  264. */
  265. void DCDC_GetDefaultDetectionConfig(dcdc_detection_config_t *config);
  266. /*!
  267. * @breif Configure the DCDC detection.
  268. *
  269. * @param base DCDC peripheral base address.
  270. * @param config Pointer to configuration structure. See to "dcdc_detection_config_t"
  271. */
  272. void DCDC_SetDetectionConfig(DCDC_Type *base, const dcdc_detection_config_t *config);
  273. /*!
  274. * @brief Get the default setting for low power configuration.
  275. *
  276. * The default configuration are set according to responding registers' setting when powered on.
  277. * They are:
  278. * @code
  279. * config->enableOverloadDetection = true;
  280. * config->enableAdjustHystereticValue = false;
  281. * config->countChargingTimePeriod = kDCDC_CountChargingTimePeriod8Cycle;
  282. * config->countChargingTimeThreshold = kDCDC_CountChargingTimeThreshold32;
  283. * @endcode
  284. *
  285. * @param config Pointer to configuration structure. See to "dcdc_low_power_config_t"
  286. */
  287. void DCDC_GetDefaultLowPowerConfig(dcdc_low_power_config_t *config);
  288. /*!
  289. * @brief Configure the DCDC low power.
  290. *
  291. * @param base DCDC peripheral base address.
  292. * @param config Pointer to configuration structure. See to "dcdc_low_power_config_t".
  293. */
  294. void DCDC_SetLowPowerConfig(DCDC_Type *base, const dcdc_low_power_config_t *config);
  295. /*!
  296. * @brief Reset current alert signal. Alert signal is generate by peak current detection.
  297. *
  298. * @param base DCDC peripheral base address.
  299. * @param enable Switcher to reset signal. True means reset signal. False means don't reset signal.
  300. */
  301. void DCDC_ResetCurrentAlertSignal(DCDC_Type *base, bool enable);
  302. /*!
  303. * @brief Set the bangap trim value to trim bandgap voltage.
  304. *
  305. * @param base DCDC peripheral base address.
  306. * @param TrimValue The bangap trim value. Available range is 0U-31U.
  307. */
  308. static inline void DCDC_SetBandgapVoltageTrimValue(DCDC_Type *base, uint32_t trimValue)
  309. {
  310. base->REG1 &= ~DCDC_REG1_VBG_TRIM_MASK;
  311. base->REG1 |= DCDC_REG1_VBG_TRIM(trimValue);
  312. }
  313. /*!
  314. * @brief Get the default setting for loop control configuration.
  315. *
  316. * The default configuration are set according to responding registers' setting when powered on.
  317. * They are:
  318. * @code
  319. * config->enableCommonHysteresis = false;
  320. * config->enableCommonThresholdDetection = false;
  321. * config->enableInvertHysteresisSign = false;
  322. * config->enableRCThresholdDetection = false;
  323. * config->enableRCScaleCircuit = 0U;
  324. * config->complementFeedForwardStep = 0U;
  325. * config->controlParameterMagnitude = 2U;
  326. * config->integralProportionalRatio = 2U;
  327. * @endcode
  328. *
  329. * @param config Pointer to configuration structure. See to "dcdc_loop_control_config_t"
  330. */
  331. void DCDC_GetDefaultLoopControlConfig(dcdc_loop_control_config_t *config);
  332. /*!
  333. * @brief Configure the DCDC loop control.
  334. *
  335. * @param base DCDC peripheral base address.
  336. * @param config Pointer to configuration structure. See to "dcdc_loop_control_config_t".
  337. */
  338. void DCDC_SetLoopControlConfig(DCDC_Type *base, const dcdc_loop_control_config_t *config);
  339. /*!
  340. * @brief Configure for the min power.
  341. *
  342. * @param base DCDC peripheral base address.
  343. * @param config Pointer to configuration structure. See to "dcdc_min_power_config_t".
  344. */
  345. void DCDC_SetMinPowerConfig(DCDC_Type *base, const dcdc_min_power_config_t *config);
  346. /*!
  347. * @brief Set the current bias of low power comparator.
  348. *
  349. * @param base DCDC peripheral base address.
  350. * @param biasVaule The current bias of low power comparator. Refer to "dcdc_comparator_current_bias_t".
  351. */
  352. static inline void DCDC_SetLPComparatorBiasValue(DCDC_Type *base, dcdc_comparator_current_bias_t biasVaule)
  353. {
  354. base->REG1 &= ~DCDC_REG1_LP_CMP_ISRC_SEL_MASK;
  355. base->REG1 |= DCDC_REG1_LP_CMP_ISRC_SEL(biasVaule);
  356. }
  357. static inline void DCDC_LockTargetVoltage(DCDC_Type *base)
  358. {
  359. base->REG3 |= DCDC_REG3_DISABLE_STEP_MASK;
  360. }
  361. /*!
  362. * @brief Adjust the target voltage of VDD_SOC in run mode and low power mode.
  363. *
  364. * This function is to adjust the target voltage of DCDC output. Change them and finally wait until the output is
  365. * stabled.
  366. * Set the target value of run mode the same as low power mode before entering power save mode, because DCDC will switch
  367. * back to run mode if it detects the current loading is larger than about 50 mA(typical value).
  368. *
  369. * @param base DCDC peripheral base address.
  370. * @param VDDRun Target value in run mode. 25 mV each step from 0x00 to 0x1F. 00 is for 0.8V, 0x1F is for 1.575V.
  371. * @param VDDStandby Target value in low power mode. 25 mV each step from 0x00 to 0x4. 00 is for 0.9V, 0x4 is for 1.0V.
  372. */
  373. void DCDC_AdjustTargetVoltage(DCDC_Type *base, uint32_t VDDRun, uint32_t VDDStandby);
  374. /*!
  375. * @brief Configure the DCDC internal regulator.
  376. *
  377. * @param base DCDC peripheral base address.
  378. * @param config Pointer to configuration structure. See to "dcdc_internal_regulator_config_t".
  379. */
  380. void DCDC_SetInternalRegulatorConfig(DCDC_Type *base, const dcdc_internal_regulator_config_t *config);
  381. /*!
  382. * @brief Ajust delay to reduce ground noise.
  383. *
  384. * @param base DCDC peripheral base address.
  385. * @param enable Enable the feature or not.
  386. */
  387. static inline void DCDC_EnableAdjustDelay(DCDC_Type *base, bool enable)
  388. {
  389. if (enable)
  390. {
  391. base->REG3 |= DCDC_REG3_MISC_DELAY_TIMING_MASK;
  392. }
  393. else
  394. {
  395. base->REG3 &= ~DCDC_REG3_MISC_DELAY_TIMING_MASK;
  396. }
  397. }
  398. /*!
  399. * @brief Enable/Disable to improve the transition from heavy load to light load. It is valid while zero
  400. * cross detection is enabled. If ouput exceeds the threshold, DCDC would return CCM from DCM.
  401. *
  402. * @param base DCDC peripheral base address.
  403. * @param enable Enable the feature or not.
  404. */
  405. static inline void DCDC_EnableImproveTransition(DCDC_Type *base, bool enable)
  406. {
  407. if (enable)
  408. {
  409. base->REG2 |= DCDC_REG2_DCM_SET_CTRL_MASK;
  410. }
  411. else
  412. {
  413. base->REG2 &= ~DCDC_REG2_DCM_SET_CTRL_MASK;
  414. }
  415. }
  416. /* @} */
  417. /*!
  418. * @name Application guideline.
  419. * @{
  420. */
  421. /*!
  422. * @brief Boot DCDC into DCM(discontinous conduction mode).
  423. *
  424. * pwd_zcd=0x0;
  425. * pwd_cmp_offset=0x0;
  426. * dcdc_loopctrl_en_rcscale=0x3 or 0x5;
  427. * DCM_set_ctrl=1'b1;
  428. *
  429. * @param base DCDC peripheral base address.
  430. */
  431. void DCDC_BootIntoDCM(DCDC_Type *base);
  432. /*!
  433. * @brief Boot DCDC into CCM(continous conduction mode).
  434. *
  435. * pwd_zcd=0x1;
  436. * pwd_cmp_offset=0x0;
  437. * dcdc_loopctrl_en_rcscale=0x3;
  438. *
  439. * @param base DCDC peripheral base address.
  440. */
  441. void DCDC_BootIntoCCM(DCDC_Type *base);
  442. #if defined(__cplusplus)
  443. }
  444. #endif
  445. #endif /* __FSL_DCDC_H__ */