2 * Copyright (c) 2013 - 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.
30 #if !defined(__FSL_FTM_HAL_H__)
31 #define __FSL_FTM_HAL_H__
33 #include "fsl_device_registers.h"
34 #include "fsl_ftm_features.h"
43 /*******************************************************************************
45 ******************************************************************************/
46 #define HW_CHAN0 (0U) /*!< Channel number for CHAN0.*/
47 #define HW_CHAN1 (1U) /*!< Channel number for CHAN1.*/
48 #define HW_CHAN2 (2U) /*!< Channel number for CHAN2.*/
49 #define HW_CHAN3 (3U) /*!< Channel number for CHAN3.*/
50 #define HW_CHAN4 (4U) /*!< Channel number for CHAN4.*/
51 #define HW_CHAN5 (5U) /*!< Channel number for CHAN5.*/
52 #define HW_CHAN6 (6U) /*!< Channel number for CHAN6.*/
53 #define HW_CHAN7 (7U) /*!< Channel number for CHAN7.*/
55 #define FTM_COMBINE_CHAN_CTRL_WIDTH (8U)
57 /*! @brief FlexTimer clock source selection*/
58 typedef enum _ftm_clock_source
60 kClock_source_FTM_None
= 0,
61 kClock_source_FTM_SystemClk
,
62 kClock_source_FTM_FixedClk
,
63 kClock_source_FTM_ExternalClk
66 /*! @brief FlexTimer counting mode selection */
67 typedef enum _ftm_counting_mode
73 /*! @brief FlexTimer pre-scaler factor selection for the clock source*/
74 typedef enum _ftm_clock_ps
86 /*! @brief FlexTimer pre-scaler factor for the deadtime insertion*/
87 typedef enum _ftm_deadtime_ps
94 /*! @brief FlexTimer operation mode, capture, output, dual */
95 typedef enum _ftm_config_mode_t
100 kFtmCenterAlignedPWM
,
105 /*! @brief FlexTimer input capture edge mode, rising edge, or falling edge */
106 typedef enum _ftm_input_capture_edge_mode_t
111 }ftm_input_capture_edge_mode_t
;
113 /*! @brief FlexTimer output compare edge mode. Toggle, clear or set.*/
114 typedef enum _ftm_output_compare_edge_mode_t
116 kFtmToggleOnMatch
= 0,
119 }ftm_output_compare_edge_mode_t
;
121 /*! @brief FlexTimer PWM output pulse mode, high-true or low-true on match up */
122 typedef enum _ftm_pwm_edge_mode_t
126 }ftm_pwm_edge_mode_t
;
128 /*! @brief FlexTimer dual capture edge mode, one shot or continuous */
129 typedef enum _ftm_dual_capture_edge_mode_t
133 }ftm_dual_capture_edge_mode_t
;
135 /*! @brief FlexTimer quadrature decode modes, phase encode or count and direction mode */
136 typedef enum _ftm_quad_decode_mode_t
138 kFtmQuadPhaseEncode
= 0,
140 }ftm_quad_decode_mode_t
;
142 /*! @brief FlexTimer quadrature phase polarities, normal or inverted polarity */
143 typedef enum _ftm_quad_phase_polarity_t
145 kFtmQuadPhaseNormal
= 0,
147 }ftm_quad_phase_polarity_t
;
149 /*! @brief FlexTimer edge mode*/
150 typedef union _ftm_edge_mode_t
152 ftm_input_capture_edge_mode_t input_capture_edge_mode
;
153 ftm_output_compare_edge_mode_t output_compare_edge_mode
;
154 ftm_pwm_edge_mode_t ftm_pwm_edge_mode
;
155 ftm_dual_capture_edge_mode_t ftm_dual_capture_edge_mode
;
159 * @brief FlexTimer driver PWM parameter
162 typedef struct FtmPwmParam
164 ftm_config_mode_t mode
; /*!< FlexTimer PWM operation mode */
165 ftm_pwm_edge_mode_t edgeMode
; /*!< PWM output mode */
166 uint32_t uFrequencyHZ
; /*!< PWM period in Hz */
167 uint32_t uDutyCyclePercent
; /*!< PWM pulse width, value should be between 0 to 100
168 0=inactive signal(0% duty cycle)...
169 100=active signal (100% duty cycle). */
170 uint16_t uFirstEdgeDelayPercent
; /*!< Used only in combined PWM mode to generate asymmetrical PWM.
171 Specifies the delay to the first edge in a PWM period.
172 If unsure please leave as 0, should be specified as
173 percentage of the PWM period*/
176 /*! @brief FlexTimer quadrature decode phase parameters */
177 typedef struct FtmPhaseParam
179 bool kFtmPhaseInputFilter
; /*!< false: disable phase filter, true: enable phase filter */
180 uint32_t kFtmPhaseFilterVal
; /*!< Filter value, used only if phase input filter is enabled */
181 ftm_quad_phase_polarity_t kFtmPhasePolarity
; /*!< kFtmQuadPhaseNormal or kFtmQuadPhaseInvert */
184 /*FTM timer control*/
186 * @brief Sets the FTM clock source.
188 * @param ftmBaseAddr The FTM base address
189 * @param clock The FTM peripheral clock selection\n
190 * bits - 00: No clock 01: system clock 10: fixed clock 11: External clock
192 static inline void FTM_HAL_SetClockSource(uint32_t ftmBaseAddr
, ftm_clock_source_t clock
)
194 BW_FTM_SC_CLKS(ftmBaseAddr
, clock
);
198 * @brief Reads the FTM clock source.
200 * @param ftmBaseAddr The FTM base address
202 * @return The FTM clock source selection\n
203 * bits - 00: No clock 01: system clock 10: fixed clock 11:External clock
205 static inline uint8_t FTM_HAL_GetClockSource(uint32_t ftmBaseAddr
)
207 return BR_FTM_SC_CLKS(ftmBaseAddr
);
211 * @brief Sets the FTM clock divider.
213 * @param ftmBaseAddr The FTM base address
214 * @param ps The FTM peripheral clock pre-scale divider
216 static inline void FTM_HAL_SetClockPs(uint32_t ftmBaseAddr
, ftm_clock_ps_t ps
)
218 BW_FTM_SC_PS(ftmBaseAddr
, ps
);
222 * @brief Reads the FTM clock divider.
224 * @param ftmBaseAddr The FTM base address
226 * @return The FTM clock pre-scale divider
228 static inline uint8_t FTM_HAL_GetClockPs(uint32_t ftmBaseAddr
)
230 return BR_FTM_SC_PS(ftmBaseAddr
);
234 * @brief Enables the FTM peripheral timer overflow interrupt.
236 * @param ftmBaseAddr The FTM base address
238 static inline void FTM_HAL_EnableTimerOverflowInt(uint32_t ftmBaseAddr
)
240 HW_FTM_SC_SET(ftmBaseAddr
, BM_FTM_SC_TOIE
);
244 * @brief Disables the FTM peripheral timer overflow interrupt.
246 * @param ftmBaseAddr The FTM base address
248 static inline void FTM_HAL_DisableTimerOverflowInt(uint32_t ftmBaseAddr
)
250 HW_FTM_SC_CLR(ftmBaseAddr
, BM_FTM_SC_TOIE
);
254 * @brief Reads the bit that controls enabling the FTM timer overflow interrupt.
256 * @param baseAddr FTM module base address.
257 * @retval true if overflow interrupt is enabled, false if not
259 static inline bool FTM_HAL_IsOverflowIntEnabled(uint32_t baseAddr
)
261 return (bool)(BR_FTM_SC_TOIE(baseAddr
));
265 * @brief Clears the timer overflow interrupt flag.
267 * @param ftmBaseAddr The FTM base address
269 static inline void FTM_HAL_ClearTimerOverflow(uint32_t ftmBaseAddr
)
271 BW_FTM_SC_TOF(ftmBaseAddr
, 0);
275 * @brief Returns the FTM peripheral timer overflow interrupt flag.
277 * @param ftmBaseAddr The FTM base address
278 * @retval true if overflow, false if not
280 static inline bool FTM_HAL_HasTimerOverflowed(uint32_t ftmBaseAddr
)
282 return BR_FTM_SC_TOF(ftmBaseAddr
);
286 * @brief Sets the FTM center-aligned PWM select.
288 * @param ftmBaseAddr The FTM base address
289 * @param mode 1:upcounting mode 0:up_down counting mode
291 static inline void FTM_HAL_SetCpwms(uint32_t ftmBaseAddr
, uint8_t mode
)
294 BW_FTM_SC_CPWMS(ftmBaseAddr
, mode
);
298 * @brief Sets the FTM peripheral current counter value.
300 * @param ftmBaseAddr The FTM base address
301 * @param val FTM timer counter value to be set
303 static inline void FTM_HAL_SetCounter(uint32_t ftmBaseAddr
,uint16_t val
)
305 BW_FTM_CNT_COUNT(ftmBaseAddr
, val
);
309 * @brief Returns the FTM peripheral current counter value.
311 * @param ftmBaseAddr The FTM base address
312 * @retval current FTM timer counter value
314 static inline uint16_t FTM_HAL_GetCounter(uint32_t ftmBaseAddr
)
316 return BR_FTM_CNT_COUNT(ftmBaseAddr
);
320 * @brief Sets the FTM peripheral timer modulo value.
322 * @param ftmBaseAddr The FTM base address
323 * @param val The value to be set to the timer modulo
325 static inline void FTM_HAL_SetMod(uint32_t ftmBaseAddr
, uint16_t val
)
327 BW_FTM_MOD_MOD(ftmBaseAddr
, val
);
331 * @brief Returns the FTM peripheral counter modulo value.
333 * @param ftmBaseAddr The FTM base address
334 * @retval FTM timer modulo value
336 static inline uint16_t FTM_HAL_GetMod(uint32_t ftmBaseAddr
)
338 return BR_FTM_MOD_MOD(ftmBaseAddr
);
342 * @brief Sets the FTM peripheral timer counter initial value.
344 * @param ftmBaseAddr The FTM base address
345 * @param val initial value to be set
347 static inline void FTM_HAL_SetCounterInitVal(uint32_t ftmBaseAddr
, uint16_t val
)
349 BW_FTM_CNTIN_INIT(ftmBaseAddr
, val
& BM_FTM_CNTIN_INIT
);
353 * @brief Returns the FTM peripheral counter initial value.
355 * @param ftmBaseAddr The FTM base address
356 * @retval FTM timer counter initial value
358 static inline uint16_t FTM_HAL_GetCounterInitVal(uint32_t ftmBaseAddr
)
360 return BR_FTM_CNTIN_INIT(ftmBaseAddr
);
363 /*FTM channel operating mode (Mode, edge and level selection) for capture, output, PWM, combine, dual */
365 * @brief Sets the FTM peripheral timer channel mode.
367 * @param ftmBaseAddr The FTM base address
368 * @param channel The FTM peripheral channel number
369 * @param selection The mode to be set valid value MSnB:MSnA :00,01, 10, 11
371 static inline void FTM_HAL_SetChnMSnBAMode(uint32_t ftmBaseAddr
, uint8_t channel
, uint8_t selection
)
373 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
374 BW_FTM_CnSC_MSA(ftmBaseAddr
, channel
, selection
& 1);
375 BW_FTM_CnSC_MSB(ftmBaseAddr
, channel
, selection
& 2 ? 1 : 0);
379 * @brief Sets the FTM peripheral timer channel edge level.
381 * @param ftmBaseAddr The FTM base address
382 * @param channel The FTM peripheral channel number
383 * @param level The rising or falling edge to be set, valid value ELSnB:ELSnA :00,01, 10, 11
385 static inline void FTM_HAL_SetChnEdgeLevel(uint32_t ftmBaseAddr
, uint8_t channel
, uint8_t level
)
387 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
388 BW_FTM_CnSC_ELSA(ftmBaseAddr
, channel
, level
& 1 ? 1 : 0);
389 BW_FTM_CnSC_ELSB(ftmBaseAddr
, channel
, level
& 2 ? 1 : 0);
393 * @brief Gets the FTM peripheral timer channel mode.
395 * @param ftmBaseAddr The FTM base address
396 * @param channel The FTM peripheral channel number
397 * @retval The MSnB:MSnA mode value, will be 00,01, 10, 11
399 static inline uint8_t FTM_HAL_GetChnMode(uint32_t ftmBaseAddr
, uint8_t channel
)
401 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
402 return (BR_FTM_CnSC_MSA(ftmBaseAddr
, channel
)|| (BR_FTM_CnSC_MSB(ftmBaseAddr
, channel
) << 1));
406 * @brief Gets the FTM peripheral timer channel edge level.
408 * @param ftmBaseAddr The FTM base address
409 * @param channel The FTM peripheral channel number
410 * @retval The ELSnB:ELSnA mode value, will be 00,01, 10, 11
412 static inline uint8_t FTM_HAL_GetChnEdgeLevel(uint32_t ftmBaseAddr
, uint8_t channel
)
414 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
415 return (BR_FTM_CnSC_ELSA(ftmBaseAddr
, channel
)|| (BR_FTM_CnSC_ELSB(ftmBaseAddr
, channel
) << 1));
419 * @brief Enables or disables the FTM peripheral timer channel DMA.
421 * @param ftmBaseAddr The FTM base address
422 * @param channel The FTM peripheral channel number
423 * @param val enable or disable
425 static inline void FTM_HAL_SetChnDmaCmd(uint32_t ftmBaseAddr
, uint8_t channel
, bool val
)
427 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
428 BW_FTM_CnSC_DMA(ftmBaseAddr
, channel
,(val
? 1 : 0));
432 * @brief Returns whether the FTM peripheral timer channel DMA is enabled.
434 * @param ftmBaseAddr The FTM base address
435 * @param channel The FTM peripheral channel number
436 * @retval true if enabled, false if disabled
438 static inline bool FTM_HAL_IsChnDma(uint32_t ftmBaseAddr
, uint8_t channel
)
440 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
441 return (BR_FTM_CnSC_DMA(ftmBaseAddr
, channel
) ? true : false);
445 * @brief Enables the FTM peripheral timer channel(n) interrupt.
447 * @param ftmBaseAddr The FTM base address
448 * @param channel The FTM peripheral channel number
450 static inline void FTM_HAL_EnableChnInt(uint32_t ftmBaseAddr
, uint8_t channel
)
452 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
453 BW_FTM_CnSC_CHIE(ftmBaseAddr
, channel
, 1);
456 * @brief Disables the FTM peripheral timer channel(n) interrupt.
458 * @param ftmBaseAddr The FTM base address
459 * @param channel The FTM peripheral channel number
461 static inline void FTM_HAL_DisableChnInt(uint32_t ftmBaseAddr
, uint8_t channel
)
463 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
464 BW_FTM_CnSC_CHIE(ftmBaseAddr
, channel
, 0);
468 * @brief Returns whether any event for the FTM peripheral timer channel has occurred.
470 * @param ftmBaseAddr The FTM base address
471 * @param channel The FTM peripheral channel number
472 * @retval true if event occurred, false otherwise.
474 static inline bool FTM_HAL_HasChnEventOccurred(uint32_t ftmBaseAddr
, uint8_t channel
)
476 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
477 return (BR_FTM_CnSC_CHF(ftmBaseAddr
, channel
)) ? true : false;
480 /*FTM channel control*/
482 * @brief Sets the FTM peripheral timer channel counter value.
484 * @param ftmBaseAddr The FTM base address
485 * @param channel The FTM peripheral channel number
486 * @param val counter value to be set
488 static inline void FTM_HAL_SetChnCountVal(uint32_t ftmBaseAddr
, uint8_t channel
, uint16_t val
)
490 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
491 HW_FTM_CnV_WR(ftmBaseAddr
, channel
, val
);
495 * @brief Gets the FTM peripheral timer channel counter value.
497 * @param ftmBaseAddr The FTM base address
498 * @param channel The FTM peripheral channel number
499 * @retval val return current channel counter value
501 static inline uint16_t FTM_HAL_GetChnCountVal(uint32_t ftmBaseAddr
, uint8_t channel
, uint16_t val
)
503 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
504 return BR_FTM_CnV_VAL(ftmBaseAddr
, channel
);
508 * @brief Gets the FTM peripheral timer channel event status.
510 * @param ftmBaseAddr The FTM base address
511 * @param channel The FTM peripheral channel number
512 * @retval val return current channel event status value
514 static inline uint32_t FTM_HAL_GetChnEventStatus(uint32_t ftmBaseAddr
, uint8_t channel
)
516 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
517 return (HW_FTM_STATUS_RD(ftmBaseAddr
)&(1U << channel
)) ? true : false;
518 /*return BR_FTM_STATUS(ftmBaseAddr, channel);*/
522 * @brief Clears the FTM peripheral timer all channel event status.
524 * @param ftmBaseAddr The FTM base address
525 * @param channel The FTM peripheral channel number
526 * @retval val return current channel counter value
528 static inline void FTM_HAL_ClearChnEventStatus(uint32_t ftmBaseAddr
, uint8_t channel
)
530 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
531 HW_FTM_STATUS_CLR(ftmBaseAddr
, 1U << channel
);
535 * @brief Sets the FTM peripheral timer channel output mask.
537 * @param ftmBaseAddr The FTM base address
538 * @param channel The FTM peripheral channel number
539 * @param mask mask to be set 0 or 1, unmasked or masked
541 static inline void FTM_HAL_SetChnOutputMask(uint32_t ftmBaseAddr
, uint8_t channel
, bool mask
)
543 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
544 mask
? HW_FTM_OUTMASK_SET(ftmBaseAddr
, 1U << channel
) : HW_FTM_OUTMASK_CLR(ftmBaseAddr
, 1U << channel
);
545 /* BW_FTM_OUTMASK_CHnOM(ftmBaseAddr, channel,mask); */
549 * @brief Sets the FTM peripheral timer channel output initial state 0 or 1.
551 * @param ftmBaseAddr The FTM base address
552 * @param channel The FTM peripheral channel number
553 * @param state counter value to be set 0 or 1
555 static inline void FTM_HAL_SetChnOutputInitState(uint32_t ftmBaseAddr
, uint8_t channel
, uint8_t state
)
557 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
558 HW_FTM_OUTINIT_CLR(ftmBaseAddr
, 1U << channel
);
559 HW_FTM_OUTINIT_SET(ftmBaseAddr
, (uint8_t)(state
<< channel
));
563 * @brief Sets the FTM peripheral timer channel output polarity.
565 * @param ftmBaseAddr The FTM base address
566 * @param channel The FTM peripheral channel number
567 * @param pol polarity to be set 0 or 1
569 static inline void FTM_HAL_SetChnOutputPolarity(uint32_t ftmBaseAddr
, uint8_t channel
, uint8_t pol
)
571 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
572 HW_FTM_POL_CLR(ftmBaseAddr
, 1U << channel
);
573 HW_FTM_POL_SET(ftmBaseAddr
, (uint8_t)(pol
<< channel
));
576 * @brief Sets the FTM peripheral timer channel input polarity.
578 * @param ftmBaseAddr The FTM base address
579 * @param channel The FTM peripheral channel number
580 * @param pol polarity to be set, 0: active high, 1:active low
582 static inline void FTM_HAL_SetChnFaultInputPolarity(uint32_t ftmBaseAddr
, uint8_t channel
, uint8_t pol
)
584 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
585 HW_FTM_FLTPOL_CLR(ftmBaseAddr
, 1U << channel
);
586 HW_FTM_FLTPOL_SET(ftmBaseAddr
, (uint8_t)(pol
<<channel
));
590 /*Feature mode selection HAL*/
591 /*FTM fault control*/
593 * @brief Enables the FTM peripheral timer fault interrupt.
595 * @param ftmBaseAddr The FTM base address
597 static inline void FTM_HAL_EnableFaultInt(uint32_t ftmBaseAddr
)
599 BW_FTM_MODE_FAULTIE(ftmBaseAddr
, 1);
603 * @brief Disables the FTM peripheral timer fault interrupt.
605 * @param ftmBaseAddr The FTM base address
607 static inline void FTM_HAL_DisableFaultInt(uint32_t ftmBaseAddr
)
609 BW_FTM_MODE_FAULTIE(ftmBaseAddr
, 0);
613 * @brief Defines the FTM fault control mode.
615 * @param ftmBaseAddr The FTM base address
616 * @param mode, valid options are 1, 2, 3, 4
618 static inline void FTM_HAL_SetFaultControlMode(uint32_t ftmBaseAddr
, uint8_t mode
)
620 BW_FTM_MODE_FAULTM(ftmBaseAddr
, mode
);
624 * @brief Enables or disables the FTM peripheral timer capture test mode.
626 * @param ftmBaseAddr The FTM base address
627 * @param enable true to enable capture test mode, false to disable
629 static inline void FTM_HAL_SetCaptureTestCmd(uint32_t ftmBaseAddr
, bool enable
)
631 BW_FTM_MODE_CAPTEST(ftmBaseAddr
, enable
? 1 : 0);
635 * @brief Enables or disables the FTM write protection.
637 * @param ftmBaseAddr The FTM base address
638 * @param enable true: Write-protection is enabled, false: Write-protection is disabled
640 static inline void FTM_HAL_SetWriteProtectionCmd(uint32_t ftmBaseAddr
, bool enable
)
642 enable
? BW_FTM_FMS_WPEN(ftmBaseAddr
, 1) : BW_FTM_MODE_WPDIS(ftmBaseAddr
, 1);
646 * @brief Enables the FTM peripheral timer group.
648 * @param ftmBaseAddr The FTM base address
649 * @param enable true: all registers including FTM-specific registers are available
650 * false: only the TPM-compatible registers are available
652 static inline void FTM_HAL_Enable(uint32_t ftmBaseAddr
, bool enable
)
654 assert(BR_FTM_MODE_WPDIS(ftmBaseAddr
));
655 BW_FTM_MODE_FTMEN(ftmBaseAddr
, enable
? 1 : 0);
659 * @brief Initializes the channels output.
661 * @param ftmBaseAddr The FTM base address
662 * @param enable true: the channels output is initialized according to the state of OUTINIT reg
663 * false: has no effect
665 static inline void FTM_HAL_SetInitChnOutputCmd(uint32_t ftmBaseAddr
, bool enable
)
667 BW_FTM_MODE_INIT(ftmBaseAddr
, enable
? 1 : 0);
671 * @brief Sets the FTM peripheral timer sync mode.
673 * @param ftmBaseAddr The FTM base address
674 * @param enable true: no restriction both software and hardware triggers can be used\n
675 * false: software trigger can only be used for MOD and CnV synch, hardware trigger
676 * only for OUTMASK and FTM counter synch.
678 static inline void FTM_HAL_SetPwmSyncMode(uint32_t ftmBaseAddr
, bool enable
)
680 BW_FTM_MODE_PWMSYNC(ftmBaseAddr
, enable
? 1 : 0);
683 /*FTM synchronization control*/
685 * @brief Enables or disables the FTM peripheral timer software trigger.
687 * @param ftmBaseAddr The FTM base address.
688 * @param enable true: software trigger is selected, false: software trigger is not selected
690 static inline void FTM_HAL_SetSoftwareTriggerCmd(uint32_t ftmBaseAddr
, bool enable
)
692 BW_FTM_SYNC_SWSYNC(ftmBaseAddr
, enable
? 1 : 0);
696 * @brief Sets the FTM peripheral timer hardware trigger.
698 * @param ftmBaseAddr The FTM base address
699 * @param trigger_num 0, 1, 2 for trigger0, trigger1 and trigger3
700 * @param enable true: enable hardware trigger from field trigger_num for PWM synch
701 * false: disable hardware trigger from field trigger_num for PWM synch
703 void FTM_HAL_SetHardwareTrigger(uint32_t ftmBaseAddr
, uint8_t trigger_num
, bool enable
);
706 * @brief Determines when the OUTMASK register is updated with the value of its buffer.
708 * @param ftmBaseAddr The FTM base address
709 * @param enable true if OUTMASK register is updated only by PWM sync\n
710 * false if OUTMASK register is updated in all rising edges of the system clock
712 static inline void FTM_HAL_SetOutmaskPwmSyncModeCmd(uint32_t ftmBaseAddr
, bool enable
)
714 BW_FTM_SYNC_SYNCHOM(ftmBaseAddr
, enable
? 1 : 0);
718 * @brief Determines if the FTM counter is re-initialized when the selected trigger for
719 * synchronization is detected.
721 * @param ftmBaseAddr The FTM base address
722 * @param enable True to update FTM counter when triggered , false to count normally
724 static inline void FTM_HAL_SetCountReinitSyncCmd(uint32_t ftmBaseAddr
, bool enable
)
726 BW_FTM_SYNC_REINIT(ftmBaseAddr
, enable
? 1 : 0);
730 * @brief Enables or disables the FTM peripheral timer maximum loading points.
732 * @param ftmBaseAddr The FTM base address
733 * @param enable True to enable maximum loading point, false to disable
735 static inline void FTM_HAL_SetMaxLoadingCmd(uint32_t ftmBaseAddr
, bool enable
)
737 BW_FTM_SYNC_CNTMAX(ftmBaseAddr
, enable
? 1 : 0);
740 * @brief Enables or disables the FTM peripheral timer minimum loading points.
742 * @param ftmBaseAddr The FTM base address
743 * @param enable True to enable minimum loading point, false to disable
745 static inline void FTM_HAL_SetMinLoadingCmd(uint32_t ftmBaseAddr
, bool enable
)
747 BW_FTM_SYNC_CNTMIN(ftmBaseAddr
, enable
? 1 : 0);
751 * @brief Combines the channel control.
753 * Returns an index for each channel pair.
755 * @param channel The FTM peripheral channel number.
756 * @return 0 for channel pair 0 & 1\n
757 * 1 for channel pair 2 & 3\n
758 * 2 for channel pair 4 & 5\n
759 * 3 for channel pair 6 & 7
761 uint32_t FTM_HAL_GetChnPairIndex(uint8_t channel
);
764 * @brief Enables the FTM peripheral timer channel pair fault control.
766 * @param ftmBaseAddr The FTM base address
767 * @param channel The FTM peripheral channel number
768 * @param enable True to enable fault control, false to disable
770 static inline void FTM_HAL_SetDualChnFaultCmd(uint32_t ftmBaseAddr
, uint8_t channel
, bool enable
)
772 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
774 enable
? HW_FTM_COMBINE_SET(ftmBaseAddr
, BM_FTM_COMBINE_FAULTEN0
<< (FTM_HAL_GetChnPairIndex(channel
) * FTM_COMBINE_CHAN_CTRL_WIDTH
)):
775 HW_FTM_COMBINE_CLR(ftmBaseAddr
, BM_FTM_COMBINE_FAULTEN0
<< (FTM_HAL_GetChnPairIndex(channel
) * FTM_COMBINE_CHAN_CTRL_WIDTH
));
779 * @brief Enables or disables the FTM peripheral timer channel pair counter PWM sync.
781 * @param ftmBaseAddr The FTM base address
782 * @param channel The FTM peripheral channel number
783 * @param enable True to enable PWM synchronization, false to disable
785 static inline void FTM_HAL_SetDualChnPwmSyncCmd(uint32_t ftmBaseAddr
, uint8_t channel
, bool enable
)
787 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
789 enable
? HW_FTM_COMBINE_SET(ftmBaseAddr
, BM_FTM_COMBINE_SYNCEN0
<< (FTM_HAL_GetChnPairIndex(channel
) * FTM_COMBINE_CHAN_CTRL_WIDTH
)):
790 HW_FTM_COMBINE_CLR(ftmBaseAddr
, BM_FTM_COMBINE_SYNCEN0
<< (FTM_HAL_GetChnPairIndex(channel
) * FTM_COMBINE_CHAN_CTRL_WIDTH
));
794 * @brief Enables or disabled the FTM peripheral timer channel pair deadtime insertion.
796 * @param ftmBaseAddr The FTM base address
797 * @param channel The FTM peripheral channel number
798 * @param enable True to enable deadtime insertion, false to disable
800 static inline void FTM_HAL_SetDualChnDeadtimeCmd(uint32_t ftmBaseAddr
, uint8_t channel
, bool enable
)
802 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
804 enable
? HW_FTM_COMBINE_SET(ftmBaseAddr
, BM_FTM_COMBINE_DTEN0
<< (FTM_HAL_GetChnPairIndex(channel
) * FTM_COMBINE_CHAN_CTRL_WIDTH
)):
805 HW_FTM_COMBINE_CLR(ftmBaseAddr
, BM_FTM_COMBINE_DTEN0
<< (FTM_HAL_GetChnPairIndex(channel
) * FTM_COMBINE_CHAN_CTRL_WIDTH
));
809 * @brief Enables or disables the FTM peripheral timer channel dual edge capture decap.
811 * @param ftmBaseAddr The FTM base address
812 * @param channel The FTM peripheral channel number
813 * @param enable True to enable dual edge capture mode, false to disable
815 static inline void FTM_HAL_SetDualChnDecapCmd(uint32_t ftmBaseAddr
, uint8_t channel
, bool enable
)
817 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
819 enable
? HW_FTM_COMBINE_SET(ftmBaseAddr
, BM_FTM_COMBINE_DECAP0
<< (FTM_HAL_GetChnPairIndex(channel
) * FTM_COMBINE_CHAN_CTRL_WIDTH
)):
820 HW_FTM_COMBINE_CLR(ftmBaseAddr
, BM_FTM_COMBINE_DECAP0
<< (FTM_HAL_GetChnPairIndex(channel
) * FTM_COMBINE_CHAN_CTRL_WIDTH
));
824 * @brief Enables the FTM peripheral timer dual edge capture mode.
826 * @param ftmBaseAddr The FTM base address
827 * @param channel The FTM peripheral channel number
828 * @param enable True to enable dual edge capture, false to disable
830 static inline void FTM_HAL_SetDualEdgeCaptureCmd(uint32_t ftmBaseAddr
, uint8_t channel
, bool enable
)
832 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
834 enable
? HW_FTM_COMBINE_SET(ftmBaseAddr
, BM_FTM_COMBINE_DECAPEN0
<< (FTM_HAL_GetChnPairIndex(channel
) * FTM_COMBINE_CHAN_CTRL_WIDTH
)):
835 HW_FTM_COMBINE_CLR(ftmBaseAddr
, BM_FTM_COMBINE_DECAPEN0
<< (FTM_HAL_GetChnPairIndex(channel
) * FTM_COMBINE_CHAN_CTRL_WIDTH
));
839 * @brief Enables or disables the FTM peripheral timer channel pair output complement mode.
841 * @param ftmBaseAddr The FTM base address
842 * @param channel The FTM peripheral channel number
843 * @param enable True to enable complementary mode, false to disable
845 static inline void FTM_HAL_SetDualChnCompCmd(uint32_t ftmBaseAddr
, uint8_t channel
, bool enable
)
847 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
849 enable
? HW_FTM_COMBINE_SET(ftmBaseAddr
, BM_FTM_COMBINE_COMP0
<< (FTM_HAL_GetChnPairIndex(channel
) * FTM_COMBINE_CHAN_CTRL_WIDTH
)):
850 HW_FTM_COMBINE_CLR(ftmBaseAddr
, BM_FTM_COMBINE_COMP0
<< (FTM_HAL_GetChnPairIndex(channel
) * FTM_COMBINE_CHAN_CTRL_WIDTH
));
855 * @brief Enables or disables the FTM peripheral timer channel pair output combine mode.
857 * @param ftmBaseAddr The FTM base address
858 * @param channel The FTM peripheral channel number
859 * @param enable True to enable channel pair to combine, false to disable
861 static inline void FTM_HAL_SetDualChnCombineCmd(uint32_t ftmBaseAddr
, uint8_t channel
, bool enable
)
863 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
865 enable
? HW_FTM_COMBINE_SET(ftmBaseAddr
, BM_FTM_COMBINE_COMBINE0
<< (FTM_HAL_GetChnPairIndex(channel
) * FTM_COMBINE_CHAN_CTRL_WIDTH
)):
866 HW_FTM_COMBINE_CLR(ftmBaseAddr
, BM_FTM_COMBINE_COMBINE0
<< (FTM_HAL_GetChnPairIndex(channel
) * FTM_COMBINE_CHAN_CTRL_WIDTH
));
869 /*FTM dead time insertion control*/
871 * @brief Sets the FTM deadtime divider.
873 * @param ftmBaseAddr The FTM base address
874 * @param divider The FTM peripheral prescale divider\n
875 * 0x :divided by 1, 10: divided by 4, 11:divided by 16
877 static inline void FTM_HAL_SetDeadtimePrescale(uint32_t ftmBaseAddr
, ftm_deadtime_ps_t divider
)
879 BW_FTM_DEADTIME_DTPS(ftmBaseAddr
, divider
);
883 * @brief Sets the FTM deadtime value.
885 * @param ftmBaseAddr The FTM base address
886 * @param count The FTM peripheral prescale divider\n
887 * 0: no counts inserted, 1: 1 count is inserted, 2: 2 count is inserted....
889 static inline void FTM_HAL_SetDeadtimeCount(uint32_t ftmBaseAddr
, uint8_t count
)
891 BW_FTM_DEADTIME_DTVAL(ftmBaseAddr
, count
);
895 * @brief Enables or disables the generation of the trigger when the FTM counter is equal to the CNTIN register.
897 * @param ftmBaseAddr The FTM base address
898 * @param enable True to enable, false to disable
900 static inline void FTM_HAL_SetInitTriggerCmd(uint32_t ftmBaseAddr
, bool enable
)
902 BW_FTM_EXTTRIG_INITTRIGEN(ftmBaseAddr
, enable
? 1 : 0);
905 /*FTM external trigger */
907 * @brief Enables or disables the generation of the FTM peripheral timer channel trigger.
909 * Enables or disables the when the generation of the FTM peripheral timer channel trigger when the
910 * FTM counter is equal to its initial value. Channels 6 and 7 cannot be used as triggers.
912 * @param ftmBaseAddr The FTM base address
913 * @param channel Channel to be enabled, valid value 0, 1, 2, 3, 4, 5
914 * @param val True to enable, false to disable
916 void FTM_HAL_SetChnTriggerCmd(uint32_t ftmBaseAddr
, uint8_t channel
, bool val
);
919 * @brief Checks whether any channel trigger event has occurred.
921 * @param ftmBaseAddr The FTM base address
922 * @retval true if there is a channel trigger event, false if not.
924 static inline bool FTM_HAL_IsChnTriggerGenerated(uint32_t ftmBaseAddr
)
926 return BR_FTM_EXTTRIG_TRIGF(ftmBaseAddr
);
930 /*Fault mode status*/
932 * @brief Gets the FTM detected fault input.
934 * This function reads the status for all fault inputs
936 * @param ftmBaseAddr The FTM base address
937 * @retval Return fault byte
939 static inline uint8_t FTM_HAL_GetDetectedFaultInput(uint32_t ftmBaseAddr
)
941 return (HW_FTM_FMS(ftmBaseAddr
).U
& 0x0f);
944 * @brief Checks whether the write protection is enabled.
946 * @param ftmBaseAddr The FTM base address
947 * @retval True if enabled, false if not
949 static inline bool FTM_HAL_IsWriteProtectionEnabled(uint32_t ftmBaseAddr
)
951 return BR_FTM_FMS_WPEN(ftmBaseAddr
) ? true : false;
954 /*Quadrature decoder control*/
957 * @brief Enables the channel quadrature decoder.
959 * @param ftmBaseAddr The FTM base address
960 * @param enable True to enable, false to disable
962 static inline void FTM_HAL_SetQuadDecoderCmd(uint32_t ftmBaseAddr
, bool enable
)
964 BW_FTM_QDCTRL_QUADEN(ftmBaseAddr
, enable
? 1 : 0);
968 * @brief Enables or disables the phase A input filter.
970 * @param ftmBaseAddr The FTM base address
971 * @param enable true enables the phase input filter, false disables the filter
973 static inline void FTM_HAL_SetQuadPhaseAFilterCmd(uint32_t ftmBaseAddr
, bool enable
)
975 BW_FTM_QDCTRL_PHAFLTREN(ftmBaseAddr
, enable
? 1 : 0);
979 * @brief Enables or disables the phase B input filter.
981 * @param ftmBaseAddr The FTM base address
982 * @param enable true enables the phase input filter, false disables the filter
984 static inline void FTM_HAL_SetQuadPhaseBFilterCmd(uint32_t ftmBaseAddr
, bool enable
)
986 BW_FTM_QDCTRL_PHBFLTREN(ftmBaseAddr
, enable
? 1 : 0);
990 * @brief Selects polarity for the quadrature decode phase A input.
992 * @param ftmBaseAddr The FTM base address
993 * @param mode 0: Normal polarity, 1: Inverted polarity
995 static inline void FTM_HAL_SetQuadPhaseAPolarity(uint32_t ftmBaseAddr
,
996 ftm_quad_phase_polarity_t mode
)
998 BW_FTM_QDCTRL_PHAPOL(ftmBaseAddr
, mode
);
1002 * @brief Selects polarity for the quadrature decode phase B input.
1004 * @param ftmBaseAddr The FTM base address
1005 * @param mode 0: Normal polarity, 1: Inverted polarity
1007 static inline void FTM_HAL_SetQuadPhaseBPolarity(uint32_t ftmBaseAddr
,
1008 ftm_quad_phase_polarity_t mode
)
1010 BW_FTM_QDCTRL_PHBPOL(ftmBaseAddr
, mode
);
1014 * @brief Sets the encoding mode used in quadrature decoding mode.
1016 * @param ftmBaseAddr The FTM base address
1017 * @param quadMode 0: Phase A and Phase B encoding mode\n
1018 * 1: Count and direction encoding mode
1020 static inline void FTM_HAL_SetQuadMode(uint32_t ftmBaseAddr
, ftm_quad_decode_mode_t quadMode
)
1022 BW_FTM_QDCTRL_QUADMODE(ftmBaseAddr
, quadMode
);
1026 * @brief Gets the FTM counter direction in quadrature mode.
1028 * @param ftmBaseAddr The FTM base address
1030 * @retval 1 if counting direction is increasing, 0 if counting direction is decreasing
1032 static inline uint8_t FTM_HAL_GetQuadDir(uint32_t ftmBaseAddr
)
1034 return BR_FTM_QDCTRL_QUADMODE(ftmBaseAddr
);
1038 * @brief Gets the Timer overflow direction in quadrature mode.
1040 * @param ftmBaseAddr The FTM base address
1042 * @retval 1 if TOF bit was set on the top of counting, o if TOF bit was set on the bottom of counting
1044 static inline uint8_t FTM_HAL_GetQuadTimerOverflowDir(uint32_t ftmBaseAddr
)
1046 return BR_FTM_QDCTRL_TOFDIR(ftmBaseAddr
);
1050 * @brief Sets the FTM peripheral timer channel input capture filter value.
1051 * @param ftmBaseAddr The FTM base address
1052 * @param channel The FTM peripheral channel number, only 0,1,2,3, channel 4, 5,6, 7 don't have.
1053 * @param val Filter value to be set
1055 void FTM_HAL_SetChnInputCaptureFilter(uint32_t ftmBaseAddr
, uint8_t channel
, uint8_t val
);
1058 * @brief Sets the fault input filter value.
1060 * @param ftmBaseAddr The FTM base address
1061 * @param val fault input filter value
1063 static inline void FTM_HAL_SetFaultInputFilterVal(uint32_t ftmBaseAddr
, uint32_t val
)
1065 BW_FTM_FLTCTRL_FFVAL(ftmBaseAddr
, val
);
1069 * @brief Enables or disables the fault input filter.
1071 * @param ftmBaseAddr The FTM base address
1072 * @param inputNum fault input to be configured, valid value 0, 1, 2, 3
1073 * @param val true to enable fault input filter, false to disable fault input filter
1075 static inline void FTM_HAL_SetFaultInputFilterCmd(uint32_t ftmBaseAddr
, uint8_t inputNum
, bool val
)
1077 assert(inputNum
< HW_CHAN4
);
1078 val
? HW_FTM_FLTCTRL_SET(ftmBaseAddr
, (1U << (inputNum
+ 4))) :
1079 HW_FTM_FLTCTRL_CLR(ftmBaseAddr
, (1U << (inputNum
+ 4)));
1083 * @brief Enables or disables the fault input.
1085 * @param ftmBaseAddr The FTM base address
1086 * @param inputNum fault input to be configured, valid value 0, 1, 2, 3
1087 * @param val true to enable fault input, false to disable fault input
1089 static inline void FTM_HAL_SetFaultInputCmd(uint32_t ftmBaseAddr
, uint8_t inputNum
, bool val
)
1091 assert(inputNum
< HW_CHAN4
);
1092 val
? HW_FTM_FLTCTRL_SET(ftmBaseAddr
, (1U << inputNum
)) :
1093 HW_FTM_FLTCTRL_CLR(ftmBaseAddr
, (1U << inputNum
));
1097 * @brief Enables or disables the channel invert for a channel pair.
1099 * @param ftmBaseAddr The FTM base address
1100 * @param channel The FTM peripheral channel number
1101 * @param val true to enable channel inverting, false to disable channel inverting
1103 static inline void FTM_HAL_SetDualChnInvertCmd(uint32_t ftmBaseAddr
, uint8_t channel
, bool val
)
1105 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
1107 val
? HW_FTM_INVCTRL_SET(ftmBaseAddr
, (1U << FTM_HAL_GetChnPairIndex(channel
))) :
1108 HW_FTM_INVCTRL_CLR(ftmBaseAddr
, (1U << FTM_HAL_GetChnPairIndex(channel
)));
1111 /*FTM software output control*/
1113 * @brief Enables or disables the channel software output control.
1114 * @param ftmBaseAddr The FTM base address
1115 * @param channel Channel to be enabled or disabled
1116 * @param val true to enable, channel output will be affected by software output control\n
1117 false to disable, channel output is unaffected
1119 static inline void FTM_HAL_SetChnSoftwareCtrlCmd(uint32_t ftmBaseAddr
, uint8_t channel
, bool val
)
1121 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
1122 val
? HW_FTM_SWOCTRL_SET(ftmBaseAddr
, (1U << channel
)) :
1123 HW_FTM_SWOCTRL_CLR(ftmBaseAddr
, (1U << channel
));
1126 * @brief Sets the channel software output control value.
1128 * @param ftmBaseAddr The FTM base address.
1129 * @param channel Channel to be configured
1130 * @param val True to set 1, false to set 0
1132 static inline void FTM_HAL_SetChnSoftwareCtrlVal(uint32_t ftmBaseAddr
, uint8_t channel
, bool val
)
1134 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
1135 val
? HW_FTM_SWOCTRL_SET(ftmBaseAddr
, (1U << (channel
+ 8))) :
1136 HW_FTM_SWOCTRL_CLR(ftmBaseAddr
, (1U << (channel
+ 8)));
1139 /*FTM PWM load control*/
1141 * @brief Enables or disables the loading of MOD, CNTIN and CV with values of their write buffer.
1143 * @param ftmBaseAddr The FTM base address
1144 * @param enable true to enable, false to disable
1146 static inline void FTM_HAL_SetPwmLoadCmd(uint32_t ftmBaseAddr
, bool enable
)
1148 BW_FTM_PWMLOAD_LDOK(ftmBaseAddr
, enable
? 1 : 0);
1152 * @brief Includes or excludes the channel in the matching process.
1154 * @param ftmBaseAddr The FTM base address
1155 * @param channel Channel to be configured
1156 * @param val true means include the channel in the matching process\n
1157 * false means do not include channel in the matching process
1159 static inline void FTM_HAL_SetPwmLoadChnSelCmd(uint32_t ftmBaseAddr
, uint8_t channel
, bool val
)
1161 assert(channel
< FSL_FEATURE_FTM_CHANNEL_COUNT
);
1162 val
? HW_FTM_PWMLOAD_SET(ftmBaseAddr
, 1U << channel
) : HW_FTM_PWMLOAD_CLR(ftmBaseAddr
, 1U << channel
);
1165 /*FTM configuration*/
1167 * @brief Enables or disables the FTM global time base signal generation to other FTM's.
1169 * @param ftmBaseAddr The FTM base address
1170 * @param enable True to enable, false to disable
1172 static inline void FTM_HAL_SetGlobalTimeBaseOutputCmd(uint32_t ftmBaseAddr
, bool enable
)
1174 BW_FTM_CONF_GTBEOUT(ftmBaseAddr
, enable
? 1 : 0);
1178 * @brief Enables or disables the FTM timer global time base.
1180 * @param ftmBaseAddr The FTM base address
1181 * @param enable True to enable, false to disable
1183 static inline void FTM_HAL_SetGlobalTimeBaseCmd(uint32_t ftmBaseAddr
, bool enable
)
1185 BW_FTM_CONF_GTBEEN(ftmBaseAddr
, enable
? 1 : 0);
1189 * @brief Sets the BDM mode..
1191 * @param ftmBaseAddr The FTM base address
1192 * @param val FTM behaviour in BDM mode, options are 0,1,2,3
1194 static inline void FTM_HAL_SetBdmMode(uint32_t ftmBaseAddr
, uint8_t val
)
1196 BW_FTM_CONF_BDMMODE(ftmBaseAddr
, val
);
1200 * @brief Sets the FTM timer TOF Frequency
1202 * @param ftmBaseAddr The FTM base address
1203 * @param val Value of the TOF bit set frequency
1205 static inline void FTM_HAL_SetTofFreq(uint32_t ftmBaseAddr
, uint8_t val
)
1207 BW_FTM_CONF_NUMTOF(ftmBaseAddr
, val
);
1210 /*FTM sync configuration*/
1213 * @brief Sets the sync mode for the FTM SWOCTRL register when using a hardware trigger.
1215 * @param ftmBaseAddr The FTM base address
1216 * @param enable true means the hardware trigger activates register sync\n
1217 * false means the hardware trigger does not activate register sync.
1219 static inline void FTM_HAL_SetSwoctrlHardwareSyncModeCmd(uint32_t ftmBaseAddr
, bool enable
)
1221 BW_FTM_SYNCONF_HWSOC(ftmBaseAddr
, enable
? 1 : 0);
1225 * @brief Sets sync mode for FTM INVCTRL register when using a hardware trigger.
1227 * @param ftmBaseAddr The FTM base address
1228 * @param enable true means the hardware trigger activates register sync\n
1229 * false means the hardware trigger does not activate register sync.
1231 static inline void FTM_HAL_SetInvctrlHardwareSyncModeCmd(uint32_t ftmBaseAddr
, bool enable
)
1233 BW_FTM_SYNCONF_HWINVC(ftmBaseAddr
, enable
? 1 : 0);
1237 * @brief Sets sync mode for FTM OUTMASK register when using a hardware trigger.
1239 * @param ftmBaseAddr The FTM base address
1240 * @param enable true means hardware trigger activates register sync\n
1241 * false means hardware trigger does not activate register sync.
1243 static inline void FTM_HAL_SetOutmaskHardwareSyncModeCmd(uint32_t ftmBaseAddr
, bool enable
)
1245 BW_FTM_SYNCONF_HWOM(ftmBaseAddr
, enable
? 1 : 0);
1249 * @brief Sets sync mode for FTM MOD, CNTIN and CV registers when using a hardware trigger.
1251 * @param ftmBaseAddr The FTM base address
1252 * @param enable true means hardware trigger activates register sync\n
1253 * false means hardware trigger does not activate register sync.
1255 static inline void FTM_HAL_SetModCntinCvHardwareSycnModeCmd(uint32_t ftmBaseAddr
, bool enable
)
1257 BW_FTM_SYNCONF_HWWRBUF(ftmBaseAddr
, enable
? 1 : 0);
1261 * @brief Sets sync mode for FTM counter register when using a hardware trigger.
1263 * @param ftmBaseAddr The FTM base address
1264 * @param enable true means hardware trigger activates register sync\n
1265 * false means hardware trigger does not activate register sync.
1267 static inline void FTM_HAL_SetCounterHardwareSyncModeCmd(uint32_t ftmBaseAddr
, bool enable
)
1269 BW_FTM_SYNCONF_HWRSTCNT(ftmBaseAddr
, enable
? 1 : 0);
1273 * @brief Sets sync mode for FTM SWOCTRL register when using a software trigger.
1275 * @param ftmBaseAddr The FTM base address
1276 * @param enable true means software trigger activates register sync\n
1277 * false means software trigger does not activate register sync.
1279 static inline void FTM_HAL_SetSwoctrlSoftwareSyncModeCmd(uint32_t ftmBaseAddr
, bool enable
)
1281 BW_FTM_SYNCONF_SWSOC(ftmBaseAddr
, enable
? 1 : 0);
1285 * @brief Sets sync mode for FTM INVCTRL register when using a software trigger.
1287 * @param ftmBaseAddr The FTM base address
1288 * @param enable true means software trigger activates register sync\n
1289 * false means software trigger does not activate register sync.
1291 static inline void FTM_HAL_SetInvctrlSoftwareSyncModeCmd(uint32_t ftmBaseAddr
, bool enable
)
1293 BW_FTM_SYNCONF_SWINVC(ftmBaseAddr
, enable
? 1 : 0);
1297 * @brief Sets sync mode for FTM OUTMASK register when using a software trigger.
1299 * @param ftmBaseAddr The FTM base address
1300 * @param enable true means software trigger activates register sync\n
1301 * false means software trigger does not activate register sync.
1303 static inline void FTM_HAL_SetOutmaskSoftwareSyncModeCmd(uint32_t ftmBaseAddr
, bool enable
)
1305 BW_FTM_SYNCONF_SWOM(ftmBaseAddr
, enable
? 1 : 0);
1309 * @brief Sets synch mode for FTM MOD, CNTIN and CV registers when using a software trigger.
1311 * @param ftmBaseAddr The FTM base address
1312 * @param enable true means software trigger activates register sync\n
1313 * false means software trigger does not activate register sync.
1315 static inline void FTM_HAL_SetModCntinCvSoftwareSyncModeCmd(uint32_t ftmBaseAddr
, bool enable
)
1317 BW_FTM_SYNCONF_SWWRBUF(ftmBaseAddr
, enable
? 1 : 0);
1321 * @brief Sets sync mode for FTM counter register when using a software trigger.
1323 * @param ftmBaseAddr The FTM base address
1324 * @param enable true means software trigger activates register sync\n
1325 * false means software trigger does not activate register sync.
1327 static inline void FTM_HAL_SetCounterSoftwareSyncModeCmd(uint32_t ftmBaseAddr
, bool enable
)
1329 BW_FTM_SYNCONF_SWRSTCNT(ftmBaseAddr
, enable
? 1 : 0);
1333 * @brief Sets the PWM synchronization mode to enhanced or legacy.
1335 * @param ftmBaseAddr The FTM base address
1336 * @param enable true means use Enhanced PWM synchronization\n
1337 * false means to use Legacy mode
1339 static inline void FTM_HAL_SetPwmSyncModeCmd(uint32_t ftmBaseAddr
, bool enable
)
1341 BW_FTM_SYNCONF_SYNCMODE(ftmBaseAddr
, enable
? 1 : 0);
1345 * @brief Sets the SWOCTRL register PWM synchronization mode.
1347 * @param ftmBaseAddr The FTM base address
1348 * @param enable true means SWOCTRL register is updated by PWM synch\n
1349 * false means SWOCTRL register is updated at all rising edges of system clock
1351 static inline void FTM_HAL_SetSwoctrlPwmSyncModeCmd(uint32_t ftmBaseAddr
, bool enable
)
1353 BW_FTM_SYNCONF_SWOC(ftmBaseAddr
, enable
? 1 : 0);
1357 * @brief Sets the INVCTRL register PWM synchronization mode.
1359 * @param ftmBaseAddr The FTM base address
1360 * @param enable true means INVCTRL register is updated by PWM synch\n
1361 * false means INVCTRL register is updated at all rising edges of system clock
1363 static inline void FTM_HAL_SetInvctrlPwmSyncModeCmd(uint32_t ftmBaseAddr
, bool enable
)
1365 BW_FTM_SYNCONF_INVC(ftmBaseAddr
, enable
? 1 : 0);
1369 * @brief Sets the CNTIN register PWM synchronization mode.
1371 * @param ftmBaseAddr The FTM base address
1372 * @param enable true means CNTIN register is updated by PWM synch\n
1373 * false means CNTIN register is updated at all rising edges of system clock
1375 static inline void FTM_HAL_SetCntinPwmSyncModeCmd(uint32_t ftmBaseAddr
, bool enable
)
1377 BW_FTM_SYNCONF_CNTINC(ftmBaseAddr
, enable
? 1 : 0);
1381 /*HAL functionality*/
1383 * @brief Resets the FTM registers
1385 * @param instance The FTM instance number
1386 * @param ftmBaseAddr The FTM base address
1388 void FTM_HAL_Reset(uint32_t ftmBaseAddr
, uint32_t instance
);
1391 * @brief Initializes the FTM.
1393 * @param ftmBaseAddr The FTM base address.
1395 void FTM_HAL_Init(uint32_t ftmBaseAddr
);
1397 /*Initializes the 5 FTM operating mode, input capture, output compare, PWM output(edge aligned, center-aligned, conbine), dual and quadrature).*/
1399 /*void FTM_HAL_input_capture_mode(uint32_t ftmBaseAddr);*/
1400 /*void FTM_HAL_output_compare_mode(uint32_t ftmBaseAddr);*/
1403 * @brief Enables the FTM timer when it is PWM output mode.
1405 * @param ftmBaseAddr The FTM base address
1406 * @param config PWM configuration parameter
1407 * @param channel The channel or channel pair number(combined mode).
1409 void FTM_HAL_EnablePwmMode(uint32_t ftmBaseAddr
, ftm_pwm_param_t
*config
, uint8_t channel
);
1412 * @brief Disables the PWM output mode.
1414 * @param ftmBaseAddr The FTM base address
1415 * @param config PWM configuration parameter
1416 * @param channel The channel or channel pair number(combined mode).
1418 void FTM_HAL_DisablePwmMode(uint32_t ftmBaseAddr
, ftm_pwm_param_t
*config
, uint8_t channel
);
1420 /*void FTM_HAL_dual_mode(uint32_t ftmBaseAddr);*/
1421 /*void FTM_HAL_quad_mode(uint32_t ftmBaseAddr);*/
1424 /*void FTM_HAL_set_counting_mode(); //up, up down or free running counting mode*/
1425 /*void FTM_HAL_set_deadtime(uint32_t ftmBaseAddr, uint_32 us);*/
1429 #endif /* __FSL_FTM_HAL_H__*/
1430 /*******************************************************************************
1432 ******************************************************************************/