The MCUXpresso SDK provides a driver for the Multi-Rate Timer (MRT) of MCUXpresso SDK devices.
Function groups
The MRT driver supports operating the module as a time counter.
Initialization and deinitialization
The function MRT_Init() initializes the MRT with specified configurations. The function MRT_GetDefaultConfig() gets the default configurations. The initialization function configures the MRT operating mode.
The function MRT_Deinit() stops the MRT timers and disables the module clock.
Timer period Operations
The function MRT_UpdateTimerPeriod() is used to update the timer period in units of count. The new value will be immediately loaded or will be loaded at the end of the current time interval.
The function MRT_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 MRT_StartTimer() starts the timer counting. After calling this function, the timer loads the period value, counts down to 0 and depending on the timer mode it will either load the respective start value again or stop. When the timer reaches 0, it generates a trigger pulse and sets the timeout interrupt flag.
The function MRT_StopTimer() stops the timer counting.
Get and release channel
These functions can be used to reserve and release a channel. The function MRT_GetIdleChannel() finds the available channel. This function returns the lowest available channel number. The function MRT_ReleaseChannel() release the channel when the timer is using the multi-task mode. In multi-task mode, the INUSE flags allow more control over when MRT channels are released for further use.
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
MRT tick example
Updates the MRT period and toggles an LED periodically. Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/mrt
This structure holds the configuration settings for the MRT peripheral. To initialize this structure to reasonable defaults, call the MRT_GetDefaultConfig() function and pass a pointer to your config structure instance.
The config struct can be made const so it resides in flash
Data Fields |
bool | enableMultiTask |
| true: Timers run in multi-task mode; false: Timers run in hardware status mode
|
|
Enumerator |
---|
kMRT_Channel_0 |
MRT channel number 0.
|
kMRT_Channel_1 |
MRT channel number 1.
|
kMRT_Channel_2 |
MRT channel number 2.
|
kMRT_Channel_3 |
MRT channel number 3.
|
Enumerator |
---|
kMRT_RepeatMode |
Repeat Interrupt mode.
|
kMRT_OneShotMode |
One-shot Interrupt mode.
|
kMRT_OneShotStallMode |
One-shot stall mode.
|
Enumerator |
---|
kMRT_TimerInterruptEnable |
Timer interrupt enable.
|
Enumerator |
---|
kMRT_TimerInterruptFlag |
Timer interrupt flag.
|
kMRT_TimerRunFlag |
Indicates state of the timer.
|
void MRT_Init |
( |
MRT_Type * |
base, |
|
|
const mrt_config_t * |
config |
|
) |
| |
- Note
- This API should be called at the beginning of the application using the MRT driver.
- Parameters
-
base | Multi-Rate timer peripheral base address |
config | Pointer to user's MRT config structure |
void MRT_Deinit |
( |
MRT_Type * |
base | ) |
|
- Parameters
-
base | Multi-Rate timer peripheral base address |
The default values are:
* config->enableMultiTask = false;
*
- Parameters
-
config | Pointer to user's MRT config structure. |
- Parameters
-
base | Multi-Rate timer peripheral base address |
channel | Channel that is being configured. |
mode | Timer mode to use for the channel. |
static void MRT_EnableInterrupts |
( |
MRT_Type * |
base, |
|
|
mrt_chnl_t |
channel, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | Multi-Rate timer peripheral base address |
channel | Timer channel number |
mask | The interrupts to enable. This is a logical OR of members of the enumeration mrt_interrupt_enable_t |
static void MRT_DisableInterrupts |
( |
MRT_Type * |
base, |
|
|
mrt_chnl_t |
channel, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | Multi-Rate timer peripheral base address |
channel | Timer channel number |
mask | The interrupts to disable. This is a logical OR of members of the enumeration mrt_interrupt_enable_t |
static uint32_t MRT_GetEnabledInterrupts |
( |
MRT_Type * |
base, |
|
|
mrt_chnl_t |
channel |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | Multi-Rate timer peripheral base address |
channel | Timer channel number |
- Returns
- The enabled interrupts. This is the logical OR of members of the enumeration mrt_interrupt_enable_t
static uint32_t MRT_GetStatusFlags |
( |
MRT_Type * |
base, |
|
|
mrt_chnl_t |
channel |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | Multi-Rate timer peripheral base address |
channel | Timer channel number |
- Returns
- The status flags. This is the logical OR of members of the enumeration mrt_status_flags_t
static void MRT_ClearStatusFlags |
( |
MRT_Type * |
base, |
|
|
mrt_chnl_t |
channel, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | Multi-Rate timer peripheral base address |
channel | Timer channel number |
mask | The status flags to clear. This is a logical OR of members of the enumeration mrt_status_flags_t |
void MRT_UpdateTimerPeriod |
( |
MRT_Type * |
base, |
|
|
mrt_chnl_t |
channel, |
|
|
uint32_t |
count, |
|
|
bool |
immediateLoad |
|
) |
| |
The new value will be immediately loaded or will be loaded at the end of the current time interval. For one-shot interrupt mode the new value will be immediately loaded.
- Note
- User can call the utility macros provided in fsl_common.h to convert to ticks
- Parameters
-
base | Multi-Rate timer peripheral base address |
channel | Timer channel number |
count | Timer period in units of ticks |
immediateLoad | true: Load the new value immediately into the TIMER register; false: Load the new value at the end of current timer interval |
static uint32_t MRT_GetCurrentTimerCount |
( |
MRT_Type * |
base, |
|
|
mrt_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 usec or msec
- Parameters
-
base | Multi-Rate timer peripheral base address |
channel | Timer channel number |
- Returns
- Current timer counting value in ticks
static void MRT_StartTimer |
( |
MRT_Type * |
base, |
|
|
mrt_chnl_t |
channel, |
|
|
uint32_t |
count |
|
) |
| |
|
inlinestatic |
After calling this function, timers load period value, counts down to 0 and depending on the timer mode it will either load the respective start value again or stop.
- Note
- User can call the utility macros provided in fsl_common.h to convert to ticks
- Parameters
-
base | Multi-Rate timer peripheral base address |
channel | Timer channel number. |
count | Timer period in units of ticks |
static void MRT_StopTimer |
( |
MRT_Type * |
base, |
|
|
mrt_chnl_t |
channel |
|
) |
| |
|
inlinestatic |
This function stops the timer from counting.
- Parameters
-
base | Multi-Rate timer peripheral base address |
channel | Timer channel number. |
static uint32_t MRT_GetIdleChannel |
( |
MRT_Type * |
base | ) |
|
|
inlinestatic |
This function returns the lowest available channel number.
- Parameters
-
base | Multi-Rate timer peripheral base address |
static void MRT_ReleaseChannel |
( |
MRT_Type * |
base, |
|
|
mrt_chnl_t |
channel |
|
) |
| |
|
inlinestatic |
In multi-task mode, the INUSE flags allow more control over when MRT channels are released for further use. The user can hold on to a channel acquired by calling MRT_GetIdleChannel() for as long as it is needed and release it by calling this function. This removes the need to ask for an available channel for every use.
- Parameters
-
base | Multi-Rate timer peripheral base address |
channel | Timer channel number. |