]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
implement the PacketLink layer
authormmaroti <mmaroti>
Mon, 30 Mar 2009 22:29:48 +0000 (22:29 +0000)
committermmaroti <mmaroti>
Mon, 30 Mar 2009 22:29:48 +0000 (22:29 +0000)
12 files changed:
tos/chips/rf2xx/layers/PacketLinkLayer.h [new file with mode: 0644]
tos/chips/rf2xx/layers/PacketLinkLayerC.nc [new file with mode: 0644]
tos/chips/rf2xx/layers/PacketLinkLayerP.nc [new file with mode: 0644]
tos/chips/rf2xx/rf212/RF212ActiveMessageC.nc
tos/chips/rf2xx/rf212/RF212Packet.h
tos/chips/rf2xx/rf212/RF212PacketC.nc
tos/chips/rf2xx/rf212/RF212PacketP.nc
tos/chips/rf2xx/rf230/RF230ActiveMessageC.nc
tos/chips/rf2xx/rf230/RF230Packet.h
tos/chips/rf2xx/rf230/RF230PacketC.nc
tos/chips/rf2xx/rf230/RF230PacketP.nc
tos/chips/rf2xx/util/PacketData.nc [new file with mode: 0644]

diff --git a/tos/chips/rf2xx/layers/PacketLinkLayer.h b/tos/chips/rf2xx/layers/PacketLinkLayer.h
new file mode 100644 (file)
index 0000000..785e61e
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ * 
+ * IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * Author: Miklos Maroti
+ */
+
+#ifndef __PACKETLINKLAYER_H__
+#define __PACKETLINKLAYER_H__
+
+typedef struct packet_link_metadata_t
+{
+       nx_uint16_t maxRetries;
+       nx_uint16_t retryDelay;
+} packet_link_metadata_t;
+
+#endif//__PACKETLINKLAYER_H__
diff --git a/tos/chips/rf2xx/layers/PacketLinkLayerC.nc b/tos/chips/rf2xx/layers/PacketLinkLayerC.nc
new file mode 100644 (file)
index 0000000..34ea891
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * "Copyright (c) 2008 The Regents of the University  of California.
+ * All rights reserved."
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+/*
+ * Copyright (c) 2005-2006 Rincon Research Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the
+ *   distribution.
+ * - Neither the name of the Rincon Research Corporation nor the names of
+ *   its contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+ * RINCON RESEARCH OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE
+ */
+
+/**
+ * Reliable Packet Link Functionality
+ * @author David Moss
+ * @author Jon Wyant
+ * @author Miklos Maroti
+ */
+
+#include <PacketLinkLayer.h>
+
+#warning "*** USING PACKET LINK LAYER"
+
+configuration PacketLinkLayerC {
+  provides {
+    interface Send;
+    interface PacketLink;
+  }
+  
+  uses {
+    interface Send as SubSend;
+    interface PacketData<packet_link_metadata_t>;
+    interface PacketAcknowledgements;
+  }
+}
+
+implementation {
+  components PacketLinkLayerP,
+      RF230PacketC,
+      new TimerMilliC() as DelayTimerC;
+  
+  PacketLink = PacketLinkLayerP;
+  Send = PacketLinkLayerP.Send;
+  SubSend = PacketLinkLayerP.SubSend;
+  PacketAcknowledgements = PacketLinkLayerP;
+  PacketData = PacketLinkLayerP;
+  
+  PacketLinkLayerP.DelayTimer -> DelayTimerC;
+}
diff --git a/tos/chips/rf2xx/layers/PacketLinkLayerP.nc b/tos/chips/rf2xx/layers/PacketLinkLayerP.nc
new file mode 100644 (file)
index 0000000..a54e135
--- /dev/null
@@ -0,0 +1,240 @@
+/*
+ * "Copyright (c) 2008 The Regents of the University  of California.
+ * All rights reserved."
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+/*
+ * Copyright (c) 2005-2006 Rincon Research Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the
+ *   distribution.
+ * - Neither the name of the Rincon Research Corporation nor the names of
+ *   its contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+ * RINCON RESEARCH OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE
+ */
+
+/**
+ * Reliable Packet Link Functionality
+ * @author David Moss
+ * @author Jon Wyant
+ * @author Miklos Maroti
+ */
+
+#include <PacketLinkLayer.h>
+
+module PacketLinkLayerP {
+  provides {
+    interface Send;
+    interface PacketLink;
+  }
+
+  uses {
+    interface Send as SubSend;
+    interface PacketAcknowledgements;
+    interface Timer<TMilli> as DelayTimer;
+    interface PacketData<packet_link_metadata_t>;
+  }
+}
+
+implementation {
+
+  /** The message currently being sent */
+  message_t *currentSendMsg;
+
+  /** Length of the current send message */
+  uint8_t currentSendLen;
+
+  /** The length of the current send message */
+  uint16_t totalRetries;
+
+  /***************** Prototypes ***************/
+
+  task void send();
+  void signalDone(error_t error);
+
+
+  /***************** PacketLink Commands ***************/
+  /**
+   * Set the maximum number of times attempt message delivery
+   * Default is 0
+   * @param msg
+   * @param maxRetries the maximum number of attempts to deliver
+   *     the message
+   */
+  command void PacketLink.setRetries(message_t *msg, uint16_t maxRetries) {
+    (call PacketData.getData(msg))->maxRetries = maxRetries;
+  }
+
+  /**
+   * Set a delay between each retry attempt
+   * @param msg
+   * @param retryDelay the delay betweeen retry attempts, in milliseconds
+   */
+  command void PacketLink.setRetryDelay(message_t *msg, uint16_t retryDelay) {
+    (call PacketData.getData(msg))->retryDelay = retryDelay;
+  }
+
+  /**
+   * @return the maximum number of retry attempts for this message
+   */
+  command uint16_t PacketLink.getRetries(message_t *msg) {
+    return (call PacketData.getData(msg))->maxRetries;
+  }
+
+  /**
+   * @return the delay between retry attempts in ms for this message
+   */
+  command uint16_t PacketLink.getRetryDelay(message_t *msg) {
+    return (call PacketData.getData(msg))->retryDelay;
+  }
+
+  /**
+   * @return TRUE if the message was delivered.
+   */
+  command bool PacketLink.wasDelivered(message_t *msg) {
+    return call PacketAcknowledgements.wasAcked(msg);
+  }
+
+  async event void PacketData.clear(packet_link_metadata_t* data) {
+    data->maxRetries = 0;
+  }
+
+  /***************** Send Commands ***************/
+  /**
+   * Each call to this send command gives the message a single
+   * DSN that does not change for every copy of the message
+   * sent out.  For messages that are not acknowledged, such as
+   * a broadcast address message, the receiving end does not
+   * signal receive() more than once for that message.
+   */
+  command error_t Send.send(message_t *msg, uint8_t len) {
+    error_t error = EBUSY;
+    if(currentSendMsg == NULL) {
+
+      if(call PacketLink.getRetries(msg) > 0) {
+        call PacketAcknowledgements.requestAck(msg);
+      }
+
+      if((error = call SubSend.send(msg, len)) == SUCCESS) {
+        currentSendMsg = msg;
+        currentSendLen = len;
+        totalRetries = 0;
+      }
+    }
+    return error;
+  }
+
+  command error_t Send.cancel(message_t *msg) {
+    if(currentSendMsg == msg) {
+      currentSendMsg = NULL;
+      return call SubSend.cancel(msg);
+    }
+
+    return FAIL;
+  }
+
+
+  command uint8_t Send.maxPayloadLength() {
+    return call SubSend.maxPayloadLength();
+  }
+
+  command void *Send.getPayload(message_t* msg, uint8_t len) {
+    return call SubSend.getPayload(msg, len);
+  }
+
+  /***************** SubSend Events ***************/
+  event void SubSend.sendDone(message_t* msg, error_t error) {
+    totalRetries++;
+
+    if(call PacketAcknowledgements.wasAcked(msg)) {
+      signalDone(SUCCESS);
+      return;
+
+    } else if(totalRetries < call PacketLink.getRetries(currentSendMsg)) {
+
+      if(call PacketLink.getRetryDelay(currentSendMsg) > 0) {
+        // Resend after some delay
+        call DelayTimer.startOneShot(call PacketLink.getRetryDelay(currentSendMsg));
+      } else {
+        // Resend immediately
+        post send();
+      }
+
+      return;
+    }
+
+    signalDone(error);
+  }
+
+  /***************** Timer Events ****************/
+  /**
+   * When this timer is running, that means we're sending repeating messages
+   * to a node that is receive check duty cycling.
+   */
+  event void DelayTimer.fired() {
+    if(currentSendMsg != NULL) {
+      post send();
+    }
+  }
+
+  /***************** Tasks ***************/
+  task void send() {
+    if(call PacketLink.getRetries(currentSendMsg) > 0) {
+      call PacketAcknowledgements.requestAck(currentSendMsg);
+    }
+
+    if(call SubSend.send(currentSendMsg, currentSendLen) != SUCCESS) {
+      post send();
+    }
+  }
+
+  /***************** Functions ***************/
+  void signalDone(error_t error) {
+    message_t* msg = currentSendMsg;
+    currentSendMsg = NULL;
+
+    // AT: A bit of a hack to be able to keep track of the number of retries
+    // printfUART("Signaling done with total retries at 0x%x\n", totalRetries);
+
+    call DelayTimer.stop();
+    call PacketLink.setRetries(msg, totalRetries);
+    signal Send.sendDone(msg, error);
+  }
+}
index d7b0f3aa5ec232a05b3c81715cc5d0322b7568ba..65eba63c45f23477b4dd47fbb9d63f0c61ffc58d 100644 (file)
@@ -36,7 +36,14 @@ configuration RF212ActiveMessageC
                interface Packet;
                interface AMPacket;
                interface PacketAcknowledgements;
