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