static void TimerHandler(void) { uint_8 index; if(TPM2SC & TPM1SC_TOF_MASK) { /* Clear RTC Interrupt */ TPM2SC_TOF = 0x0; /* Call Pending Timer CallBacks */ for (index = 0; index < MAX_TIMER_OBJECTS; index++) { PTIMER_OBJECT ptemp = &g_TimerObjectArray[index]; if(ptemp->pfnTimerCallback == NULL) { continue; } ptemp->msCount--; if (ptemp->msCount == 0) { PFNTIMER_CALLBACK pfnTimerCallback = ptemp->pfnTimerCallback; #ifdef TIMER_CALLBACK_ARG void *parg = ptemp->arg; #endif (void)RemoveTimerQ(index); #ifdef TIMER_CALLBACK_ARG pfnTimerCallback(parg); #else pfnTimerCallback(); #endif } } } }
/****************************************************************************** * @name Timer_ISR * * @brief This routine services RTC Interrupt * * @param None * * @return None * ****************************************************************************** * Services RTC Interrupt. If a Timer Object expires, then removes the object * from Timer Queue and Calls the callback function (if registered) *****************************************************************************/ void Timer_ISR(void) { uint_8 index; if(PIT_TFLG0 & PIT_TFLG_TIF_MASK) { /* Clear RTC Interrupt */ PIT_TFLG0 |= PIT_TFLG_TIF_MASK; DisableTimerInterrupt(); NVICICPR2|=(1<<4); /* Clear any pending interrupts on LPT */ NVICISER2|=(1<<4); /* Enable interrupts from LPT module */ /* Call Pending Timer CallBacks */ for (index = 0; index < MAX_TIMER_OBJECTS; index++) { PTIMER_OBJECT ptemp = &g_TimerObjectArray[index]; if(ptemp->pfnTimerCallback == NULL) { continue; } ptemp->msCount--; if (ptemp->msCount < 0) { PFNTIMER_CALLBACK pfnTimerCallback = ptemp->pfnTimerCallback; #ifdef TIMER_CALLBACK_ARG void *parg = ptemp->arg; #endif (void)RemoveTimerQ(index); #ifdef TIMER_CALLBACK_ARG pfnTimerCallback(parg); #else pfnTimerCallback(); #endif } } } EnableTimerInterrupt(); }