Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
LPTMR Peripheral driver

Overview

This section describes the programming interface of the LPTMR Peripheral driver. The LPTMR driver configures the LPTMR.

LPTMR Initialization

  1. To initialize the LPTMR module, call the LPTMR_DRV_Init() function and pass in the user configuration data structure. This function automatically enables the LPTMR module and clock .
  2. After the LPTMR_DRV_Init() function is called, call the LPTRM_DRV_Start to start the LPTMR.
  3. To stop the LPTMR counter, call the LPTMR_DRV_Stop.

This is example code to configure the driver:

// Defines the LPTM user configuration structure . //
const lptmr_user_config_t config =
{
.timerMode = kLptmrTimerModeTimerCounter, // timer counter is selected//
.freeRunningEnable = false, // free running is disabled //
.intEnable = true, // interrupt is enabled //
.compareValue = 1024, // compare value is 1024 //
.prescalerEnable = true, // prescaler is enabled //
.prescalerClockSource = kLptmrPrescalerClockSourceLpo, // prescaler clock is LPO //
.prescalerValue = kLptmrPrescalerDivede2, // prelscaler divide is 2 //
};
// Initializes the LPTMR 0. //
LPTMR_DRV_Init(0,&config);
// Starts the LPTMR 0. //
// Stops LPTMR 0. //
// Deinitializes LPTMR 0. //

LPTMR Interrupt

  1. Enable the LPTMR interrupt. The LPTMR interrupt is enabled in the user configuration structure with the lptmr_user_config_t.intEnable=true.

  2. Define the LPTMR IRQ function.
void LPTimer_IRQHandler()
{
if(true == LPTMR_DRV_IsIntPending(0))
{
LPTMR_DRV_ClearIntFlag(0);
}
lptmrIsrAssertCount++;
}

Data Structures

struct  lptmr_user_config_t
 Data structure to initialize the LPTMR. More...
 
struct  lptmr_state_t
 Internal driver state information. More...
 

Typedefs

typedef void(* lptmr_callback_t )(void)
 Defines a type of the user-defined callback function.
 

Variables

LPTMR_Type *const g_lptmrBase []
 Table of base addresses for LPTMR instances. More...
 
const IRQn_Type g_lptmrIrqId [LPTMR_INSTANCE_COUNT]
 Table to save LPTMR IRQ enumeration numbers defined in the CMSIS header file. More...
 
lptmr_state_tg_lptmrStatePtr [LPTMR_INSTANCE_COUNT]
 Table to save pointers to context data. More...
 

LPTMR Driver

lptmr_status_t LPTMR_DRV_Init (uint32_t instance, lptmr_state_t *userStatePtr, const lptmr_user_config_t *userConfigPtr)
 Initializes the LPTMR driver. More...
 
lptmr_status_t LPTMR_DRV_Deinit (uint32_t instance)
 Deinitializes the LPTMR driver. More...
 
lptmr_status_t LPTMR_DRV_Start (uint32_t instance)
 Starts the LPTMR counter. More...
 
lptmr_status_t LPTMR_DRV_Stop (uint32_t instance)
 Stops the LPTMR counter. More...
 
lptmr_status_t LPTMR_DRV_SetTimerPeriodUs (uint32_t instance, uint32_t us)
 Configures the LPTMR timer period in microseconds. More...
 
uint32_t LPTMR_DRV_GetCurrentTimeUs (uint32_t instance)
 Gets the current LPTMR time in microseconds. More...
 
lptmr_status_t LPTMR_DRV_SetPulsePeriodCount (uint32_t instance, uint32_t pulsePeriodCount)
 Sets the pulse period value. More...
 
uint32_t LPTMR_DRV_GetCurrentPulseCount (uint32_t instance)
 Gets the current pulse count. More...
 
lptmr_status_t LPTMR_DRV_InstallCallback (uint32_t instance, lptmr_callback_t userCallback)
 Installs the user-defined callback in the LPTMR module. More...
 
void LPTMR_DRV_IRQHandler (uint32_t instance)
 Driver-defined ISR in the LPTMR module. More...
 

Data Structure Documentation

struct lptmr_user_config_t

This structure is used when initializing the LPTMR during the LPTMR_DRV_Init function call.

Data Fields

lptmr_timer_mode_t timerMode
 Timer counter mode or pulse counter mode.
 
lptmr_pin_select_t pinSelect
 LPTMR pulse input pin select.
 
lptmr_pin_polarity_t pinPolarity
 LPTMR pulse input pin polarity.
 
bool freeRunningEnable
 Free running configure. More...
 
bool prescalerEnable
 Prescaler enable configure. More...
 
clock_lptmr_src_t prescalerClockSource
 LPTMR clock source.
 
lptmr_prescaler_value_t prescalerValue
 Prescaler value.
 
bool isInterruptEnabled
 Timer interrupt 0-disable/1-enable.
 

