/** * @brief MRT example main function * @return Status (This function will not return) */ int main(void) { int mrtch; /* Generic Initialization */ SystemCoreClockUpdate(); Board_Init(); DEBUGSTR("LPC15xx MRT Example \r\n"); /* MRT Initialization and disable all timers */ Chip_MRT_Init(); for (mrtch = 0; mrtch < MRT_CHANNELS_NUM; mrtch++) { Chip_MRT_SetDisabled(Chip_MRT_GetRegPtr(mrtch)); } /* Enable the interrupt for the MRT */ NVIC_EnableIRQ(MRT_IRQn); /* Enable timers 0 and 1 in repeat mode with different rates */ setupMRT(0, MRT_MODE_REPEAT, 2);/* 2Hz rate */ setupMRT(1, MRT_MODE_REPEAT, 5);/* 5Hz rate */ /* Enable timer 2 in single one mode with the interrupt restarting the timer */ setupMRT(2, MRT_MODE_ONESHOT, 7); /* Will fire in 1/7 seconds */ /* All processing and MRT reset in the interrupt handler */ while (1) { __WFI(); } return 0; }
/** * @brief MRT example main function * @return Status (This function will not return) */ int main(void) { int mrtch; static uint32_t mSecShot; /* Generic Initialization */ SystemCoreClockUpdate(); Board_Init(); DEBUGSTR("LPC8xx MRT Example \r\n"); /* MRT Initialization and disable all timers */ Chip_MRT_Init(); for (mrtch = 0; mrtch < MRT_CHANNELS_NUM; mrtch++) { Chip_MRT_SetDisabled(Chip_MRT_GetRegPtr(mrtch)); } /* Enable the interrupt for the MRT */ NVIC_EnableIRQ(MRT_IRQn); /* Enable timers 0 and 1 in repeat mode with different rates */ setupMRT(0, MRT_MODE_REPEAT, 5);/* 5Hz rate */ setupMRT(1, MRT_MODE_REPEAT, 4);/* 4Hz rate */ /* Enable timer 2 in single one mode with the interrupt restarting the timer */ setupMRT(2, MRT_MODE_ONESHOT, 500); /* Will fire in (1/500) seconds */ mSecShot = 100; Board_LED_Set(0, false); /* Timer 3 processing loop - places timer 3 into one shot mode whenever it has been handled in the IRQ handler */ while (1) { if (!t3Fired) { t3Fired = true; setupMRT(3, MRT_MODE_ONESHOT, mSecShot);/* Will fire in (1/mSecShot) seconds */ Board_LED_Toggle(2); mSecShot += 10; if (mSecShot > 1000) { mSecShot = 100; } } __WFI(); } return 0; }
/** * @brief Handle interrupt from MRT * @return Nothing */ void MRT_IRQHandler(void) { uint32_t int_pend; /* Get interrupt pending status for all timers */ int_pend = Chip_MRT_GetIntPending(); Chip_MRT_ClearIntPending(int_pend); /* Channel 0 and 1 are periodic, toggle on either interrupt */ if (int_pend & (MRTn_INTFLAG(0) | MRTn_INTFLAG(1))) { Board_LED_Toggle(0); t01++; } /* Channel 2 is single shot, reset it here */ if (int_pend & (MRTn_INTFLAG(2))) { setupMRT(2, MRT_MODE_ONESHOT, 500); /* Will fire in (1/500) seconds */ Board_LED_Toggle(1); t2++; } /* Channel 3 is single shot, set flag so background loop resets it */ if (int_pend & (MRTn_INTFLAG(3))) { t3Fired = false; t3++; } }
void Board::init() { initSwitchMatrix(); initIOCON(); setupSysClock(); SystemCoreClockUpdate(); setupMRT(SystemCoreClock); setupSysTick(); GPIOInit(); }
/** * @brief Handle interrupt from MRT * @return Nothing */ void MRT_IRQHandler(void) { uint32_t int_pend; /* Get and clear interrupt pending status for all timers */ int_pend = Chip_MRT_GetIntPending(); Chip_MRT_ClearIntPending(int_pend); /* Channel 0 */ if (int_pend & MRTn_INTFLAG(0)) { Board_LED_Toggle(0); } /* Channel 1 */ if (int_pend & MRTn_INTFLAG(1)) { Board_LED_Toggle(1); } /* Channel 2 is single shot, reset it here */ if (int_pend & (MRTn_INTFLAG(2))) { setupMRT(2, MRT_MODE_ONESHOT, 2); /* Will fire in 0.5 seconds */ Board_LED_Toggle(2); } }