]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
some low-level optimisation
authoridgay <idgay>
Thu, 29 Mar 2007 21:29:33 +0000 (21:29 +0000)
committeridgay <idgay>
Thu, 29 Mar 2007 21:29:33 +0000 (21:29 +0000)
tos/chips/atm128/timer/Atm128AlarmAsyncP.nc
tos/chips/atm128/timer/HplAtm128Timer0AsyncP.nc
tos/chips/atm128/timer/HplAtm128TimerAsync.nc

index a97c69e3938925d61b9bf37d000d7d08bd2f8988..326f6cd000c81afb3487748abacb136d1c93009d 100644 (file)
@@ -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) {
index ce05c7567d2ab8700ed6a176812ddd36e875e423..eb2c0bfb4609102cc15e75bc6058525bba00e112 100644 (file)
@@ -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;
   }
 }
index 0965e98c6d6f070400d2f4cf9698fa4d50ddead4..2ee33ec76aaba00842bfe43e135bf2ddd0df64aa 100644 (file)
@@ -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();
 
 }