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

Overview

The MCUXpresso SDK provides a driver for the Low-Power Interrupt Timer (LPIT) of MCUXpresso SDK devices.

Function groups

The LPIT driver supports operating the module as a time counter.

Initialization and deinitialization

The function LPIT_Init() initializes the LPIT with specified configurations. The function LPIT_GetDefaultConfig() gets the default configurations. The initialization function configures the LPIT operation in doze mode and debug mode.

The function LPIT_SetupChannel() configures the operation of each LPIT channel.

The function LPIT_Deinit() disables the LPIT module and disables the module clock.

Timer period Operations

The function LPITR_SetTimerPeriod() sets the timer period in units of count. Timers begin counting down from the value set by this function until it reaches 0.

The function LPIT_GetCurrentTimerCount() reads the current timer counting value. This function returns the real-time timer counting value, in a range from 0 to a timer period.

The timer period operation functions takes the count value in ticks. User can call the utility macros provided in fsl_common.h to convert to microseconds or milliseconds

Start and Stop timer operations

The function LPIT_StartTimer() starts the timer counting. After calling this function, the timer loads the period value set earlier via the LPIT_SetPeriod() function and starts counting down to 0. When the timer reaches 0, it generates a trigger pulse and sets the timeout interrupt flag.

The function LPIT_StopTimer() stops the timer counting.

Status

Provides functions to get and clear the LPIT status.

Interrupt

Provides functions to enable/disable LPIT interrupts and get current enabled interrupts.

Typical use case

LPIT tick example

Updates the LPIT period and toggles an LED periodically.

int main(void)
{
/* Structure of initialize LPIT */
lpit_config_t lpitConfig;
lpit_chnl_params_t lpitChannelConfig;
/* Initialize and enable LED */
LED_Init();
/* Board pin, clock, debug console init */
BOARD_InitHardware();
LPIT_GetDefaultConfig(&lpitConfig);
/* Init lpit module */
LPIT_Init(LPIT0, &lpitConfig);
lpitChannelConfig.chainChannel = false;
lpitChannelConfig.enableReloadOnTrigger = false;
lpitChannelConfig.enableStartOnTrigger = false;
lpitChannelConfig.enableStopOnTimeout = false;
lpitChannelConfig.timerMode = kLPIT_PeriodicCounter;
/* Set default values for the trigger source */
/* Init lpit channel 0 */
LPIT_SetupChannel(LPIT0, kLPIT_Chnl_0, &lpitChannelConfig);
/* Set timer period for channel 0 */
LPIT_SetTimerPeriod(LPIT0, kLPIT_Chnl_0, USEC_TO_COUNT(1000000U, LPIT_SOURCECLOCK));
/* Enable timer interrupts for channel 0 */
/* Enable at the NVIC */
EnableIRQ(LPIT0_IRQn);
/* Start channel 0 */
PRINTF("\r\nStarting channel No.0 ...");
while (true)
{
/* Check whether occur interupt and toggle LED */
if (true == lpitIsrFlag)
{
PRINTF("\r\n Channel No.0 interrupt is occured !");
LED_Toggle();
lpitIsrFlag = false;
}
}
}

Data Structures

struct  lpit_chnl_params_t
 Structure to configure the channel timer. More...
 
struct  lpit_config_t
 LPIT configuration structure. More...
 

Functions

static void LPIT_Reset (LPIT_Type *base)
 Performs a software reset on the LPIT module. More...
 

Driver version

enum  lpit_chnl_t {
  kLPIT_Chnl_0 = 0U,
  kLPIT_Chnl_1,
  kLPIT_Chnl_2,
  kLPIT_Chnl_3
}
 List of LPIT channels. More...
 
enum  lpit_timer_modes_t {
  kLPIT_PeriodicCounter = 0U,
  kLPIT_DualPeriodicCounter,
  kLPIT_TriggerAccumulator,
  kLPIT_InputCapture
}
 Mode options available for the LPIT timer. More...
 
