![]() |
MCUXpresso SDK API Reference Manual
Rev. 0
NXP Semiconductors
|
The MCUXpresso SDK provides a driver for the Multi-Rate Timer (MRT) of MCUXpresso SDK devices.
The MRT driver supports operating the module as a time counter.
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.
The function MRT_UpdateTimerPeriod() is used to update the timer period in units of count. The new value is 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. The user can call the utility macros provided in fsl_common.h to convert to microseconds or milliseconds
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 either loads 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.
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.
Provides functions to get and clear the PIT status.
Provides functions to enable/disable PIT interrupts and get current enabled interrupts.
Updates the MRT period and toggles an LED periodically. Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/mrt
Files | |
file | fsl_mrt.h |
file | fsl_mrt.h |
Data Structures | |
struct | mrt_config_t |
MRT configuration structure. More... | |
Enumerations | |
enum | mrt_chnl_t { kMRT_Channel_0 = 0U, kMRT_Channel_1, kMRT_Channel_2, kMRT_Channel_3, kMRT_Channel_0 = 0U, kMRT_Channel_1, kMRT_Channel_2, kMRT_Channel_3 } |
List of MRT channels. More... | |
enum | mrt_timer_mode_t { kMRT_RepeatMode = (0 << MRT_CHANNEL_CTRL_MODE_SHIFT), kMRT_OneShotMode = (1 << MRT_CHANNEL_CTRL_MODE_SHIFT), kMRT_OneShotStallMode = (2 << MRT_CHANNEL_CTRL_MODE_SHIFT), kMRT_RepeatMode = (0 << MRT_CHANNEL_CTRL_MODE_SHIFT), kMRT_OneShotMode = (1 << MRT_CHANNEL_CTRL_MODE_SHIFT), kMRT_OneShotStallMode = (2 << MRT_CHANNEL_CTRL_MODE_SHIFT) } |
List of MRT timer modes. More... | |
enum | mrt_interrupt_enable_t { kMRT_TimerInterruptEnable = MRT_CHANNEL_CTRL_INTEN_MASK, kMRT_TimerInterruptEnable = MRT_CHANNEL_CTRL_INTEN_MASK } |
List of MRT interrupts. More... | |
enum | mrt_status_flags_t { kMRT_TimerInterruptFlag = MRT_CHANNEL_STAT_INTFLAG_MASK, kMRT_TimerRunFlag = MRT_CHANNEL_STAT_RUN_MASK, kMRT_TimerInterruptFlag = MRT_CHANNEL_STAT_INTFLAG_MASK, kMRT_TimerRunFlag = MRT_CHANNEL_STAT_RUN_MASK } |
List of MRT status flags. More... | |
enum | mrt_chnl_t { kMRT_Channel_0 = 0U, kMRT_Channel_1, kMRT_Channel_2, kMRT_Channel_3, kMRT_Channel_0 = 0U, kMRT_Channel_1, kMRT_Channel_2, kMRT_Channel_3 } |
List of MRT channels. More... | |
enum | mrt_timer_mode_t { kMRT_RepeatMode = (0 << MRT_CHANNEL_CTRL_MODE_SHIFT), kMRT_OneShotMode = (1 << MRT_CHANNEL_CTRL_MODE_SHIFT), kMRT_OneShotStallMode = (2 << MRT_CHANNEL_CTRL_MODE_SHIFT), kMRT_RepeatMode = (0 << MRT_CHANNEL_CTRL_MODE_SHIFT), kMRT_OneShotMode = (1 << MRT_CHANNEL_CTRL_MODE_SHIFT), kMRT_OneShotStallMode = (2 << MRT_CHANNEL_CTRL_MODE_SHIFT) } |
List of MRT timer modes. More... | |
enum | mrt_interrupt_enable_t { kMRT_TimerInterruptEnable = MRT_CHANNEL_CTRL_INTEN_MASK, kMRT_TimerInterruptEnable = MRT_CHANNEL_CTRL_INTEN_MASK } |
List of MRT interrupts. More... | |
enum | mrt_status_flags_t { kMRT_TimerInterruptFlag = MRT_CHANNEL_STAT_INTFLAG_MASK, kMRT_TimerRunFlag = MRT_CHANNEL_STAT_RUN_MASK, kMRT_TimerInterruptFlag = MRT_CHANNEL_STAT_INTFLAG_MASK, kMRT_TimerRunFlag = MRT_CHANNEL_STAT_RUN_MASK } |
List of MRT status flags. More... | |
Driver version | |
#define | FSL_MRT_DRIVER_VERSION (MAKE_VERSION(2, 0, 2)) |
Version 2.0.2. | |
Initialization and deinitialization | |
void | MRT_Init (MRT_Type *base, const mrt_config_t *config) |
Ungates the MRT clock and configures the peripheral for basic operation. More... | |
void | MRT_Deinit (MRT_Type *base) |
Gate the MRT clock. More... | |
static void | MRT_GetDefaultConfig (mrt_config_t *config) |
Fill in the MRT config struct with the default settings. More... | |
static void | MRT_SetupChannelMode (MRT_Type *base, mrt_chnl_t channel, const mrt_timer_mode_t mode) |
Sets up an MRT channel mode. More... | |
Interrupt Interface | |
static void | MRT_EnableInterrupts (MRT_Type *base, mrt_chnl_t channel, uint32_t mask) |
Enables the MRT interrupt. More... | |
static void | MRT_DisableInterrupts (MRT_Type *base, mrt_chnl_t channel, uint32_t mask) |
Disables the selected MRT interrupt. More... | |
static uint32_t | MRT_GetEnabledInterrupts (MRT_Type *base, mrt_chnl_t channel) |
Gets the enabled MRT interrupts. More... | |
Status Interface | |
static uint32_t | MRT_GetStatusFlags (MRT_Type *base, mrt_chnl_t channel) |
Gets the MRT status flags. More... | |
static void | MRT_ClearStatusFlags (MRT_Type *base, mrt_chnl_t channel, uint32_t mask) |
Clears the MRT status flags. More... | |
Read and Write the timer period | |
void | MRT_UpdateTimerPeriod (MRT_Type *base, mrt_chnl_t channel, uint32_t count, bool immediateLoad) |
Used to update the timer period in units of count. More... | |
static uint32_t | MRT_GetCurrentTimerCount (MRT_Type *base, mrt_chnl_t channel) |
Reads the current timer counting value. More... | |
Timer Start and Stop | |
static void | MRT_StartTimer (MRT_Type *base, mrt_chnl_t channel, uint32_t count) |
Starts the timer counting. More... | |
static void | MRT_StopTimer (MRT_Type *base, mrt_chnl_t channel) |
Stops the timer counting. More... | |
Get & release channel | |
static uint32_t | MRT_GetIdleChannel (MRT_Type *base) |
Find the available channel. More... | |
static void | MRT_ReleaseChannel (MRT_Type *base, mrt_chnl_t channel) |
Release the channel when the timer is using the multi-task mode. More... | |
Driver version | |
#define | FSL_MRT_DRIVER_VERSION (MAKE_VERSION(2, 0, 1)) |
Version 2.0.1. | |
struct mrt_config_t |
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 | |
enum mrt_chnl_t |
enum mrt_timer_mode_t |
enum mrt_status_flags_t |
enum mrt_chnl_t |
enum mrt_timer_mode_t |
enum mrt_status_flags_t |
void MRT_Init | ( | MRT_Type * | base, |
const mrt_config_t * | config | ||
) |
base | Multi-Rate timer peripheral base address |
config | Pointer to user's MRT config structure. If MRT has MULTITASK bit field in MODCFG reigster, param config is useless. |
void MRT_Deinit | ( | MRT_Type * | base | ) |
base | Multi-Rate timer peripheral base address |
|
inlinestatic |
The default values are:
config | Pointer to user's MRT config structure. |
|
inlinestatic |
base | Multi-Rate timer peripheral base address |
channel | Channel that is being configured. |
mode | Timer mode to use for the channel. |
|
inlinestatic |
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 |
|
inlinestatic |
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 |
|
inlinestatic |
base | Multi-Rate timer peripheral base address |
channel | Timer channel number |
|
inlinestatic |
base | Multi-Rate timer peripheral base address |
channel | Timer channel number |
|
inlinestatic |
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.
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 |
|
inlinestatic |
This function returns the real-time timer counting value, in a range from 0 to a timer period.
base | Multi-Rate timer peripheral base address |
channel | Timer channel number |
|
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.
base | Multi-Rate timer peripheral base address |
channel | Timer channel number. |
count | Timer period in units of ticks |
|
inlinestatic |
This function stops the timer from counting.
base | Multi-Rate timer peripheral base address |
channel | Timer channel number. |
|
inlinestatic |
This function returns the lowest available channel number.
base | Multi-Rate timer peripheral base address |
|
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.
base | Multi-Rate timer peripheral base address |
channel | Timer channel number. |