]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Make TOSThreads the default for serial receive. This prevents fan-out problem when...
authorliang_mike <liang_mike>
Sun, 11 Jan 2009 06:04:04 +0000 (06:04 +0000)
committerliang_mike <liang_mike>
Sun, 11 Jan 2009 06:04:04 +0000 (06:04 +0000)
support/make/threads.extra
tos/lib/tosthreads/lib/serial/SerialActiveMessageC.nc [new file with mode: 0644]
tos/lib/tosthreads/lib/serial/SerialActiveMessageP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingActiveMessageC.nc
tos/lib/tosthreads/system/BlockingSerialActiveMessageC.nc

index fc88c98a4b854058d7f99bc44ee5db72c9f6b625..50e21d3e95be35dde2edc0671a24ddb1d9b07a6d 100644 (file)
@@ -11,6 +11,7 @@ TOS_THREADS_DIR ?= $(TOSDIR)/lib/tosthreads
 CFLAGS += -I$(TOS_THREADS_DIR)/system
 CFLAGS += -I$(TOS_THREADS_DIR)/interfaces
 CFLAGS += -I$(TOS_THREADS_DIR)/types
+CFLAGS += -I$(TOS_THREADS_DIR)/lib/serial
 
 #Setup the thread scheduler for use by redefining the name of the task scheduler to use
 PFLAGS += -tosscheduler=TinyTaskSchedulerC,TinyTaskSchedulerC.TaskBasic,TaskBasic,TaskBasic,runTask,postTask