+
+               // we provide a dummy LowPowerListening interface if LOW_POWER_LISTENING is not defined
                interface LowPowerListening;
+
+#ifdef PACKET_LINK
+               interface PacketLink;
+#endif
+
                interface RadioChannel;
 
                interface PacketField<uint8_t> as PacketLinkQuality;
@@ -77,19 +84,35 @@ implementation
 #else
        components IEEE154NetworkLayerC;
 #endif
+
 #ifdef LOW_POWER_LISTENING
        components LowPowerListeningLayerC;
+       LowPowerListeningLayerC.PacketSleepInterval -> RF230PacketC;
+       LowPowerListeningLayerC.IEEE154Packet2 -> IEEE154Packet2C;
+       LowPowerListeningLayerC.PacketAcknowledgements -> RF230PacketC;
 #else  
        components new DummyLayerC() as LowPowerListeningLayerC;
 #endif
+
+#ifdef PACKET_LINK
+       components PacketLinkLayerC;
+       PacketLink = PacketLinkLayerC;
+       PacketLinkLayerC.PacketData -> RF230PacketC;
+       PacketLinkLayerC.PacketAcknowledgements -> RF230PacketC;
+#else
+       components new DummyLayerC() as PacketLinkLayerC;
+#endif
+
        components MessageBufferLayerC;
        components UniqueLayerC;
        components TrafficMonitorLayerC;
