MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
PIT: Periodic Interrupt Timer

Overview

The MCUXpresso SDK provides a driver for the Periodic Interrupt Timer (PIT) of MCUXpresso SDK devices.

Function groups

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

Initialization and deinitialization

The function PIT_Init() initializes the PIT with specified configurations. The function PIT_GetDefaultConfig() gets the default configurations. The initialization function configures the PIT operation in debug mode.

The function PIT_SetTimerChainMode() configures the chain mode operation of each PIT channel.

The function PIT_Deinit() disables the PIT timers and disables the module clock.

Timer period Operations

The function PITR_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 PIT_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. Users can call the utility macros provided in fsl_common.h to convert to microseconds or milliseconds.

Start and Stop timer operations

The function PIT_StartTimer() starts the timer counting. After calling this function, the timer loads the period value set earlier via the PIT_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 PIT_StopTimer() stops the timer counting.

Status

Provides functions to get and clear the PIT status.

Interrupt

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

Typical use case

PIT tick example

Updates the PIT period and toggles an LED periodically.

int main(void)
{
/* Structure of initialize PIT */
pit_config_t pitConfig;
/* Initialize and enable LED */
LED_INIT();
/* Board pin, clock, debug console init */
BOARD_InitHardware();
PIT_GetDefaultConfig(&pitConfig);
/* Init pit module */
PIT_Init(PIT, &pitConfig);
/* Set timer period for channel 0 */
PIT_SetTimerPeriod(PIT, kPIT_Chnl_0, USEC_TO_COUNT(1000000U, PIT_SOURCE_CLOCK));
/* Enable timer interrupts for channel 0 */
/* Enable at the NVIC */
EnableIRQ(PIT_IRQ_ID);
/* Start channel 0 */
PRINTF("\r\nStarting channel No.0 ...");
while (true)
{
/* Check whether occur interupt and toggle LED */
if (true == pitIsrFlag)
{
PRINTF("\r\n Channel No.0 interrupt is occured !");
LED_TOGGLE();
pitIsrFlag = false;
}
}
}

Data Structures

struct  pit_config_t
 PIT configuration structure. More...
 

Enumerations

enum  pit_chnl_t {
  kPIT_Chnl_0 = 0U,
  kPIT_Chnl_1,
  kPIT_Chnl_2,
  kPIT_Chnl_3
}
 List of PIT channels. More...
 
enum  pit_interrupt_enable_t { kPIT_TimerInterruptEnable = PIT_TCTRL_TIE_MASK }
 List of PIT interrupts. More...
 
enum  pit_status_flags_t { kPIT_TimerFlag = PIT_TFLG_TIF_MASK }
 List of PIT status flags. More...
 

Driver version

#define FSL_PIT_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))
 Version 2.0.0.
 

Initialization and deinitialization

void PIT_Init (PIT_Type *base, const pit_config_t *config)
 Ungates the PIT clock, enables the PIT module, and configures the peripheral for basic operations. More...
 
void PIT_Deinit (PIT_Type *base)
 Gates the PIT clock and disables the PIT module. More...
 
static void PIT_GetDefaultConfig (pit_config_t *config)
 Fills in the PIT configuration structure with the default settings. More...
 
static void PIT_SetTimerChainMode (PIT_Type *base, pit_chnl_t channel, bool enable)
 Enables or disables chaining a timer with the previous timer. More...
 

Interrupt Interface

static void PIT_EnableInterrupts (PIT_Type *base, pit_chnl_t channel, uint32_t mask)
 Enables the selected PIT interrupts. More...
 
static void PIT_DisableInterrupts (PIT_Type *base, pit_chnl_t channel, uint32_t mask)
 Disables the selected PIT interrupts. More...
 
static uint32_t PIT_GetEnabledInterrupts (PIT_Type *base, pit_chnl_t channel)
 Gets the enabled PIT interrupts. More...
 

Status Interface

static uint32_t PIT_GetStatusFlags (PIT_Type *base, pit_chnl_t channel)
 Gets the PIT status flags. More...
 
static void PIT_ClearStatusFlags (PIT_Type *base, pit_chnl_t channel, uint32_t mask)
 Clears the PIT status flags. More...
 

Read and Write the timer period

static void PIT_SetTimerPeriod (PIT_Type *base, pit_chnl_t channel, uint32_t count)
 Sets the timer period in units of count. More...
 
static uint32_t PIT_GetCurrentTimerCount (PIT_Type *base, pit_chnl_t channel)
 Reads the current timer counting value. More...
 

Timer Start and Stop

static void PIT_StartTimer (PIT_Type *base, pit_chnl_t channel)
 Starts the timer counting. More...
 
static void PIT_StopTimer (PIT_Type *base, pit_chnl_t channel)
 Stops the timer counting. More...
 

