]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Fix fan-out warnings due to changes in CC2420 radio stack
authorliang_mike <liang_mike>
Wed, 28 Oct 2009 05:29:02 +0000 (05:29 +0000)
committerliang_mike <liang_mike>
Wed, 28 Oct 2009 05:29:02 +0000 (05:29 +0000)
tos/lib/tosthreads/chips/cc2420/CC2420ActiveMessageC.nc
tos/lib/tosthreads/chips/cc2420/CC2420ActiveMessageP.nc

index ccbccfb11862eaba6c6203a52f9e7836ed6c911d..1c45d6bca349b07058e14eca1867591f7113ffd9 100644 (file)
 
 #include "CC2420.h"
 #include "AM.h"
+#include "Ieee154.h"
+
+#ifdef IEEE154FRAMES_ENABLED
+#error "CC2420 AM layer cannot work when IEEE 802.15.4 frames only are used"
+#endif
 
 configuration CC2420ActiveMessageC {
   provides {
@@ -57,29 +62,18 @@ configuration CC2420ActiveMessageC {
   }
 }
 implementation {
+  enum {
+    CC2420_AM_SEND_ID     = unique(IEEE154_SEND_CLIENT),
+  };
 
+  components CC2420RadioC as Radio;
   components CC2420ActiveMessageP as AM;
-  components CC2420CsmaC as CsmaC;
   components ActiveMessageAddressC;
-  components UniqueSendC;
-  components UniqueReceiveC;
-  components CC2420TinyosNetworkC;
-  components CC2420PacketC;
+  components CC2420CsmaC as CsmaC;
   components CC2420ControlC;
+  components CC2420PacketC;
   
-#if defined(LOW_POWER_LISTENING) || defined(ACK_LOW_POWER_LISTENING)
-  components DefaultLplC as LplC;
-#else
-  components DummyLplC as LplC;
-#endif
-
-#if defined(PACKET_LINK)
-  components PacketLinkC as LinkC;
-#else
-  components PacketLinkDummyC as LinkC;
-#endif
-
-  
+  SplitControl = Radio;
   RadioBackoff = AM;
   Packet = AM;
   AMSend = AM;
@@ -89,28 +83,16 @@ implementation {
   Snoop = AM.Snoop;
   SnoopDefault = AM.SnoopDefault;
   AMPacket = AM;
-  PacketLink = LinkC;
-  LowPowerListening = LplC;
-  CC2420Packet = CC2420PacketC;
-  PacketAcknowledgements = CC2420PacketC;
-  LinkPacketMetadata = CC2420PacketC;
-  
-  // SplitControl Layers
-  SplitControl = LplC;
-  LplC.SubControl -> CsmaC;
-  
-  // Send Layers
-  AM.SubSend -> UniqueSendC;
-  UniqueSendC.SubSend -> LinkC;
-  LinkC.SubSend -> LplC.Send;
-  LplC.SubSend -> CC2420TinyosNetworkC.Send;
-  CC2420TinyosNetworkC.SubSend -> CsmaC;
+  PacketLink = Radio;
+  LowPowerListening = Radio;
+  CC2420Packet = Radio;
+  PacketAcknowledgements = Radio;
+  LinkPacketMetadata = Radio;
   
-  // Receive Layers
-  AM.SubReceive -> LplC;
-  LplC.SubReceive -> UniqueReceiveC.Receive;
-  UniqueReceiveC.SubReceive -> CC2420TinyosNetworkC.Receive;
-  CC2420TinyosNetworkC.SubReceive -> CsmaC;
+  // Radio resource for the AM layer
+  AM.RadioResource -> Radio.Resource[CC2420_AM_SEND_ID];
+  AM.SubSend -> Radio.ActiveSend;
+  AM.SubReceive -> Radio.ActiveReceive;
 
   AM.ActiveMessageAddress -> ActiveMessageAddressC;
   AM.CC2420Packet -> CC2420PacketC;
@@ -118,5 +100,9 @@ implementation {
   AM.CC2420Config -> CC2420ControlC;
   
   AM.SubBackoff -> CsmaC;
-  
+
+  components LedsC;
+  AM.Leds -> LedsC;
 }
+
+
index 89ca391e9ea7172ebf6d80ff8cc17cc5f11aa72e..36ee724f2d9bfb9cdb206e2bfc4e1309257e52ca 100644 (file)
@@ -55,23 +55,57 @@ module CC2420ActiveMessageP @safe() {
     interface CC2420Config;
     interface ActiveMessageAddress;
     interface RadioBackoff as SubBackoff;
+
+    interface Resource as RadioResource;
+    interface Leds;
   }
 }
 implementation {
+  uint16_t pending_length;
+  message_t *pending_message = NULL;
+  /***************** Resource event  ****************/
+  event void RadioResource.granted() {
+    uint8_t rc;
+    cc2420_header_t* header = call CC2420PacketBody.getHeader( pending_message );
+
+    signal SendNotifier.aboutToSend[header->type](header->dest, pending_message);
+    rc = call SubSend.send( pending_message, pending_length );
+    if (rc != SUCCESS) {
+      call RadioResource.release();
+      signal AMSend.sendDone[header->type]( pending_message, rc );
+    }
+  }
 
   /***************** AMSend Commands ****************/
   command error_t AMSend.send[am_id_t id](am_addr_t addr,
                                          message_t* msg,
                                          uint8_t len) {
     cc2420_header_t* header = call CC2420PacketBody.getHeader( msg );
+    
+    if (len > call Packet.maxPayloadLength()) {
+      return ESIZE;
+    }
+    
     header->type = id;
     header->dest = addr;
     header->destpan = call CC2420Config.getPanAddr();
     header->src = call AMPacket.address();
     
-    signal SendNotifier.aboutToSend[id](addr, msg);
-    
-    return call SubSend.send( msg, len );
+    if (call RadioResource.immediateRequest() == SUCCESS) {
+      error_t rc;
+      signal SendNotifier.aboutToSend[id](addr, msg);
+      
+      rc = call SubSend.send( msg, len );
+      if (rc != SUCCESS) {
+        call RadioResource.release();
+      }
+
+      return rc;
+    } else {
+      pending_length  = len;
+      pending_message = msg;
+      return call RadioResource.request();
+    }
   }
 
   command error_t AMSend.cancel[am_id_t id](message_t* msg) {
@@ -155,7 +189,7 @@ implementation {
   }
   
   command uint8_t Packet.maxPayloadLength() {
-    return TOSH_DATA_LENGTH;
+    return call SubSend.maxPayloadLength();
   }
   
   command void* Packet.getPayload(message_t* msg, uint8_t len) {
@@ -165,6 +199,7 @@ implementation {
   
   /***************** SubSend Events ****************/
   event void SubSend.sendDone(message_t* msg, error_t result) {
+    call RadioResource.release();
     signal AMSend.sendDone[call AMPacket.type(msg)](msg, result);
   }
 
@@ -172,10 +207,6 @@ implementation {
   /***************** SubReceive Events ****************/
   event message_t* SubReceive.receive(message_t* msg, void* payload, uint8_t len) {
     
-    if(!(call CC2420PacketBody.getMetadata(msg))->crc) {
-      return msg;
-    }
-    
     if (call AMPacket.isForMe(msg)) {
       return signal Receive.receive[call AMPacket.type(msg)](msg, payload, len);
     }
@@ -232,8 +263,6 @@ implementation {
   async command void RadioBackoff.setCca[am_id_t amId](bool useCca) {
     call SubBackoff.setCca(useCca);
   }
-
-
   
   /***************** Defaults ****************/
   default event message_t* Receive.receive[am_id_t id](message_t* msg, void* payload, uint8_t len) {
@@ -251,13 +280,13 @@ implementation {
   default event message_t* SnoopDefault.receive[am_id_t id](message_t* msg, void* payload, uint8_t len) {
     return msg;
   }
-  
+
   default event void AMSend.sendDone[uint8_t id](message_t* msg, error_t err) {
+    call RadioResource.release();
   }
 
   default event void SendNotifier.aboutToSend[am_id_t amId](am_addr_t addr, message_t *msg) {
   }
-  
   default async event void RadioBackoff.requestInitialBackoff[am_id_t id](
       message_t *msg) {
   }