X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fchips%2Frf230%2FRF230LayerP.nc;h=85058a77ae29271d2bf52797a55947a62ab0623c;hb=e90b80efe22dc89b94b4d032715269849ff6796e;hp=42d0401bc7748ba6c39435c9e6eb7df8fabd9856;hpb=19ab41ca05393d0aa547acb921cd048b7641ed4f;p=tinyos-2.x.git diff --git a/tos/chips/rf230/RF230LayerP.nc b/tos/chips/rf230/RF230LayerP.nc index 42d0401b..85058a77 100644 --- a/tos/chips/rf230/RF230LayerP.nc +++ b/tos/chips/rf230/RF230LayerP.nc @@ -54,15 +54,18 @@ module RF230LayerP interface BusyWait; - interface RF230Config; interface PacketField as PacketLinkQuality; interface PacketField as PacketTransmitPower; - interface PacketTimeStamp; + interface PacketField as PacketRSSI; + 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 @@ -388,12 +391,13 @@ 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; if( call RF230Config.requiresRssiCca(msg) - && readRegister(RF230_PHY_RSSI) > ((rssiClear + rssiBusy) >> 3) ) + && (readRegister(RF230_PHY_RSSI) & RF230_RSSI_MASK) > ((rssiClear + rssiBusy) >> 3) ) return EBUSY; writeRegister(RF230_TRX_STATE, RF230_PLL_ON); @@ -408,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 ) { @@ -444,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++)); @@ -469,19 +477,10 @@ implementation * radio can even receive a message, and generate a TRX_UR interrupt * because of concurrent access, but that message probably cannot be * recovered. + * + * TODO: this needs to be verified, and make sure that the chip is + * not locked up in this case. */ - if( (readRegister(RF230_TRX_STATUS) & RF230_TRX_STATUS_MASK) != RF230_BUSY_TX ) - { - ASSERT( (readRegister(RF230_TRX_STATUS) & RF230_TRX_STATUS_MASK) == RF230_PLL_ON ); - - writeRegister(RF230_TRX_STATE, RF230_RX_ON); - readRegister(RF230_IRQ_STATUS); - radioIrq = FALSE; - - call PacketTimeStamp.clear(msg); - - return FAIL; - } // go back to RX_ON state when finished writeRegister(RF230_TRX_STATE, RF230_RX_ON); @@ -499,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; @@ -594,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.isValid(rxMsg) ? call PacketTimeStamp.timestamp(rxMsg) : 0); call DiagMsg.uint16(call RadioAlarm.getNow()); call DiagMsg.uint8(crc != 0); call DiagMsg.uint8(length); @@ -630,7 +634,9 @@ implementation if( isSpiAcquired() ) { uint16_t time; + uint32_t time32; uint8_t irq; + uint8_t temp; atomic time = capturedTime; radioIrq = FALSE; @@ -683,8 +689,21 @@ implementation { ASSERT( state == STATE_RX_ON || state == STATE_PLL_ON_2_RX_ON ); - // the most likely place for busy channel - rssiBusy += readRegister(RF230_PHY_RSSI) - (rssiBusy >> 2); + // the most likely place for busy channel, with no TRX_END interrupt + if( irq == RF230_IRQ_RX_START ) + { + temp = readRegister(RF230_PHY_RSSI) & RF230_RSSI_MASK; + + rssiBusy += temp - (rssiBusy >> 2); + +#ifdef RF230_RSSI_ENERGY + temp = readRegister(RF230_PHY_ED_LEVEL); +#endif + + call PacketRSSI.set(rxMsg, temp); + } + else + call PacketRSSI.clear(rxMsg); /* * The timestamp corresponds to the first event which could not @@ -695,7 +714,11 @@ implementation * CMD_TRANSMIT. */ if( irq == RF230_IRQ_RX_START ) // just to be cautious - call PacketTimeStamp.set(rxMsg, time - RX_SFD_DELAY); + { + time32 = call LocalTime.get(); + time32 += (int16_t)(time - RX_SFD_DELAY) - (int16_t)(time32); + call PacketTimeStamp.set(rxMsg, time32); + } else call PacketTimeStamp.clear(rxMsg); @@ -732,7 +755,7 @@ implementation else { // the most likely place for clear channel (hope to avoid acks) - rssiClear += readRegister(RF230_PHY_RSSI) - (rssiClear >> 2); + rssiClear += (readRegister(RF230_PHY_RSSI) & RF230_RSSI_MASK) - (rssiClear >> 2); } cmd = CMD_DOWNLOAD;