]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/rf230/RF230PacketP.nc
Proper MSP_BSL_FLAGS for telosa and telosb based platforms using TMI modular tos...
[tinyos-2.x.git] / tos / chips / rf230 / RF230PacketP.nc
index 4458dd862853a63aa4f4720fcb2707f7dcf92408..09b4977742ddd71ab9ac07418c0113af2ae52ba6 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 #include <RF230Packet.h>
+#include <TimeSyncMessage.h>
 
 module RF230PacketP
 {
@@ -33,16 +34,18 @@ module RF230PacketP
                interface PacketField<uint8_t> as PacketTransmitPower;
                interface PacketField<uint8_t> as PacketRSSI;
                interface PacketField<uint16_t> as PacketSleepInterval;
+               interface PacketField<uint8_t> as PacketTimeSyncOffset;
 
-               interface PacketTimeStamp<TRF230, uint16_t>;
-               interface PacketLastTouch;
-
-               async event void lastTouch(message_t* msg);
+               interface PacketTimeStamp<TRF230, uint32_t> as PacketTimeStampRadio;
+               interface PacketTimeStamp<TMilli, uint32_t> as PacketTimeStampMilli;
        }
 
        uses
        {
                interface IEEE154Packet;
+
+               interface LocalTime<TRF230> as LocalTimeRadio;
+               interface LocalTime<TMilli> 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
        }
 }