]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Fix the time stamping correction code
authormmaroti <mmaroti>
Fri, 12 Feb 2010 21:52:45 +0000 (21:52 +0000)
committermmaroti <mmaroti>
Fri, 12 Feb 2010 21:52:45 +0000 (21:52 +0000)
Committed on the Free edition of March Hare Software CVSNT Server.
Upgrade to CVS Suite for more features and support:
http://march-hare.com/cvsnt/

tos/chips/rf2xx/rf230/RF230DriverHwAckP.nc

index 2bd762d394f8d32be60f8275c273157bd1ffff83..790e79ed9dff0df02328d912c874f6b5de74d01d 100644 (file)
@@ -186,8 +186,11 @@ implementation
                PLL_CALIBRATION_TIME = (uint16_t)(180 * RADIO_ALARM_MICROSEC),
                CCA_REQUEST_TIME = (uint16_t)(140 * RADIO_ALARM_MICROSEC),
 
-               TX_SFD_DELAY = (uint16_t)((128 + 5*32 + 16) * RADIO_ALARM_MICROSEC),
-               RX_SFD_DELAY = (uint16_t)((16 + 32) * RADIO_ALARM_MICROSEC),
+               // 8 undocumented delay, 128 for CSMA, 16 for delay, 5*32 for preamble and SFD
+               TX_SFD_DELAY = (uint16_t)((8 + 128 + 16 + 5*32) * RADIO_ALARM_MICROSEC),
+               
+               // 32 for frame length, 16 for delay
+               RX_SFD_DELAY = (uint16_t)((32 + 16) * RADIO_ALARM_MICROSEC),
        };
 
        tasklet_async event void RadioAlarm.fired()
@@ -689,7 +692,18 @@ tasklet_async command uint8_t RadioState.getChannel()
                if( crcValid && call PacketTimeStamp.isValid(rxMsg) )
                {
                        uint32_t time32 = call PacketTimeStamp.timestamp(rxMsg);
-                       time32 -= RX_SFD_DELAY + (length << (RADIO_ALARM_MILLI_EXP - 5));
+                       length = getHeader(rxMsg)->length;
+
+/*
+ * If you hate floating point arithmetics and do not care of up to 400 microsecond time stamping errors,
+ * then define RF230_HWACK_SLOPPY_TIMESTAMP, which will be significantly faster.
+ */
+#ifdef RF230_HWACK_SLOPPY_TIMESTAMP
+                       time32 -= (uint16_t)(RX_SFD_DELAY) + ((uint16_t)(length) << (RADIO_ALARM_MILLI_EXP - 5));
+#else
+                       time32 -= (uint16_t)(RX_SFD_DELAY) + (uint16_t)(32.0 * RADIO_ALARM_MICROSEC * (uint16_t)length);
+#endif
+
                        call PacketTimeStamp.set(rxMsg, time32);
                }