]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/rf2xx/rf230/RF230ActiveMessageP.nc
reorganized packet header handling, added RF212Ieee154MessageC for BLIP
[tinyos-2.x.git] / tos / chips / rf2xx / rf230 / RF230ActiveMessageP.nc
index 9c8044cd34a704c34e6e17c2a52c5956b01ffc5b..57fa1c22acf2f91c1679c35fb3db242581fd60f5 100644 (file)
@@ -21,7 +21,7 @@
  * Author: Miklos Maroti
  */
 
-#include <RF230Packet.h>
+#include <RF230ActiveMessage.h>
 #include <RadioConfig.h>
 #include <Tasklet.h>
 
@@ -38,90 +38,84 @@ module RF230ActiveMessageP
                interface SlottedCollisionConfig;
                interface ActiveMessageConfig;
                interface DummyConfig;
+
+#ifdef LOW_POWER_LISTENING
+               interface LowPowerListeningConfig;
+#endif
        }
 
        uses
        {
-               interface IEEE154Packet2;
-               interface Packet;
+               interface IEEE154MessageLayer;
                interface RadioAlarm;
+               interface RadioPacket as ActiveMessagePacket;
+               interface RadioPacket as RF230Packet;
+
+               interface PacketTimeStamp<TRadio, uint32_t>;
        }
 }
 
 implementation
 {
-/*----------------- RF230DriverConfig -----------------*/
 
-       async command uint8_t RF230DriverConfig.getLength(message_t* msg)
-       {
-               return call IEEE154Packet2.getLength(msg);
-       }
+/*----------------- RF230DriverConfig -----------------*/
 
-       async command void RF230DriverConfig.setLength(message_t* msg, uint8_t len)
+       async command uint8_t RF230DriverConfig.headerLength(message_t* msg)
        {
-               call IEEE154Packet2.setLength(msg, len);
+               return offsetof(message_t, data) - sizeof(rf230packet_header_t);
        }
 
-       async command uint8_t* RF230DriverConfig.getPayload(message_t* msg)
+       async command uint8_t RF230DriverConfig.maxPayloadLength()
        {
-               return ((uint8_t*)(call IEEE154Packet2.getHeader(msg))) + 1;
+               return sizeof(rf230packet_header_t) + TOSH_DATA_LENGTH;
        }
 
-       inline rf230packet_metadata_t* getMeta(message_t* msg)
+       async command uint8_t RF230DriverConfig.metadataLength(message_t* msg)
        {
-               return (rf230packet_metadata_t*)(msg->metadata);
+               return 0;
        }
 
-       async command uint8_t RF230DriverConfig.getHeaderLength()
+       async command uint8_t RF230DriverConfig.headerPreloadLength()
        {
                // we need the fcf, dsn, destpan and dest
                return 7;
        }
 
-       async command uint8_t RF230DriverConfig.getMaxLength()
-       {
-               // note, that the ieee154_footer_t is not stored, but we should include it here
-               return sizeof(rf230packet_header_t) - 1 + TOSH_DATA_LENGTH + sizeof(ieee154_footer_t);
-       }
-
        async command bool RF230DriverConfig.requiresRssiCca(message_t* msg)
        {
-               return call IEEE154Packet2.isDataFrame(msg);
+               return call IEEE154MessageLayer.isDataFrame(msg);
        }
 
 /*----------------- SoftwareAckConfig -----------------*/
 
        async command bool SoftwareAckConfig.requiresAckWait(message_t* msg)
        {
-               return call IEEE154Packet2.requiresAckWait(msg);
+               return call IEEE154MessageLayer.requiresAckWait(msg);
        }
 
        async command bool SoftwareAckConfig.isAckPacket(message_t* msg)
        {
-               return call IEEE154Packet2.isAckFrame(msg);
+               return call IEEE154MessageLayer.isAckFrame(msg);
        }
 
        async command bool SoftwareAckConfig.verifyAckPacket(message_t* data, message_t* ack)
        {
-               return call IEEE154Packet2.verifyAckReply(data, ack);
+               return call IEEE154MessageLayer.verifyAckReply(data, ack);
        }
 
-       async command bool SoftwareAckConfig.requiresAckReply(message_t* msg)
+       async command void SoftwareAckConfig.setAckRequired(message_t* msg, bool ack)
        {
-               return call IEEE154Packet2.requiresAckReply(msg);
+               call IEEE154MessageLayer.setAckRequired(msg, ack);
        }
 
-       async command void SoftwareAckConfig.createAckPacket(message_t* data, message_t* ack)
+       async command bool SoftwareAckConfig.requiresAckReply(message_t* msg)
        {
-               call IEEE154Packet2.createAckReply(data, ack);
+               return call IEEE154MessageLayer.requiresAckReply(msg);
        }
 
-       async command void SoftwareAckConfig.setAckReceived(message_t* msg, bool acked)
+       async command void SoftwareAckConfig.createAckPacket(message_t* data, message_t* ack)
        {
-               if( acked )
-                       getMeta(msg)->flags |= RF230PACKET_WAS_ACKED;
-               else
-                       getMeta(msg)->flags &= ~RF230PACKET_WAS_ACKED;
+               call IEEE154MessageLayer.createAckReply(data, ack);
        }
 
        async command uint16_t SoftwareAckConfig.getAckTimeout()
@@ -138,17 +132,17 @@ implementation
 
        async command uint8_t UniqueConfig.getSequenceNumber(message_t* msg)
        {
-               return call IEEE154Packet2.getDSN(msg);
+               return call IEEE154MessageLayer.getDSN(msg);
        }
 
        async command void UniqueConfig.setSequenceNumber(message_t* msg, uint8_t dsn)
        {
-               call IEEE154Packet2.setDSN(msg, dsn);
+               call IEEE154MessageLayer.setDSN(msg, dsn);
        }
 
        async command am_addr_t UniqueConfig.getSender(message_t* msg)
        {
-               return call IEEE154Packet2.getSrcAddr(msg);
+               return call IEEE154MessageLayer.getSrcAddr(msg);
        }
 
        tasklet_async command void UniqueConfig.reportChannelError()
@@ -158,20 +152,46 @@ implementation
 
 /*----------------- ActiveMessageConfig -----------------*/
 
-       command error_t ActiveMessageConfig.checkPacket(message_t* msg)
+       command bool ActiveMessageConfig.forgotToClear(message_t* msg)
+       {
+               return ! call IEEE154MessageLayer.isDataFrame(msg);
+       }
+
+       command am_addr_t ActiveMessageConfig.destination(message_t* msg)
+       {
+               return call IEEE154MessageLayer.getDestAddr(msg);
+       }
+
+       command void ActiveMessageConfig.setDestination(message_t* msg, am_addr_t addr)
        {
-               // the user forgot to call clear, we should return EINVAL
-               if( ! call IEEE154Packet2.isDataFrame(msg) )
-                       call Packet.clear(msg);
+               call IEEE154MessageLayer.setDestAddr(msg, addr);
+       }
+
+       command am_addr_t ActiveMessageConfig.source(message_t* msg)
+       {
+               return call IEEE154MessageLayer.getSrcAddr(msg);
+       }
+
+       command void ActiveMessageConfig.setSource(message_t* msg, am_addr_t addr)
+       {
+               call IEEE154MessageLayer.setSrcAddr(msg, addr);
+       }
+
+       command am_group_t ActiveMessageConfig.group(message_t* msg)
+       {
+               return call IEEE154MessageLayer.getDestPan(msg);
+       }
 
-               return SUCCESS;
+       command void ActiveMessageConfig.setGroup(message_t* msg, am_group_t grp)
+       {
+               call IEEE154MessageLayer.setDestPan(msg, grp);
        }
 
 /*----------------- CsmaConfig -----------------*/
 
        async command bool CsmaConfig.requiresSoftwareCCA(message_t* msg)
        {
-               return call IEEE154Packet2.isDataFrame(msg);
+               return call IEEE154MessageLayer.isDataFrame(msg);
        }
 
 /*----------------- TrafficMonitorConfig -----------------*/
@@ -196,13 +216,13 @@ implementation
                 * ack required: 8-16 byte separation, 11 bytes airtime, 5-10 bytes separation
                 */
 
-               uint8_t len = call IEEE154Packet2.getLength(msg);
-               return call IEEE154Packet2.getAckRequired(msg) ? len + 6 + 16 + 11 + 10 : len + 6 + 10;
+               uint8_t len = call RF230Packet.payloadLength(msg);
+               return call IEEE154MessageLayer.getAckRequired(msg) ? len + 6 + 16 + 11 + 10 : len + 6 + 10;
        }
 
        async command am_addr_t TrafficMonitorConfig.getSender(message_t* msg)
        {
-               return call IEEE154Packet2.getSrcAddr(msg);
+               return call IEEE154MessageLayer.getSrcAddr(msg);
        }
 
        tasklet_async command void TrafficMonitorConfig.timerTick()