diff --git a/tos/lib/tosthreads/lib/serial/SerialActiveMessageC.nc b/tos/lib/tosthreads/lib/serial/SerialActiveMessageC.nc
new file mode 100644 (file)
index 0000000..3c88aff
--- /dev/null
@@ -0,0 +1,64 @@
+//$Id$
+
+/* "Copyright (c) 2000-2005 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."
+ */
+
+/**
+ * Sending active messages over the serial port.
+ *
+ * @author Philip Levis
+ * @author Ben Greenstein
+ * @date August 7 2005
+ *
+ */
+
+#include "Serial.h"
+configuration SerialActiveMessageC {
+  provides {
+    interface SplitControl;
+    interface AMSend[am_id_t id];
+    interface Receive as ReceiveDefault[am_id_t id];
+    interface Receive[am_id_t id];
+    interface Packet;
+    interface AMPacket;
+    interface PacketAcknowledgements;
+  }
+  uses interface Leds;
+}
+implementation {
+  components new SerialActiveMessageP() as AM, SerialDispatcherC;
+  components SerialPacketInfoActiveMessageP as Info, MainC;
+
+  MainC.SoftwareInit -> SerialDispatcherC;
+  Leds = SerialDispatcherC;
+  SplitControl = SerialDispatcherC;
+  
+  AMSend = AM;
+  Receive = AM.Receive;
+  ReceiveDefault = AM.ReceiveDefault;
+  Packet = AM;
+  AMPacket = AM;
+  PacketAcknowledgements = AM;
+  
+  AM.SubSend -> SerialDispatcherC.Send[TOS_SERIAL_ACTIVE_MESSAGE_ID];
+  AM.SubReceive -> SerialDispatcherC.Receive[TOS_SERIAL_ACTIVE_MESSAGE_ID];
+  
+  SerialDispatcherC.SerialPacketInfo[TOS_SERIAL_ACTIVE_MESSAGE_ID] -> Info;
+}
diff --git a/tos/lib/tosthreads/lib/serial/SerialActiveMessageP.nc b/tos/lib/tosthreads/lib/serial/SerialActiveMessageP.nc
new file mode 100644 (file)
index 0000000..e2f8caa
--- /dev/null
@@ -0,0 +1,197 @@
+//$Id$
+
+/* "Copyright (c) 2000-2005 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."
+ */
+
+/**
+ * Sending active messages over the serial port.
+ *
+ * @author Philip Levis
+ * @author Ben Greenstein
+ * @date August 7 2005
+ *
+ */
+
+#include <Serial.h>
+
+generic module SerialActiveMessageP () {
+  provides {
+    interface AMSend[am_id_t id];
+    interface Receive[am_id_t id];
+    interface Receive as ReceiveDefault[am_id_t id];
+    interface AMPacket;
+    interface Packet;
+    interface PacketAcknowledgements;
+  }
+  uses {
+    interface Send as SubSend;
+    interface Receive as SubReceive;
+  }
+}
+implementation {
+
+  serial_header_t* ONE getHeader(message_t* ONE msg) {
+    return TCAST(serial_header_t* ONE, (uint8_t*)msg + offsetof(message_t, data) - sizeof(serial_header_t));
+  }
+
+  serial_metadata_t* getMetadata(message_t* msg) {
+    return (serial_metadata_t*)(msg->metadata);
+  }
+  
+  command error_t AMSend.send[am_id_t id](am_addr_t dest,
+                                         message_t* msg,
+                                         uint8_t len) {
+    serial_header_t* header = getHeader(msg);
+    header->dest = dest;
+    // Do not set the source address or group, as doing so
+    // prevents transparent bridging. Need a better long-term
+    // solution for this.
+    //header->src = call AMPacket.address();
+    //header->group = TOS_AM_GROUP;
+    header->type = id;
+    header->length = len;
+
+    return call SubSend.send(msg, len);
+  }
+
+  command error_t AMSend.cancel[am_id_t id](message_t* msg) {
+    return call SubSend.cancel(msg);
+  }
+
+  command uint8_t AMSend.maxPayloadLength[am_id_t id]() {
+    return call Packet.maxPayloadLength();
+  }
+
+  command void* AMSend.getPayload[am_id_t id](message_t* m, uint8_t len) {
+    return call Packet.getPayload(m, len);
+  }
+  
+  event void SubSend.sendDone(message_t* msg, error_t result) {
+    signal AMSend.sendDone[call AMPacket.type(msg)](msg, result);
+  }
+
+  default event void AMSend.sendDone[uint8_t id](message_t* msg, error_t result) {
+    return;
+  }
+  
+  default event message_t* Receive.receive[uint8_t id](message_t* msg, void* payload, uint8_t len) {
+    return signal ReceiveDefault.receive[id](msg, payload, len);
+  }
+  default event message_t* ReceiveDefault.receive[am_id_t id](message_t* msg, void* payload, uint8_t len) {
+    return msg;
+  }
+  event message_t* SubReceive.receive(message_t* msg, void* payload, uint8_t len) {
+    return signal Receive.receive[call AMPacket.type(msg)](msg, msg->data, len);
+  }
+
+  command void Packet.clear(message_t* msg) {
+    memset(getHeader(msg), 0, sizeof(serial_header_t));
+    return;
+  }
+
+  command uint8_t Packet.payloadLength(message_t* msg) {
+    serial_header_t* header = getHeader(msg);    
+    return header->length;
+  }
+
+  command void Packet.setPayloadLength(message_t* msg, uint8_t len) {
+    getHeader(msg)->length  = len;
+  }
+  
+  command uint8_t Packet.maxPayloadLength() {
+    return TOSH_DATA_LENGTH;
+  }
+  
+  command void* Packet.getPayload(message_t* msg, uint8_t len) {
+    if (len > call Packet.maxPayloadLength()) {
+      return NULL;
+    }
+    else {
+      return (void * COUNT_NOK(len))msg->data;
+    }
+  }
+
+  command am_addr_t AMPacket.address() {
+    return 0;
+  }
+
+  command am_addr_t AMPacket.destination(message_t* amsg) {
+    serial_header_t* header = getHeader(amsg);
+    return header->dest;
+  }
+
+  command am_addr_t AMPacket.source(message_t* amsg) {
+    serial_header_t* header = getHeader(amsg);
+    return header->src;
+  }
+
+  command void AMPacket.setDestination(message_t* amsg, am_addr_t addr) {
+    serial_header_t* header = getHeader(amsg);
+    header->dest = addr;
+  }
+
+  command void AMPacket.setSource(message_t* amsg, am_addr_t addr) {
+    serial_header_t* header = getHeader(amsg);
+    header->src = addr;
+  }
+  
+  command bool AMPacket.isForMe(message_t* amsg) {
+    return TRUE;
+  }
+
+  command am_id_t AMPacket.type(message_t* amsg) {
+    serial_header_t* header = getHeader(amsg);
+    return header->type;
+  }
+
+  command void AMPacket.setType(message_t* amsg, am_id_t type) {
+    serial_header_t* header = getHeader(amsg);
+    header->type = type;
+  }
+
+  async command error_t PacketAcknowledgements.requestAck( message_t* msg ) {
+    return FAIL;
+  }
+  async command error_t PacketAcknowledgements.noAck( message_t* msg ) {
+    return SUCCESS;
+  }
+  
+  command void AMPacket.setGroup(message_t* msg, am_group_t group) {
+    serial_header_t* header = getHeader(msg);
+    header->group = group;
+  }
+
+  command am_group_t AMPacket.group(message_t* msg) {
+    serial_header_t* header = getHeader(msg);
+    return header->group;
+  }
+
+  command am_group_t AMPacket.localGroup() {
+    return TOS_AM_GROUP;
+  }
+
+  async command bool PacketAcknowledgements.wasAcked(message_t* msg) {
+    return FALSE;
+  }
+
+}
index f3ab2dcdfc4f3c7cc8cb06d18f01fcc70b88bb75..26b29ffce28164885301d6d192c70a8f0570d368 100644 (file)
@@ -61,8 +61,8 @@ implementation {
   BlockingAMSend = AMSenderP;
   
   BlockingStdControlC.SplitControl -> AM;
-  AMReceiverP.Receive -> AM.Receive;
-  AMSnooperP.Snoop -> AM.Snoop;
+  AMReceiverP.Receive -> AM.ReceiveDefault;
+  AMSnooperP.Snoop -> AM.SnoopDefault;
   AMSenderP.AMSend -> AM.AMSend;
     
   Packet       = AM;
index 82ef08db204e1ece1ef2691ac2dc3e3acee7bab2..69c12ec77ead8051d57367e40ee8563c3aecacb6 100644 (file)
@@ -57,7 +57,7 @@ implementation {
   BlockingAMSend = AMSenderP;
   
   BlockingStdControlC.SplitControl -> AM;
-  AMReceiverP.Receive -> AM.Receive;
+  AMReceiverP.Receive -> AM.ReceiveDefault;
   AMSenderP.AMSend -> AM.AMSend;
     
   Packet       = AM;