From: liang_mike Date: Sun, 11 Jan 2009 06:04:04 +0000 (+0000) Subject: Make TOSThreads the default for serial receive. This prevents fan-out problem when... X-Git-Tag: rc_6_tinyos_2_1_1~532 X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=commitdiff_plain;h=6aa5152b73e4bfbd5b5e655e10cdb573ce4d4f06 Make TOSThreads the default for serial receive. This prevents fan-out problem when other TinyOS services also want to use serial. --- diff --git a/support/make/threads.extra b/support/make/threads.extra index fc88c98a..50e21d3e 100644 --- a/support/make/threads.extra +++ b/support/make/threads.extra @@ -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 index 00000000..3c88aff4 --- /dev/null +++ b/tos/lib/tosthreads/lib/serial/SerialActiveMessageC.nc @@ -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 index 00000000..e2f8caae --- /dev/null +++ b/tos/lib/tosthreads/lib/serial/SerialActiveMessageP.nc @@ -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 + +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; + } + +} diff --git a/tos/lib/tosthreads/system/BlockingActiveMessageC.nc b/tos/lib/tosthreads/system/BlockingActiveMessageC.nc index f3ab2dcd..26b29ffc 100644 --- a/tos/lib/tosthreads/system/BlockingActiveMessageC.nc +++ b/tos/lib/tosthreads/system/BlockingActiveMessageC.nc @@ -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; diff --git a/tos/lib/tosthreads/system/BlockingSerialActiveMessageC.nc b/tos/lib/tosthreads/system/BlockingSerialActiveMessageC.nc index 82ef08db..69c12ec7 100644 --- a/tos/lib/tosthreads/system/BlockingSerialActiveMessageC.nc +++ b/tos/lib/tosthreads/system/BlockingSerialActiveMessageC.nc @@ -57,7 +57,7 @@ implementation { BlockingAMSend = AMSenderP; BlockingStdControlC.SplitControl -> AM; - AMReceiverP.Receive -> AM.Receive; + AMReceiverP.Receive -> AM.ReceiveDefault; AMSenderP.AMSend -> AM.AMSend; Packet = AM;