@@ -244,7 +264,7 @@ implementation
                time = call RadioAlarm.getNow();
 
                // estimated response time (download the message, etc) is 5-8 bytes
-               if( call IEEE154Packet2.requiresAckReply(msg) )
+               if( call IEEE154MessageLayer.requiresAckReply(msg) )
                        time += (uint16_t)(32 * (-5 + 16 + 11 + 5) * RADIO_ALARM_MICROSEC);
                else
                        time += (uint16_t)(32 * (-5 + 5) * RADIO_ALARM_MICROSEC);
@@ -252,7 +272,9 @@ implementation
                return time;
        }
 
-       tasklet_async event void RadioAlarm.fired()     { }
+       tasklet_async event void RadioAlarm.fired()
+       {
+       }
 
 /*----------------- SlottedCollisionConfig -----------------*/
 
@@ -269,13 +291,13 @@ implementation
        async command uint16_t SlottedCollisionConfig.getTransmitTime(message_t* msg)
        {
                // TODO: check if the timestamp is correct
-               return getMeta(msg)->timestamp;
+               return call PacketTimeStamp.timestamp(msg);
        }
 
        async command uint16_t SlottedCollisionConfig.getCollisionWindowStart(message_t* msg)
        {
                // the preamble (4 bytes), SFD (1 byte), plus two extra for safety
-               return getMeta(msg)->timestamp - (uint16_t)(7 * 32 * RADIO_ALARM_MICROSEC);
+               return (call PacketTimeStamp.timestamp(msg)) - (uint16_t)(7 * 32 * RADIO_ALARM_MICROSEC);
        }
 
        async command uint16_t SlottedCollisionConfig.getCollisionWindowLength(message_t* msg)
@@ -290,4 +312,16 @@ implementation
        async command void DummyConfig.nothing()
        {
        }
+
+/*----------------- LowPowerListening -----------------*/
+
+#ifdef LOW_POWER_LISTENING
+
+       async command bool LowPowerListeningConfig.getAckRequired(message_t* msg)
+       {
+               return call IEEE154MessageLayer.getAckRequired(msg);
+       }
+
+#endif
+
 }