enum  lpit_trigger_select_t {
  kLPIT_Trigger_TimerChn0 = 0U,
  kLPIT_Trigger_TimerChn1,
  kLPIT_Trigger_TimerChn2,
  kLPIT_Trigger_TimerChn3,
  kLPIT_Trigger_TimerChn4,
  kLPIT_Trigger_TimerChn5,
  kLPIT_Trigger_TimerChn6,
  kLPIT_Trigger_TimerChn7,
  kLPIT_Trigger_TimerChn8,
  kLPIT_Trigger_TimerChn9,
  kLPIT_Trigger_TimerChn10,
  kLPIT_Trigger_TimerChn11,
  kLPIT_Trigger_TimerChn12,
  kLPIT_Trigger_TimerChn13,
  kLPIT_Trigger_TimerChn14,
  kLPIT_Trigger_TimerChn15
}
 Trigger options available. More...
 
enum  lpit_trigger_source_t {
  kLPIT_TriggerSource_External = 0U,
  kLPIT_TriggerSource_Internal
}
 Trigger source options available. More...
 
enum  lpit_interrupt_enable_t {
  kLPIT_Channel0TimerInterruptEnable = (1U << 0),
  kLPIT_Channel1TimerInterruptEnable = (1U << 1),
  kLPIT_Channel2TimerInterruptEnable = (1U << 2),
  kLPIT_Channel3TimerInterruptEnable = (1U << 3)
}
 List of LPIT interrupts. More...
 
enum  lpit_status_flags_t {
  kLPIT_Channel0TimerFlag = (1U << 0),
  kLPIT_Channel1TimerFlag = (1U << 1),
  kLPIT_Channel2TimerFlag = (1U << 2),
  kLPIT_Channel3TimerFlag = (1U << 3)
}
 List of LPIT status flags. More...
 
#define FSL_LPIT_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))
 Version 2.0.0.
 

Initialization and deinitialization

void LPIT_Init (LPIT_Type *base, const lpit_config_t *config)
 Ungates the LPIT clock and configures the peripheral for a basic operation. More...
 
void LPIT_Deinit (LPIT_Type *base)
 Disables the module and gates the LPIT clock. More...
 
void LPIT_GetDefaultConfig (lpit_config_t *config)
 Fills in the LPIT configuration structure with default settings. More...
 
status_t LPIT_SetupChannel (LPIT_Type *base, lpit_chnl_t channel, const lpit_chnl_params_t *chnlSetup)
 Sets up an LPIT channel based on the user's preference. More...
 

Interrupt Interface

static void LPIT_EnableInterrupts (LPIT_Type *base, uint32_t mask)
 Enables the selected PIT interrupts. More...
 
static void LPIT_DisableInterrupts (LPIT_Type *base, uint32_t mask)
 Disables the selected PIT interrupts. More...
 
static uint32_t LPIT_GetEnabledInterrupts (LPIT_Type *base)
 Gets the enabled LPIT interrupts. More...
 

Status Interface

static uint32_t LPIT_GetStatusFlags (LPIT_Type *base)
 Gets the LPIT status flags. More...
 
static void LPIT_ClearStatusFlags (LPIT_Type *base, uint32_t mask)
 Clears the LPIT status flags. More...
 

Read and Write the timer period

static void LPIT_SetTimerPeriod (LPIT_Type *base, lpit_chnl_t channel, uint32_t ticks)
 Sets the timer period in units of count. More...
 
static uint32_t LPIT_GetCurrentTimerCount (LPIT_Type *base, lpit_chnl_t channel)
 Reads the current timer counting value. More...
 

Timer Start and Stop

static void LPIT_StartTimer (LPIT_Type *base, lpit_chnl_t channel)
 Starts the timer counting. More...
 
static void LPIT_StopTimer (LPIT_Type *base, lpit_chnl_t channel)
 Stops the timer counting. More...
 

Data Structure Documentation

struct lpit_chnl_params_t

Data Fields

bool chainChannel
 true: Timer chained to previous timer; false: Timer not chained
 
lpit_timer_modes_t timerMode
 Timers mode of operation. More...
 
lpit_trigger_select_t triggerSelect
 Trigger selection for the timer.
 
lpit_trigger_source_t triggerSource
 Decides if we use external or internal trigger. More...
 
