NetBurner 3.5.6
PDF Version
fsl_qtmr.h
1/*
2 * Copyright 2017-2022 NXP
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7#ifndef FSL_QTMR_H_
8#define FSL_QTMR_H_
9
10#include "fsl_common.h"
11
17/*******************************************************************************
18 * Definitions
19 ******************************************************************************/
20#ifndef TMR_CSCTRL_OFLAG_MASK
21#define TMR_CSCTRL_OFLAG_MASK (0x100UL)
22#endif
23
24#ifndef TMR_CSCTRL_OFLAG_SHIFT
25#define TMR_CSCTRL_OFLAG_SHIFT (8UL)
26#endif
27
30#define FSL_QTMR_DRIVER_VERSION (MAKE_VERSION(2, 2, 2))
53
62
75
82
95
104
112
121
123// typedef enum _qtmr_interrupt_enable
132
142
151
159
181
182/*******************************************************************************
183 * API
184 ******************************************************************************/
185
186#if defined(__cplusplus)
187extern "C" {
188#endif
189
204void QTMR_Init(TMR_Type *base, qtmr_channel_selection_t channel, const qtmr_config_t *config);
205
212void QTMR_Deinit(TMR_Type *base, qtmr_channel_selection_t channel);
213
230
250status_t QTMR_SetupPwm(TMR_Type *base,
252 uint32_t pwmFreqHz,
253 uint8_t dutyCyclePercent,
254 bool outputPolarity,
255 uint32_t srcClock_Hz);
256
269void QTMR_SetupInputCapture(TMR_Type *base,
271 qtmr_input_source_t capturePin,
272 bool inputPolarity,
273 bool reloadOnCapture,
274 qtmr_input_capture_edge_t captureMode);
275
289void QTMR_EnableInterrupts(TMR_Type *base, qtmr_channel_selection_t channel, uint32_t mask);
290
299void QTMR_DisableInterrupts(TMR_Type *base, qtmr_channel_selection_t channel, uint32_t mask);
300
310uint32_t QTMR_GetEnabledInterrupts(TMR_Type *base, qtmr_channel_selection_t channel);
311
328uint32_t QTMR_GetStatus(TMR_Type *base, qtmr_channel_selection_t channel);
329
338void QTMR_ClearStatusFlags(TMR_Type *base, qtmr_channel_selection_t channel, uint32_t mask);
339
363void QTMR_SetTimerPeriod(TMR_Type *base, qtmr_channel_selection_t channel, uint16_t ticks);
364
374void QTMR_SetCompareValue(TMR_Type *base, qtmr_channel_selection_t channel, uint16_t ticks);
375
385static inline void QTMR_SetLoadValue(TMR_Type *base, qtmr_channel_selection_t channel, uint16_t value)
386{
387 base->CHANNEL[channel].LOAD &= (uint16_t)(~TMR_LOAD_LOAD_MASK);
388 base->CHANNEL[channel].LOAD = value;
389}
390
404static inline uint16_t QTMR_GetCurrentTimerCount(TMR_Type *base, qtmr_channel_selection_t channel)
405{
406 return base->CHANNEL[channel].CNTR;
407}
408
424static inline void QTMR_StartTimer(TMR_Type *base, qtmr_channel_selection_t channel, qtmr_counting_mode_t clockSource)
425{
426 uint16_t reg = base->CHANNEL[channel].CTRL;
427
428 reg &= (uint16_t)(~(TMR_CTRL_CM_MASK));
429 reg |= TMR_CTRL_CM(clockSource);
430 base->CHANNEL[channel].CTRL = reg;
431}
432
439static inline void QTMR_StopTimer(TMR_Type *base, qtmr_channel_selection_t channel)
440{
441 base->CHANNEL[channel].CTRL &= (uint16_t)(~TMR_CTRL_CM_MASK);
442}
443
459void QTMR_EnableDma(TMR_Type *base, qtmr_channel_selection_t channel, uint32_t mask);
460
469void QTMR_DisableDma(TMR_Type *base, qtmr_channel_selection_t channel, uint32_t mask);
470
480void QTMR_SetPwmOutputToIdle(TMR_Type *base, qtmr_channel_selection_t channel, bool idleStatus);
481
490static inline qtmr_pwm_out_state_t QTMR_GetPwmOutputStatus(TMR_Type *base, qtmr_channel_selection_t channel)
491{
492 if (0U != ((base->CHANNEL[channel].CSCTRL) & TMR_CSCTRL_OFLAG_MASK))
493 {
494 return kQTMR_PwmHigh;
495 }
496 else
497 {
498 return kQTMR_PwmLow;
499 }
500}
501
510uint8_t QTMR_GetPwmChannelStatus(TMR_Type *base, qtmr_channel_selection_t channel);
511
519void QTMR_SetPwmClockMode(TMR_Type *base, qtmr_channel_selection_t channel, qtmr_primary_count_source_t prescaler);
520
523#if defined(__cplusplus)
524}
525#endif
526
529#endif /* FSL_QTMR_H_ */
int32_t status_t
Type used for all status and error return values.
Definition fsl_common.h:228
void QTMR_DisableDma(TMR_Type *base, qtmr_channel_selection_t channel, uint32_t mask)
Disable the Quad Timer DMA.
Definition fsl_qtmr.c:642
enum _qtmr_output_mode qtmr_output_mode_t
Quad Timer output mode selection.
void QTMR_SetTimerPeriod(TMR_Type *base, qtmr_channel_selection_t channel, uint16_t ticks)
Sets the timer period in ticks.
Definition fsl_qtmr.c:556
void QTMR_SetPwmClockMode(TMR_Type *base, qtmr_channel_selection_t channel, qtmr_primary_count_source_t prescaler)
This function set the value of the prescaler on QTimer channels.
Definition fsl_qtmr.c:718
enum _qtmr_channel_selection qtmr_channel_selection_t
List of channel selection.
status_t QTMR_SetupPwm(TMR_Type *base, qtmr_channel_selection_t channel, uint32_t pwmFreqHz, uint8_t dutyCyclePercent, bool outputPolarity, uint32_t srcClock_Hz)
Sets up Quad timer module for PWM signal output.
Definition fsl_qtmr.c:169
_qtmr_counting_mode
Quad Timer counting mode selection.
Definition fsl_qtmr.h:65
enum _qtmr_primary_count_source qtmr_primary_count_source_t
Quad Timer primary clock source selection.
void QTMR_EnableInterrupts(TMR_Type *base, qtmr_channel_selection_t channel, uint32_t mask)
Enables the selected Quad Timer interrupts.
Definition fsl_qtmr.c:320
enum _qtmr_status_flags qtmr_status_flags_t
List of Quad Timer flags.
_qtmr_debug_action
List of Quad Timer run options when in Debug mode.
Definition fsl_qtmr.h:115
enum _qtmr_dma_enable qtmr_dma_enable_t
List of Quad Timer DMA enable.
_qtmr_channel_selection
List of channel selection.
Definition fsl_qtmr.h:145
enum _qtmr_input_capture_edge qtmr_input_capture_edge_t
Quad Timer input capture edge mode, rising edge, or falling edge.
_qtmr_preload_control
Quad Timer input capture edge mode, rising edge, or falling edge.
Definition fsl_qtmr.h:107
void QTMR_SetPwmOutputToIdle(TMR_Type *base, qtmr_channel_selection_t channel, bool idleStatus)
Set PWM output in idle status (high or low).
Definition fsl_qtmr.c:674
enum _qtmr_debug_action qtmr_debug_action_t
List of Quad Timer run options when in Debug mode.
void QTMR_GetDefaultConfig(qtmr_config_t *config)
Fill in the Quad Timer config struct with the default settings.
Definition fsl_qtmr.c:129
void QTMR_DisableInterrupts(TMR_Type *base, qtmr_channel_selection_t channel, uint32_t mask)
Disables the selected Quad Timer interrupts.
Definition fsl_qtmr.c:366
void QTMR_EnableDma(TMR_Type *base, qtmr_channel_selection_t channel, uint32_t mask)
Enable the Quad Timer DMA.
Definition fsl_qtmr.c:609
_qtmr_pwm_out_state
Quad Timer PWM output state.
Definition fsl_qtmr.h:78
_qtmr_input_capture_edge
Quad Timer input capture edge mode, rising edge, or falling edge.
Definition fsl_qtmr.h:98
uint32_t QTMR_GetStatus(TMR_Type *base, qtmr_channel_selection_t channel)
Gets the Quad Timer status flags.
Definition fsl_qtmr.c:457
enum _qtmr_counting_mode qtmr_counting_mode_t
Quad Timer counting mode selection.
enum _qtmr_input_source qtmr_input_source_t
Quad Timer input sources selection.
_qtmr_input_source
Quad Timer input sources selection.
Definition fsl_qtmr.h:56
void QTMR_SetCompareValue(TMR_Type *base, qtmr_channel_selection_t channel, uint16_t ticks)
Set compare value.
Definition fsl_qtmr.c:585
struct _qtmr_config qtmr_config_t
Quad Timer config structure.
void QTMR_Deinit(TMR_Type *base, qtmr_channel_selection_t channel)
Stops the counter and gates the Quad Timer clock.
Definition fsl_qtmr.c:103
void QTMR_SetupInputCapture(TMR_Type *base, qtmr_channel_selection_t channel, qtmr_input_source_t capturePin, bool inputPolarity, bool reloadOnCapture, qtmr_input_capture_edge_t captureMode)
Allows the user to count the source clock cycles until a capture event arrives.
Definition fsl_qtmr.c:278
enum _qtmr_preload_control qtmr_preload_control_t
Quad Timer input capture edge mode, rising edge, or falling edge.
_qtmr_primary_count_source
Quad Timer primary clock source selection.
Definition fsl_qtmr.h:35
void QTMR_Init(TMR_Type *base, qtmr_channel_selection_t channel, const qtmr_config_t *config)
Ungates the Quad Timer clock and configures the peripheral for basic operation.
Definition fsl_qtmr.c:72
void QTMR_ClearStatusFlags(TMR_Type *base, qtmr_channel_selection_t channel, uint32_t mask)
Clears the Quad Timer status flags.
Definition fsl_qtmr.c:502
enum _qtmr_pwm_out_state qtmr_pwm_out_state_t
Quad Timer PWM output state.
enum _qtmr_interrupt_enable qtmr_interrupt_enable_t
List of Quad Timer interrupts.
_qtmr_output_mode
Quad Timer output mode selection.
Definition fsl_qtmr.h:85
_qtmr_dma_enable
List of Quad Timer DMA enable.
Definition fsl_qtmr.h:154
_qtmr_interrupt_enable
List of Quad Timer interrupts.
Definition fsl_qtmr.h:125
uint8_t QTMR_GetPwmChannelStatus(TMR_Type *base, qtmr_channel_selection_t channel)
Get the PWM channel dutycycle value.
Definition fsl_qtmr.c:706
_qtmr_status_flags
List of Quad Timer flags.
Definition fsl_qtmr.h:135
uint32_t QTMR_GetEnabledInterrupts(TMR_Type *base, qtmr_channel_selection_t channel)
Gets the enabled Quad Timer interrupts.
Definition fsl_qtmr.c:411
@ kQTMR_PriSrcRiseEdgeSecInpHigh
Definition fsl_qtmr.h:69
@ kQTMR_PriSrcRiseAndFallEdge
Definition fsl_qtmr.h:68
@ kQTMR_PriSrcRiseEdgeSecDir
Definition fsl_qtmr.h:71
@ kQTMR_CascadeCount
Definition fsl_qtmr.h:73
@ kQTMR_SecSrcTrigPriCnt
Definition fsl_qtmr.h:72
@ kQTMR_NoOperation
Definition fsl_qtmr.h:66
@ kQTMR_PriSrcRiseEdge
Definition fsl_qtmr.h:67
@ kQTMR_QuadCountMode
Definition fsl_qtmr.h:70
@ kQTMR_HaltCountForceOutZero
Definition fsl_qtmr.h:119
@ kQTMR_HaltCounter
Definition fsl_qtmr.h:117
@ kQTMR_RunNormalInDebug
Definition fsl_qtmr.h:116
@ kQTMR_ForceOutToZero
Definition fsl_qtmr.h:118
@ kQTMR_Channel_2
Definition fsl_qtmr.h:148
@ kQTMR_Channel_3
Definition fsl_qtmr.h:149
@ kQTMR_Channel_0
Definition fsl_qtmr.h:146
@ kQTMR_Channel_1
Definition fsl_qtmr.h:147
@ kQTMR_NoPreload
Definition fsl_qtmr.h:108
@ kQTMR_LoadOnComp2
Definition fsl_qtmr.h:110
@ kQTMR_LoadOnComp1
Definition fsl_qtmr.h:109
@ kQTMR_PwmHigh
Definition fsl_qtmr.h:80
@ kQTMR_PwmLow
Definition fsl_qtmr.h:79
@ kQTMR_NoCapture
Definition fsl_qtmr.h:99
@ kQTMR_RisingAndFallingEdge
Definition fsl_qtmr.h:102
@ kQTMR_RisingEdge
Definition fsl_qtmr.h:100
@ kQTMR_FallingEdge
Definition fsl_qtmr.h:101
@ kQTMR_Counter3InputPin
Definition fsl_qtmr.h:60
@ kQTMR_Counter1InputPin
Definition fsl_qtmr.h:58
@ kQTMR_Counter0InputPin
Definition fsl_qtmr.h:57
@ kQTMR_Counter2InputPin
Definition fsl_qtmr.h:59
@ kQTMR_ClockCounter1Output
Definition fsl_qtmr.h:41
@ kQTMR_ClockDivide_16
Definition fsl_qtmr.h:48
@ kQTMR_ClockDivide_4
Definition fsl_qtmr.h:46
@ kQTMR_ClockDivide_8
Definition fsl_qtmr.h:47
@ kQTMR_ClockCounter1InputPin
Definition fsl_qtmr.h:37
@ kQTMR_ClockDivide_1
Definition fsl_qtmr.h:44
@ kQTMR_ClockCounter2Output
Definition fsl_qtmr.h:42
@ kQTMR_ClockCounter3Output
Definition fsl_qtmr.h:43
@ kQTMR_ClockCounter0InputPin
Definition fsl_qtmr.h:36
@ kQTMR_ClockDivide_64
Definition fsl_qtmr.h:50
@ kQTMR_ClockCounter0Output
Definition fsl_qtmr.h:40
@ kQTMR_ClockDivide_2
Definition fsl_qtmr.h:45
@ kQTMR_ClockDivide_32
Definition fsl_qtmr.h:49
@ kQTMR_ClockCounter2InputPin
Definition fsl_qtmr.h:38
@ kQTMR_ClockDivide_128
Definition fsl_qtmr.h:51
@ kQTMR_ClockCounter3InputPin
Definition fsl_qtmr.h:39
@ kQTMR_ClearOnCompare
Definition fsl_qtmr.h:87
@ kQTMR_AssertWhenCountActive
Definition fsl_qtmr.h:86
@ kQTMR_SetOnCompareClearOnCountRoll
Definition fsl_qtmr.h:92
@ kQTMR_SetOnCompareClearOnSecSrcInp
Definition fsl_qtmr.h:91
@ kQTMR_SetOnCompare
Definition fsl_qtmr.h:88
@ kQTMR_EnableGateClock
Definition fsl_qtmr.h:93
@ kQTMR_ToggleOnCompare
Definition fsl_qtmr.h:89
@ kQTMR_ToggleOnAltCompareReg
Definition fsl_qtmr.h:90
@ kQTMR_InputEdgeFlagDmaEnable
Definition fsl_qtmr.h:155
@ kQTMR_ComparatorPreload1DmaEnable
Definition fsl_qtmr.h:156
@ kQTMR_ComparatorPreload2DmaEnable
Definition fsl_qtmr.h:157
@ kQTMR_Compare1InterruptEnable
Definition fsl_qtmr.h:127
@ kQTMR_EdgeInterruptEnable
Definition fsl_qtmr.h:130
@ kQTMR_Compare2InterruptEnable
Definition fsl_qtmr.h:128
@ kQTMR_OverflowInterruptEnable
Definition fsl_qtmr.h:129
@ kQTMR_CompareInterruptEnable
Definition fsl_qtmr.h:126
@ kQTMR_CompareFlag
Definition fsl_qtmr.h:136
@ kQTMR_Compare1Flag
Definition fsl_qtmr.h:137
@ kQTMR_Compare2Flag
Definition fsl_qtmr.h:138
@ kQTMR_OverflowFlag
Definition fsl_qtmr.h:139
@ kQTMR_EdgeFlag
Definition fsl_qtmr.h:140
Quad Timer config structure.
Definition fsl_qtmr.h:170
bool enableMasterMode
Definition fsl_qtmr.h:173
uint8_t faultFilterPeriod
Definition fsl_qtmr.h:178
qtmr_primary_count_source_t primarySource
Definition fsl_qtmr.h:171
qtmr_input_source_t secondarySource
Definition fsl_qtmr.h:172
uint8_t faultFilterCount
Definition fsl_qtmr.h:177
qtmr_debug_action_t debugMode
Definition fsl_qtmr.h:179
bool enableExternalForce
Definition fsl_qtmr.h:175