+
 #ifdef SLOTTED_MAC
        components SlottedCollisionLayerC as CollisionAvoidanceLayerC;
 #else
        components RandomCollisionLayerC as CollisionAvoidanceLayerC;
 #endif
+
        components SoftwareAckLayerC;
        components new DummyLayerC() as CsmaLayerC;
        components RF212DriverLayerC;
@@ -112,13 +135,10 @@ implementation
        UniqueLayerC.SubSend -> LowPowerListeningLayerC;
 
        LowPowerListeningLayerC.SubControl -> MessageBufferLayerC;
-       LowPowerListeningLayerC.SubSend -> MessageBufferLayerC;
+       LowPowerListeningLayerC.SubSend -> PacketLinkLayerC;
        LowPowerListeningLayerC.SubReceive -> MessageBufferLayerC;
-#ifdef LOW_POWER_LISTENING
-       LowPowerListeningLayerC.PacketSleepInterval -> RF212PacketC;
-       LowPowerListeningLayerC.IEEE154Packet2 -> IEEE154Packet2C;
-       LowPowerListeningLayerC.PacketAcknowledgements -> RF212PacketC;
-#endif
+
+       PacketLinkLayerC.SubSend -> MessageBufferLayerC;
 
        MessageBufferLayerC.Packet -> RF212PacketC;
        MessageBufferLayerC.RadioSend -> TrafficMonitorLayerC;
