]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/atm128/timer/Atm128AlarmAsyncP.nc
Added AM group.
[tinyos-2.x.git] / tos / chips / atm128 / timer / Atm128AlarmAsyncP.nc
index 326f6cd000c81afb3487748abacb136d1c93009d..c5b80b41beb788ff30e52bdf8c22a6afdd7568e1 100644 (file)
@@ -97,17 +97,27 @@ implementation
           3, the interrupt will happen whjen TCNT0 is 4) */
        uint8_t interrupt_in = 1 + call Compare.get() - call Timer.get();
        uint8_t newOcr0;
-
-       if (interrupt_in < MINDT || (call TimerCtrl.getInterruptFlag()).bits.ocf0)
+       uint8_t tifr = (uint8_t)((call TimerCtrl.getInterruptFlag()).flat);
+       dbg("Atm128AlarmAsyncP", "Atm128AlarmAsyncP: TIFR is %hhx\n", tifr);
+       if ((interrupt_in != 0 && interrupt_in < MINDT) || (tifr & (1 << OCF0))) {
+         if (interrupt_in < MINDT) {
+           dbg("Atm128AlarmAsyncP", "Atm128AlarmAsyncP: under min: %hhu.\n", interrupt_in);
+         }
+         else {
+           dbg("Atm128AlarmAsyncP", "Atm128AlarmAsyncP: OCF set.\n");
+         }
          return; // wait for next interrupt
+       }
 
        /* When no alarm is set, we just ask for an interrupt every MAXT */
-       if (!set)
+       if (!set) {
          newOcr0 = MAXT;
+         dbg("Atm128AlarmAsyncP", "Atm128AlarmAsyncP: no alarm set, set at max.\n");
+       }
        else
          {
            uint32_t now = call Counter.get();
-
+           dbg("Atm128AlarmAsyncP", "Atm128AlarmAsyncP: now-t0 = %llu, dt = %llu\n", (now-t0), dt);
            /* Check if alarm expired */
            if ((uint32_t)(now - t0) >= dt)
              {