2 * Copyright (c) 2014, Freescale Semiconductor, Inc.
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * o Redistributions of source code must retain the above copyright notice, this list
9 * of conditions and the following disclaimer.
11 * o Redistributions in binary form must reproduce the above copyright notice, this
12 * list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef __FSL_PDB_HAL_H__
32 #define __FSL_PDB_HAL_H__
37 #include "fsl_device_registers.h"
38 #include "fsl_pdb_features.h"
45 /******************************************************************************
47 *****************************************************************************/
50 * @brief PDB status return codes.
52 typedef enum _pdb_status
54 kStatus_PDB_Success
= 0U, /*!< Success. */
55 kStatus_PDB_InvalidArgument
= 1U, /*!< Invalid argument existed. */
56 kStatus_PDB_Failed
= 2U /*!< Execution failed. */
60 * @brief Defines the type of value load mode for the PDB module.
62 * Some timing related registers, such as the MOD, IDLY, CHnDLYm, INTx and POyDLY,
63 * buffer the setting values. Only the load operation is triggered.
64 * The setting value is loaded from a buffer and takes effect. There are
65 * four loading modes to fit different applications.
67 typedef enum _pdb_load_mode
69 kPdbLoadImmediately
= 0U,
70 /*!< Loaded immediately after load operation. */
71 kPdbLoadAtModuloCounter
= 1U,
72 /*!< Loaded when counter hits the modulo after load operation. */
73 kPdbLoadAtNextTrigger
= 2U,
74 /*!< Loaded when detecting an input trigger after load operation. */
75 kPdbLoadAtModuloCounterOrNextTrigger
= 3U
76 /*!< Loaded when counter hits the modulo or detecting an input trigger after load operation. */
80 * @brief Defines the type of prescaler divider for the PDB counter clock.
82 typedef enum _pdb_clk_prescaler_div_mode
84 kPdbClkPreDivBy1
= 0U, /*!< Counting divided by multiplication factor selected by MULT. */
85 kPdbClkPreDivBy2
= 1U, /*!< Counting divided by multiplication factor selected by 2 times ofMULT. */
86 kPdbClkPreDivBy4
= 2U, /*!< Counting divided by multiplication factor selected by 4 times ofMULT. */
87 kPdbClkPreDivBy8
= 3U, /*!< Counting divided by multiplication factor selected by 8 times ofMULT. */
88 kPdbClkPreDivBy16
= 4U, /*!< Counting divided by multiplication factor selected by 16 times ofMULT. */
89 kPdbClkPreDivBy32
= 5U, /*!< Counting divided by multiplication factor selected by 32 times ofMULT. */
90 kPdbClkPreDivBy64
= 6U, /*!< Counting divided by multiplication factor selected by 64 times ofMULT. */
91 kPdbClkPreDivBy128
= 7U, /*!< Counting divided by multiplication factor selected by 128 times ofMULT. */
92 } pdb_clk_prescaler_div_mode_t
;
95 * @brief Defines the type of trigger source mode for the PDB.
97 * Selects the trigger input source for the PDB. The trigger input source can
98 * be internal or external (EXTRG pin), or the software trigger.
100 typedef enum _pdb_trigger_src_mode
102 kPdbTrigger0
= 0U, /*!< Select trigger-In 0. */
103 kPdbTrigger1
= 1U, /*!< Select trigger-In 1. */
104 kPdbTrigger2
= 2U, /*!< Select trigger-In 2. */
105 kPdbTrigger3
= 3U, /*!< Select trigger-In 3. */
106 kPdbTrigger4
= 4U, /*!< Select trigger-In 4. */
107 kPdbTrigger5
= 5U, /*!< Select trigger-In 5. */
108 kPdbTrigger6
= 6U, /*!< Select trigger-In 6. */
109 kPdbTrigger7
= 7U, /*!< Select trigger-In 7. */
110 kPdbTrigger8
= 8U, /*!< Select trigger-In 8. */
111 kPdbTrigger9
= 9U, /*!< Select trigger-In 8. */
112 kPdbTrigger10
= 10U, /*!< Select trigger-In 10. */
113 kPdbTrigger11
= 11U, /*!< Select trigger-In 11. */
114 kPdbTrigger12
= 12U, /*!< Select trigger-In 12. */
115 kPdbTrigger13
= 13U, /*!< Select trigger-In 13. */
116 kPdbTrigger14
= 14U, /*!< Select trigger-In 14. */
117 kPdbSoftTrigger
= 15U, /*!< Select software trigger. */
118 } pdb_trigger_src_mode_t
;
121 * @brief Defines the type of the multiplication source mode for PDB.
123 * Selects the multiplication factor of the prescaler divider for the PDB counter clock.
125 typedef enum _pdb_mult_factor_mode
127 kPdbMultFactorAs1
= 0U, /*!< Multiplication factor is 1. */
128 kPdbMultFactorAs10
= 1U, /*!< Multiplication factor is 10. */
129 kPdbMultFactorAs20
= 2U, /*!< Multiplication factor is 20. */
130 kPdbMultFactorAs40
= 3U /*!< Multiplication factor is 40. */
131 } pdb_mult_factor_mode_t
;
133 #if defined(__cplusplus)
137 /*******************************************************************************
139 ******************************************************************************/
142 * @brief Resets the PDB registers to a known state.
144 * This function resets the PDB registers to a known state. This state is
145 * defined in a reference manual and is power on reset value.
147 * @param baseAddr Register base address for the module.
149 void PDB_HAL_Init(uint32_t baseAddr
);
152 * @brief Sets the load mode for timing registers.
154 * This function sets the load mode for some timing registers including
155 * MOD, IDLY, CHnDLYm, INTx and POyDLY.
157 * @param baseAddr Register base address for the module.
158 * @param mode Selection of mode, see to "pdb_load_mode_t".
160 static inline void PDB_HAL_SetLoadMode(uint32_t baseAddr
, pdb_load_mode_t mode
)
162 BW_PDB_SC_LDMOD(baseAddr
, (uint32_t)mode
);
166 * @brief Switches to enable the PDB sequence error interrupt.
168 * This function switches to enable the PDB sequence error interrupt.
170 * @param baseAddr Register base address for the module.
171 * @param enable The switcher to assert the feature.
173 static inline void PDB_HAL_SetSeqErrIntCmd(uint32_t baseAddr
, bool enabled
)
175 BW_PDB_SC_PDBEIE(baseAddr
, (enabled
? 1U : 0U) );
179 * @brief Triggers the DAC by software if enabled.
181 * If enabled, this function triggers the DAC by using software.
183 * @param baseAddr Register base address for the module.
185 static inline void PDB_HAL_SetSoftTriggerCmd(uint32_t baseAddr
)
187 BW_PDB_SC_SWTRIG(baseAddr
, 1U);
191 * @brief Switches to enable the PDB DMA support.
193 * This function switches to enable the PDB DMA support.
195 * @param baseAddr Register base address for the module.
196 * @param enable The switcher to assert the feature.
198 static inline void PDB_HAL_SetDmaCmd(uint32_t baseAddr
, bool enable
)
200 BW_PDB_SC_DMAEN(baseAddr
, (enable
? 1U : 0U) );
204 * @brief Sets the prescaler divider from the peripheral bus clock for the PDB.
206 * This function sets the prescaler divider from the peripheral bus clock for the PDB.
208 * @param baseAddr Register base address for the module.
209 * @param mode Selection of mode, see to "pdb_clk_prescaler_div_mode_t".
211 static inline void PDB_HAL_SetPreDivMode(uint32_t baseAddr
, pdb_clk_prescaler_div_mode_t mode
)
213 BW_PDB_SC_PRESCALER(baseAddr
, (uint32_t)mode
);
217 * @brief Sets the trigger source mode for the PDB module.
219 * This function sets the trigger source mode for the PDB module.
221 * @param baseAddr Register base address for the module.
222 * @param mode Selection of mode, see to "pdb_trigger_src_mode_t".
224 static inline void PDB_HAL_SetTriggerSrcMode(uint32_t baseAddr
, pdb_trigger_src_mode_t mode
)
226 BW_PDB_SC_TRGSEL(baseAddr
, (uint32_t)mode
);
230 * @brief Switches on to enable the PDB module.
232 * This function switches on to enable the PDB module.
234 * @param baseAddr Register base address for the module.
236 static inline void PDB_HAL_Enable(uint32_t baseAddr
)
238 BW_PDB_SC_PDBEN(baseAddr
, 1U);
242 * @brief Switches off to enable the PDB module.
244 * This function switches off to enable the PDB module.
246 * @param baseAddr Register base address for the module.
248 static inline void PDB_HAL_Disable(uint32_t baseAddr
)
250 BW_PDB_SC_PDBEN(baseAddr
, 0U);
254 * @brief Gets the PDB delay interrupt flag.
256 * This function gets the PDB delay interrupt flag.
258 * @param baseAddr Register base address for the module.
259 * @return Flat status, true if the flag is set.
261 static inline bool PDB_HAL_GetIntFlag(uint32_t baseAddr
)
263 return (1U == BR_PDB_SC_PDBIF(baseAddr
));
267 * @brief Clears the PDB delay interrupt flag.
269 * This function clears PDB delay interrupt flag.
271 * @param baseAddr Register base address for the module.
272 * @return Flat status, true if the flag is set.
274 static inline void PDB_HAL_ClearIntFlag(uint32_t baseAddr
)
276 BW_PDB_SC_PDBIF(baseAddr
, 0U);
280 * @brief Switches to enable the PDB interrupt.
282 * This function switches to enable the PDB interrupt.
284 * @param baseAddr Register base address for the module.
285 * @param enable The switcher to assert the feature.
287 static inline void PDB_HAL_SetIntCmd(uint32_t baseAddr
, bool enable
)
289 BW_PDB_SC_PDBIE(baseAddr
, (enable
? 1U : 0U) );
293 * @brief Sets the PDB prescaler multiplication factor.
295 * This function sets the PDB prescaler multiplication factor.
297 * @param baseAddr Register base address for the module.
298 * @param mode Selection of mode, see to "pdb_mult_factor_mode_t".
300 static inline void PDB_HAL_SetPreMultFactorMode(uint32_t baseAddr
,
301 pdb_mult_factor_mode_t mode
)
303 BW_PDB_SC_MULT(baseAddr
, (uint32_t)mode
);
307 * @brief Switches to enable the PDB continuous mode.
309 * This function switches to enable the PDB continuous mode.
311 * @param baseAddr Register base address for the module.
312 * @param enable The switcher to assert the feature.
314 static inline void PDB_HAL_SetContinuousModeCmd(uint32_t baseAddr
, bool enable
)
316 BW_PDB_SC_CONT(baseAddr
, (enable
? 1U : 0U) );
320 * @brief Loads the delay registers value for the PDB module.
322 * This function sets the LDOK bit and loads the delay registers value.
323 * Writing one to this bit updates the internal registers MOD, IDLY, CHnDLYm,
324 * DACINTx, and POyDLY with the values written to their buffers. The MOD, IDLY,
325 * CHnDLYm, DACINTx, and POyDLY take effect according to the load mode settings.
327 * After one is written to the LDOK bit, the values in the buffers of above mentioned registers
328 * are not effective and cannot be written until the values in the
329 * buffers are loaded into their internal registers.
330 * The LDOK can be written only when the the PDB is enabled or as alone with it. It is
331 * automatically cleared either when the values in the buffers are loaded into the
332 * internal registers or when the PDB is disabled.
334 * @param baseAddr Register base address for the module.
336 static inline void PDB_HAL_SetLoadRegsCmd(uint32_t baseAddr
)
338 BW_PDB_SC_LDOK(baseAddr
, 1U);
342 * @brief Sets the modulus value for the PDB module.
344 * This function sets the modulus value for the PDB module.
345 * When the counter reaches the setting value, it is automatically reset to zero.
346 * When in continuous mode, the counter begins to increase
349 * @param baseAddr Register base address for the module.
350 * @param value The setting value of upper limit for PDB counter.
352 static inline void PDB_HAL_SetModulusValue(uint32_t baseAddr
, uint32_t value
)
354 BW_PDB_MOD_MOD(baseAddr
, value
);
358 * @brief Gets the modulus value for the PDB module.
360 * This function gets the modulus value for the PDB module.
362 * @param baseAddr Register base address for the module.
363 * @return The current value of upper limit for counter.
365 static inline uint32_t PDB_HAL_GetModulusValue(uint32_t baseAddr
)
367 return BR_PDB_MOD_MOD(baseAddr
);
371 * @brief Gets the PDB counter value.
373 * This function gets the PDB counter value.
375 * @param baseAddr Register base address for the module.
376 * @return The current counter value.
378 static inline uint32_t PDB_HAL_GetCounterValue(uint32_t baseAddr
)
380 return BR_PDB_CNT_CNT(baseAddr
);
384 * @brief Sets the interrupt delay milestone of the PDB counter.
386 * This function sets the interrupt delay milestone of the PDB counter.
387 * If enabled, a PDB interrupt is generated when the counter is equal to the
390 * @param baseAddr Register base address for the module.
391 * @param value The setting value for interrupt delay milestone of PDB counter.
393 static inline void PDB_HAL_SetIntDelayValue(uint32_t baseAddr
, uint32_t value
)
395 BW_PDB_IDLY_IDLY(baseAddr
, value
);
399 * @brief Gets the current interrupt delay milestone of the PDB counter.
401 * This function gets the current interrupt delay milestone of the PDB counter.
403 * @param baseAddr Register base address for the module.
404 * @return The current setting value for interrupt delay milestone of PDB counter.
406 static inline uint32_t PDB_HAL_GetIntDelayValue(uint32_t baseAddr
)
408 return BR_PDB_IDLY_IDLY(baseAddr
);
412 * @brief Switches to enable the pre-trigger back-to-back mode.
414 * This function switches to enable the pre-trigger back-to-back mode.
416 * @param baseAddr Register base address for the module.
417 * @param chn ADC instance index for trigger.
418 * @param preChn ADC channel group index for trigger.
419 * @param enable Switcher to assert the feature.
421 void PDB_HAL_SetPreTriggerBackToBackCmd(uint32_t baseAddr
, uint32_t chn
, uint32_t preChn
, bool enable
);
424 * @brief Switches to enable the pre-trigger output.
426 * This function switches to enable pre-trigger output.
428 * @param baseAddr Register base address for the module.
429 * @param chn ADC instance index for trigger.
430 * @param preChn ADC channel group index for trigger.
431 * @param enable Switcher to assert the feature.
433 void PDB_HAL_SetPreTriggerOutputCmd(uint32_t baseAddr
, uint32_t chn
, uint32_t preChn
, bool enable
);
436 * @brief Switches to enable the pre-trigger.
438 * This function switches to enable the pre-trigger.
440 * @param baseAddr Register base address for the module.
441 * @param chn ADC instance index for trigger.
442 * @param preChn ADC channel group index for trigger.
443 * @param enable Switcher to assert the feature.
445 void PDB_HAL_SetPreTriggerCmd(uint32_t baseAddr
, uint32_t chn
, uint32_t preChn
, bool enable
);
448 * @brief Gets the flag which indicates whether the PDB counter has reached the pre-trigger delay value.
450 * This function gets the flag which indicates the PDB counter has reached the
451 * pre-trigger delay value.
453 * @param baseAddr Register base address for the module.
454 * @param chn ADC instance index for trigger.
455 * @param preChn ADC channel group index for trigger.
456 * @return Flag status. True if the event is asserted.
458 static inline bool PDB_HAL_GetPreTriggerFlag(uint32_t baseAddr
, uint32_t chn
, uint32_t preChn
)
460 assert(chn
< HW_PDB_CHnC1_COUNT
);
461 assert(preChn
< FSL_FEATURE_PDB_ADC_PRE_CHANNEL_COUNT
);
462 return ( ((1U<< preChn
) & BR_PDB_CHnS_CF(baseAddr
, chn
))? true: false);
466 * @brief Clears the flag which indicates that the PDB counter has reached the pre-trigger delay value.
468 * This function clears the flag which indicates that the PDB counter has reached the
469 * pre-trigger delay value.
471 * @param baseAddr Register base address for the module.
472 * @param chn ADC instance index for trigger.
473 * @param preChn ADC channel group index for trigger.
475 void PDB_HAL_ClearPreTriggerFlag(uint32_t baseAddr
, uint32_t chn
, uint32_t preChn
);
478 * @brief Gets the flag which indicates whether a sequence error is detected.
480 * This function gets the flag which indicates whether a sequence error is detected.
482 * @param baseAddr Register base address for the module.
483 * @param chn ADC instance index for trigger.
484 * @param preChn ADC channel group index for trigger.
485 * @return Flag status. True if the event is asserted.
487 static inline bool PDB_HAL_GetPreTriggerSeqErrFlag(uint32_t baseAddr
, uint32_t chn
, uint32_t preChn
)
489 assert(chn
< HW_PDB_CHnC1_COUNT
);
490 assert(preChn
< FSL_FEATURE_PDB_ADC_PRE_CHANNEL_COUNT
);
491 return ( ((1U<< preChn
) & BR_PDB_CHnS_ERR(baseAddr
, chn
))? true: false);
495 * @brief Clears the flag which indicates that a sequence error has been detected.
497 * This function clears the flag which indicates that the sequence error has been detected.
499 * @param baseAddr Register base address for the module.
500 * @param chn ADC instance index for trigger.
501 * @param preChn ADC channel group index for trigger.
503 void PDB_HAL_ClearPreTriggerSeqErrFlag(uint32_t baseAddr
, uint32_t chn
, uint32_t preChn
);
506 * @brief Sets the pre-trigger delay value.
508 * This function sets the pre-trigger delay value.
510 * @param baseAddr Register base address for the module.
511 * @param chn ADC instance index for trigger.
512 * @param preChn ADC channel group index for trigger.
513 * @param value Setting value for pre-trigger's delay value.
515 void PDB_HAL_SetPreTriggerDelayCount(uint32_t baseAddr
, uint32_t chn
, uint32_t preChn
, uint32_t value
);
518 * @brief Switches to enable the DAC external trigger input.
520 * This function switches to enable the DAC external trigger input.
522 * @param baseAddr Register base address for the module.
523 * @param dacChn DAC instance index for trigger.
524 * @param value Setting value for pre-trigger's delay value.
526 static inline void PDB_HAL_SetDacExtTriggerInputCmd(uint32_t baseAddr
, uint32_t dacChn
, bool enable
)
528 assert(dacChn
< HW_PDB_DACINTCn_COUNT
);
529 BW_PDB_DACINTCn_EXT(baseAddr
, dacChn
, (enable
? 1U: 0U) );
533 * @brief Switches to enable the DAC external trigger input.
535 * This function switches to enable the DAC external trigger input.
537 * @param baseAddr Register base address for the module.
538 * @param dacChn DAC instance index for trigger.
539 * @param enable Switcher to assert the feature.
541 static inline void PDB_HAL_SetDacIntervalTriggerCmd(uint32_t baseAddr
, uint32_t dacChn
, bool enable
)
543 assert(dacChn
< HW_PDB_DACINTCn_COUNT
);
544 BW_PDB_DACINTCn_TOE(baseAddr
, dacChn
, (enable
? 1U: 0U) );
548 * @brief Sets the interval value for the DAC trigger.
550 * This function sets the interval value for the DAC trigger.
552 * @param baseAddr Register base address for the module.
553 * @param dacChn DAC instance index for trigger.
554 * @param value Setting value for DAC trigger interval.
556 static inline void PDB_HAL_SetDacIntervalValue(uint32_t baseAddr
, uint32_t dacChn
, uint32_t value
)
558 assert(dacChn
< HW_PDB_DACINTn_COUNT
);
559 BW_PDB_DACINTn_INT(baseAddr
, dacChn
, value
);
563 * @brief Gets the interval value for the DAC trigger.
565 * This function gets the interval value for the DAC trigger.
567 * @param baseAddr Register base address for the module.
568 * @param dacChn DAC instance index for trigger.
569 * @return The current setting value for DAC trigger interval.
571 static inline uint32_t PDB_HAL_GetDacIntervalValue(uint32_t baseAddr
, uint32_t dacChn
)
573 assert(dacChn
< HW_PDB_DACINTn_COUNT
);
574 return BR_PDB_DACINTn_INT(baseAddr
, dacChn
);
578 * @brief Switches to enable the pulse-out trigger.
580 * This function switches to enable the pulse-out trigger.
582 * @param baseAddr Register base address for the module.
583 * @param pulseChn Pulse-out channle index for trigger.
584 * @param enable Switcher to assert the feature.
586 void PDB_HAL_SetPulseOutCmd(uint32_t baseAddr
, uint32_t pulseChn
, bool enable
);
589 * @brief Sets the counter delay value for the pulse-out goes high.
591 * This function sets the counter delay value for the pulse-out goes high.
593 * @param baseAddr Register base address for the module.
594 * @param pulseChn Pulse-out channel index for trigger.
595 * @param value Setting value for PDB delay .
597 static inline void PDB_HAL_SetPulseOutDelayForHigh(uint32_t baseAddr
, uint32_t pulseChn
, uint32_t value
)
599 assert(pulseChn
< HW_PDB_POnDLY_COUNT
);
600 BW_PDB_POnDLY_DLY1(baseAddr
, pulseChn
, value
);
604 * @brief Sets the counter delay value for the pulse-out goes low.
606 * This function sets the counter delay value for the pulse-out goes low.
608 * @param baseAddr Register base address for the module.
609 * @param pulseChn Pulse-out channel index for trigger.
610 * @param value Setting value for PDB delay .
612 static inline void PDB_HAL_SetPulseOutDelayForLow(uint32_t baseAddr
, uint32_t pulseChn
, uint32_t value
)
614 assert(pulseChn
< HW_PDB_POnDLY_COUNT
);
615 BW_PDB_POnDLY_DLY2(baseAddr
, pulseChn
, value
);
618 #if defined(__cplusplus)
626 #endif /* __FSL_PDB_HAL_H__ */
628 /******************************************************************************
630 *****************************************************************************/