index 15866b7a616b14500149b6fc1cce66a0cc3c1181..ed37875932f980ac784e4a3999fa080bdddf045d 100644 (file)
@@ -25,6 +25,7 @@
 #define __RF212PACKET_H__
 
 #include <IEEE154Packet2.h>
+#include <PacketLinkLayer.h>
 
 typedef ieee154_header_t rf212packet_header_t;
 
@@ -40,6 +41,9 @@ typedef struct rf212packet_metadata_t
        uint8_t power;                          // shared between TXPOWER and RSSI
 #ifdef LOW_POWER_LISTENING
        uint16_t lpl_sleepint;
+#endif
+#ifdef PACKET_LINK
+       packet_link_metadata_t packet_link;
 #endif
        uint32_t timestamp;
 } rf212packet_metadata_t;
index 5a53cf42e3e6147d39d77cfd2c83f5bf635c1e6d..89f82459aec77be013e7241311c77e6420c3f58a 100644 (file)
@@ -36,6 +36,9 @@ configuration RF212PacketC
 
                interface PacketTimeStamp<TRadio, uint32_t> as PacketTimeStampRadio;
                interface PacketTimeStamp<TMilli, uint32_t> as PacketTimeStampMilli;
+#ifdef PACKET_LINK
+               interface PacketData<packet_link_metadata_t> as PaketLinkMetadata;
+#endif
        }
 }
 
@@ -59,4 +62,8 @@ implementation
 
        PacketTimeStampRadio    = RF212PacketP;
        PacketTimeStampMilli    = RF212PacketP;
+
+#ifdef PACKET_LINK
+       PaketLinkMetadata       = RF212PacketP;
+#endif
 }
index 3641c1bd99cf6bf6b17317c0546651f69dd435a2..165816822e518d50786a61e04fe1d90e8451fb9e 100644 (file)
@@ -6,12 +6,12 @@
  * documentation for any purpose, without fee, and without written agreement is
  * hereby granted, provided that the above copyright notice, the following
  * two paragraphs and the author appear in all copies of this software.
- * 
+ *
  * IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
  * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
+ *
  * THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
@@ -24,6 +24,7 @@
 #include <RF212Packet.h>
 #include <GenericTimeSyncMessage.h>
 #include <RadioConfig.h>
+#include <PacketLinkLayer.h>
 
 module RF212PacketP
 {
@@ -39,6 +40,10 @@ module RF212PacketP
 
                interface PacketTimeStamp<TRadio, uint32_t> as PacketTimeStampRadio;
                interface PacketTimeStamp<TMilli, uint32_t> as PacketTimeStampMilli;
+
+#ifdef PACKET_LINK
+               interface PacketData<packet_link_metadata_t> as PacketLinkMetadata;
+#endif
        }
 
        uses
@@ -54,7 +59,7 @@ implementation
 {
        enum
        {
-               PACKET_LENGTH_INCREASE = 
+               PACKET_LENGTH_INCREASE =
                        sizeof(rf212packet_header_t) - 1        // the 8-bit length field is not counted
                        + sizeof(ieee154_footer_t),             // the CRC is not stored in memory
        };
@@ -66,19 +71,19 @@ implementation
 
 /*----------------- Packet -----------------*/
 
-       command void Packet.clear(message_t* msg) 
+       command void Packet.clear(message_t* msg)
        {
                call IEEE154Packet2.createDataFrame(msg);
 
                getMeta(msg)->flags = RF212PACKET_CLEAR_METADATA;
        }
 
-       inline command void Packet.setPayloadLength(message_t* msg, uint8_t len) 
+       inline command void Packet.setPayloadLength(message_t* msg, uint8_t len)
        {
                call IEEE154Packet2.setLength(msg, len + PACKET_LENGTH_INCREASE);
        }
 
-       inline command uint8_t Packet.payloadLength(message_t* msg) 
+       inline command uint8_t Packet.payloadLength(message_t* msg)
        {
                return call IEEE154Packet2.getLength(msg) - PACKET_LENGTH_INCREASE;
        }
@@ -287,4 +292,14 @@ implementation
                getMeta(msg)->lpl_sleepint = value;
 #endif
        }
