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)
{
LED_INIT();
BOARD_InitHardware();
EnableIRQ(PIT_IRQ_ID);
PRINTF("\r\nStarting channel No.0 ...");
while (true)
{
if (true == pitIsrFlag)
{
PRINTF("\r\n Channel No.0 interrupt is occured !");
LED_TOGGLE();
pitIsrFlag = false;
}
}
}
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
|
|
- 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.
|
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
-
base | PIT peripheral base address |
config | Pointer to the user's PIT config structure |
void PIT_Deinit |
( |
PIT_Type * |
base | ) |
|
- Parameters
-
base | PIT peripheral base address |
The default values are as follows.
* config->enableRunInDebug = false;
*
- Parameters
-
config | Pointer 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
-
base | PIT peripheral base address |
channel | Timer channel number which is chained with the previous timer |
enable | Enable 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
-
base | PIT peripheral base address |
channel | Timer channel number |
mask | The 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
-
base | PIT peripheral base address |
channel | Timer channel number |
mask | The 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
-
base | PIT peripheral base address |
channel | Timer 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
-
base | PIT peripheral base address |
channel | Timer 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
-
base | PIT peripheral base address |
channel | Timer channel number |
mask | The 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
-
base | PIT peripheral base address |
channel | Timer channel number |
count | Timer 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
-
base | PIT peripheral base address |
channel | Timer 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
-
base | PIT peripheral base address |
channel | Timer 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
-
base | PIT peripheral base address |
channel | Timer channel number. |