void timer_isr(void) { CPU_TIMER_START_OF_ISR(); CPU_DEBUG_TICK_START(); BYTE count=0; KERNEL_TIMER_T * timer_p; PRESTO_PRIORITY_T current_pri; // update the system clock clock_add_ms(&system_clock,PRESTO_KERNEL_MSPERTICK); // schedule a hardware timer interrupt one tick into the future CPU_TIMER_RESTART(); // find out the priority of the current running task current_pri=presto_priority_get(kernel_current_task()); while ((timer_list!=NULL)&&(clock_compare(&timer_list->delivery_time,&system_clock)<=0)) { // save a pointer to the first timer in the list timer_p=timer_list; // remove timer from master list timer_list=timer_list->next; // we know that timer_list!=NULL kernel_trigger_set_noswitch(timer_p->owner_tid, timer_p->trigger); if (timer_p->timer_period>0) { // This timer is a repeating timer. // Keep the structure, but update the delivery time. clock_add_ms(&timer_p->delivery_time,timer_p->timer_period); timer_insert_into_master_list(timer_p); } // indicate that a timer expired, and that it made a high priority task ready if (presto_priority_get(timer_p->owner_tid)>current_pri) count++; } CPU_DEBUG_TICK_END(); if (count>0) { kernel_context_switch(); } CPU_TIMER_END_OF_ISR(); }
void timers_updateNearest(){ uint8_t min=0; Clock* minc=NULL; for(uint8_t i=timers_stopwatch_count();i<timers_count();i++){ Timer* t=timers_get(i); Clock* c=timer_getNextFinish(t); if(c==NULL){ continue; } if(minc==NULL||clock_compare(minc,c)>0){ clock_destroy(minc); minc=c; min=i; }else{ clock_destroy(c); } } nearest=min; scheduler_update(minc); }
static void timer_insert_into_master_list(KERNEL_TIMER_T * timer_p) { CPU_LOCK_T lock; KERNEL_TIMER_T ** p0; KERNEL_TIMER_T * p1; cpu_lock_save(lock); // Start at the head, look at delivery times. p0=&timer_list; p1=timer_list; while (1) { if ((p1==NULL)||(clock_compare(&p1->delivery_time,&timer_p->delivery_time)>0)) { // Insert our item between p0 and p1 timer_p->next=p1; *p0=timer_p; break; // out of the while (1) loop } p0=&(p1->next); p1=p1->next; } cpu_unlock_restore(lock); }