]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/tda5250/mac/SpeckMacDP.nc
refactor MAC protocols:
[tinyos-2.x.git] / tos / chips / tda5250 / mac / SpeckMacDP.nc
index 271cdd513dd4e638f003b0d4cf92656e0fc538fd..5b2bf7706535157b455993393dbb0d7c732b065d 100644 (file)
@@ -73,6 +73,8 @@ module SpeckMacDP {
         interface LocalTime<T32khz> as LocalTime32kHz;
 
         interface Duplicate;
+        interface TimeDiff16;
+        interface TimeDiff32;
 
         async command am_addr_t amAddress();
 /*
@@ -474,17 +476,9 @@ implementation
     }
 
     void interruptBackoffTimer() {
-        uint16_t now;
         if(call Timer.isRunning()) {
-            restLaufzeit = call Timer.getAlarm();
-            call Timer.stop(); 
-            now = call Timer.getNow(); 
-            if(restLaufzeit >= now) {
-                restLaufzeit = restLaufzeit - now;
-            }
-            else {
-                restLaufzeit =  (uint16_t)(-1) - restLaufzeit + now;
-            }
+            restLaufzeit = call TimeDiff16.computeDelta(call Timer.getAlarm(), call Timer.getNow());
+            call Timer.stop();
             if(restLaufzeit > MIN_BACKOFF_MASK << MAX_LONG_RETRY) {
                 restLaufzeit = call Random.rand16() & ZERO_BACKOFF_MASK;
             }
@@ -1006,19 +1000,10 @@ implementation
         }
     }
     
-    async event void RadioTimeStamping.transmittedSFD( uint16_t time, message_t* p_msg ) {
-        uint32_t now;
-        uint32_t mTime;
+    async event void RadioTimeStamping.transmittedSFD(uint16_t time, message_t* p_msg ) {
         if((macState == TX) && (p_msg == txBufPtr)) {
-            now = call LocalTime32kHz.get();
-            mTime = getMetadata(p_msg)->time;
-            if(now >= mTime) {
-                txMacHdr->time = now - mTime;
-            }
-            else {
-                // assume a clock wrap here
-                txMacHdr->time = (uint32_t)(-1) - mTime + now;
-            }
+            txMacHdr->time =
+                call TimeDiff32.computeDelta(call LocalTime32kHz.get(), getMetadata(p_msg)->time);
         }
     }