]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
refactor MAC protocols:
authorandreaskoepke <andreaskoepke>
Mon, 1 Oct 2007 17:58:07 +0000 (17:58 +0000)
committerandreaskoepke <andreaskoepke>
Mon, 1 Oct 2007 17:58:07 +0000 (17:58 +0000)
- separate time difference computation (need to pin point  a bug)

tos/chips/tda5250/mac/CsmaMacC.nc
tos/chips/tda5250/mac/CsmaMacP.nc
tos/chips/tda5250/mac/RedMacC.nc
tos/chips/tda5250/mac/RedMacP.nc
tos/chips/tda5250/mac/SpeckMacDC.nc
tos/chips/tda5250/mac/SpeckMacDP.nc
tos/chips/tda5250/mac/TimeDiff.nc [new file with mode: 0644]
tos/chips/tda5250/mac/TimeDiff16.nc [new file with mode: 0644]
tos/chips/tda5250/mac/TimeDiff32.nc [new file with mode: 0644]
tos/chips/tda5250/mac/TimeDiffC.nc [new file with mode: 0644]

index 9966cf8b87a71441ba7857d41dfcc1f2cb0df4d6..6413c88d1b0de5a735f00263f8fc88ed56abb73d 100644 (file)
@@ -60,6 +60,7 @@ implementation {
       new Alarm32khz16C() as Timer,
       new TimerMilliC() as ReRxTimer,
       DuplicateC,
+      TimeDiffC,
       RandomLfsrC
 #ifdef MAC_DEBUG
       ,PlatformLedsC
@@ -99,6 +100,7 @@ implementation {
     CsmaMacP.ReRxTimer -> ReRxTimer;
 
     CsmaMacP.Duplicate -> DuplicateC;
+    CsmaMacP.TimeDiff16 -> TimeDiffC;
     
 #ifdef MAC_DEBUG
     CsmaMacP.Led0 -> PlatformLedsC.Led0;
index 46c19d3f00ade28edadea12a44a6d46a3bf95847..ec790e743cddf87a9fbe930b175d470b446bf753 100644 (file)
@@ -72,6 +72,7 @@ module CsmaMacP {
 
         interface Timer<TMilli> as ReRxTimer;
         interface Duplicate;
+        interface TimeDiff16;
         
         interface Alarm<T32khz, uint16_t> as Timer;
         async command am_addr_t amAddress();
@@ -303,17 +304,9 @@ implementation
     }
 
     void interruptBackoffTimer() {
-        uint16_t now;
         if(call Timer.isRunning()) {
-            restLaufzeit = call Timer.getAlarm();
+            restLaufzeit = call TimeDiff16.computeDelta(call Timer.getAlarm(), call Timer.getNow());
             call Timer.stop();
-            now = call Timer.getNow();
-            if(restLaufzeit >= now) {
-                restLaufzeit = restLaufzeit - now;
-            }
-            else {
-                restLaufzeit =  (uint16_t)(-1) - restLaufzeit + now;
-            }
             if(restLaufzeit > BACKOFF_MASK) {
                 restLaufzeit = call Random.rand16() & 0xFF;
             }
index 3421fe920cc7c9bf1e8fc1082b8cb325223649d4..2da8ffa6b5c3bd4b55dd5b57f0167ec5486c5ffc 100644 (file)
@@ -63,7 +63,7 @@ implementation {
         RssiFixedThresholdCMC as Cca,
         new Alarm32khz16C() as Timer,
         new Alarm32khz16C() as SampleTimer,
-        RandomLfsrC, LocalTimeC, DuplicateC;
+        RandomLfsrC, LocalTimeC, DuplicateC, TimeDiffC;
     
     components ActiveMessageAddressC;
     RedMacP.amAddress -> ActiveMessageAddressC;
@@ -98,6 +98,8 @@ implementation {
     RedMacP.LocalTime32kHz -> LocalTimeC;
 
     RedMacP.Duplicate -> DuplicateC;
+    RedMacP.TimeDiff16 -> TimeDiffC;
+    RedMacP.TimeDiff32 -> TimeDiffC;
     
 /*    components PlatformLedsC;
     RedMacP.Led0 -> PlatformLedsC.Led0;
index 41739aa300136fbeb28e6e7e8bd67967c4d7fb5f..b6ecbc8854d0e1621cad0b22b73419df88ab2ec4 100644 (file)
@@ -74,6 +74,8 @@ module RedMacP {
         interface LocalTime<T32khz> as LocalTime32kHz;
 
         interface Duplicate;
+        interface TimeDiff16;
+        interface TimeDiff32;
         
         async command am_addr_t amAddress();
 /*
@@ -485,17 +487,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;
             }
@@ -1023,18 +1017,9 @@ implementation
     }
     
     async event void RadioTimeStamping.transmittedSFD( uint16_t time, message_t* p_msg ) {
-        uint32_t now;
-        uint32_t mTime;
         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);
         }
     }
     
index 77b9bc83b03c0134f7b6587ad6534f1d5a34d794..b58dc71c42ba19381a76848ad642db55d883e8de 100644 (file)
@@ -64,7 +64,9 @@ implementation {
         new Alarm32khz16C() as Timer,
         new Alarm32khz16C() as SampleTimer,
         RandomLfsrC,
-        LocalTimeC, DuplicateC;
+        LocalTimeC,
+        DuplicateC,
+        TimeDiffC;
     
     components ActiveMessageAddressC;
     SpeckMacDP.amAddress -> ActiveMessageAddressC;
@@ -100,6 +102,8 @@ implementation {
     SpeckMacDP.LocalTime32kHz -> LocalTimeC;
 
     SpeckMacDP.Duplicate -> DuplicateC;
+    SpeckMacDP.TimeDiff16 -> TimeDiffC;
+    SpeckMacDP.TimeDiff32 -> TimeDiffC;
     
 /*    components PlatformLedsC;
     SpeckMacDP.Led0 -> PlatformLedsC.Led0;
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);
         }
     }
     
diff --git a/tos/chips/tda5250/mac/TimeDiff.nc b/tos/chips/tda5250/mac/TimeDiff.nc
new file mode 100644 (file)
index 0000000..7e7edbc
--- /dev/null
@@ -0,0 +1,39 @@
+/* -*- mode:c++; indent-tabs-mode: nil -*-
+ * Copyright (c) 2007, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ *   this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ *   of its contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES {} LOSS OF USE, DATA,
+ * OR PROFITS {} OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * Manipulate time differences, with overflow checking
+ * @author: Andreas Koepke (koepke@tkn.tu-berlin.de
+ */
+
+interface TimeDiff {
+    /** compute delta of two times (now - past),
+        checks for overflow assuming that now is always > past */
+    async command uint32_t computeDelta(uint32_t time_now, uint32_t time_past);
+}
diff --git a/tos/chips/tda5250/mac/TimeDiff16.nc b/tos/chips/tda5250/mac/TimeDiff16.nc
new file mode 100644 (file)
index 0000000..44955b1
--- /dev/null
@@ -0,0 +1,39 @@
+/* -*- mode:c++; indent-tabs-mode: nil -*-
+ * Copyright (c) 2007, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ *   this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ *   of its contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES {} LOSS OF USE, DATA,
+ * OR PROFITS {} OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * Manipulate time differences, with overflow checking
+ * @author: Andreas Koepke (koepke@tkn.tu-berlin.de
+ */
+
+interface TimeDiff16 {
+    /** compute delta of two times (now - past),
+        checks for overflow assuming that now is always > past */
+    async command uint16_t computeDelta(uint16_t time_now, uint16_t time_past);
+}
diff --git a/tos/chips/tda5250/mac/TimeDiff32.nc b/tos/chips/tda5250/mac/TimeDiff32.nc
new file mode 100644 (file)
index 0000000..8f4b0ea
--- /dev/null
@@ -0,0 +1,39 @@
+/* -*- mode:c++; indent-tabs-mode: nil -*-
+ * Copyright (c) 2007, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ *   this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ *   of its contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES {} LOSS OF USE, DATA,
+ * OR PROFITS {} OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * Manipulate time differences, with overflow checking
+ * @author: Andreas Koepke (koepke@tkn.tu-berlin.de
+ */
+
+interface TimeDiff32 {
+    /** compute delta of two times (now - past),
+        checks for overflow assuming that now is always > past */
+    async command uint32_t computeDelta(uint32_t time_now, uint32_t time_past);
+}
diff --git a/tos/chips/tda5250/mac/TimeDiffC.nc b/tos/chips/tda5250/mac/TimeDiffC.nc
new file mode 100644 (file)
index 0000000..162084d
--- /dev/null
@@ -0,0 +1,64 @@
+/* -*- mode:c++; indent-tabs-mode: nil -*-
+ * Copyright (c) 2007, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ *   this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ *   of its contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES {} LOSS OF USE, DATA,
+ * OR PROFITS {} OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * Implementation of timediff interface
+ * @author: Andreas Koepke (koepke@tkn.tu-berlin.de)
+ */
+
+module TimeDiffC {
+    provides {
+        interface TimeDiff32;
+        interface TimeDiff16;
+    }
+}
+implementation {
+    async command uint32_t TimeDiff32.computeDelta(uint32_t time_now, uint32_t time_past) {
+        uint32_t rval;
+        if(time_now >= time_past) {
+            rval = time_now - time_past;
+        }
+        else {
+            rval = (uint32_t)(-1) - time_past + time_now;
+        }
+        return rval;
+    }
+
+    async command uint16_t TimeDiff16.computeDelta(uint16_t time_now, uint16_t time_past) {
+        uint16_t rval;
+        if(time_now >= time_past) {
+            rval = time_now - time_past;
+        }
+        else {
+            rval = (uint16_t)(-1) - time_past + time_now;
+        }
+        return rval;
+    }
+}
+