]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
uff -- resolved hardware race conditions (hopefully)
authorandreaskoepke <andreaskoepke>
Thu, 6 Dec 2007 18:32:11 +0000 (18:32 +0000)
committerandreaskoepke <andreaskoepke>
Thu, 6 Dec 2007 18:32:11 +0000 (18:32 +0000)
tos/platforms/eyesIFX/LocalTimeP.nc
tos/platforms/eyesIFX/RadioDataLinkC.nc
tos/platforms/eyesIFX/WideLocalTime.nc

index 6e00648de802127ec9f446798b9d56e6bb8bcb12..d696ad0d959eda4009942e2f7e43821c05031a12 100644 (file)
@@ -37,51 +37,51 @@ module LocalTimeP {
     }
 }
 implementation  {
-    typedef union 
-    {
-        uint32_t op;
-        struct {
-            uint16_t lo;
-            uint16_t hi;
-        };
-    } ui32parts_t;
-    
-    typedef union 
-    {
-        uint64_t op;
-        struct {
-            uint32_t lo;
-            uint32_t hi;
-        };
-    } ui64parts_t;
-
-    uint16_t counter2sec = 127;
-    uint32_t dayCounter = 0;
-    
+    uint16_t counter2sec = 40000U;
+    int32_t dayCounter = 0;
+    bool increaseDay = FALSE;
     async command uint32_t LocalTime32kHz.get() {
-        ui32parts_t time;
+        int64_t time;
+        unsigned t;
+        bool dirty1;
+        bool dirty2;
         atomic {
-            time.lo = call Counter32khz16.get();
-            time.hi = counter2sec;
-            if(call Counter32khz16.isOverflowPending()) {
-                time.hi++;
+            increaseDay = FALSE;
+            do {
+                dirty1 = call Counter32khz16.isOverflowPending();
+                t = call Counter32khz16.get();
+                dirty2 = call Counter32khz16.isOverflowPending();
+            } while (dirty1 != dirty2);
+            time = counter2sec;
+            if(dirty1) {
+                ++time;
+                if(time == 0) {
+                    increaseDay = TRUE;
+                }
             }
+            time = (time << 16) + t;
         }
-        return time.op;
+        return time;
     }
 
-    async command uint64_t WideLocalTime.get() {
-        ui64parts_t time;
+    async command int64_t WideLocalTime.get() {
+        int64_t time;
+        uint32_t t;
         atomic {
-            time.lo = call LocalTime32kHz.get();
-            time.hi = dayCounter;
+            t = call LocalTime32kHz.get();
+            time = dayCounter;
+            if(increaseDay) time++;
+            if(time < 0) time = 0;
+            time <<= 32;
+            time += t;
         }
-        return time.op;
+        return time;
     }
     
     async event void Counter32khz16.overflow() {
         ++counter2sec;
         if(counter2sec == 0) ++dayCounter;
+        if(dayCounter < 0) dayCounter = 0;
     }
 }
 
index fb47e88f6ec614e7c2ac5e79af93ffff51c4c2d2..dd90bfc2792f3cab9d467466eb25cf8be35d1484 100644 (file)
@@ -51,9 +51,9 @@ implementation
         Tda5250RadioC as Radio,                  //The actual Tda5250 radio over which data is receives/transmitted
         Uart4b6bPhyC as UartPhy,                 //The UartPhy turns Bits into Bytes
         PacketSerializerP  as PacketSerializer,  //The PacketSerializer turns Bytes into Packets
-        RedMacC as Mac,                         //The MAC protocol to use
+        // RedMacC as Mac,                         //The MAC protocol to use
         // SpeckMacDC as Mac,                         //The MAC protocol to use
-        // CsmaMacC as Mac,                         //The MAC protocol to use
+        CsmaMacC as Mac,                         //The MAC protocol to use
         LinkLayerC as Llc;                       //The Link Layer Control module to use
     
     //Don't change wirings below this point, just change which components
index f0fe733521dffdb07164b7a90af095eaa656110b..4fc86d897ffef36fb240c3e4c772793753f9c1d2 100644 (file)
@@ -39,6 +39,6 @@ interface WideLocalTime<precision_tag>
    *
    * @return Current time.
    */
-  async command uint64_t get();
+  async command int64_t get();
 }