MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
LPTMR: Low-Power Timer

Overview

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.

int main(void)
{
uint32_t currentCounter = 0U;
lptmr_config_t lptmrConfig;
LED_INIT();
/* Board pin, clock, debug console initialization */
BOARD_InitHardware();
/* Configures the LPTMR */
LPTMR_GetDefaultConfig(&lptmrConfig);
/* Initializes the LPTMR */
LPTMR_Init(LPTMR0, &lptmrConfig);
/* Sets the timer period */
LPTMR_SetTimerPeriod(LPTMR0, USEC_TO_COUNT(1000000U, LPTMR_SOURCE_CLOCK));
/* Enables a timer interrupt */
/* Enables the NVIC */
EnableIRQ(LPTMR0_IRQn);
PRINTF("Low Power Timer Example\r\n");
/* Starts counting */
while (1)
{
if (currentCounter != lptmrCounter)
{
currentCounter = lptmrCounter;
PRINTF("LPTMR interrupt No.%d \r\n", currentCounter);
}
}
}

Data Structures

struct  lptmr_config_t
 LPTMR config structure. More...
 

Enumerations

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_1 = 0x1U,
  kLPTMR_PrescalerClock_2 = 0x2U,
  kLPTMR_PrescalerClock_3 = 0x3U
}
 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...
 

Driver version

#define FSL_LPTMR_DRIVER_VERSION   (MAKE_VERSION(2, 0, 1))
 Version 2.0.1.
 

Initialization and deinitialization

void LPTMR_Init (LPTMR_Type *base, const lptmr_config_t *config)
 Ungates the LPTMR clock and configures the peripheral for a basic operation. More...
 
void LPTMR_Deinit (LPTMR_Type *base)
 Gates the LPTMR clock. More...
 
void LPTMR_GetDefaultConfig (lptmr_config_t *config)
 Fills in the LPTMR configuration structure with default settings. More...
 

Interrupt Interface

static void LPTMR_EnableInterrupts (LPTMR_Type *base, uint32_t mask)
 Enables the selected LPTMR interrupts. More...
 
static void LPTMR_DisableInterrupts (LPTMR_Type *base, uint32_t mask)
 Disables the selected LPTMR interrupts. More...
 
static uint32_t LPTMR_GetEnabledInterrupts (LPTMR_Type *base)
 Gets the enabled LPTMR interrupts. More...
 

Status Interface

static uint32_t LPTMR_GetStatusFlags (LPTMR_Type *base)
 Gets the LPTMR status flags. More...
 
static void LPTMR_ClearStatusFlags (LPTMR_Type *base, uint32_t mask)
 Clears the LPTMR status flags. More...
 

Read and write the timer period

static void LPTMR_SetTimerPeriod (LPTMR_Type *base, uint32_t ticks)
 Sets the timer period in units of count. More...
 
static uint32_t LPTMR_GetCurrentTimerCount (LPTMR_Type *base)
 Reads the current timer counting value. More...
 

Timer Start and Stop

static void LPTMR_StartTimer (LPTMR_Type *base)
 Starts the timer. More...
 
static void LPTMR_StopTimer (LPTMR_Type *base)
 Stops the timer. More...
 

Data Structure Documentation

struct lptmr_config_t

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.

Data Fields

lptmr_timer_mode_t timerMode
 Time counter mode or pulse counter mode.
 
lptmr_pin_select_t pinSelect
 LPTMR pulse input pin select; used only in pulse counter mode.
 
lptmr_pin_polarity_t pinPolarity
 LPTMR pulse input pin polarity; used only in pulse counter mode.
 
bool enableFreeRunning
 True: enable free running, counter is reset on overflow False: counter is reset when the compare flag is set.
 
bool bypassPrescaler
 True: bypass prescaler; false: use clock from prescaler.
 
lptmr_prescaler_clock_select_t prescalerClockSource
 LPTMR clock source.
 
lptmr_prescaler_glitch_value_t value
 Prescaler or glitch filter value.
 

Enumeration Type Documentation

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_1 

Prescaler/glitch filter clock 1 selected.

kLPTMR_PrescalerClock_2 

Prescaler/glitch filter clock 2 selected.

kLPTMR_PrescalerClock_3 

Prescaler/glitch filter clock 3 selected.

Enumerator
kLPTMR_TimerInterruptEnable 

Timer interrupt enable.

Enumerator
kLPTMR_TimerCompareFlag 

Timer compare flag.

Function Documentation

void LPTMR_Init ( LPTMR_Type *  base,
const lptmr_config_t config 
)
Note
This API should be called at the beginning of the application using the LPTMR driver.
Parameters
baseLPTMR peripheral base address
configA pointer to the LPTMR configuration structure.
void LPTMR_Deinit ( LPTMR_Type *  base)
Parameters
baseLPTMR peripheral base address
void LPTMR_GetDefaultConfig ( lptmr_config_t config)

The default values are as follows.

* config->timerMode = kLPTMR_TimerModeTimeCounter;
* config->pinSelect = kLPTMR_PinSelectInput_0;
* config->pinPolarity = kLPTMR_PinPolarityActiveHigh;
* config->enableFreeRunning = false;
* config->bypassPrescaler = true;
* config->prescalerClockSource = kLPTMR_PrescalerClock_1;
* config->value = kLPTMR_Prescale_Glitch_0;
*
Parameters
configA pointer to the LPTMR configuration structure.
static void LPTMR_EnableInterrupts ( LPTMR_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseLPTMR peripheral base address
maskThe 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
baseLPTMR peripheral base address
maskThe 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
baseLPTMR peripheral base address
Returns
The enabled interrupts. This is the logical OR of members of the enumeration lptmr_interrupt_enable_t
static uint32_t LPTMR_GetStatusFlags ( LPTMR_Type *  base)
inlinestatic
Parameters
baseLPTMR 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
baseLPTMR peripheral base address
maskThe 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
  1. The TCF flag is set with the CNR equals the count provided here and then increments.
  2. Call the utility macros provided in the fsl_common.h to convert to ticks.
Parameters
baseLPTMR peripheral base address
ticksA 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
baseLPTMR 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
baseLPTMR peripheral base address
static void LPTMR_StopTimer ( LPTMR_Type *  base)
inlinestatic

This function stops the timer and resets the timer's counter register.

Parameters
baseLPTMR peripheral base address