MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
MRT: Multi-Rate Timer

Overview

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

Files

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
}
 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)
}
 List of MRT timer modes. More...
 
enum  mrt_interrupt_enable_t { 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
}
 List of MRT status flags. More...
 

Driver version

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

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...
 

Data Structure Documentation

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
 

Enumeration Type Documentation

enum mrt_chnl_t
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.

Function Documentation

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
baseMulti-Rate timer peripheral base address
configPointer to user's MRT config structure
void MRT_Deinit ( MRT_Type *  base)
Parameters
baseMulti-Rate timer peripheral base address
static void MRT_GetDefaultConfig ( mrt_config_t config)
inlinestatic

The default values are:

* config->enableMultiTask = false;
*
Parameters
configPointer to user's MRT config structure.
static void MRT_SetupChannelMode ( MRT_Type *  base,
mrt_chnl_t  channel,
const mrt_timer_mode_t  mode 
)
inlinestatic
Parameters
baseMulti-Rate timer peripheral base address
channelChannel that is being configured.
modeTimer mode to use for the channel.
static void MRT_EnableInterrupts ( MRT_Type *  base,
mrt_chnl_t  channel,
uint32_t  mask 
)
inlinestatic
Parameters
baseMulti-Rate timer peripheral base address
channelTimer channel number
maskThe 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
baseMulti-Rate timer peripheral base address
channelTimer channel number
maskThe 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
baseMulti-Rate timer peripheral base address
channelTimer 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
baseMulti-Rate timer peripheral base address
channelTimer 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
baseMulti-Rate timer peripheral base address
channelTimer channel number
maskThe 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
baseMulti-Rate timer peripheral base address
channelTimer channel number
countTimer period in units of ticks
immediateLoadtrue: 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
baseMulti-Rate timer peripheral base address
channelTimer 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
baseMulti-Rate timer peripheral base address
channelTimer channel number.
countTimer 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
baseMulti-Rate timer peripheral base address
channelTimer channel number.
static uint32_t MRT_GetIdleChannel ( MRT_Type *  base)
inlinestatic

This function returns the lowest available channel number.

Parameters
baseMulti-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
baseMulti-Rate timer peripheral base address
channelTimer channel number.