From b410ae3a294c1858497ece38de0b60b43fbfee92 Mon Sep 17 00:00:00 2001 From: idgay Date: Thu, 29 Mar 2007 21:29:33 +0000 Subject: [PATCH] some low-level optimisation --- tos/chips/atm128/timer/Atm128AlarmAsyncP.nc | 32 ++++++++----------- .../atm128/timer/HplAtm128Timer0AsyncP.nc | 6 ++-- tos/chips/atm128/timer/HplAtm128TimerAsync.nc | 6 ++-- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/tos/chips/atm128/timer/Atm128AlarmAsyncP.nc b/tos/chips/atm128/timer/Atm128AlarmAsyncP.nc index a97c69e3..326f6cd0 100644 --- a/tos/chips/atm128/timer/Atm128AlarmAsyncP.nc +++ b/tos/chips/atm128/timer/Atm128AlarmAsyncP.nc @@ -37,7 +37,7 @@ implementation { uint8_t set; /* Is the alarm set? */ uint32_t t0, dt; /* Time of the next alarm */ - uint32_t base; /* base+TCNT0 is the current time if no + norace uint32_t base; /* base+TCNT0 is the current time if no interrupt is pending. See Counter.get() for the full details. */ @@ -63,8 +63,8 @@ implementation call TimerCtrl.setControl(x); call Compare.set(MAXT); /* setInterrupt needs a valid value here */ call Compare.start(); - setInterrupt(); } + setInterrupt(); return SUCCESS; } @@ -84,11 +84,6 @@ implementation call Compare.set(n); } - void fire() { - __nesc_enable_interrupt(); - signal Alarm.fired(); - } - /* Update the compare register to trigger an interrupt at the appropriate time based on the current alarm settings */ @@ -128,7 +123,7 @@ implementation if (alarm_in > MAXT) newOcr0 = MAXT; - else if (alarm_in < MINDT) + else if ((uint8_t)alarm_in < MINDT) // alarm_in < MAXT ... newOcr0 = MINDT; else newOcr0 = alarm_in; @@ -138,20 +133,19 @@ implementation setOcr0(newOcr0); } if (fired) - fire(); - } - - void overflow() { - __nesc_enable_interrupt(); - signal Counter.overflow(); + signal Alarm.fired(); } async event void Compare.fired() { + int overflowed; + /* Compare register fired. Update time knowledge */ - base += call Compare.get() + 1; // interrupt is 1ms late + base += call Compare.get() + 1U; // interrupt is 1ms late + overflowed = !base; + __nesc_enable_interrupt(); setInterrupt(); - if (!base) - overflow(); + if (overflowed) + signal Counter.overflow(); } async command uint32_t Counter.get() { @@ -187,8 +181,10 @@ implementation { base = 0; call Compare.reset(); - setInterrupt(); } + else + return; + setInterrupt(); } async command void Alarm.start(uint32_t ndt) { diff --git a/tos/chips/atm128/timer/HplAtm128Timer0AsyncP.nc b/tos/chips/atm128/timer/HplAtm128Timer0AsyncP.nc index ce05c756..eb2c0bfb 100644 --- a/tos/chips/atm128/timer/HplAtm128Timer0AsyncP.nc +++ b/tos/chips/atm128/timer/HplAtm128Timer0AsyncP.nc @@ -199,15 +199,15 @@ implementation ASSR |= 1 << AS0; } - async command bool TimerAsync.controlBusy() { + async command int TimerAsync.controlBusy() { return (ASSR & (1 << TCR0UB)) != 0; } - async command bool TimerAsync.compareBusy() { + async command int TimerAsync.compareBusy() { return (ASSR & (1 << OCR0UB)) != 0; } - async command bool TimerAsync.countBusy() { + async command int TimerAsync.countBusy() { return (ASSR & (1 << TCN0UB)) != 0; } } diff --git a/tos/chips/atm128/timer/HplAtm128TimerAsync.nc b/tos/chips/atm128/timer/HplAtm128TimerAsync.nc index 0965e98c..2ee33ec7 100644 --- a/tos/chips/atm128/timer/HplAtm128TimerAsync.nc +++ b/tos/chips/atm128/timer/HplAtm128TimerAsync.nc @@ -35,18 +35,18 @@ interface HplAtm128TimerAsync * Check if control register TCCR0 is busy (should not be updated if true) * @return TRUE if TCCR0 is busy, FALSE otherwise (can be updated) */ - async command bool controlBusy(); + async command int controlBusy(); /** * Check if compare register OCR0 is busy (should not be updated if true) * @return TRUE if OCR0 is busy, FALSE otherwise (can be updated) */ - async command bool compareBusy(); + async command int compareBusy(); /** * Check if current timer value (TCNT0) is busy (should not be updated if true) * @return TRUE if TCNT0 is busy, FALSE otherwise (can be updated) */ - async command bool countBusy(); + async command int countBusy(); } -- 2.39.2