The MCUXpresso SDK provides a driver for the Low-Power Timer (LPTMR) of MCUXpresso SDK devices.
Function groups
The LPTMR driver supports operating the module as a time counter or as a pulse counter.
Initialization and deinitialization
The function LPTMR_Init() initializes the LPTMR with specified configurations. The function LPTMR_GetDefaultConfig() gets the default configurations. The initialization function configures the LPTMR for a timer or a pulse counter mode mode. It also sets up the LPTMR's free running mode operation and a clock source.
The function LPTMR_DeInit() disables the LPTMR module and gates the module clock.
Timer period Operations
The function LPTMR_SetTimerPeriod() sets the timer period in units of count. Timers counts from 0 to the count value set here.
The function LPTMR_GetCurrentTimerCount() reads the current timer counting value. This function returns the real-time timer counting value ranging from 0 to a timer period.
The timer period operation function takes the count value in ticks. Call the utility macros provided in the fsl_common.h file to convert to microseconds or milliseconds.
Start and Stop timer operations
The function LPTMR_StartTimer() starts the timer counting. After calling this function, the timer counts up to the counter value set earlier by using the LPTMR_SetPeriod() function. Each time the timer reaches the count value and increments, it generates a trigger pulse and sets the timeout interrupt flag. An interrupt is also triggered if the timer interrupt is enabled.
The function LPTMR_StopTimer() stops the timer counting and resets the timer's counter register.
Status
Provides functions to get and clear the LPTMR status.
Interrupt
Provides functions to enable/disable LPTMR interrupts and get the currently enabled interrupts.
Typical use case
LPTMR tick example
Updates the LPTMR period and toggles an LED periodically. Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/lptmr
|
enum | lptmr_pin_select_t {
kLPTMR_PinSelectInput_0 = 0x0U,
kLPTMR_PinSelectInput_1 = 0x1U,
kLPTMR_PinSelectInput_2 = 0x2U,
kLPTMR_PinSelectInput_3 = 0x3U
} |
| LPTMR pin selection used in pulse counter mode. More...
|
|
enum | lptmr_pin_polarity_t {
kLPTMR_PinPolarityActiveHigh = 0x0U,
kLPTMR_PinPolarityActiveLow = 0x1U
} |
| LPTMR pin polarity used in pulse counter mode. More...
|
|
enum | lptmr_timer_mode_t {
kLPTMR_TimerModeTimeCounter = 0x0U,
kLPTMR_TimerModePulseCounter = 0x1U
} |
| LPTMR timer mode selection. More...
|
|
enum | lptmr_prescaler_glitch_value_t {
kLPTMR_Prescale_Glitch_0 = 0x0U,
kLPTMR_Prescale_Glitch_1 = 0x1U,
kLPTMR_Prescale_Glitch_2 = 0x2U,
kLPTMR_Prescale_Glitch_3 = 0x3U,
kLPTMR_Prescale_Glitch_4 = 0x4U,
kLPTMR_Prescale_Glitch_5 = 0x5U,
kLPTMR_Prescale_Glitch_6 = 0x6U,
kLPTMR_Prescale_Glitch_7 = 0x7U,
kLPTMR_Prescale_Glitch_8 = 0x8U,
kLPTMR_Prescale_Glitch_9 = 0x9U,
kLPTMR_Prescale_Glitch_10 = 0xAU,
kLPTMR_Prescale_Glitch_11 = 0xBU,
kLPTMR_Prescale_Glitch_12 = 0xCU,
kLPTMR_Prescale_Glitch_13 = 0xDU,
kLPTMR_Prescale_Glitch_14 = 0xEU,
kLPTMR_Prescale_Glitch_15 = 0xFU
} |
| LPTMR prescaler/glitch filter values. More...
|
|
enum | lptmr_prescaler_clock_select_t {
kLPTMR_PrescalerClock_0 = 0x0U,
kLPTMR_PrescalerClock_2 = 0x2U
} |
| LPTMR prescaler/glitch filter clock select. More...
|
|
enum | lptmr_interrupt_enable_t { kLPTMR_TimerInterruptEnable = LPTMR_CSR_TIE_MASK
} |
| List of the LPTMR interrupts. More...
|
|
enum | lptmr_status_flags_t { kLPTMR_TimerCompareFlag = LPTMR_CSR_TCF_MASK
} |
| List of the LPTMR status flags. More...
|
|
This structure holds the configuration settings for the LPTMR peripheral. To initialize this structure to reasonable defaults, call the LPTMR_GetDefaultConfig() function and pass a pointer to your configuration structure instance.
The configuration struct can be made constant so it resides in flash.
Enumerator |
---|
kLPTMR_PinSelectInput_0 |
Pulse counter input 0 is selected.
|
kLPTMR_PinSelectInput_1 |
Pulse counter input 1 is selected.
|
kLPTMR_PinSelectInput_2 |
Pulse counter input 2 is selected.
|
kLPTMR_PinSelectInput_3 |
Pulse counter input 3 is selected.
|
Enumerator |
---|
kLPTMR_PinPolarityActiveHigh |
Pulse Counter input source is active-high.
|
kLPTMR_PinPolarityActiveLow |
Pulse Counter input source is active-low.
|
Enumerator |
---|
kLPTMR_TimerModeTimeCounter |
Time Counter mode.
|
kLPTMR_TimerModePulseCounter |
Pulse Counter mode.
|
Enumerator |
---|
kLPTMR_Prescale_Glitch_0 |
Prescaler divide 2, glitch filter does not support this setting.
|
kLPTMR_Prescale_Glitch_1 |
Prescaler divide 4, glitch filter 2.
|
kLPTMR_Prescale_Glitch_2 |
Prescaler divide 8, glitch filter 4.
|
kLPTMR_Prescale_Glitch_3 |
Prescaler divide 16, glitch filter 8.
|
kLPTMR_Prescale_Glitch_4 |
Prescaler divide 32, glitch filter 16.
|
kLPTMR_Prescale_Glitch_5 |
Prescaler divide 64, glitch filter 32.
|
kLPTMR_Prescale_Glitch_6 |
Prescaler divide 128, glitch filter 64.
|
kLPTMR_Prescale_Glitch_7 |
Prescaler divide 256, glitch filter 128.
|
kLPTMR_Prescale_Glitch_8 |
Prescaler divide 512, glitch filter 256.
|
kLPTMR_Prescale_Glitch_9 |
Prescaler divide 1024, glitch filter 512.
|
kLPTMR_Prescale_Glitch_10 |
Prescaler divide 2048 glitch filter 1024.
|
kLPTMR_Prescale_Glitch_11 |
Prescaler divide 4096, glitch filter 2048.
|
kLPTMR_Prescale_Glitch_12 |
Prescaler divide 8192, glitch filter 4096.
|
kLPTMR_Prescale_Glitch_13 |
Prescaler divide 16384, glitch filter 8192.
|
kLPTMR_Prescale_Glitch_14 |
Prescaler divide 32768, glitch filter 16384.
|
kLPTMR_Prescale_Glitch_15 |
Prescaler divide 65536, glitch filter 32768.
|
- Note
- Clock connections are SoC-specific
Enumerator |
---|
kLPTMR_PrescalerClock_0 |
Prescaler/glitch filter clock 0 selected.
|
kLPTMR_PrescalerClock_2 |
Prescaler/glitch filter clock 2 selected.
|
Enumerator |
---|
kLPTMR_TimerInterruptEnable |
Timer interrupt enable.
|
Enumerator |
---|
kLPTMR_TimerCompareFlag |
Timer compare flag.
|
- Note
- This API should be called at the beginning of the application using the LPTMR driver.
- Parameters
-
base | LPTMR peripheral base address |
config | A pointer to the LPTMR configuration structure. |
void LPTMR_Deinit |
( |
LPTMR_Type * |
base | ) |
|
- Parameters
-
base | LPTMR peripheral base address |
The default values are as follows.
* config->enableFreeRunning = false;
* config->bypassPrescaler = true;
* config->prescalerClockSource = kLPTMR_PrescalerClock_1;
*
- Parameters
-
config | A pointer to the LPTMR configuration structure. |
static void LPTMR_EnableInterrupts |
( |
LPTMR_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | LPTMR peripheral base address |
mask | The interrupts to enable. This is a logical OR of members of the enumeration lptmr_interrupt_enable_t |
static void LPTMR_DisableInterrupts |
( |
LPTMR_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | LPTMR peripheral base address |
mask | The interrupts to disable. This is a logical OR of members of the enumeration lptmr_interrupt_enable_t. |
static uint32_t LPTMR_GetEnabledInterrupts |
( |
LPTMR_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | LPTMR peripheral base address |
- Returns
- The enabled interrupts. This is the logical OR of members of the enumeration lptmr_interrupt_enable_t
static void LPTMR_EnableTimerDMA |
( |
LPTMR_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | base LPTMR peripheral base address |
enable | Switcher of timer DMA feature. "true" means to enable, "false" means to disable. |
static uint32_t LPTMR_GetStatusFlags |
( |
LPTMR_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | LPTMR peripheral base address |
- Returns
- The status flags. This is the logical OR of members of the enumeration lptmr_status_flags_t
static void LPTMR_ClearStatusFlags |
( |
LPTMR_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | LPTMR peripheral base address |
mask | The status flags to clear. This is a logical OR of members of the enumeration lptmr_status_flags_t. |
static void LPTMR_SetTimerPeriod |
( |
LPTMR_Type * |
base, |
|
|
uint32_t |
ticks |
|
) |
| |
|
inlinestatic |
Timers counts from 0 until it equals the count value set here. The count value is written to the CMR register.
- Note
- The TCF flag is set with the CNR equals the count provided here and then increments.
- Call the utility macros provided in the fsl_common.h to convert to ticks.
- Parameters
-
base | LPTMR peripheral base address |
ticks | A timer period in units of ticks, which should be equal or greater than 1. |
static uint32_t LPTMR_GetCurrentTimerCount |
( |
LPTMR_Type * |
base | ) |
|
|
inlinestatic |
This function returns the real-time timer counting value in a range from 0 to a timer period.
- Note
- Call the utility macros provided in the fsl_common.h to convert ticks to usec or msec.
- Parameters
-
base | LPTMR peripheral base address |
- Returns
- The current counter value in ticks
static void LPTMR_StartTimer |
( |
LPTMR_Type * |
base | ) |
|
|
inlinestatic |
After calling this function, the timer counts up to the CMR register value. Each time the timer reaches the CMR value and then increments, it generates a trigger pulse and sets the timeout interrupt flag. An interrupt is also triggered if the timer interrupt is enabled.
- Parameters
-
base | LPTMR peripheral base address |
static void LPTMR_StopTimer |
( |
LPTMR_Type * |
base | ) |
|
|
inlinestatic |
This function stops the timer and resets the timer's counter register.
- Parameters
-
base | LPTMR peripheral base address |