+
+/*----------------- PacketLinkMetadata -----------------*/
+#ifdef PACKET_LINK
+
+       async command packet_link_metadata_t* PacketLinkMetadata.getData(message_t* msg)
+       {
+               return &(getMeta(msg)->packet_link);
+       }
+
+#endif
 }
index a6ecda760ff9e24fa0d45cbd7ad64f047b47f74e..af6e816e6441d6ce2a8e57919247f0b78baf3ce2 100644 (file)
@@ -36,7 +36,14 @@ configuration RF230ActiveMessageC
                interface Packet;
                interface AMPacket;
                interface PacketAcknowledgements;
+
+               // we provide a dummy LowPowerListening interface if LOW_POWER_LISTENING is not defined
                interface LowPowerListening;
+
+#ifdef PACKET_LINK
+               interface PacketLink;
+#endif
+
                interface RadioChannel;
 
                interface PacketField<uint8_t> as PacketLinkQuality;
@@ -77,19 +84,35 @@ implementation
 #else
        components IEEE154NetworkLayerC;
 #endif
+
 #ifdef LOW_POWER_LISTENING
        components LowPowerListeningLayerC;
+       LowPowerListeningLayerC.PacketSleepInterval -> RF230PacketC;
+       LowPowerListeningLayerC.IEEE154Packet2 -> IEEE154Packet2C;
+       LowPowerListeningLayerC.PacketAcknowledgements -> RF230PacketC;
 #else  
        components new DummyLayerC() as LowPowerListeningLayerC;
 #endif
+
+#ifdef PACKET_LINK
+       components PacketLinkLayerC;
+       PacketLink = PacketLinkLayerC;
+       PacketLinkLayerC.PacketData -> RF230PacketC;
+       PacketLinkLayerC.PacketAcknowledgements -> RF230PacketC;
+#else
+       components new DummyLayerC() as PacketLinkLayerC;
+#endif
+
        components MessageBufferLayerC;
        components UniqueLayerC;
        components TrafficMonitorLayerC;
+
 #ifdef SLOTTED_MAC
        components SlottedCollisionLayerC as CollisionAvoidanceLayerC;
 #else
        components RandomCollisionLayerC as CollisionAvoidanceLayerC;
 #endif
+
        components SoftwareAckLayerC;
        components new DummyLayerC() as CsmaLayerC;
        components RF230DriverLayerC;
@@ -112,13 +135,10 @@ implementation
        UniqueLayerC.SubSend -> LowPowerListeningLayerC;
 
        LowPowerListeningLayerC.SubControl -> MessageBufferLayerC;
-       LowPowerListeningLayerC.SubSend -> MessageBufferLayerC;
+       LowPowerListeningLayerC.SubSend -> PacketLinkLayerC;
        LowPowerListeningLayerC.SubReceive -> MessageBufferLayerC;
-#ifdef LOW_POWER_LISTENING
-       LowPowerListeningLayerC.PacketSleepInterval -> RF230PacketC;
-       LowPowerListeningLayerC.IEEE154Packet2 -> IEEE154Packet2C;
-       LowPowerListeningLayerC.PacketAcknowledgements -> RF230PacketC;
-#endif
+
+       PacketLinkLayerC.SubSend -> MessageBufferLayerC;
 
        MessageBufferLayerC.Packet -> RF230PacketC;
        MessageBufferLayerC.RadioSend -> TrafficMonitorLayerC;
index 5e3e8bd7007d88963c6dcbc1198d9d55790e90d1..802aa51cdbc14ccdc527034b976ee95c5f99f999 100644 (file)
@@ -25,6 +25,7 @@
 #define __RF230PACKET_H__
 
 #include <IEEE154Packet2.h>
+#include <PacketLinkLayer.h>
 
 typedef ieee154_header_t rf230packet_header_t;
 
@@ -40,6 +41,9 @@ typedef struct rf230packet_metadata_t
        uint8_t power;                          // shared between TXPOWER and RSSI
 #ifdef LOW_POWER_LISTENING
        uint16_t lpl_sleepint;
+#endif
+#ifdef PACKET_LINK
+       packet_link_metadata_t packet_link;
 #endif
        uint32_t timestamp;
 } rf230packet_metadata_t;
