MCUXpresso SDK API Reference Manual  Rev 2.15.000
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. Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/lpit

Data Structures

struct  _lpit_chnl_params
 Structure to configure the channel timer. More...
 
struct  _lpit_config
 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 {
  kLPIT_Chnl_0 = 0U,
  kLPIT_Chnl_1,
  kLPIT_Chnl_2,
  kLPIT_Chnl_3
}
 List of LPIT channels. More...
 
enum  _lpit_timer_modes {
  kLPIT_PeriodicCounter = 0U,
  kLPIT_DualPeriodicCounter,
  kLPIT_TriggerAccumulator,
  kLPIT_InputCapture
}
 Mode options available for the LPIT timer. More...
 
enum  _lpit_trigger_select {
  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 {
  kLPIT_TriggerSource_External = 0U,
  kLPIT_TriggerSource_Internal
}
 Trigger source options available. More...
 
enum  _lpit_interrupt_enable {
  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 {
  kLPIT_Channel0TimerFlag = (1U << 0),
  kLPIT_Channel1TimerFlag = (1U << 1),
  kLPIT_Channel2TimerFlag = (1U << 2),
  kLPIT_Channel3TimerFlag = (1U << 3)
}
 List of LPIT status flags. More...
 
typedef enum _lpit_chnl lpit_chnl_t
 List of LPIT channels. More...
 
typedef enum _lpit_timer_modes lpit_timer_modes_t
 Mode options available for the LPIT timer. More...
 
typedef enum _lpit_trigger_select lpit_trigger_select_t
 Trigger options available. More...
 
typedef enum _lpit_trigger_source lpit_trigger_source_t
 Trigger source options available.
 
typedef enum _lpit_interrupt_enable lpit_interrupt_enable_t
 List of LPIT interrupts. More...
 
typedef enum _lpit_status_flags lpit_status_flags_t
 List of LPIT status flags. More...
 
typedef struct _lpit_chnl_params lpit_chnl_params_t
 Structure to configure the channel timer. More...
 
typedef struct _lpit_config lpit_config_t
 LPIT configuration structure. More...
 
#define FSL_LPIT_DRIVER_VERSION   (MAKE_VERSION(2, 1, 1))
 Version 2.1.1.
 

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 void LPIT_SetTimerValue (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

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::timerMode
lpit_trigger_source_t _lpit_chnl_params::triggerSource
struct _lpit_config

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
 

Typedef Documentation

typedef enum _lpit_chnl lpit_chnl_t
Note
Actual number of available channels is SoC-dependent

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.

Note
Number of timer channels are SoC-specific. See the SoC Reference Manual.
Note
Number of timer channels are SoC-specific. See the SoC Reference Manual.
typedef struct _lpit_config 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.

Enumeration Type Documentation

enum _lpit_chnl
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 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 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 void LPIT_SetTimerValue ( LPIT_Type *  base,
lpit_chnl_t  channel,
uint32_t  ticks 
)
inlinestatic

In the Dual 16-bit Periodic Counter mode, the counter will load and then the lower 16-bits will decrement down to zero, which will assert the output pre-trigger. The upper 16-bits will then decrement down to zero, which will negate the output pre-trigger and set the timer interrupt flag.

Note
Set TVAL register to 0 or 1 is invalid in compare mode.
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.