bool enableReloadOnTrigger
 true: Timer reloads when a trigger is detected; false: No effect
 
bool enableStopOnTimeout
 true: Timer will stop after timeout; false: does not stop after timeout
 
bool enableStartOnTrigger
 true: Timer starts when a trigger is detected; false: decrement immediately
 

Field Documentation

lpit_timer_modes_t lpit_chnl_params_t::timerMode
lpit_trigger_source_t lpit_chnl_params_t::triggerSource
struct lpit_config_t

This structure holds the configuration settings for the LPIT peripheral. To initialize this structure to reasonable defaults, call the LPIT_GetDefaultConfig() function and pass a pointer to the configuration structure instance.

The configuration structure can be made constant so as to reside in flash.

Data Fields

bool enableRunInDebug
 true: Timers run in debug mode; false: Timers stop in debug mode
 
bool enableRunInDoze
 true: Timers run in doze mode; false: Timers stop in doze mode
 

Enumeration Type Documentation

Note
Actual number of available channels is SoC-dependent
Enumerator
kLPIT_Chnl_0 

LPIT channel number 0.

kLPIT_Chnl_1 

LPIT channel number 1.

kLPIT_Chnl_2 

LPIT channel number 2.

kLPIT_Chnl_3 

LPIT channel number 3.

Enumerator
kLPIT_PeriodicCounter 

Use the all 32-bits, counter loads and decrements to zero.

kLPIT_DualPeriodicCounter 

Counter loads, lower 16-bits decrement to zero, then upper 16-bits decrement.

kLPIT_TriggerAccumulator 

Counter loads on first trigger and decrements on each trigger.

kLPIT_InputCapture 

Counter loads with 0xFFFFFFFF, decrements to zero.

It stores the inverse of the current value when a input trigger is detected

This is used for both internal and external trigger sources. The actual trigger options available is SoC-specific, user should refer to the reference manual.

Enumerator
kLPIT_Trigger_TimerChn0 

Channel 0 is selected as a trigger source.

kLPIT_Trigger_TimerChn1 

Channel 1 is selected as a trigger source.

kLPIT_Trigger_TimerChn2 

Channel 2 is selected as a trigger source.

kLPIT_Trigger_TimerChn3 

Channel 3 is selected as a trigger source.

kLPIT_Trigger_TimerChn4 

Channel 4 is selected as a trigger source.

kLPIT_Trigger_TimerChn5 

Channel 5 is selected as a trigger source.

kLPIT_Trigger_TimerChn6 

Channel 6 is selected as a trigger source.

kLPIT_Trigger_TimerChn7 

Channel 7 is selected as a trigger source.

kLPIT_Trigger_TimerChn8 

Channel 8 is selected as a trigger source.

kLPIT_Trigger_TimerChn9 

Channel 9 is selected as a trigger source.

kLPIT_Trigger_TimerChn10 

Channel 10 is selected as a trigger source.

kLPIT_Trigger_TimerChn11 

Channel 11 is selected as a trigger source.

kLPIT_Trigger_TimerChn12 

Channel 12 is selected as a trigger source.

kLPIT_Trigger_TimerChn13 

Channel 13 is selected as a trigger source.

kLPIT_Trigger_TimerChn14 

Channel 14 is selected as a trigger source.

kLPIT_Trigger_TimerChn15 

Channel 15 is selected as a trigger source.

Enumerator
kLPIT_TriggerSource_External 

Use external trigger input.

kLPIT_TriggerSource_Internal 

Use internal trigger.

Note
Number of timer channels are SoC-specific. See the Kinetis SoC Reference Manual.
Enumerator
kLPIT_Channel0TimerInterruptEnable 

Channel 0 Timer interrupt.

kLPIT_Channel1TimerInterruptEnable 

Channel 1 Timer interrupt.

kLPIT_Channel2TimerInterruptEnable 

Channel 2 Timer interrupt.

kLPIT_Channel3TimerInterruptEnable 

Channel 3 Timer interrupt.

Note
Number of timer channels are SoC-specific. See the Kinetis SoC Reference Manual.
Enumerator
kLPIT_Channel0TimerFlag 

