From: mmaroti Date: Fri, 12 Feb 2010 21:52:45 +0000 (+0000) Subject: Fix the time stamping correction code X-Git-Tag: rc_6_tinyos_2_1_1~18 X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=commitdiff_plain;h=3c311f1b2729f43a356b02542a7001db623395e1 Fix the time stamping correction code 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/ --- diff --git a/tos/chips/rf2xx/rf230/RF230DriverHwAckP.nc b/tos/chips/rf2xx/rf230/RF230DriverHwAckP.nc index 2bd762d3..790e79ed 100644 --- a/tos/chips/rf2xx/rf230/RF230DriverHwAckP.nc +++ b/tos/chips/rf2xx/rf230/RF230DriverHwAckP.nc @@ -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); }