X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fchips%2Frf230%2FRF230LayerP.nc;h=4ba79fca8bf74f60d948f3f78c71a38f29e0186e;hb=adf1de6c009d13b7b52e68535c63b28f59c97400;hp=1485d226d8e23e092c2db96e854cd1de38b581d6;hpb=963fc08bb8df6e1466480985c8b2dda65283e287;p=tinyos-2.x.git diff --git a/tos/chips/rf230/RF230LayerP.nc b/tos/chips/rf230/RF230LayerP.nc index 1485d226..4ba79fca 100644 --- a/tos/chips/rf230/RF230LayerP.nc +++ b/tos/chips/rf230/RF230LayerP.nc @@ -25,6 +25,7 @@ #include #include #include +#include module RF230LayerP { @@ -149,11 +150,11 @@ implementation enum { - SLEEP_WAKEUP_TIME = (uint16_t)(880 * RF230_ALARM_MICROSEC), - CCA_REQUEST_TIME = (uint16_t)(140 * RF230_ALARM_MICROSEC), + SLEEP_WAKEUP_TIME = (uint16_t)(880 * RF230_ALARM_SEC / 1000000UL), + CCA_REQUEST_TIME = (uint16_t)(140 * RF230_ALARM_SEC / 1000000UL), - TX_SFD_DELAY = (uint16_t)(176 * RF230_ALARM_MICROSEC), - RX_SFD_DELAY = (uint16_t)(8 * RF230_ALARM_MICROSEC), + TX_SFD_DELAY = (uint16_t)(176 * RF230_ALARM_SEC / 1000000UL), + RX_SFD_DELAY = (uint16_t)(8 * RF230_ALARM_SEC / 1000000UL), }; tasklet_async event void RadioAlarm.fired() @@ -392,17 +393,11 @@ implementation uint8_t* data; uint8_t header; uint32_t time32; + void* timesync; if( cmd != CMD_NONE || state != STATE_RX_ON || ! isSpiAcquired() || radioIrq ) return EBUSY; - if( call RF230Config.requiresRssiCca(msg) - && (readRegister(RF230_PHY_RSSI) & RF230_RSSI_MASK) > ((rssiClear + rssiBusy) >> 3) ) - return EBUSY; - - writeRegister(RF230_TRX_STATE, RF230_PLL_ON); - - // do something useful, just to wait a little length = (call PacketTransmitPower.isSet(msg) ? call PacketTransmitPower.get(msg) : RF230_DEF_RFPOWER) & RF230_TX_PWR_MASK; @@ -412,7 +407,15 @@ implementation writeRegister(RF230_PHY_TX_PWR, RF230_TX_AUTO_CRC_ON | txPower); } + if( call RF230Config.requiresRssiCca(msg) + && (readRegister(RF230_PHY_RSSI) & RF230_RSSI_MASK) > ((rssiClear + rssiBusy) >> 3) ) + return EBUSY; + + writeRegister(RF230_TRX_STATE, RF230_PLL_ON); + + // do something useful, just to wait a little time32 = call LocalTime.get(); + timesync = call PacketTimeSyncOffset.isSet(msg) ? msg->data + call PacketTimeSyncOffset.get(msg) : 0; // we have missed an incoming message in this short amount of time if( (readRegister(RF230_TRX_STATUS) & RF230_TRX_STATUS_MASK) != RF230_PLL_ON ) @@ -458,8 +461,8 @@ implementation time32 += (int16_t)(time) - (int16_t)(time32); - if( call PacketTimeSyncOffset.isSet(msg) ) - ((timesync_footer_t*)(msg->data + call PacketTimeSyncOffset.get(msg)))->time_offset += time32; + if( timesync != 0 ) + *(timesync_relative_t*)timesync = (*(timesync_absolute_t*)timesync) - time32; do { call HplRF230.spiSplitReadWrite(*(data++)); @@ -498,8 +501,8 @@ implementation } #endif - if( call PacketTimeSyncOffset.isSet(msg) ) - ((timesync_footer_t*)(msg->data + call PacketTimeSyncOffset.get(msg)))->time_offset -= time32; + if( timesync != 0 ) + *(timesync_absolute_t*)timesync = (*(timesync_relative_t*)timesync) + time32; call PacketTimeStamp.set(msg, time32); @@ -598,7 +601,7 @@ implementation length = call RF230Config.getLength(rxMsg); call DiagMsg.str("rx"); - call DiagMsg.uint32(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); @@ -634,6 +637,7 @@ implementation if( isSpiAcquired() ) { uint16_t time; + uint32_t time32; uint8_t irq; uint8_t temp; @@ -692,17 +696,15 @@ implementation 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 - +#ifndef RF230_RSSI_ENERGY call PacketRSSI.set(rxMsg, temp); } else + { call PacketRSSI.clear(rxMsg); +#endif + } /* * The timestamp corresponds to the first event which could not @@ -713,7 +715,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); @@ -739,7 +745,12 @@ implementation else if( cmd == CMD_RECEIVE ) { ASSERT( state == STATE_RX_ON || state == STATE_PLL_ON_2_RX_ON ); - +#ifdef RF230_RSSI_ENERGY + if( irq == RF230_IRQ_TRX_END ) + call PacketRSSI.set(rxMsg, readRegister(RF230_PHY_ED_LEVEL)); + else + call PacketRSSI.clear(rxMsg); +#endif if( state == STATE_PLL_ON_2_RX_ON ) { ASSERT( (readRegister(RF230_TRX_STATUS) & RF230_TRX_STATUS_MASK) == RF230_PLL_ON );