X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fchips%2Frf230%2FRF230LayerP.nc;h=1485d226d8e23e092c2db96e854cd1de38b581d6;hb=963fc08bb8df6e1466480985c8b2dda65283e287;hp=cda1a21615df48d11208c5282af4e3e83927b7ac;hpb=fdfa9cb846adb5d4819dd08cf9218f6c31ffd624;p=tinyos-2.x.git diff --git a/tos/chips/rf230/RF230LayerP.nc b/tos/chips/rf230/RF230LayerP.nc index cda1a216..1485d226 100644 --- a/tos/chips/rf230/RF230LayerP.nc +++ b/tos/chips/rf230/RF230LayerP.nc @@ -57,14 +57,15 @@ module RF230LayerP interface PacketField as PacketLinkQuality; interface PacketField as PacketTransmitPower; interface PacketField as PacketRSSI; - interface PacketTimeStamp; + interface PacketField as PacketTimeSyncOffset; + + interface PacketTimeStamp; + interface LocalTime; interface RF230Config; interface Tasklet; interface RadioAlarm; - async event void lastTouch(message_t* msg); - #ifdef RF230_DEBUG interface DiagMsg; #endif @@ -390,6 +391,7 @@ implementation uint8_t length; uint8_t* data; uint8_t header; + uint32_t time32; if( cmd != CMD_NONE || state != STATE_RX_ON || ! isSpiAcquired() || radioIrq ) return EBUSY; @@ -410,6 +412,8 @@ implementation writeRegister(RF230_PHY_TX_PWR, RF230_TX_AUTO_CRC_ON | txPower); } + time32 = call LocalTime.get(); + // we have missed an incoming message in this short amount of time if( (readRegister(RF230_TRX_STATUS) & RF230_TRX_STATUS_MASK) != RF230_PLL_ON ) { @@ -446,14 +450,16 @@ implementation length -= header; - // first upload the header + // first upload the header to gain some time do { call HplRF230.spiSplitReadWrite(*(data++)); } while( --header != 0 ); - call PacketTimeStamp.set(msg, time); - signal lastTouch(msg); + time32 += (int16_t)(time) - (int16_t)(time32); + + if( call PacketTimeSyncOffset.isSet(msg) ) + ((timesync_footer_t*)(msg->data + call PacketTimeSyncOffset.get(msg)))->time_offset += time32; do { call HplRF230.spiSplitReadWrite(*(data++)); @@ -492,6 +498,11 @@ implementation } #endif + if( call PacketTimeSyncOffset.isSet(msg) ) + ((timesync_footer_t*)(msg->data + call PacketTimeSyncOffset.get(msg)))->time_offset -= time32; + + call PacketTimeStamp.set(msg, time32); + // wait for the TRX_END interrupt state = STATE_BUSY_TX_2_RX_ON; cmd = CMD_TRANSMIT; @@ -587,7 +598,7 @@ implementation length = call RF230Config.getLength(rxMsg); call DiagMsg.str("rx"); - call DiagMsg.uint16(call PacketTimeStamp.isSet(rxMsg) ? call PacketTimeStamp.get(rxMsg) : 0); + call DiagMsg.uint32(call PacketTimeStamp.isSet(rxMsg) ? call PacketTimeStamp.get(rxMsg) : 0); call DiagMsg.uint16(call RadioAlarm.getNow()); call DiagMsg.uint8(crc != 0); call DiagMsg.uint8(length);