index 23115e83f27b9440122fcbc648e776580c23c59c..31e826996d488a1faddbe3751cdbad7bf9ac5f97 100644 (file)
@@ -36,6 +36,9 @@ configuration RF230PacketC
 
                interface PacketTimeStamp<TRadio, uint32_t> as PacketTimeStampRadio;
                interface PacketTimeStamp<TMilli, uint32_t> as PacketTimeStampMilli;
+#ifdef PACKET_LINK
+               interface PacketData<packet_link_metadata_t> as PaketLinkMetadata;
+#endif
        }
 }
 
@@ -59,4 +62,8 @@ implementation
 
        PacketTimeStampRadio    = RF230PacketP;
        PacketTimeStampMilli    = RF230PacketP;
+
+#ifdef PACKET_LINK
+       PaketLinkMetadata       = RF230PacketP;
+#endif
 }
index 45b94bf6d7eee82ae7aa120a05401e98c6818356..de875b0240440e0a09773e5fa3c24bf2f8d19ba3 100644 (file)
@@ -6,12 +6,12 @@
  * documentation for any purpose, without fee, and without written agreement is
  * hereby granted, provided that the above copyright notice, the following
  * two paragraphs and the author appear in all copies of this software.
- * 
+ *
  * IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
  * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
+ *
  * THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
@@ -24,6 +24,7 @@
 #include <RF230Packet.h>
 #include <GenericTimeSyncMessage.h>
 #include <RadioConfig.h>
+#include <PacketLinkLayer.h>
 
 module RF230PacketP
 {
@@ -39,6 +40,10 @@ module RF230PacketP
 
                interface PacketTimeStamp<TRadio, uint32_t> as PacketTimeStampRadio;
                interface PacketTimeStamp<TMilli, uint32_t> as PacketTimeStampMilli;
+
+#ifdef PACKET_LINK
+               interface PacketData<packet_link_metadata_t> as PacketLinkMetadata;
+#endif
        }
 
        uses
@@ -54,7 +59,7 @@ implementation
 {
        enum
        {
-               PACKET_LENGTH_INCREASE = 
+               PACKET_LENGTH_INCREASE =
                        sizeof(rf230packet_header_t) - 1        // the 8-bit length field is not counted
                        + sizeof(ieee154_footer_t),             // the CRC is not stored in memory
        };
@@ -66,19 +71,19 @@ implementation
 
 /*----------------- Packet -----------------*/
 
-       command void Packet.clear(message_t* msg) 
+       command void Packet.clear(message_t* msg)
        {
                call IEEE154Packet2.createDataFrame(msg);
 
                getMeta(msg)->flags = RF230PACKET_CLEAR_METADATA;
        }
 
-       inline command void Packet.setPayloadLength(message_t* msg, uint8_t len) 
+       inline command void Packet.setPayloadLength(message_t* msg, uint8_t len)
        {
                call IEEE154Packet2.setLength(msg, len + PACKET_LENGTH_INCREASE);
        }
 
-       inline command uint8_t Packet.payloadLength(message_t* msg) 
+       inline command uint8_t Packet.payloadLength(message_t* msg)
        {
                return call IEEE154Packet2.getLength(msg) - PACKET_LENGTH_INCREASE;
        }
@@ -287,4 +292,14 @@ implementation
                getMeta(msg)->lpl_sleepint = value;
 #endif
        }
+
+/*----------------- PacketLinkMetadata -----------------*/
+#ifdef PACKET_LINK
+
+       async command packet_link_metadata_t* PacketLinkMetadata.getData(message_t* msg)
+       {
+               return &(getMeta(msg)->packet_link);
+       }
+
+#endif
 }
diff --git a/tos/chips/rf2xx/util/PacketData.nc b/tos/chips/rf2xx/util/PacketData.nc
new file mode 100644 (file)
index 0000000..ea42595
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ * 
+ * IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * Author: Miklos Maroti
+ */
+
+interface PacketData<data_t>
+{
+       /**
+        * This command returns a pointer to a set of packet fields (in the header, footer 
+        * or metadata) with the given data type.
+        */
+       async command data_t* getData(message_t* msg);
+
+       /**
+        * This event is signalled, when the these fields should be reset to their default
+        * value (usually called from Packet.clear)
+        */
+       async event void clear(data_t* data);
+}