MRT多速率定时器定时器的完整的代码:
void MRT0_IRQHandler(void)
{
/* Clear interrupt flag.*/
MRT_ClearStatusFlags(MRT0, kMRT_Channel_0, kMRT_TimerInterruptFlag);
if (mrtEnableCount == true)
{
mrtCountValue++;
if (mrtCountValue == (4 << mrtDividerValue))
{
mrtIsrFlag = true;
}
}
else
{
mrtIsrFlag = true;
}
SDK_ISR_EXIT_BARRIER;
}
/*!
* @brief Main function
*/
int main(void)
{
uint32_t mrt_clock;
/* Structure of initialize MRT */
mrt_config_t mrtConfig;
/* Board pin, clock, debug console init */
/* set BOD VBAT level to 1.65V */
POWER_SetBodVbatLevel(kPOWER_BodVbatLevel1650mv, kPOWER_BodHystLevel50mv, false);
/* enable clock for GPIO; used to toggle the LED's */
CLOCK_EnableClock(kCLOCK_Gpio1);
/* attach 12 MHz clock to FLEXCOMM0 (debug console) */
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
/* Initialize and enable LED */
APP_LED_INIT;
mrt_clock = MRT_CLK_FREQ;
/* mrtConfig.enableMultiTask = false; */
MRT_GetDefaultConfig(&mrtConfig);
/* Init mrt module */
MRT_Init(MRT0, &mrtConfig);
/* Setup Channel 0 to be repeated */
MRT_SetupChannelMode(MRT0, kMRT_Channel_0, kMRT_RepeatMode);
/* Enable timer interrupts for channel 0 */
MRT_EnableInterrupts(MRT0, kMRT_Channel_0, kMRT_TimerInterruptEnable);
/* Enable at the NVIC */
EnableIRQ(MRT0_IRQn);
/* Start channel 0 */
PRINTF("\r\nStarting channel No.0 ...");
if (USEC_TO_COUNT(500000U, mrt_clock) > MRT_CHANNEL_INTVAL_IVALUE_MASK)
{
mrtDividerValue = 0;
mrtEnableCount = true;
while (USEC_TO_COUNT((500000U >> (++mrtDividerValue)), mrt_clock) > MRT_CHANNEL_INTVAL_IVALUE_MASK)
{
}
MRT_StartTimer(MRT0, kMRT_Channel_0, USEC_TO_COUNT((500000U >> mrtDividerValue), mrt_clock));
}
else
{
MRT_StartTimer(MRT0, kMRT_Channel_0, USEC_TO_COUNT(500000U, mrt_clock));
}
while (true)
{
/* Check whether occur interupt and toggle LED */
if (true == mrtIsrFlag)
{
//PRINTF("\r\n Channel No.0 interrupt is occurred !");
APP_LED_TOGGLE;
mrtCountValue = 0;
mrtIsrFlag = false;
PRINTF("********* mrtCountValue: %d ***********\n", mrtCountValue);
}
}
}
也可以通过配置工具配置MRT:
参考链接:
https://www.nxpic.org.cn/module/forum/forum.php?mod=viewthread&tid=620210&highlight=mrt
https://www.nxpic.org.cn/module/forum/forum.php?mod=viewthread&tid=606793&highlight=mrt
https://www.nxpic.org.cn/module/forum/forum.php?mod=viewthread&tid=606796&highlight=mrt