Field Documentation

bool lptmr_user_config_t::freeRunningEnable

True means enable free running

bool lptmr_user_config_t::prescalerEnable

True means enable prescaler

struct lptmr_state_t

The contents of this structure are internal to the driver and should not be modified by users. Contents of the structure are subject to change in future releases.

Data Fields

lptmr_callback_t userCallbackFunc
 Callback function that is executed in ISR. More...
 

Field Documentation

lptmr_callback_t lptmr_state_t::userCallbackFunc

Function Documentation

lptmr_status_t LPTMR_DRV_Init ( uint32_t  instance,
lptmr_state_t userStatePtr,
const lptmr_user_config_t userConfigPtr 
)

This function initializes the LPTMR. The LPTMR can be initialized as a time counter or pulse counter, which is determined by the timerMode in the lptmr_user_config_t. pinSelect and pinPolarity do not need to be configured while working as a time counter.

Parameters
instanceThe LPTMR peripheral instance number.
userStatePtrThe pointer to the structure of the context memory, see lptmr_state_t.
userConfigPtrThe pointer to the LPTMR user configure structure, see lptmr_user_config_t.
Returns
kStatus_LPTMR_Success means succeed, otherwise means failed.
lptmr_status_t LPTMR_DRV_Deinit ( uint32_t  instance)

This function deinitializes the LPTMR. It disables the interrupt and turns off the LPTMR clock.

Parameters
instanceThe LPTMR peripheral instance number.
Returns
kStatus_LPTMR_Success means succeed, otherwise means failed.
lptmr_status_t LPTMR_DRV_Start ( uint32_t  instance)

This function starts the LPTMR counter. Ensure that all necessary configurations are set before calling this function.

Parameters
instanceThe LPTMR peripheral instance number.
Returns
kStatus_LPTMR_Success means success. Otherwise, means failure.
lptmr_status_t LPTMR_DRV_Stop ( uint32_t  instance)

This function stops the LPTMR counter.

Parameters
instanceThe LPTMR peripheral instance number.
Returns
kStatus_LPTMR_Success means success. Otherwise, means failure.
lptmr_status_t LPTMR_DRV_SetTimerPeriodUs ( uint32_t  instance,
uint32_t  us 
)

This function configures the LPTMR time period while the LPTMR is working as a time counter. After the time period in microseconds, the callback function is called. This function cannot be called while the LPTMR is working as a pulse counter. The value in microseconds (us) should be integer multiple of the clock source time slice. If the clock source is 1 kHz, then both 2000 µs and 3000 µs are valid while 2500 µs gets the same result as the 2000 µs, because 2500 µs cannot be generated in 1 kHz clock source.

Parameters
instanceThe LPTMR peripheral instance number.
ustime period in microseconds.
Returns
kStatus_LPTMR_Success means success. Otherwise, means failure.
uint32_t LPTMR_DRV_GetCurrentTimeUs ( uint32_t  instance)

This function gets the current time while operating as a time counter. This function cannot be called while operating as a pulse counter.

Parameters
instanceThe LPTMR peripheral instance number.
Returns
current time in microsecond unit.
lptmr_status_t LPTMR_DRV_SetPulsePeriodCount ( uint32_t  instance,
uint32_t  pulsePeriodCount 
)

This function configures the pulse period of the LPTMR while working as a pulse counter. After the count of pulsePeriodValue pulse is captured, the callback function is called. This function cannot be called while operating as a time counter.

Parameters
instanceThe LPTMR peripheral instance number.
pulsePeriodCountpulse period value.
Returns
kStatus_LPTMR_Success means success. Otherwise, means failure.
uint32_t LPTMR_DRV_GetCurrentPulseCount ( uint32_t  instance)

This function gets the current pulse count captured on the pulse input pin. This function cannot be called while operating as a time counter.

Parameters
instanceThe LPTMR peripheral instance number.
Returns
pulse count captured on the pulse input pin.
lptmr_status_t LPTMR_DRV_InstallCallback ( uint32_t  instance,
lptmr_callback_t  userCallback 
)

This function installs the user-defined callback in the LPTMR module. When an LPTMR interrupt request is served, the callback is executed inside the ISR.

Parameters
instanceLPTMR instance ID.
userCallbackUser-defined callback function.
Returns
kStatus_LPTMR_Success means success. Otherwise, means failure.
void LPTMR_DRV_IRQHandler ( uint32_t  instance)

This function is the driver-defined ISR in the LPTMR module. It includes the process for interrupt mode defined by the driver. Currently, it is called inside the system-defined ISR.

Parameters
instanceLPTMR instance ID.

Variable Documentation

LPTMR_Type* const g_lptmrBase[]
const IRQn_Type g_lptmrIrqId[LPTMR_INSTANCE_COUNT]
lptmr_state_t* g_lptmrStatePtr[LPTMR_INSTANCE_COUNT]