Channel 0 Timer interrupt flag.

kLPIT_Channel1TimerFlag 

Channel 1 Timer interrupt flag.

kLPIT_Channel2TimerFlag 

Channel 2 Timer interrupt flag.

kLPIT_Channel3TimerFlag 

Channel 3 Timer interrupt flag.

Function Documentation

void LPIT_Init ( LPIT_Type *  base,
const lpit_config_t config 
)

This function issues a software reset to reset all channels and registers except the Module Control register.

Note
This API should be called at the beginning of the application using the LPIT driver.
Parameters
baseLPIT peripheral base address.
configPointer to the user configuration structure.
void LPIT_Deinit ( LPIT_Type *  base)
Parameters
baseLPIT peripheral base address.
void LPIT_GetDefaultConfig ( lpit_config_t config)

The default values are:

* config->enableRunInDebug = false;
* config->enableRunInDoze = false;
*
Parameters
configPointer to the user configuration structure.
status_t LPIT_SetupChannel ( LPIT_Type *  base,
lpit_chnl_t  channel,
const lpit_chnl_params_t chnlSetup 
)

This function sets up the operation mode to one of the options available in the enumeration lpit_timer_modes_t. It sets the trigger source as either internal or external, trigger selection and the timers behaviour when a timeout occurs. It also chains the timer if a prior timer if requested by the user.

Parameters
baseLPIT peripheral base address.
channelChannel that is being configured.
chnlSetupConfiguration parameters.
static void LPIT_EnableInterrupts ( LPIT_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseLPIT peripheral base address.
maskThe interrupts to enable. This is a logical OR of members of the enumeration lpit_interrupt_enable_t
static void LPIT_DisableInterrupts ( LPIT_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseLPIT peripheral base address.
maskThe interrupts to enable. This is a logical OR of members of the enumeration lpit_interrupt_enable_t
static uint32_t LPIT_GetEnabledInterrupts ( LPIT_Type *  base)
inlinestatic
Parameters
baseLPIT peripheral base address.
Returns
The enabled interrupts. This is the logical OR of members of the enumeration lpit_interrupt_enable_t
static uint32_t LPIT_GetStatusFlags ( LPIT_Type *  base)
inlinestatic
Parameters
baseLPIT peripheral base address.
Returns
The status flags. This is the logical OR of members of the enumeration lpit_status_flags_t
static void LPIT_ClearStatusFlags ( LPIT_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseLPIT peripheral base address.
maskThe status flags to clear. This is a logical OR of members of the enumeration lpit_status_flags_t
static void LPIT_SetTimerPeriod ( LPIT_Type *  base,
lpit_chnl_t  channel,
uint32_t  ticks 
)
inlinestatic

Timers begin counting down from the value set by this function until it reaches 0, at which point it generates an interrupt and loads this register value again. Writing a new value to this register does not restart the timer. Instead, the value is loaded after the timer expires.

Note
User can call the utility macros provided in fsl_common.h to convert to ticks.
Parameters
baseLPIT peripheral base address.
channelTimer channel number.
ticksTimer period in units of ticks.
static uint32_t LPIT_GetCurrentTimerCount ( LPIT_Type *  base,
lpit_chnl_t  channel 
)
inlinestatic

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 microseconds or milliseconds.
Parameters
baseLPIT peripheral base address.
channelTimer channel number.
Returns
Current timer counting value in ticks.
static void LPIT_StartTimer ( LPIT_Type *  base,
lpit_chnl_t  channel 
)
inlinestatic

After calling this function, timers load the period value and count down to 0. When the timer reaches 0, it generates a trigger pulse and sets the timeout interrupt flag.

Parameters
baseLPIT peripheral base address.
channelTimer channel number.
static void LPIT_StopTimer ( LPIT_Type *  base,
lpit_chnl_t  channel 
)
inlinestatic
Parameters
baseLPIT peripheral base address.
channelTimer channel number.
static void LPIT_Reset ( LPIT_Type *  base)
inlinestatic

This resets all channels and registers except the Module Control Register.

Parameters
baseLPIT peripheral base address.