| Kinetis SDK v.2.0 API Reference Manual Rev. 0 Freescale Semiconductor, Inc.

- Main Page
- Related Pages
- API Reference

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Files | Data Structures | Enumerations
LPTMR: LPTMR Driver

## Overview

The KSDK provides a driver for the LPTMR module of Kinetis devices.

## Files
file | fsl_lptmr.h

## 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 LPTMR interrupts. More...
enum | lptmr_status_flags_t { kLPTMR_TimerCompareFlag = LPTMR_CSR_TCF_MASK }
| List of LPTMR status flags. More...

## Driver version
#define | FSL_LPTMR_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
| Version 2.0.0.

## Initialization and deinitialization
void | LPTMR_Init (LPTMR_Type *base, const lptmr_config_t *config)
| Ungate the LPTMR clock and configures the peripheral for basic operation. More...
void | LPTMR_Deinit (LPTMR_Type *base)
| Gate the LPTMR clock. More...
void | LPTMR_GetDefaultConfig (lptmr_config_t *config)
| Fill in the LPTMR config struct with the 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, uint16_t ticks)
| Sets the timer period in units of count. More...
static uint16_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 counting. More...
static void | LPTMR_StopTimer (LPTMR_Type *base)
| Stops the timer counting. 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 config structure instance.

The config struct can be made const 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

enum lptmr_pin_select_t

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.

enum lptmr_pin_polarity_t

Enumerator
kLPTMR_PinPolarityActiveHigh | Pulse Counter input source is active-high.
kLPTMR_PinPolarityActiveLow | Pulse Counter input source is active-low.

enum lptmr_timer_mode_t

Enumerator
kLPTMR_TimerModeTimeCounter | Time Counter mode.
kLPTMR_TimerModePulseCounter | Pulse Counter mode.

enum lptmr_prescaler_glitch_value_t

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.

enum lptmr_prescaler_clock_select_t

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.

enum lptmr_interrupt_enable_t

Enumerator
kLPTMR_TimerInterruptEnable | Timer interrupt enable.

enum lptmr_status_flags_t

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

  base | LPTMR peripheral base address
  config | Pointer to user's LPTMR config structure.

void LPTMR_Deinit | ( | LPTMR_Type * | base | ) |

Parameters

  base | LPTMR peripheral base address

void LPTMR_GetDefaultConfig | ( | lptmr_config_t * | config | ) |

The default values are:

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

  config | Pointer to user's LPTMR config structure.

static void LPTMR_EnableInterrupts | ( | LPTMR_Type * | base,
|  | uint32_t | mask
| ) |  |
| inline static

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
| ) |  |
| inline static

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 | ) |
| inline static

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 uint32_t LPTMR_GetStatusFlags | ( | LPTMR_Type * | base | ) |
| inline static

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
| ) |  |
| inline static

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,
|  | uint16_t | ticks
| ) |  |
| inline static

Timers counts from 0 till 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. User can call the utility macros provided in fsl_common.h to convert to ticks

Parameters

  base | LPTMR peripheral base address
  ticks | Timer period in units of ticks

static uint16_t LPTMR_GetCurrentTimerCount | ( | LPTMR_Type * | base | ) |
| inline static

This function returns the real-time timer counting value, in a range from 0 to a timer period.

Note
  User can call the utility macros provided in fsl_common.h to convert ticks to usec or msec

Parameters

  base | LPTMR peripheral base address

Returns
  Current counter value in ticks

static void LPTMR_StartTimer | ( | LPTMR_Type * | base | ) |
| inline static

After calling this function, the timer counts up to the CMR register value. Each time the timer reaches CMR value and then increments, it generates a trigger pulse and sets the timeout interrupt flag. An interrupt will also be triggered if the timer interrupt is enabled.

Parameters

  base | LPTMR peripheral base address

static void LPTMR_StopTimer | ( | LPTMR_Type * | base | ) |
| inline static

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

Parameters

  base | LPTMR peripheral base address