style fix; added fas check for cycle_time being a power of two or not.

This commit is contained in:
Adam Dunkels 2011-12-05 16:28:04 +01:00
parent 50342fa801
commit 0a428c9489

View file

@ -204,22 +204,24 @@ phase_wait(struct phase_list *list,
sync = (e == NULL) ? now : e->time; sync = (e == NULL) ? now : e->time;
#if PHASE_DRIFT_CORRECT #if PHASE_DRIFT_CORRECT
{ int32_t s; {
if (e->drift > cycle_time) { int32_t s;
s = e->drift%cycle_time/(e->drift/cycle_time); //drift per cycle if(e->drift > cycle_time) {
s = s*(now-sync)/cycle_time; //estimated drift to now s = e->drift % cycle_time / (e->drift / cycle_time); /* drift per cycle */
sync += s; //add it in s = s * (now - sync) / cycle_time; /* estimated drift to now */
} sync += s; /* add it in */
} }
}
#endif #endif
#if 1 /* Check if cycle_time is a power of two */
/* Faster if cycle_time is a power of two */ if(!(cycle_time & (cycle_time - 1))) {
wait = (rtimer_clock_t)((sync - now) & (cycle_time - 1)); /* Faster if cycle_time is a power of two */
#else wait = (rtimer_clock_t)((sync - now) & (cycle_time - 1));
/* Works generally */ } else {
wait = cycle_time - (rtimer_clock_t)((now - sync) % cycle_time); /* Works generally */
#endif wait = cycle_time - (rtimer_clock_t)((now - sync) % cycle_time);
}
if(wait < guard_time) { if(wait < guard_time) {
wait += cycle_time; wait += cycle_time;