X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fchips%2Frf230%2FRF230PacketP.nc;h=09b4977742ddd71ab9ac07418c0113af2ae52ba6;hb=adf1de6c009d13b7b52e68535c63b28f59c97400;hp=4458dd862853a63aa4f4720fcb2707f7dcf92408;hpb=83a2281d106e4f029e97523d2e7f53034a152212;p=tinyos-2.x.git diff --git a/tos/chips/rf230/RF230PacketP.nc b/tos/chips/rf230/RF230PacketP.nc index 4458dd86..09b49777 100644 --- a/tos/chips/rf230/RF230PacketP.nc +++ b/tos/chips/rf230/RF230PacketP.nc @@ -22,6 +22,7 @@ */ #include +#include module RF230PacketP { @@ -33,16 +34,18 @@ module RF230PacketP interface PacketField as PacketTransmitPower; interface PacketField as PacketRSSI; interface PacketField as PacketSleepInterval; + interface PacketField as PacketTimeSyncOffset; - interface PacketTimeStamp; - interface PacketLastTouch; - - async event void lastTouch(message_t* msg); + interface PacketTimeStamp as PacketTimeStampRadio; + interface PacketTimeStamp as PacketTimeStampMilli; } uses { interface IEEE154Packet; + + interface LocalTime as LocalTimeRadio; + interface LocalTime as LocalTimeMilli; } } @@ -66,10 +69,6 @@ implementation { call IEEE154Packet.createDataFrame(msg); -#ifdef IEEE154_6LOWPAN - call IEEE154Packet.set6LowPan(msg, TINYOS_6LOWPAN_NETWORK_ID); -#endif - getMeta(msg)->flags = RF230PACKET_CLEAR_METADATA; } @@ -78,13 +77,11 @@ implementation call IEEE154Packet.setLength(msg, len + PACKET_LENGTH_INCREASE); } - // TODO: make Packet.payloadLength async inline command uint8_t Packet.payloadLength(message_t* msg) { return call IEEE154Packet.getLength(msg) - PACKET_LENGTH_INCREASE; } - // TODO: make Packet.maxPayloadLength async inline command uint8_t Packet.maxPayloadLength() { return TOSH_DATA_LENGTH; @@ -140,29 +137,57 @@ implementation getMeta(msg)->lqi = value; } -/*----------------- PacketTimeStamp -----------------*/ +/*----------------- PacketTimeStampRadio -----------------*/ - async command bool PacketTimeStamp.isSet(message_t* msg) + async command bool PacketTimeStampRadio.isValid(message_t* msg) { return getMeta(msg)->flags & RF230PACKET_TIMESTAMP; } - async command uint16_t PacketTimeStamp.get(message_t* msg) + async command uint32_t PacketTimeStampRadio.timestamp(message_t* msg) { return getMeta(msg)->timestamp; } - async command void PacketTimeStamp.clear(message_t* msg) + async command void PacketTimeStampRadio.clear(message_t* msg) { getMeta(msg)->flags &= ~RF230PACKET_TIMESTAMP; } - async command void PacketTimeStamp.set(message_t* msg, uint16_t value) + async command void PacketTimeStampRadio.set(message_t* msg, uint32_t value) { getMeta(msg)->flags |= RF230PACKET_TIMESTAMP; getMeta(msg)->timestamp = value; } +/*----------------- PacketTimeStampMilli -----------------*/ + + async command bool PacketTimeStampMilli.isValid(message_t* msg) + { + return call PacketTimeStampRadio.isValid(msg); + } + + async command uint32_t PacketTimeStampMilli.timestamp(message_t* msg) + { + int32_t offset = call PacketTimeStampRadio.timestamp(msg) - call LocalTimeRadio.get(); + + // TODO: Make the shift constant configurable + return (offset >> 10) + call LocalTimeMilli.get(); + } + + async command void PacketTimeStampMilli.clear(message_t* msg) + { + call PacketTimeStampRadio.clear(msg); + } + + async command void PacketTimeStampMilli.set(message_t* msg, uint32_t value) + { + // TODO: Make the shift constant configurable + int32_t offset = (value - call LocalTimeMilli.get()) << 10; + + call PacketTimeStampRadio.set(msg, offset + call LocalTimeRadio.get()); + } + /*----------------- PacketTransmitPower -----------------*/ async command bool PacketTransmitPower.isSet(message_t* msg) @@ -211,64 +236,56 @@ implementation getMeta(msg)->power = value; } -/*----------------- Global fields -----------------*/ - - norace uint8_t flags; - enum - { - FLAG_SLEEPINT = 0x01, - }; - - // TODO: Move sleepInterval into the metadata - norace uint16_t sleepInterval; - -/*----------------- PacketSleepInterval -----------------*/ +/*----------------- PacketTimeSyncOffset -----------------*/ - async command bool PacketSleepInterval.isSet(message_t* msg) + async command bool PacketTimeSyncOffset.isSet(message_t* msg) { - return flags & FLAG_SLEEPINT; + return getMeta(msg)->flags & RF230PACKET_TIMESYNC; } - async command uint16_t PacketSleepInterval.get(message_t* msg) + async command uint8_t PacketTimeSyncOffset.get(message_t* msg) { - return sleepInterval; + return call IEEE154Packet.getLength(msg) - PACKET_LENGTH_INCREASE - sizeof(timesync_absolute_t); } - async command void PacketSleepInterval.clear(message_t* msg) + async command void PacketTimeSyncOffset.clear(message_t* msg) { - flags &= ~FLAG_SLEEPINT; + getMeta(msg)->flags &= ~RF230PACKET_TIMESYNC; } - async command void PacketSleepInterval.set(message_t* msg, uint16_t value) + async command void PacketTimeSyncOffset.set(message_t* msg, uint8_t value) { - flags |= FLAG_SLEEPINT; - sleepInterval = value; + // the value is ignored, the offset always points to the timesync footer at the end of the payload + getMeta(msg)->flags |= RF230PACKET_TIMESYNC; } -/*----------------- PacketLastTouch -----------------*/ - - async command void PacketLastTouch.request(message_t* msg) - { - getMeta(msg)->flags |= RF230PACKET_LAST_TOUCH; - } +/*----------------- PacketSleepInterval -----------------*/ - async command void PacketLastTouch.cancel(message_t* msg) + async command bool PacketSleepInterval.isSet(message_t* msg) { - getMeta(msg)->flags &= ~RF230PACKET_LAST_TOUCH; + return getMeta(msg)->flags & RF230PACKET_LPL_SLEEPINT; } - async command bool PacketLastTouch.isPending(message_t* msg) + async command uint16_t PacketSleepInterval.get(message_t* msg) { - return getMeta(msg)->flags & RF230PACKET_LAST_TOUCH; +#ifdef LOW_POWER_LISTENING + return getMeta(msg)->lpl_sleepint; +#else + return 0; +#endif } - async event void lastTouch(message_t* msg) + async command void PacketSleepInterval.clear(message_t* msg) { - if( getMeta(msg)->flags & RF230PACKET_LAST_TOUCH ) - signal PacketLastTouch.touch(msg); + getMeta(msg)->flags &= ~RF230PACKET_LPL_SLEEPINT; } - default async event void PacketLastTouch.touch(message_t* msg) + async command void PacketSleepInterval.set(message_t* msg, uint16_t value) { + getMeta(msg)->flags |= RF230PACKET_LPL_SLEEPINT; + +#ifdef LOW_POWER_LISTENING + getMeta(msg)->lpl_sleepint = value; +#endif } }