fsl_pdb.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _FSL_PDB_H_
  35. #define _FSL_PDB_H_
  36. #include "fsl_common.h"
  37. /*!
  38. * @addtogroup pdb
  39. * @{
  40. */
  41. /*******************************************************************************
  42. * Definitions
  43. ******************************************************************************/
  44. /*! @name Driver version */
  45. /*@{*/
  46. /*! @brief PDB driver version 2.0.1. */
  47. #define FSL_PDB_DRIVER_VERSION (MAKE_VERSION(2, 0, 1))
  48. /*@}*/
  49. /*!
  50. * @brief PDB flags.
  51. */
  52. enum _pdb_status_flags
  53. {
  54. kPDB_LoadOKFlag = PDB_SC_LDOK_MASK, /*!< This flag is automatically cleared when the values in buffers are
  55. loaded into the internal registers after the LDOK bit is set or the
  56. PDBEN is cleared. */
  57. kPDB_DelayEventFlag = PDB_SC_PDBIF_MASK, /*!< PDB timer delay event flag. */
  58. };
  59. /*!
  60. * @brief PDB ADC PreTrigger channel flags.
  61. */
  62. enum _pdb_adc_pretrigger_flags
  63. {
  64. /* PDB PreTrigger channel match flags. */
  65. kPDB_ADCPreTriggerChannel0Flag = PDB_S_CF(1U << 0), /*!< Pre-trigger 0 flag. */
  66. kPDB_ADCPreTriggerChannel1Flag = PDB_S_CF(1U << 1), /*!< Pre-trigger 1 flag. */
  67. #if (PDB_DLY_COUNT2 > 2)
  68. kPDB_ADCPreTriggerChannel2Flag = PDB_S_CF(1U << 2), /*!< Pre-trigger 2 flag. */
  69. kPDB_ADCPreTriggerChannel3Flag = PDB_S_CF(1U << 3), /*!< Pre-trigger 3 flag. */
  70. #endif /* PDB_DLY_COUNT2 > 2 */
  71. #if (PDB_DLY_COUNT2 > 4)
  72. kPDB_ADCPreTriggerChannel4Flag = PDB_S_CF(1U << 4), /*!< Pre-trigger 4 flag. */
  73. kPDB_ADCPreTriggerChannel5Flag = PDB_S_CF(1U << 5), /*!< Pre-trigger 5 flag. */
  74. kPDB_ADCPreTriggerChannel6Flag = PDB_S_CF(1U << 6), /*!< Pre-trigger 6 flag. */
  75. kPDB_ADCPreTriggerChannel7Flag = PDB_S_CF(1U << 7), /*!< Pre-trigger 7 flag. */
  76. #endif /* PDB_DLY_COUNT2 > 4 */
  77. /* PDB PreTrigger channel error flags. */
  78. kPDB_ADCPreTriggerChannel0ErrorFlag = PDB_S_ERR(1U << 0), /*!< Pre-trigger 0 Error. */
  79. kPDB_ADCPreTriggerChannel1ErrorFlag = PDB_S_ERR(1U << 1), /*!< Pre-trigger 1 Error. */
  80. #if (PDB_DLY_COUNT2 > 2)
  81. kPDB_ADCPreTriggerChannel2ErrorFlag = PDB_S_ERR(1U << 2), /*!< Pre-trigger 2 Error. */
  82. kPDB_ADCPreTriggerChannel3ErrorFlag = PDB_S_ERR(1U << 3), /*!< Pre-trigger 3 Error. */
  83. #endif /* PDB_DLY_COUNT2 > 2 */
  84. #if (PDB_DLY_COUNT2 > 4)
  85. kPDB_ADCPreTriggerChannel4ErrorFlag = PDB_S_ERR(1U << 4), /*!< Pre-trigger 4 Error. */
  86. kPDB_ADCPreTriggerChannel5ErrorFlag = PDB_S_ERR(1U << 5), /*!< Pre-trigger 5 Error. */
  87. kPDB_ADCPreTriggerChannel6ErrorFlag = PDB_S_ERR(1U << 6), /*!< Pre-trigger 6 Error. */
  88. kPDB_ADCPreTriggerChannel7ErrorFlag = PDB_S_ERR(1U << 7), /*!< Pre-trigger 7 Error. */
  89. #endif /* PDB_DLY_COUNT2 > 4 */
  90. };
  91. /*!
  92. * @brief PDB buffer interrupts.
  93. */
  94. enum _pdb_interrupt_enable
  95. {
  96. kPDB_SequenceErrorInterruptEnable = PDB_SC_PDBEIE_MASK, /*!< PDB sequence error interrupt enable. */
  97. kPDB_DelayInterruptEnable = PDB_SC_PDBIE_MASK, /*!< PDB delay interrupt enable. */
  98. };
  99. /*!
  100. * @brief PDB load value mode.
  101. *
  102. * Selects the mode to load the internal values after doing the load operation (write 1 to PDBx_SC[LDOK]).
  103. * These values are for the following operations.
  104. * - PDB counter (PDBx_MOD, PDBx_IDLY)
  105. * - ADC trigger (PDBx_CHnDLYm)
  106. * - DAC trigger (PDBx_DACINTx)
  107. * - CMP trigger (PDBx_POyDLY)
  108. */
  109. typedef enum _pdb_load_value_mode
  110. {
  111. kPDB_LoadValueImmediately = 0U, /*!< Load immediately after 1 is written to LDOK. */
  112. kPDB_LoadValueOnCounterOverflow = 1U, /*!< Load when the PDB counter overflows (reaches the MOD
  113. register value). */
  114. kPDB_LoadValueOnTriggerInput = 2U, /*!< Load a trigger input event is detected. */
  115. kPDB_LoadValueOnCounterOverflowOrTriggerInput = 3U, /*!< Load either when the PDB counter overflows or a trigger
  116. input is detected. */
  117. } pdb_load_value_mode_t;
  118. /*!
  119. * @brief Prescaler divider.
  120. *
  121. * Counting uses the peripheral clock divided by multiplication factor selected by times of MULT.
  122. */
  123. typedef enum _pdb_prescaler_divider
  124. {
  125. kPDB_PrescalerDivider1 = 0U, /*!< Divider x1. */
  126. kPDB_PrescalerDivider2 = 1U, /*!< Divider x2. */
  127. kPDB_PrescalerDivider4 = 2U, /*!< Divider x4. */
  128. kPDB_PrescalerDivider8 = 3U, /*!< Divider x8. */
  129. kPDB_PrescalerDivider16 = 4U, /*!< Divider x16. */
  130. kPDB_PrescalerDivider32 = 5U, /*!< Divider x32. */
  131. kPDB_PrescalerDivider64 = 6U, /*!< Divider x64. */
  132. kPDB_PrescalerDivider128 = 7U, /*!< Divider x128. */
  133. } pdb_prescaler_divider_t;
  134. /*!
  135. * @brief Multiplication factor select for prescaler.
  136. *
  137. * Selects the multiplication factor of the prescaler divider for the counter clock.
  138. */
  139. typedef enum _pdb_divider_multiplication_factor
  140. {
  141. kPDB_DividerMultiplicationFactor1 = 0U, /*!< Multiplication factor is 1. */
  142. kPDB_DividerMultiplicationFactor10 = 1U, /*!< Multiplication factor is 10. */
  143. kPDB_DividerMultiplicationFactor20 = 2U, /*!< Multiplication factor is 20. */
  144. kPDB_DividerMultiplicationFactor40 = 3U, /*!< Multiplication factor is 40. */
  145. } pdb_divider_multiplication_factor_t;
  146. /*!
  147. * @brief Trigger input source
  148. *
  149. * Selects the trigger input source for the PDB. The trigger input source can be internal or external (EXTRG pin), or
  150. * the software trigger. See chip configuration details for the actual PDB input trigger connections.
  151. */
  152. typedef enum _pdb_trigger_input_source
  153. {
  154. kPDB_TriggerInput0 = 0U, /*!< Trigger-In 0. */
  155. kPDB_TriggerInput1 = 1U, /*!< Trigger-In 1. */
  156. kPDB_TriggerInput2 = 2U, /*!< Trigger-In 2. */
  157. kPDB_TriggerInput3 = 3U, /*!< Trigger-In 3. */
  158. kPDB_TriggerInput4 = 4U, /*!< Trigger-In 4. */
  159. kPDB_TriggerInput5 = 5U, /*!< Trigger-In 5. */
  160. kPDB_TriggerInput6 = 6U, /*!< Trigger-In 6. */
  161. kPDB_TriggerInput7 = 7U, /*!< Trigger-In 7. */
  162. kPDB_TriggerInput8 = 8U, /*!< Trigger-In 8. */
  163. kPDB_TriggerInput9 = 9U, /*!< Trigger-In 9. */
  164. kPDB_TriggerInput10 = 10U, /*!< Trigger-In 10. */
  165. kPDB_TriggerInput11 = 11U, /*!< Trigger-In 11. */
  166. kPDB_TriggerInput12 = 12U, /*!< Trigger-In 12. */
  167. kPDB_TriggerInput13 = 13U, /*!< Trigger-In 13. */
  168. kPDB_TriggerInput14 = 14U, /*!< Trigger-In 14. */
  169. kPDB_TriggerSoftware = 15U, /*!< Trigger-In 15, software trigger. */
  170. } pdb_trigger_input_source_t;
  171. /*!
  172. * @brief List of PDB ADC trigger channels
  173. * @note Actual number of available channels is SoC dependent
  174. */
  175. typedef enum _pdb_adc_trigger_channel
  176. {
  177. kPDB_ADCTriggerChannel0 = 0U, /*!< PDB ADC trigger channel number 0 */
  178. kPDB_ADCTriggerChannel1 = 1U, /*!< PDB ADC trigger channel number 1 */
  179. kPDB_ADCTriggerChannel2 = 2U, /*!< PDB ADC trigger channel number 2 */
  180. kPDB_ADCTriggerChannel3 = 3U, /*!< PDB ADC trigger channel number 3 */
  181. } pdb_adc_trigger_channel_t;
  182. /*!
  183. * @brief List of PDB ADC pretrigger
  184. * @note Actual number of available pretrigger channels is SoC dependent
  185. */
  186. typedef enum _pdb_adc_pretrigger
  187. {
  188. kPDB_ADCPreTrigger0 = 0U, /*!< PDB ADC pretrigger number 0 */
  189. kPDB_ADCPreTrigger1 = 1U, /*!< PDB ADC pretrigger number 1 */
  190. kPDB_ADCPreTrigger2 = 2U, /*!< PDB ADC pretrigger number 2 */
  191. kPDB_ADCPreTrigger3 = 3U, /*!< PDB ADC pretrigger number 3 */
  192. kPDB_ADCPreTrigger4 = 4U, /*!< PDB ADC pretrigger number 4 */
  193. kPDB_ADCPreTrigger5 = 5U, /*!< PDB ADC pretrigger number 5 */
  194. kPDB_ADCPreTrigger6 = 6U, /*!< PDB ADC pretrigger number 6 */
  195. kPDB_ADCPreTrigger7 = 7U, /*!< PDB ADC pretrigger number 7 */
  196. } pdb_adc_pretrigger_t;
  197. /*!
  198. * @brief List of PDB DAC trigger channels
  199. * @note Actual number of available channels is SoC dependent
  200. */
  201. typedef enum _pdb_dac_trigger_channel
  202. {
  203. kPDB_DACTriggerChannel0 = 0U, /*!< PDB DAC trigger channel number 0 */
  204. kPDB_DACTriggerChannel1 = 1U, /*!< PDB DAC trigger channel number 1 */
  205. } pdb_dac_trigger_channel_t;
  206. /*!
  207. * @brief List of PDB pulse out trigger channels
  208. * @note Actual number of available channels is SoC dependent
  209. */
  210. typedef enum _pdb_pulse_out_trigger_channel
  211. {
  212. kPDB_PulseOutTriggerChannel0 = 0U, /*!< PDB pulse out trigger channel number 0 */
  213. kPDB_PulseOutTriggerChannel1 = 1U, /*!< PDB pulse out trigger channel number 1 */
  214. kPDB_PulseOutTriggerChannel2 = 2U, /*!< PDB pulse out trigger channel number 2 */
  215. kPDB_PulseOutTriggerChannel3 = 3U, /*!< PDB pulse out trigger channel number 3 */
  216. } pdb_pulse_out_trigger_channel_t;
  217. /*!
  218. * @brief List of PDB pulse out trigger channels mask
  219. * @note Actual number of available channels mask is SoC dependent
  220. */
  221. typedef enum _pdb_pulse_out_channel_mask
  222. {
  223. kPDB_PulseOutChannel0Mask = (1U << 0U), /*!< PDB pulse out trigger channel number 0 mask */
  224. kPDB_PulseOutChannel1Mask = (1U << 1U), /*!< PDB pulse out trigger channel number 1 mask */
  225. kPDB_PulseOutChannel2Mask = (1U << 2U), /*!< PDB pulse out trigger channel number 2 mask */
  226. kPDB_PulseOutChannel3Mask = (1U << 3U), /*!< PDB pulse out trigger channel number 3 mask */
  227. } pdb_pulse_out_channel_mask_t;
  228. /*!
  229. * @brief PDB module configuration.
  230. */
  231. typedef struct _pdb_config
  232. {
  233. pdb_load_value_mode_t loadValueMode; /*!< Select the load value mode. */
  234. pdb_prescaler_divider_t prescalerDivider; /*!< Select the prescaler divider. */
  235. pdb_divider_multiplication_factor_t dividerMultiplicationFactor; /*!< Multiplication factor select for prescaler. */
  236. pdb_trigger_input_source_t triggerInputSource; /*!< Select the trigger input source. */
  237. bool enableContinuousMode; /*!< Enable the PDB operation in Continuous mode.*/
  238. } pdb_config_t;
  239. /*!
  240. * @brief PDB ADC Pre-trigger configuration.
  241. */
  242. typedef struct _pdb_adc_pretrigger_config
  243. {
  244. uint32_t enablePreTriggerMask; /*!< PDB Channel Pre-trigger Enable. */
  245. uint32_t enableOutputMask; /*!< PDB Channel Pre-trigger Output Select.
  246. PDB channel's corresponding pre-trigger asserts when the counter
  247. reaches the channel delay register. */
  248. uint32_t enableBackToBackOperationMask; /*!< PDB Channel pre-trigger Back-to-Back Operation Enable.
  249. Back-to-back operation enables the ADC conversions complete to trigger
  250. the next PDB channel pre-trigger and trigger output, so that the ADC
  251. conversions can be triggered on next set of configuration and results
  252. registers.*/
  253. } pdb_adc_pretrigger_config_t;
  254. /*!
  255. * @brief PDB DAC trigger configuration.
  256. */
  257. typedef struct _pdb_dac_trigger_config
  258. {
  259. bool enableExternalTriggerInput; /*!< Enables the external trigger for DAC interval counter. */
  260. bool enableIntervalTrigger; /*!< Enables the DAC interval trigger. */
  261. } pdb_dac_trigger_config_t;
  262. /*******************************************************************************
  263. * API
  264. ******************************************************************************/
  265. #if defined(__cplusplus)
  266. extern "C" {
  267. #endif
  268. /*!
  269. * @name Initialization
  270. * @{
  271. */
  272. /*!
  273. * @brief Initializes the PDB module.
  274. *
  275. * This function initializes the PDB module. The operations included are as follows.
  276. * - Enable the clock for PDB instance.
  277. * - Configure the PDB module.
  278. * - Enable the PDB module.
  279. *
  280. * @param base PDB peripheral base address.
  281. * @param config Pointer to the configuration structure. See "pdb_config_t".
  282. */
  283. void PDB_Init(PDB_Type *base, const pdb_config_t *config);
  284. /*!
  285. * @brief De-initializes the PDB module.
  286. *
  287. * @param base PDB peripheral base address.
  288. */
  289. void PDB_Deinit(PDB_Type *base);
  290. /*!
  291. * @brief Initializes the PDB user configuration structure.
  292. *
  293. * This function initializes the user configuration structure to a default value. The default values are as follows.
  294. * @code
  295. * config->loadValueMode = kPDB_LoadValueImmediately;
  296. * config->prescalerDivider = kPDB_PrescalerDivider1;
  297. * config->dividerMultiplicationFactor = kPDB_DividerMultiplicationFactor1;
  298. * config->triggerInputSource = kPDB_TriggerSoftware;
  299. * config->enableContinuousMode = false;
  300. * @endcode
  301. * @param config Pointer to configuration structure. See "pdb_config_t".
  302. */
  303. void PDB_GetDefaultConfig(pdb_config_t *config);
  304. /*!
  305. * @brief Enables the PDB module.
  306. *
  307. * @param base PDB peripheral base address.
  308. * @param enable Enable the module or not.
  309. */
  310. static inline void PDB_Enable(PDB_Type *base, bool enable)
  311. {
  312. if (enable)
  313. {
  314. base->SC |= PDB_SC_PDBEN_MASK;
  315. }
  316. else
  317. {
  318. base->SC &= ~PDB_SC_PDBEN_MASK;
  319. }
  320. }
  321. /* @} */
  322. /*!
  323. * @name Basic Counter
  324. * @{
  325. */
  326. /*!
  327. * @brief Triggers the PDB counter by software.
  328. *
  329. * @param base PDB peripheral base address.
  330. */
  331. static inline void PDB_DoSoftwareTrigger(PDB_Type *base)
  332. {
  333. base->SC |= PDB_SC_SWTRIG_MASK;
  334. }
  335. /*!
  336. * @brief Loads the counter values.
  337. *
  338. * This function loads the counter values from the internal buffer.
  339. * See "pdb_load_value_mode_t" about PDB's load mode.
  340. *
  341. * @param base PDB peripheral base address.
  342. */
  343. static inline void PDB_DoLoadValues(PDB_Type *base)
  344. {
  345. base->SC |= PDB_SC_LDOK_MASK;
  346. }
  347. /*!
  348. * @brief Enables the DMA for the PDB module.
  349. *
  350. * @param base PDB peripheral base address.
  351. * @param enable Enable the feature or not.
  352. */
  353. static inline void PDB_EnableDMA(PDB_Type *base, bool enable)
  354. {
  355. if (enable)
  356. {
  357. base->SC |= PDB_SC_DMAEN_MASK;
  358. }
  359. else
  360. {
  361. base->SC &= ~PDB_SC_DMAEN_MASK;
  362. }
  363. }
  364. /*!
  365. * @brief Enables the interrupts for the PDB module.
  366. *
  367. * @param base PDB peripheral base address.
  368. * @param mask Mask value for interrupts. See "_pdb_interrupt_enable".
  369. */
  370. static inline void PDB_EnableInterrupts(PDB_Type *base, uint32_t mask)
  371. {
  372. assert(0U == (mask & ~(PDB_SC_PDBEIE_MASK | PDB_SC_PDBIE_MASK)));
  373. base->SC |= mask;
  374. }
  375. /*!
  376. * @brief Disables the interrupts for the PDB module.
  377. *
  378. * @param base PDB peripheral base address.
  379. * @param mask Mask value for interrupts. See "_pdb_interrupt_enable".
  380. */
  381. static inline void PDB_DisableInterrupts(PDB_Type *base, uint32_t mask)
  382. {
  383. assert(0U == (mask & ~(PDB_SC_PDBEIE_MASK | PDB_SC_PDBIE_MASK)));
  384. base->SC &= ~mask;
  385. }
  386. /*!
  387. * @brief Gets the status flags of the PDB module.
  388. *
  389. * @param base PDB peripheral base address.
  390. *
  391. * @return Mask value for asserted flags. See "_pdb_status_flags".
  392. */
  393. static inline uint32_t PDB_GetStatusFlags(PDB_Type *base)
  394. {
  395. return base->SC & (PDB_SC_PDBIF_MASK | PDB_SC_LDOK_MASK);
  396. }
  397. /*!
  398. * @brief Clears the status flags of the PDB module.
  399. *
  400. * @param base PDB peripheral base address.
  401. * @param mask Mask value of flags. See "_pdb_status_flags".
  402. */
  403. static inline void PDB_ClearStatusFlags(PDB_Type *base, uint32_t mask)
  404. {
  405. assert(0U == (mask & ~PDB_SC_PDBIF_MASK));
  406. base->SC &= ~mask;
  407. }
  408. /*!
  409. * @brief Specifies the counter period.
  410. *
  411. * @param base PDB peripheral base address.
  412. * @param value Setting value for the modulus. 16-bit is available.
  413. */
  414. static inline void PDB_SetModulusValue(PDB_Type *base, uint32_t value)
  415. {
  416. base->MOD = PDB_MOD_MOD(value);
  417. }
  418. /*!
  419. * @brief Gets the PDB counter's current value.
  420. *
  421. * @param base PDB peripheral base address.
  422. *
  423. * @return PDB counter's current value.
  424. */
  425. static inline uint32_t PDB_GetCounterValue(PDB_Type *base)
  426. {
  427. return base->CNT;
  428. }
  429. /*!
  430. * @brief Sets the value for the PDB counter delay event.
  431. *
  432. * @param base PDB peripheral base address.
  433. * @param value Setting value for PDB counter delay event. 16-bit is available.
  434. */
  435. static inline void PDB_SetCounterDelayValue(PDB_Type *base, uint32_t value)
  436. {
  437. base->IDLY = PDB_IDLY_IDLY(value);
  438. }
  439. /* @} */
  440. /*!
  441. * @name ADC Pre-trigger
  442. * @{
  443. */
  444. /*!
  445. * @brief Configures the ADC pre-trigger in the PDB module.
  446. *
  447. * @param base PDB peripheral base address.
  448. * @param channel Channel index for ADC instance.
  449. * @param config Pointer to the configuration structure. See "pdb_adc_pretrigger_config_t".
  450. */
  451. static inline void PDB_SetADCPreTriggerConfig(PDB_Type *base, pdb_adc_trigger_channel_t channel, pdb_adc_pretrigger_config_t *config)
  452. {
  453. assert(channel < PDB_C1_COUNT);
  454. assert(NULL != config);
  455. base->CH[channel].C1 = PDB_C1_BB(config->enableBackToBackOperationMask) | PDB_C1_TOS(config->enableOutputMask) |
  456. PDB_C1_EN(config->enablePreTriggerMask);
  457. }
  458. /*!
  459. * @brief Sets the value for the ADC pre-trigger delay event.
  460. *
  461. * This function sets the value for ADC pre-trigger delay event. It specifies the delay value for the channel's
  462. * corresponding pre-trigger. The pre-trigger asserts when the PDB counter is equal to the set value.
  463. *
  464. * @param base PDB peripheral base address.
  465. * @param channel Channel index for ADC instance.
  466. * @param pretriggerNumber Channel group index for ADC instance.
  467. * @param value Setting value for ADC pre-trigger delay event. 16-bit is available.
  468. */
  469. static inline void PDB_SetADCPreTriggerDelayValue(PDB_Type *base, pdb_adc_trigger_channel_t channel, pdb_adc_pretrigger_t pretriggerNumber, uint32_t value)
  470. {
  471. assert(channel < PDB_C1_COUNT);
  472. assert(pretriggerNumber < PDB_DLY_COUNT2);
  473. /* xx_COUNT2 is actually the count for pre-triggers in header file. xx_COUNT is used for the count of channels. */
  474. base->CH[channel].DLY[pretriggerNumber] = PDB_DLY_DLY(value);
  475. }
  476. /*!
  477. * @brief Gets the ADC pre-trigger's status flags.
  478. *
  479. * @param base PDB peripheral base address.
  480. * @param channel Channel index for ADC instance.
  481. *
  482. * @return Mask value for asserted flags. See "_pdb_adc_pretrigger_flags".
  483. */
  484. static inline uint32_t PDB_GetADCPreTriggerStatusFlags(PDB_Type *base, pdb_adc_trigger_channel_t channel)
  485. {
  486. assert(channel < PDB_C1_COUNT);
  487. return base->CH[channel].S;
  488. }
  489. /*!
  490. * @brief Clears the ADC pre-trigger status flags.
  491. *
  492. * @param base PDB peripheral base address.
  493. * @param channel Channel index for ADC instance.
  494. * @param mask Mask value for flags. See "_pdb_adc_pretrigger_flags".
  495. */
  496. static inline void PDB_ClearADCPreTriggerStatusFlags(PDB_Type *base, pdb_adc_trigger_channel_t channel, uint32_t mask)
  497. {
  498. assert(channel < PDB_C1_COUNT);
  499. base->CH[channel].S &= ~mask;
  500. }
  501. /* @} */
  502. #if defined(FSL_FEATURE_PDB_HAS_DAC) && FSL_FEATURE_PDB_HAS_DAC
  503. /*!
  504. * @name DAC Interval Trigger
  505. * @{
  506. */
  507. /*!
  508. * @brief Configures the DAC trigger in the PDB module.
  509. *
  510. * @param base PDB peripheral base address.
  511. * @param channel Channel index for DAC instance.
  512. * @param config Pointer to the configuration structure. See "pdb_dac_trigger_config_t".
  513. */
  514. void PDB_SetDACTriggerConfig(PDB_Type *base, pdb_dac_trigger_channel_t channel, pdb_dac_trigger_config_t *config);
  515. /*!
  516. * @brief Sets the value for the DAC interval event.
  517. *
  518. * This fucntion sets the value for DAC interval event. DAC interval trigger triggers the DAC module to update
  519. * the buffer when the DAC interval counter is equal to the set value.
  520. *
  521. * @param base PDB peripheral base address.
  522. * @param channel Channel index for DAC instance.
  523. * @param value Setting value for the DAC interval event.
  524. */
  525. static inline void PDB_SetDACTriggerIntervalValue(PDB_Type *base, pdb_dac_trigger_channel_t channel, uint32_t value)
  526. {
  527. assert(channel < PDB_INT_COUNT);
  528. base->DAC[channel].INT = PDB_INT_INT(value);
  529. }
  530. /* @} */
  531. #endif /* FSL_FEATURE_PDB_HAS_DAC */
  532. /*!
  533. * @name Pulse-Out Trigger
  534. * @{
  535. */
  536. /*!
  537. * @brief Enables the pulse out trigger channels.
  538. *
  539. * @param base PDB peripheral base address.
  540. * @param channelMask Channel mask value for multiple pulse out trigger channel.
  541. * @param enable Whether the feature is enabled or not.
  542. */
  543. static inline void PDB_EnablePulseOutTrigger(PDB_Type *base, pdb_pulse_out_channel_mask_t channelMask, bool enable)
  544. {
  545. assert(channelMask < (1 << PDB_PODLY_COUNT));
  546. if (enable)
  547. {
  548. base->POEN |= PDB_POEN_POEN(channelMask);
  549. }
  550. else
  551. {
  552. base->POEN &= ~(PDB_POEN_POEN(channelMask));
  553. }
  554. }
  555. /*!
  556. * @brief Sets event values for the pulse out trigger.
  557. *
  558. * This function is used to set event values for the pulse output trigger.
  559. * These pulse output trigger delay values specify the delay for the PDB Pulse-out. Pulse-out goes high when the PDB
  560. * counter is equal to the pulse output high value (value1). Pulse-out goes low when the PDB counter is equal to the
  561. * pulse output low value (value2).
  562. *
  563. * @param base PDB peripheral base address.
  564. * @param channel Channel index for pulse out trigger channel.
  565. * @param value1 Setting value for pulse out high.
  566. * @param value2 Setting value for pulse out low.
  567. */
  568. static inline void PDB_SetPulseOutTriggerDelayValue(PDB_Type *base, pdb_pulse_out_trigger_channel_t channel, uint32_t value1, uint32_t value2)
  569. {
  570. assert(channel < PDB_PODLY_COUNT);
  571. base->PODLY[channel] = PDB_PODLY_DLY1(value1) | PDB_PODLY_DLY2(value2);
  572. }
  573. /* @} */
  574. #if defined(__cplusplus)
  575. }
  576. #endif
  577. /*!
  578. * @}
  579. */
  580. #endif /* _FSL_PDB_H_ */