diff -r f36f09f08b62 -r 95cd3376cc9f src/timer.c --- a/src/timer.c Thu Jan 25 16:49:51 2007 +0100 +++ b/src/timer.c Thu Jan 25 17:36:58 2007 +0100 @@ -20,35 +20,35 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -//#define DEBUG_WAR_CONSOLE_ON -//#define DEBUG_ERR_CONSOLE_ON +/* #define DEBUG_WAR_CONSOLE_ON */ +/* #define DEBUG_ERR_CONSOLE_ON */ #include #include "timer.h" -// --------- The timer table --------- +/* --------- The timer table --------- */ s_timer_entry timers[MAX_NB_TIMER] = {{TIMER_FREE, NULL, NULL, 0, 0, 0},}; -// + TIMEVAL total_sleep_time = TIMEVAL_MAX; TIMER_HANDLE last_timer_raw = -1; #define minval(a,b) ((astate == TIMER_FREE) // and empty row - { // just store + if (callback && /* if something to store */ + row->state == TIMER_FREE) /* and empty row */ + { /* just store */ row->callback = callback; row->d = d; row->id = id; @@ -60,30 +60,33 @@ } } - if (row_number != TIMER_NONE) // if successfull + if (row_number != TIMER_NONE) /* if successfull **/ { + TIMEVAL real_timer_value; + TIMEVAL elapsed_time; + if (row_number == last_timer_raw + 1) last_timer_raw++; - // set next wakeup alarm if new entry is sooner than others, or if it is alone - TIMEVAL real_timer_value = minval(value, TIMEVAL_MAX); - TIMEVAL elapsed_time = getElapsedTime(); + /* set next wakeup alarm if new entry is sooner than others, or if it is alone */ + real_timer_value = minval(value, TIMEVAL_MAX); + elapsed_time = getElapsedTime(); - //printf("elapsed_time=%d real_timer_value=%d total_sleep_time=%d\n", elapsed_time, real_timer_value, total_sleep_time); + /*printf("elapsed_time=%d real_timer_value=%d total_sleep_time=%d\n", elapsed_time, real_timer_value, total_sleep_time); */ if (total_sleep_time > elapsed_time && total_sleep_time - elapsed_time > real_timer_value) { total_sleep_time = elapsed_time + real_timer_value; setTimer(real_timer_value); } - //printf("SetAlarm() return %d\n", row_number); + /*printf("SetAlarm() return %d\n", row_number); */ return row_number; } return TIMER_NONE; } -// --------- Use this to remove an alarm --------- +/* --------- Use this to remove an alarm --------- */ TIMER_HANDLE DelAlarm(TIMER_HANDLE handle) { - // Quick and dirty. system timer will continue to be trigged, but no action will be preformed. + /* Quick and dirty. system timer will continue to be trigged, but no action will be preformed. */ MSG_WAR(0x3320, "DelAlarm. handle = ", handle); if(handle != TIMER_NONE) { @@ -97,66 +100,66 @@ } -// --------- TimeDispatch is called on each timer expiration --------- +/* --------- TimeDispatch is called on each timer expiration --------- */ void TimeDispatch() { TIMER_HANDLE i; - TIMEVAL next_wakeup = TIMEVAL_MAX; // used to compute when should normaly occur next wakeup - // First run : change timer state depending on time - // Get time since timer signal + TIMEVAL next_wakeup = TIMEVAL_MAX; /* used to compute when should normaly occur next wakeup */ + /* First run : change timer state depending on time */ + /* Get time since timer signal */ TIMEVAL overrun = getElapsedTime(); TIMEVAL real_total_sleep_time = total_sleep_time + overrun; - //printf("total_sleep_time %d + overrun %d\n", total_sleep_time , overrun); + /*printf("total_sleep_time %d + overrun %d\n", total_sleep_time , overrun); */ for(i=0; i <= last_timer_raw; i++) { s_timer_entry *row = (timers+i); - if (row->state & TIMER_ARMED) // if row is active + if (row->state & TIMER_ARMED) /* if row is active */ { - if (row->val <= real_total_sleep_time) // to be trigged + if (row->val <= real_total_sleep_time) /* to be trigged */ { - //printf("row->val(%d) <= (%d)real_total_sleep_time\n", row->val, real_total_sleep_time); - if (!row->interval) // if simply outdated + /*printf("row->val(%d) <= (%d)real_total_sleep_time\n", row->val, real_total_sleep_time); */ + if (!row->interval) /* if simply outdated */ { - row->state = TIMER_TRIG; // ask for trig + row->state = TIMER_TRIG; /* ask for trig */ } - else // or period have expired + else /* or period have expired */ { - // set val as interval, with overrun correction + /* set val as interval, with overrun correction */ row->val = row->interval - (overrun % row->interval); - row->state = TIMER_TRIG_PERIOD; // ask for trig, periodic - // Check if this new timer value is the soonest + row->state = TIMER_TRIG_PERIOD; /* ask for trig, periodic */ + /* Check if this new timer value is the soonest */ next_wakeup = minval(row->val,next_wakeup); } } else { - // Each armed timer value in decremented. + /* Each armed timer value in decremented. */ row->val -= real_total_sleep_time; - // Check if this new timer value is the soonest + /* Check if this new timer value is the soonest */ next_wakeup = minval(row->val,next_wakeup); } } } - // Remember how much time we should sleep. + /* Remember how much time we should sleep. */ total_sleep_time = next_wakeup; - // Set timer to soonest occurence + /* Set timer to soonest occurence */ setTimer(next_wakeup); - // Then trig them or not. + /* Then trig them or not. */ for(i=0; i<=last_timer_raw; i++) { s_timer_entry *row = (timers+i); if (row->state & TIMER_TRIG) { - row->state &= ~TIMER_TRIG; // reset trig state (will be free if not periodic) - (*row->callback)(row->d, row->id); // trig ! + row->state &= ~TIMER_TRIG; /* reset trig state (will be free if not periodic) */ + (*row->callback)(row->d, row->id); /* trig ! */ } } }