Data Structure Documentation

struct pit_config_t

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

The configuration structure can be made constant so it resides in flash.

Data Fields

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

Enumeration Type Documentation

enum pit_chnl_t
Note
Actual number of available channels is SoC dependent
Enumerator
kPIT_Chnl_0 

PIT channel number 0.

kPIT_Chnl_1 

PIT channel number 1.

kPIT_Chnl_2 

PIT channel number 2.

kPIT_Chnl_3 

PIT channel number 3.

Enumerator
kPIT_TimerInterruptEnable 

Timer interrupt enable.

Enumerator
kPIT_TimerFlag 

Timer flag.

Function Documentation

void PIT_Init ( PIT_Type *  base,
const pit_config_t config 
)
Note
This API should be called at the beginning of the application using the PIT driver.
Parameters
basePIT peripheral base address
configPointer to the user's PIT config structure
void PIT_Deinit ( PIT_Type *  base)
Parameters
basePIT peripheral base address
static void PIT_GetDefaultConfig ( pit_config_t config)
inlinestatic

The default values are as follows.

* config->enableRunInDebug = false;
*
Parameters
configPointer to the onfiguration structure.
static void PIT_SetTimerChainMode ( PIT_Type *  base,
pit_chnl_t  channel,
bool  enable 
)
inlinestatic

When a timer has a chain mode enabled, it only counts after the previous timer has expired. If the timer n-1 has counted down to 0, counter n decrements the value by one. Each timer is 32-bits, which allows the developers to chain timers together and form a longer timer (64-bits and larger). The first timer (timer 0) can't be chained to any other timer.

Parameters
basePIT peripheral base address
channelTimer channel number which is chained with the previous timer
enableEnable or disable chain. true: Current timer is chained with the previous timer. false: Timer doesn't chain with other timers.
static void PIT_EnableInterrupts ( PIT_Type *  base,
pit_chnl_t  channel,
uint32_t  mask 
)
inlinestatic
Parameters
basePIT peripheral base address
channelTimer channel number
maskThe interrupts to enable. This is a logical OR of members of the enumeration pit_interrupt_enable_t
static void PIT_DisableInterrupts ( PIT_Type *  base,
pit_chnl_t  channel,
uint32_t  mask 
)
inlinestatic
Parameters
basePIT peripheral base address
channelTimer channel number
maskThe interrupts to disable. This is a logical OR of members of the enumeration pit_interrupt_enable_t
static uint32_t PIT_GetEnabledInterrupts ( PIT_Type *  base,
pit_chnl_t  channel 
)
inlinestatic
Parameters
basePIT peripheral base address
channelTimer channel number
Returns
The enabled interrupts. This is the logical OR of members of the enumeration pit_interrupt_enable_t
static uint32_t PIT_GetStatusFlags ( PIT_Type *  base,
pit_chnl_t  channel 
)
inlinestatic
Parameters
basePIT peripheral base address
channelTimer channel number
Returns
The status flags. This is the logical OR of members of the enumeration pit_status_flags_t
static void PIT_ClearStatusFlags ( PIT_Type *  base,
pit_chnl_t  channel,
uint32_t  mask 
)
inlinestatic
Parameters
basePIT peripheral base address
channelTimer channel number
maskThe status flags to clear. This is a logical OR of members of the enumeration pit_status_flags_t
static void PIT_SetTimerPeriod ( PIT_Type *  base,
pit_chnl_t  channel,
uint32_t  count 
)
inlinestatic

Timers begin counting from the value set by this function until it reaches 0, then it generates an interrupt and load 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
Users can call the utility macros provided in fsl_common.h to convert to ticks.
Parameters
basePIT peripheral base address
channelTimer channel number
countTimer period in units of ticks
static uint32_t PIT_GetCurrentTimerCount ( PIT_Type *  base,
pit_chnl_t  channel 
)
inlinestatic

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

Note
Users can call the utility macros provided in fsl_common.h to convert ticks to usec or msec.
Parameters
basePIT peripheral base address
channelTimer channel number
Returns
Current timer counting value in ticks
static void PIT_StartTimer ( PIT_Type *  base,
pit_chnl_t  channel 
)
inlinestatic

After calling this function, timers load period value, count down to 0 and then load the respective start value again. Each time a timer reaches 0, it generates a trigger pulse and sets the timeout interrupt flag.

Parameters
basePIT peripheral base address
channelTimer channel number.
static void PIT_StopTimer ( PIT_Type *  base,
pit_chnl_t  channel 
)
inlinestatic

This function stops every timer counting. Timers reload their periods respectively after the next time they call the PIT_DRV_StartTimer.

Parameters
basePIT peripheral base address
channelTimer channel number.