fsl_dcdc.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. /*
  2. * Copyright 2017-2021, NXP
  3. * All rights reserved.
  4. *
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #include "fsl_dcdc.h"
  9. /* Component ID definition, used by tools. */
  10. #ifndef FSL_COMPONENT_ID
  11. #define FSL_COMPONENT_ID "platform.drivers.dcdc_1"
  12. #endif
  13. /*******************************************************************************
  14. * Prototypes
  15. ******************************************************************************/
  16. /*!
  17. * @brief Get instance number for DCDC module.
  18. *
  19. * @param base DCDC peripheral base address
  20. */
  21. static uint32_t DCDC_GetInstance(DCDC_Type *base);
  22. #if (defined(DCDC_REG4_ENABLE_SP_MASK) && DCDC_REG4_ENABLE_SP_MASK)
  23. /*!
  24. * @brief Convert the byte array to word.
  25. *
  26. * @param ptrArray Pointer to the byte array.
  27. * @return The converted result.
  28. */
  29. static uint32_t DCDC_ConvertByteArrayToWord(uint8_t *ptrArray);
  30. #endif /* DCDC_REG4_ENABLE_SP_MASK */
  31. /*******************************************************************************
  32. * Variables
  33. ******************************************************************************/
  34. /*! @brief Pointers to DCDC bases for each instance. */
  35. static DCDC_Type *const s_dcdcBases[] = DCDC_BASE_PTRS;
  36. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  37. /*! @brief Pointers to DCDC clocks for each instance. */
  38. static const clock_ip_name_t s_dcdcClocks[] = DCDC_CLOCKS;
  39. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  40. /*******************************************************************************
  41. * Code
  42. ******************************************************************************/
  43. static uint32_t DCDC_GetInstance(DCDC_Type *base)
  44. {
  45. uint32_t instance;
  46. /* Find the instance index from base address mappings. */
  47. for (instance = 0; instance < ARRAY_SIZE(s_dcdcBases); instance++)
  48. {
  49. if (s_dcdcBases[instance] == base)
  50. {
  51. break;
  52. }
  53. }
  54. assert(instance < ARRAY_SIZE(s_dcdcBases));
  55. return instance;
  56. }
  57. #if (defined(DCDC_REG4_ENABLE_SP_MASK) && DCDC_REG4_ENABLE_SP_MASK)
  58. static uint32_t DCDC_ConvertByteArrayToWord(uint8_t *ptrArray)
  59. {
  60. assert(ptrArray != NULL);
  61. uint32_t temp32 = 0UL;
  62. uint8_t index;
  63. for (index = 0U; index < 4U; index++)
  64. {
  65. temp32 |= ptrArray[index] << ((index % 4U) * 8U);
  66. }
  67. return temp32;
  68. }
  69. #endif /* DCDC_REG4_ENABLE_SP_MASK */
  70. #if defined(FSL_FEATURE_DCDC_HAS_CTRL_REG) && FSL_FEATURE_DCDC_HAS_CTRL_REG
  71. /*!
  72. * brief Enable the access to DCDC registers.
  73. *
  74. * param base DCDC peripheral base address.
  75. * param config Pointer to the configuration structure.
  76. */
  77. void DCDC_Init(DCDC_Type *base, dcdc_config_t *config)
  78. {
  79. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  80. /* Enable the clock. */
  81. CLOCK_EnableClock(s_dcdcClocks[DCDC_GetInstance(base)]);
  82. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  83. uint32_t tmp32 = base->CTRL0;
  84. tmp32 |= DCDC_CTRL0_CONTROL_MODE(config->controlMode) | DCDC_CTRL0_TRIM_HOLD(config->trimInputMode);
  85. if (config->enableDcdcTimeout)
  86. {
  87. tmp32 |= DCDC_CTRL0_ENABLE_DCDC_CNT_MASK;
  88. }
  89. if (config->enableSwitchingConverterOutput)
  90. {
  91. tmp32 |= DCDC_CTRL0_DIG_EN_MASK;
  92. }
  93. base->CTRL0 |= DCDC_CTRL0_ENABLE_MASK;
  94. base->CTRL0 = tmp32;
  95. }
  96. #else
  97. /*!
  98. * brief Enable the access to DCDC registers.
  99. *
  100. * param base DCDC peripheral base address.
  101. */
  102. void DCDC_Init(DCDC_Type *base)
  103. {
  104. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  105. /* Enable the clock. */
  106. CLOCK_EnableClock(s_dcdcClocks[DCDC_GetInstance(base)]);
  107. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  108. }
  109. #endif /* FSL_FEATURE_DCDC_HAS_CTRL_REG */
  110. /*!
  111. * brief Disable the access to DCDC registers.
  112. *
  113. * param base DCDC peripheral base address.
  114. */
  115. void DCDC_Deinit(DCDC_Type *base)
  116. {
  117. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  118. /* Disable the clock. */
  119. CLOCK_DisableClock(s_dcdcClocks[DCDC_GetInstance(base)]);
  120. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  121. }
  122. #if defined(FSL_FEATURE_DCDC_HAS_CTRL_REG) && FSL_FEATURE_DCDC_HAS_CTRL_REG
  123. /*!
  124. * brief Get the default setting for DCDC user configuration structure.
  125. *
  126. * This function initializes the user configuration structure to a default value. The default values are:
  127. * code
  128. * config->controlMode = kDCDC_StaticControl;
  129. * config->trimInputMode = kDCDC_SampleTrimInput;
  130. * config->enableDcdcTimeout = false;
  131. * config->enableSwitchingConverterOutput = false;
  132. * endcode
  133. *
  134. * param config Pointer to configuration structure. See to "dcdc_config_t"
  135. */
  136. void DCDC_GetDefaultConfig(DCDC_Type *base, dcdc_config_t *config)
  137. {
  138. assert(NULL != config);
  139. /* Initializes the configure structure to zero. */
  140. (void)memset(config, 0, sizeof(*config));
  141. config->controlMode = kDCDC_StaticControl;
  142. config->trimInputMode = kDCDC_SampleTrimInput;
  143. config->enableDcdcTimeout = false;
  144. config->enableSwitchingConverterOutput = false;
  145. }
  146. /*!
  147. * @brief Make DCDC enter into low power modes.
  148. *
  149. * @param base DCDC peripheral base address.
  150. * @param mode DCDC low power mode selection. See to "_dcdc_low_power_mode"
  151. */
  152. void DCDC_EnterLowPowerMode(DCDC_Type *base, dcdc_low_power_mode_t mode)
  153. {
  154. switch (mode)
  155. {
  156. case kDCDC_StandbyMode:
  157. base->CTRL0 |= DCDC_CTRL0_STBY_EN_MASK;
  158. break;
  159. case kDCDC_LowPowerMode:
  160. base->CTRL0 |= DCDC_CTRL0_LP_MODE_EN_MASK;
  161. break;
  162. case kDCDC_GpcStandbyLowPowerMode:
  163. base->CTRL0 |= DCDC_CTRL0_STBY_LP_MODE_EN_MASK;
  164. break;
  165. default:
  166. assert(false);
  167. break;
  168. }
  169. }
  170. #endif /* FSL_FEATURE_DCDC_HAS_CTRL_REG */
  171. /*!
  172. * brief Configure the DCDC clock source.
  173. *
  174. * param base DCDC peripheral base address.
  175. * param clockSource Clock source for DCDC. See to "dcdc_clock_source_t".
  176. */
  177. void DCDC_SetClockSource(DCDC_Type *base, dcdc_clock_source_t clockSource)
  178. {
  179. uint32_t tmp32;
  180. /* Configure the DCDC_REG0 register. */
  181. tmp32 = base->REG0 & ~(DCDC_REG0_XTAL_24M_OK_MASK | DCDC_REG0_DISABLE_AUTO_CLK_SWITCH_MASK |
  182. DCDC_REG0_SEL_CLK_MASK | DCDC_REG0_PWD_OSC_INT_MASK);
  183. switch (clockSource)
  184. {
  185. case kDCDC_ClockInternalOsc:
  186. tmp32 |= DCDC_REG0_DISABLE_AUTO_CLK_SWITCH_MASK;
  187. break;
  188. case kDCDC_ClockExternalOsc:
  189. /* Choose the external clock and disable the internal clock. */
  190. tmp32 |= DCDC_REG0_DISABLE_AUTO_CLK_SWITCH_MASK | DCDC_REG0_SEL_CLK_MASK | DCDC_REG0_PWD_OSC_INT_MASK;
  191. break;
  192. case kDCDC_ClockAutoSwitch:
  193. /* Set to switch from internal ring osc to xtal 24M if auto mode is enabled. */
  194. tmp32 |= DCDC_REG0_XTAL_24M_OK_MASK;
  195. break;
  196. default:
  197. assert(false);
  198. break;
  199. }
  200. base->REG0 = tmp32;
  201. }
  202. /*!
  203. * brief Get the default setting for detection configuration.
  204. *
  205. * The default configuration are set according to responding registers' setting when powered on.
  206. * They are:
  207. * code
  208. * config->enableXtalokDetection = false;
  209. * config->powerDownOverVoltageDetection = true;
  210. * config->powerDownLowVlotageDetection = false;
  211. * config->powerDownOverCurrentDetection = true;
  212. * config->powerDownPeakCurrentDetection = true;
  213. * config->powerDownZeroCrossDetection = true;
  214. * config->OverCurrentThreshold = kDCDC_OverCurrentThresholdAlt0;
  215. * config->PeakCurrentThreshold = kDCDC_PeakCurrentThresholdAlt0;
  216. * endcode
  217. *
  218. * param config Pointer to configuration structure. See to "dcdc_detection_config_t"
  219. */
  220. void DCDC_GetDefaultDetectionConfig(dcdc_detection_config_t *config)
  221. {
  222. assert(NULL != config);
  223. /* Initializes the configure structure to zero. */
  224. (void)memset(config, 0, sizeof(*config));
  225. config->enableXtalokDetection = false;
  226. #if (defined(FSL_FEATURE_DCDC_VDD_OUTPUT_COUNT) && (FSL_FEATURE_DCDC_VDD_OUTPUT_COUNT == 2))
  227. config->powerDownOverVoltageVdd1P8Detection = true;
  228. config->powerDownOverVoltageVdd1P0Detection = true;
  229. #else
  230. config->powerDownOverVoltageDetection = true;
  231. #endif /* FSL_FEATURE_DCDC_VDD_OUTPUT_COUNT */
  232. config->powerDownLowVlotageDetection = false;
  233. config->powerDownOverCurrentDetection = true;
  234. config->powerDownPeakCurrentDetection = true;
  235. config->powerDownZeroCrossDetection = true;
  236. config->OverCurrentThreshold = kDCDC_OverCurrentThresholdAlt0;
  237. config->PeakCurrentThreshold = kDCDC_PeakCurrentThresholdAlt0;
  238. }
  239. /*!
  240. * breif Configure the DCDC detection.
  241. *
  242. * param base DCDC peripheral base address.
  243. * param config Pointer to configuration structure. See to "dcdc_detection_config_t"
  244. */
  245. void DCDC_SetDetectionConfig(DCDC_Type *base, const dcdc_detection_config_t *config)
  246. {
  247. assert(NULL != config);
  248. uint32_t tmp32;
  249. /* Configure the DCDC_REG0 register. */
  250. tmp32 = base->REG0 & ~(DCDC_REG0_XTALOK_DISABLE_MASK
  251. #if (defined(FSL_FEATURE_DCDC_VDD_OUTPUT_COUNT) && (FSL_FEATURE_DCDC_VDD_OUTPUT_COUNT == 2))
  252. | DCDC_REG0_PWD_HIGH_VDD1P8_DET_MASK | DCDC_REG0_PWD_HIGH_VDD1P0_DET_MASK
  253. #else
  254. | DCDC_REG0_PWD_HIGH_VOLT_DET_MASK
  255. #endif /* FSL_FEATURE_DCDC_VDD_OUTPUT_COUNT */
  256. #if defined(FSL_FEATURE_DCDC_HAS_REG0_DCDC_IN_DET) && FSL_FEATURE_DCDC_HAS_REG0_DCDC_IN_DET
  257. | DCDC_REG0_PWD_CMP_DCDC_IN_DET_MASK
  258. #else
  259. | DCDC_REG0_PWD_CMP_BATT_DET_MASK
  260. #endif /* FSL_FEATURE_DCDC_HAS_REG0_DCDC_IN_DET */
  261. | DCDC_REG0_PWD_OVERCUR_DET_MASK | DCDC_REG0_PWD_CUR_SNS_CMP_MASK | DCDC_REG0_PWD_ZCD_MASK |
  262. DCDC_REG0_CUR_SNS_THRSH_MASK | DCDC_REG0_OVERCUR_TRIG_ADJ_MASK);
  263. tmp32 |= DCDC_REG0_CUR_SNS_THRSH(config->PeakCurrentThreshold) |
  264. DCDC_REG0_OVERCUR_TRIG_ADJ(config->OverCurrentThreshold);
  265. if (false == config->enableXtalokDetection)
  266. {
  267. tmp32 |= DCDC_REG0_XTALOK_DISABLE_MASK;
  268. }
  269. #if (defined(FSL_FEATURE_DCDC_VDD_OUTPUT_COUNT) && (FSL_FEATURE_DCDC_VDD_OUTPUT_COUNT == 2))
  270. if (config->powerDownOverVoltageVdd1P8Detection)
  271. {
  272. tmp32 |= DCDC_REG0_PWD_HIGH_VDD1P8_DET_MASK;
  273. }
  274. if (config->powerDownOverVoltageVdd1P0Detection)
  275. {
  276. tmp32 |= DCDC_REG0_PWD_HIGH_VDD1P0_DET_MASK;
  277. }
  278. #else
  279. if (config->powerDownOverVoltageDetection)
  280. {
  281. tmp32 |= DCDC_REG0_PWD_HIGH_VOLT_DET_MASK;
  282. }
  283. #endif /* FSL_FEATURE_DCDC_VDD_OUTPUT_COUNT */
  284. if (config->powerDownLowVlotageDetection)
  285. {
  286. #if defined(FSL_FEATURE_DCDC_HAS_REG0_DCDC_IN_DET) && FSL_FEATURE_DCDC_HAS_REG0_DCDC_IN_DET
  287. tmp32 |= DCDC_REG0_PWD_CMP_DCDC_IN_DET_MASK;
  288. #else
  289. tmp32 |= DCDC_REG0_PWD_CMP_BATT_DET_MASK;
  290. #endif /* FSL_FEATURE_DCDC_HAS_REG0_DCDC_IN_DET */
  291. }
  292. if (config->powerDownOverCurrentDetection)
  293. {
  294. tmp32 |= DCDC_REG0_PWD_OVERCUR_DET_MASK;
  295. }
  296. if (config->powerDownPeakCurrentDetection)
  297. {
  298. tmp32 |= DCDC_REG0_PWD_CUR_SNS_CMP_MASK;
  299. }
  300. if (config->powerDownZeroCrossDetection)
  301. {
  302. tmp32 |= DCDC_REG0_PWD_ZCD_MASK;
  303. }
  304. base->REG0 = tmp32;
  305. }
  306. /*!
  307. * brief Get the default setting for low power configuration.
  308. *
  309. * The default configuration are set according to responding registers' setting when powered on.
  310. * They are:
  311. * code
  312. * config->enableOverloadDetection = true;
  313. * config->enableAdjustHystereticValue = false;
  314. * config->countChargingTimePeriod = kDCDC_CountChargingTimePeriod8Cycle;
  315. * config->countChargingTimeThreshold = kDCDC_CountChargingTimeThreshold32;
  316. * endcode
  317. *
  318. * param config Pointer to configuration structure. See to "dcdc_low_power_config_t"
  319. */
  320. void DCDC_GetDefaultLowPowerConfig(dcdc_low_power_config_t *config)
  321. {
  322. assert(NULL != config);
  323. /* Initializes the configure structure to zero. */
  324. (void)memset(config, 0, sizeof(*config));
  325. #if !(defined(FSL_FEATURE_DCDC_HAS_NO_REG0_EN_LP_OVERLOAD_SNS) && FSL_FEATURE_DCDC_HAS_NO_REG0_EN_LP_OVERLOAD_SNS)
  326. config->enableOverloadDetection = true;
  327. #endif /* FSL_FEATURE_DCDC_HAS_NO_REG0_EN_LP_OVERLOAD_SNS */
  328. config->enableAdjustHystereticValue = false;
  329. config->countChargingTimePeriod = kDCDC_CountChargingTimePeriod8Cycle;
  330. config->countChargingTimeThreshold = kDCDC_CountChargingTimeThreshold32;
  331. }
  332. /*!
  333. * brief Configure the DCDC low power.
  334. *
  335. * param base DCDC peripheral base address.
  336. * param config Pointer to configuration structure. See to "dcdc_low_power_config_t".
  337. */
  338. void DCDC_SetLowPowerConfig(DCDC_Type *base, const dcdc_low_power_config_t *config)
  339. {
  340. assert(NULL != config);
  341. uint32_t tmp32;
  342. /* Configure the DCDC_REG0 register. */
  343. tmp32 = base->REG0 &
  344. ~(DCDC_REG0_LP_HIGH_HYS_MASK | DCDC_REG0_LP_OVERLOAD_FREQ_SEL_MASK | DCDC_REG0_LP_OVERLOAD_THRSH_MASK
  345. #if !(defined(FSL_FEATURE_DCDC_HAS_NO_REG0_EN_LP_OVERLOAD_SNS) && FSL_FEATURE_DCDC_HAS_NO_REG0_EN_LP_OVERLOAD_SNS)
  346. | DCDC_REG0_EN_LP_OVERLOAD_SNS_MASK
  347. #endif /* FSL_FEATURE_DCDC_HAS_NO_REG0_EN_LP_OVERLOAD_SNS */
  348. );
  349. tmp32 |= DCDC_REG0_LP_OVERLOAD_FREQ_SEL(config->countChargingTimePeriod) |
  350. DCDC_REG0_LP_OVERLOAD_THRSH(config->countChargingTimeThreshold);
  351. #if !(defined(FSL_FEATURE_DCDC_HAS_NO_REG0_EN_LP_OVERLOAD_SNS) && FSL_FEATURE_DCDC_HAS_NO_REG0_EN_LP_OVERLOAD_SNS)
  352. if (config->enableOverloadDetection)
  353. {
  354. tmp32 |= DCDC_REG0_EN_LP_OVERLOAD_SNS_MASK;
  355. }
  356. #endif /* FSL_FEATURE_DCDC_HAS_NO_REG0_EN_LP_OVERLOAD_SNS */
  357. if (config->enableAdjustHystereticValue)
  358. {
  359. tmp32 |= DCDC_REG0_LP_HIGH_HYS_MASK;
  360. }
  361. base->REG0 = tmp32;
  362. }
  363. /*!
  364. * brief Get DCDC status flags.
  365. *
  366. * param base peripheral base address.
  367. * return Mask of asserted status flags. See to "_dcdc_status_flags_t".
  368. */
  369. uint32_t DCDC_GetstatusFlags(DCDC_Type *base)
  370. {
  371. uint32_t tmp32 = 0U;
  372. if (DCDC_REG0_STS_DC_OK_MASK == (DCDC_REG0_STS_DC_OK_MASK & base->REG0))
  373. {
  374. tmp32 |= (uint32_t)kDCDC_LockedOKStatus;
  375. }
  376. return tmp32;
  377. }
  378. #if !(defined(FSL_FEATURE_DCDC_HAS_NO_CURRENT_ALERT_FUNC) && FSL_FEATURE_DCDC_HAS_NO_CURRENT_ALERT_FUNC)
  379. /*!
  380. * brief Reset current alert signal. Alert signal is generate by peak current detection.
  381. *
  382. * param base DCDC peripheral base address.
  383. * param enable Switcher to reset signal. True means reset signal. False means don't reset signal.
  384. */
  385. void DCDC_ResetCurrentAlertSignal(DCDC_Type *base, bool enable)
  386. {
  387. if (enable)
  388. {
  389. base->REG0 |= DCDC_REG0_CURRENT_ALERT_RESET_MASK;
  390. }
  391. else
  392. {
  393. base->REG0 &= ~DCDC_REG0_CURRENT_ALERT_RESET_MASK;
  394. }
  395. }
  396. #endif /* FSL_FEATURE_DCDC_HAS_NO_CURRENT_ALERT_FUNC */
  397. /*!
  398. * brief Get the default setting for loop control configuration.
  399. *
  400. * The default configuration are set according to responding registers' setting when powered on.
  401. * They are:
  402. * code
  403. * config->enableCommonHysteresis = false;
  404. * config->enableCommonThresholdDetection = false;
  405. * config->enableInvertHysteresisSign = false;
  406. * config->enableRCThresholdDetection = false;
  407. * config->enableRCScaleCircuit = 0U;
  408. * config->complementFeedForwardStep = 0U;
  409. * endcode
  410. *
  411. * param config Pointer to configuration structure. See to "dcdc_loop_control_config_t"
  412. */
  413. void DCDC_GetDefaultLoopControlConfig(dcdc_loop_control_config_t *config)
  414. {
  415. assert(NULL != config);
  416. /* Initializes the configure structure to zero. */
  417. (void)memset(config, 0, sizeof(*config));
  418. config->enableCommonHysteresis = false;
  419. config->enableCommonThresholdDetection = false;
  420. config->enableInvertHysteresisSign = false;
  421. config->enableRCThresholdDetection = false;
  422. config->enableRCScaleCircuit = 0U;
  423. config->complementFeedForwardStep = 0U;
  424. }
  425. /*!
  426. * brief Configure the DCDC loop control.
  427. *
  428. * param base DCDC peripheral base address.
  429. * param config Pointer to configuration structure. See to "dcdc_loop_control_config_t".
  430. */
  431. void DCDC_SetLoopControlConfig(DCDC_Type *base, const dcdc_loop_control_config_t *config)
  432. {
  433. assert(NULL != config);
  434. uint32_t tmp32;
  435. /* Configure the DCDC_REG1 register. */
  436. #if defined(FSL_FEATURE_DCDC_HAS_SWITCHING_CONVERTER_DIFFERENTIAL_MODE) && \
  437. FSL_FEATURE_DCDC_HAS_SWITCHING_CONVERTER_DIFFERENTIAL_MODE
  438. tmp32 = base->REG1 & ~(DCDC_REG1_LOOPCTRL_EN_DF_HYST_MASK | DCDC_REG1_LOOPCTRL_EN_CM_HYST_MASK |
  439. DCDC_REG1_LOOPCTRL_DF_HST_THRESH_MASK | DCDC_REG1_LOOPCTRL_CM_HST_THRESH_MASK);
  440. if (config->enableCommonHysteresis)
  441. {
  442. tmp32 |= DCDC_REG1_LOOPCTRL_EN_CM_HYST_MASK;
  443. }
  444. if (config->enableCommonThresholdDetection)
  445. {
  446. tmp32 |= DCDC_REG1_LOOPCTRL_CM_HST_THRESH_MASK;
  447. }
  448. if (config->enableDifferentialHysteresis)
  449. {
  450. tmp32 |= DCDC_REG1_LOOPCTRL_EN_DF_HYST_MASK;
  451. }
  452. if (config->enableDifferentialThresholdDetection)
  453. {
  454. tmp32 |= DCDC_REG1_LOOPCTRL_DF_HST_THRESH_MASK;
  455. }
  456. #else
  457. tmp32 = base->REG1 & ~(DCDC_REG1_LOOPCTRL_EN_HYST_MASK | DCDC_REG1_LOOPCTRL_HST_THRESH_MASK);
  458. if (config->enableCommonHysteresis)
  459. {
  460. tmp32 |= DCDC_REG1_LOOPCTRL_EN_HYST_MASK;
  461. }
  462. if (config->enableCommonThresholdDetection)
  463. {
  464. tmp32 |= DCDC_REG1_LOOPCTRL_HST_THRESH_MASK;
  465. }
  466. #endif /* FSL_FEATURE_DCDC_HAS_SWITCHING_CONVERTER_DIFFERENTIAL_MODE */
  467. base->REG1 = tmp32;
  468. /* configure the DCDC_REG2 register. */
  469. tmp32 = base->REG2 & ~(DCDC_REG2_LOOPCTRL_HYST_SIGN_MASK | DCDC_REG2_LOOPCTRL_RCSCALE_THRSH_MASK |
  470. DCDC_REG2_LOOPCTRL_EN_RCSCALE_MASK | DCDC_REG2_LOOPCTRL_DC_FF_MASK);
  471. tmp32 |= DCDC_REG2_LOOPCTRL_DC_FF(config->complementFeedForwardStep) |
  472. DCDC_REG2_LOOPCTRL_EN_RCSCALE(config->enableRCScaleCircuit);
  473. if (config->enableInvertHysteresisSign)
  474. {
  475. tmp32 |= DCDC_REG2_LOOPCTRL_HYST_SIGN_MASK;
  476. }
  477. if (config->enableRCThresholdDetection)
  478. {
  479. tmp32 |= DCDC_REG2_LOOPCTRL_RCSCALE_THRSH_MASK;
  480. }
  481. base->REG2 = tmp32;
  482. }
  483. /*!
  484. * brief Configure for the min power.
  485. *
  486. * param base DCDC peripheral base address.
  487. * param config Pointer to configuration structure. See to "dcdc_min_power_config_t".
  488. */
  489. void DCDC_SetMinPowerConfig(DCDC_Type *base, const dcdc_min_power_config_t *config)
  490. {
  491. assert(NULL != config);
  492. uint32_t tmp32;
  493. tmp32 = base->REG3 & ~DCDC_REG3_MINPWR_DC_HALFCLK_MASK;
  494. if (config->enableUseHalfFreqForContinuous)
  495. {
  496. tmp32 |= DCDC_REG3_MINPWR_DC_HALFCLK_MASK;
  497. }
  498. base->REG3 = tmp32;
  499. }
  500. #if (defined(FSL_FEATURE_DCDC_VDD_OUTPUT_COUNT) && (FSL_FEATURE_DCDC_VDD_OUTPUT_COUNT == 2))
  501. /*!
  502. * brief Adjust the target voltage of VDD_SOC in run mode and low power mode.
  503. * Do not use this function. It has been superceded by DCDC_AdjustRunTargetVoltage
  504. * and DCDC_AdjustLowPowerTargetVoltage.
  505. *
  506. * This function is to adjust the target voltage of DCDC output. Change them and finally wait until the output is
  507. * stabled.
  508. * Set the target value of run mode the same as low power mode before entering power save mode, because DCDC will switch
  509. * back to run mode if it detects the current loading is larger than about 50 mA(typical value).
  510. *
  511. * param base DCDC peripheral base address.
  512. * 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.
  513. * 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.
  514. * param sel sel DCDC target voltage output selection. See to "_dcdc_voltage_output_sel".
  515. */
  516. void DCDC_AdjustTargetVoltage(DCDC_Type *base, uint32_t VDDRun, uint32_t VDDStandby, dcdc_voltage_output_sel_t sel)
  517. {
  518. uint32_t tmp32;
  519. if (sel == kDCDC_VoltageOutput1P8)
  520. {
  521. /* Unlock the step for the VDD 1P8. */
  522. base->REG3 &= ~DCDC_REG3_VDD1P8CTRL_DISABLE_STEP_MASK;
  523. /* Configure the DCDC_CTRL1 register. */
  524. tmp32 = base->CTRL1 & ~(DCDC_CTRL1_VDD1P8CTRL_STBY_TRG_MASK | DCDC_CTRL1_VDD1P8CTRL_TRG_MASK);
  525. tmp32 |= DCDC_CTRL1_VDD1P8CTRL_STBY_TRG(VDDStandby) | DCDC_CTRL1_VDD1P8CTRL_TRG(VDDRun);
  526. base->CTRL1 = tmp32;
  527. }
  528. else if (sel == kDCDC_VoltageOutput1P0)
  529. {
  530. /* Unlock the step for the VDD 1P0. */
  531. base->REG3 &= ~DCDC_REG3_VDD1P0CTRL_DISABLE_STEP_MASK;
  532. /* Configure the DCDC_CTRL1 register. */
  533. tmp32 = base->CTRL1 & ~(DCDC_CTRL1_VDD1P0CTRL_STBY_TRG_MASK | DCDC_CTRL1_VDD1P0CTRL_TRG_MASK);
  534. tmp32 |= DCDC_CTRL1_VDD1P0CTRL_STBY_TRG(VDDStandby) | DCDC_CTRL1_VDD1P0CTRL_TRG(VDDRun);
  535. base->CTRL1 = tmp32;
  536. }
  537. else
  538. {
  539. ; /* Intentional empty */
  540. }
  541. /* DCDC_STS_DC_OK bit will be de-asserted after target register changes. After output voltage is set to new
  542. * target value, DCDC_STS_DC_OK will be asserted. */
  543. while (DCDC_REG0_STS_DC_OK_MASK != (DCDC_REG0_STS_DC_OK_MASK & base->REG0))
  544. {
  545. }
  546. }
  547. /*!
  548. * brief Adjust the target voltage of VDD_SOC in run mode.
  549. *
  550. * This function is to adjust the target voltage of DCDC output. Change them and finally wait until the output is
  551. * stabled.
  552. * Set the target value of run mode the same as low power mode before entering power save mode, because DCDC will switch
  553. * back to run mode if it detects the current loading is larger than about 50 mA(typical value).
  554. *
  555. * param base DCDC peripheral base address.
  556. * 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.
  557. * param sel sel DCDC target voltage output selection. See to "_dcdc_voltage_output_sel".
  558. */
  559. void DCDC_AdjustRunTargetVoltage(DCDC_Type *base, uint32_t VDDRun, dcdc_voltage_output_sel_t sel)
  560. {
  561. uint32_t tmp32;
  562. if (sel == kDCDC_VoltageOutput1P8)
  563. {
  564. /* Unlock the step for the VDD 1P8. */
  565. base->REG3 &= ~DCDC_REG3_VDD1P8CTRL_DISABLE_STEP_MASK;
  566. /* Configure the DCDC_CTRL1 register. */
  567. tmp32 = base->CTRL1 & ~DCDC_CTRL1_VDD1P8CTRL_TRG_MASK;
  568. tmp32 |= DCDC_CTRL1_VDD1P8CTRL_TRG(VDDRun);
  569. base->CTRL1 = tmp32;
  570. }
  571. else if (sel == kDCDC_VoltageOutput1P0)
  572. {
  573. /* Unlock the step for the VDD 1P0. */
  574. base->REG3 &= ~DCDC_REG3_VDD1P0CTRL_DISABLE_STEP_MASK;
  575. /* Configure the DCDC_CTRL1 register. */
  576. tmp32 = base->CTRL1 & ~DCDC_CTRL1_VDD1P0CTRL_TRG_MASK;
  577. tmp32 |= DCDC_CTRL1_VDD1P0CTRL_TRG(VDDRun);
  578. base->CTRL1 = tmp32;
  579. }
  580. else
  581. {
  582. ; /* Intentional empty */
  583. }
  584. /* DCDC_STS_DC_OK bit will be de-asserted after target register changes. After output voltage is set to new
  585. * target value, DCDC_STS_DC_OK will be asserted. */
  586. while (DCDC_REG0_STS_DC_OK_MASK != (DCDC_REG0_STS_DC_OK_MASK & base->REG0))
  587. {
  588. }
  589. }
  590. /*!
  591. * brief Adjust the target voltage of VDD_SOC in low power mode.
  592. *
  593. * This function is to adjust the target voltage of DCDC output. Change them and finally wait until the output is
  594. * stabled.
  595. * Set the target value of run mode the same as low power mode before entering power save mode, because DCDC will switch
  596. * back to run mode if it detects the current loading is larger than about 50 mA(typical value).
  597. *
  598. * param base DCDC peripheral base address.
  599. * 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.
  600. * param sel sel DCDC target voltage output selection. See to "_dcdc_voltage_output_sel".
  601. */
  602. void DCDC_AdjustLowPowerTargetVoltage(DCDC_Type *base, uint32_t VDDStandby, dcdc_voltage_output_sel_t sel)
  603. {
  604. uint32_t tmp32;
  605. if (sel == kDCDC_VoltageOutput1P8)
  606. {
  607. /* Unlock the step for the VDD 1P8. */
  608. base->REG3 &= ~DCDC_REG3_VDD1P8CTRL_DISABLE_STEP_MASK;
  609. /* Configure the DCDC_CTRL1 register. */
  610. tmp32 = base->CTRL1 & ~(DCDC_CTRL1_VDD1P8CTRL_STBY_TRG_MASK);
  611. tmp32 |= DCDC_CTRL1_VDD1P8CTRL_STBY_TRG(VDDStandby);
  612. base->CTRL1 = tmp32;
  613. }
  614. else if (sel == kDCDC_VoltageOutput1P0)
  615. {
  616. /* Unlock the step for the VDD 1P0. */
  617. base->REG3 &= ~DCDC_REG3_VDD1P0CTRL_DISABLE_STEP_MASK;
  618. /* Configure the DCDC_CTRL1 register. */
  619. tmp32 = base->CTRL1 & ~(DCDC_CTRL1_VDD1P0CTRL_STBY_TRG_MASK);
  620. tmp32 |= DCDC_CTRL1_VDD1P0CTRL_STBY_TRG(VDDStandby);
  621. base->CTRL1 = tmp32;
  622. }
  623. else
  624. {
  625. ; /* Intentional empty */
  626. }
  627. /* DCDC_STS_DC_OK bit will be de-asserted after target register changes. After output voltage is set to new
  628. * target value, DCDC_STS_DC_OK will be asserted. */
  629. while (DCDC_REG0_STS_DC_OK_MASK != (DCDC_REG0_STS_DC_OK_MASK & base->REG0))
  630. {
  631. }
  632. }
  633. #else
  634. /*!
  635. * brief Adjust the target voltage of VDD_SOC in run mode and low power mode.
  636. * Do not use this function. It has been superceded by DCDC_AdjustRunTargetVoltage
  637. * and DCDC_AdjustLowPowerTargetVoltage
  638. *
  639. * This function is to adjust the target voltage of DCDC output. Change them and finally wait until the output is
  640. * stabled.
  641. * Set the target value of run mode the same as low power mode before entering power save mode, because DCDC will switch
  642. * back to run mode if it detects the current loading is larger than about 50 mA(typical value).
  643. *
  644. * param base DCDC peripheral base address.
  645. * 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.
  646. * 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.
  647. */
  648. void DCDC_AdjustTargetVoltage(DCDC_Type *base, uint32_t VDDRun, uint32_t VDDStandby)
  649. {
  650. uint32_t tmp32;
  651. /* Unlock the step for the output. */
  652. base->REG3 &= ~DCDC_REG3_DISABLE_STEP_MASK;
  653. /* Configure the DCDC_REG3 register. */
  654. tmp32 = base->REG3 & ~(DCDC_REG3_TARGET_LP_MASK | DCDC_REG3_TRG_MASK);
  655. tmp32 |= DCDC_REG3_TARGET_LP(VDDStandby) | DCDC_REG3_TRG(VDDRun);
  656. base->REG3 = tmp32;
  657. /* DCDC_STS_DC_OK bit will be de-asserted after target register changes. After output voltage is set to new
  658. * target value, DCDC_STS_DC_OK will be asserted. */
  659. while (DCDC_REG0_STS_DC_OK_MASK != (DCDC_REG0_STS_DC_OK_MASK & base->REG0))
  660. {
  661. }
  662. }
  663. /*!
  664. * brief Adjust the target voltage of VDD_SOC in run mode.
  665. *
  666. * This function is to adjust the target voltage of DCDC output. Change them and finally wait until the output is
  667. * stabled.
  668. * Set the target value of run mode the same as low power mode before entering power save mode, because DCDC will switch
  669. * back to run mode if it detects the current loading is larger than about 50 mA(typical value).
  670. *
  671. * param base DCDC peripheral base address.
  672. * 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.
  673. */
  674. void DCDC_AdjustRunTargetVoltage(DCDC_Type *base, uint32_t VDDRun)
  675. {
  676. uint32_t tmp32;
  677. /* Unlock the step for the output. */
  678. base->REG3 &= ~DCDC_REG3_DISABLE_STEP_MASK;
  679. /* Configure the DCDC_REG3 register. */
  680. tmp32 = base->REG3 & ~DCDC_REG3_TRG_MASK;
  681. tmp32 |= DCDC_REG3_TRG(VDDRun);
  682. base->REG3 = tmp32;
  683. /* DCDC_STS_DC_OK bit will be de-asserted after target register changes. After output voltage is set to new
  684. * target value, DCDC_STS_DC_OK will be asserted. */
  685. while (DCDC_REG0_STS_DC_OK_MASK != (DCDC_REG0_STS_DC_OK_MASK & base->REG0))
  686. {
  687. }
  688. }
  689. /*!
  690. * brief Adjust the target voltage of VDD_SOC in low power mode.
  691. *
  692. * This function is to adjust the target voltage of DCDC output. Change them and finally wait until the output is
  693. * stabled.
  694. * Set the target value of run mode the same as low power mode before entering power save mode, because DCDC will switch
  695. * back to run mode if it detects the current loading is larger than about 50 mA(typical value).
  696. *
  697. * param base DCDC peripheral base address.
  698. * 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.
  699. */
  700. void DCDC_AdjustLowPowerTargetVoltage(DCDC_Type *base, uint32_t VDDStandby)
  701. {
  702. uint32_t tmp32;
  703. /* Unlock the step for the output. */
  704. base->REG3 &= ~DCDC_REG3_DISABLE_STEP_MASK;
  705. /* Configure the DCDC_REG3 register. */
  706. tmp32 = base->REG3 & ~DCDC_REG3_TARGET_LP_MASK;
  707. tmp32 |= DCDC_REG3_TARGET_LP(VDDStandby);
  708. base->REG3 = tmp32;
  709. /* DCDC_STS_DC_OK bit will be de-asserted after target register changes. After output voltage is set to new
  710. * target value, DCDC_STS_DC_OK will be asserted. */
  711. while (DCDC_REG0_STS_DC_OK_MASK != (DCDC_REG0_STS_DC_OK_MASK & base->REG0))
  712. {
  713. }
  714. }
  715. #endif /* FSL_FEATURE_DCDC_VDD_OUTPUT_COUNT == 2 */
  716. /*!
  717. * brief Configure the DCDC internal regulator.
  718. *
  719. * param base DCDC peripheral base address.
  720. * param config Pointer to configuration structure. See to "dcdc_internal_regulator_config_t".
  721. */
  722. void DCDC_SetInternalRegulatorConfig(DCDC_Type *base, const dcdc_internal_regulator_config_t *config)
  723. {
  724. assert(NULL != config);
  725. uint32_t tmp32;
  726. #if (defined(FSL_FEATURE_DCDC_HAS_REG3_FBK_SEL) && FSL_FEATURE_DCDC_HAS_REG3_FBK_SEL)
  727. tmp32 = base->REG3 & ~DCDC_REG3_REG_FBK_SEL_MASK;
  728. tmp32 |= DCDC_REG3_REG_FBK_SEL(config->feedbackPoint);
  729. base->REG3 = tmp32;
  730. tmp32 = base->REG1 & ~DCDC_REG1_REG_RLOAD_SW_MASK;
  731. #else
  732. /* Configure the DCDC_REG1 register. */
  733. tmp32 = base->REG1 & ~(DCDC_REG1_REG_FBK_SEL_MASK | DCDC_REG1_REG_RLOAD_SW_MASK);
  734. tmp32 |= DCDC_REG1_REG_FBK_SEL(config->feedbackPoint);
  735. #endif /* FSL_FEATURE_DCDC_HAS_REG3_FBK_SEL */
  736. if (config->enableLoadResistor)
  737. {
  738. tmp32 |= DCDC_REG1_REG_RLOAD_SW_MASK;
  739. }
  740. base->REG1 = tmp32;
  741. }
  742. #if (defined(DCDC_REG4_ENABLE_SP_MASK) && DCDC_REG4_ENABLE_SP_MASK)
  743. /*!
  744. * brief Init DCDC module when the control mode selected as setpoint mode.
  745. *
  746. * note The function should be invoked in the initial step to config the
  747. * DCDC via setpoint control mode.
  748. *
  749. * param base DCDC peripheral base address.
  750. * param config The pointer to the structure @ref dcdc_setpoint_config_t.
  751. */
  752. void DCDC_SetPointInit(DCDC_Type *base, const dcdc_setpoint_config_t *config)
  753. {
  754. assert(config != NULL);
  755. /* Enable DCDC Dig Logic. */
  756. base->REG5 = config->enableDigLogicMap;
  757. /* Set DCDC power mode. */
  758. base->REG6 = config->lowpowerMap;
  759. base->REG7 = config->standbyMap;
  760. base->REG7P = config->standbyLowpowerMap;
  761. /* Set target voltage of VDD1P8 in buck mode. */
  762. base->REG8 = DCDC_ConvertByteArrayToWord(config->buckVDD1P8TargetVoltage);
  763. base->REG9 = DCDC_ConvertByteArrayToWord(config->buckVDD1P8TargetVoltage + 4U);
  764. base->REG10 = DCDC_ConvertByteArrayToWord(config->buckVDD1P8TargetVoltage + 8U);
  765. base->REG11 = DCDC_ConvertByteArrayToWord(config->buckVDD1P8TargetVoltage + 12U);
  766. /* Set target voltage of VDD1P0 in buck mode. */
  767. base->REG12 = DCDC_ConvertByteArrayToWord(config->buckVDD1P0TargetVoltage);
  768. base->REG13 = DCDC_ConvertByteArrayToWord(config->buckVDD1P0TargetVoltage + 4U);
  769. base->REG14 = DCDC_ConvertByteArrayToWord(config->buckVDD1P0TargetVoltage + 8U);
  770. base->REG15 = DCDC_ConvertByteArrayToWord(config->buckVDD1P0TargetVoltage + 12U);
  771. /* Set target voltage of VDD1P8 in low power mode. */
  772. base->REG16 = DCDC_ConvertByteArrayToWord(config->standbyVDD1P8TargetVoltage);
  773. base->REG17 = DCDC_ConvertByteArrayToWord(config->standbyVDD1P8TargetVoltage + 4U);
  774. base->REG18 = DCDC_ConvertByteArrayToWord(config->standbyVDD1P8TargetVoltage + 8U);
  775. base->REG19 = DCDC_ConvertByteArrayToWord(config->standbyVDD1P8TargetVoltage + 12U);
  776. /* Set target voltage of VDD1P0 in low power mode. */
  777. base->REG20 = DCDC_ConvertByteArrayToWord(config->standbyVDD1P0TargetVoltage);
  778. base->REG21 = DCDC_ConvertByteArrayToWord(config->standbyVDD1P0TargetVoltage + 4U);
  779. base->REG22 = DCDC_ConvertByteArrayToWord(config->standbyVDD1P0TargetVoltage + 8U);
  780. base->REG23 = DCDC_ConvertByteArrayToWord(config->standbyVDD1P0TargetVoltage + 12U);
  781. /* Enable DCDC module. */
  782. base->REG4 = config->enableDCDCMap;
  783. }
  784. #endif /* DCDC_REG4_ENABLE_SP_MASK */
  785. /*!
  786. * brief Boot DCDC into DCM(discontinous conduction mode).
  787. *
  788. * pwd_zcd=0x0;
  789. * pwd_cmp_offset=0x0;
  790. * dcdc_loopctrl_en_rcscale= 0x5;
  791. * DCM_set_ctrl=1'b1;
  792. *
  793. * param base DCDC peripheral base address.
  794. */
  795. void DCDC_BootIntoDCM(DCDC_Type *base)
  796. {
  797. base->REG0 &= ~(DCDC_REG0_PWD_ZCD_MASK | DCDC_REG0_PWD_CMP_OFFSET_MASK);
  798. base->REG2 = (~DCDC_REG2_LOOPCTRL_EN_RCSCALE_MASK & base->REG2) | DCDC_REG2_LOOPCTRL_EN_RCSCALE(0x5U) |
  799. DCDC_REG2_DCM_SET_CTRL_MASK;
  800. }
  801. /*!
  802. * brief Boot DCDC into CCM(continous conduction mode).
  803. *
  804. * pwd_zcd=0x1;
  805. * pwd_cmp_offset=0x0;
  806. * dcdc_loopctrl_en_rcscale=0x3;
  807. *
  808. * param base DCDC peripheral base address.
  809. */
  810. void DCDC_BootIntoCCM(DCDC_Type *base)
  811. {
  812. base->REG0 = (~DCDC_REG0_PWD_CMP_OFFSET_MASK & base->REG0) | DCDC_REG0_PWD_ZCD_MASK;
  813. base->REG2 = (~DCDC_REG2_LOOPCTRL_EN_RCSCALE_MASK & base->REG2) | DCDC_REG2_LOOPCTRL_EN_RCSCALE(0x3U);
  814. }