From 80cfb0a4f848228be947dab0b14af67e07f085ad Mon Sep 17 00:00:00 2001 From: mmaroti Date: Sat, 29 Mar 2008 20:10:33 +0000 Subject: [PATCH] fixing TimeSyncMessage for the IRIS --- tos/chips/rf230/DefaultMacC.nc | 5 ++ tos/chips/rf230/DefaultMacP.nc | 1 - tos/chips/rf230/DefaultPacket.h | 5 +- tos/chips/rf230/DefaultPacketC.nc | 8 ++- tos/chips/rf230/DefaultPacketP.nc | 30 +++++++++++ tos/chips/rf230/PacketLastTouch.nc | 5 ++ tos/chips/rf230/PacketTimeSynch.nc | 59 --------------------- tos/chips/rf230/RF230Config.nc | 4 +- tos/chips/rf230/RF230LayerC.nc | 4 ++ tos/chips/rf230/RF230LayerP.nc | 24 ++++++++- tos/chips/rf230/TimeSyncMessageC.nc | 7 ++- tos/chips/rf230/TimeSyncMessageP.nc | 7 +-- tos/platforms/iris/ActiveMessageC.nc | 2 + tos/platforms/iris/chips/rf230/HplRF230C.nc | 9 ---- 14 files changed, 90 insertions(+), 80 deletions(-) delete mode 100644 tos/chips/rf230/PacketTimeSynch.nc diff --git a/tos/chips/rf230/DefaultMacC.nc b/tos/chips/rf230/DefaultMacC.nc index 2143adc3..9db81a0d 100644 --- a/tos/chips/rf230/DefaultMacC.nc +++ b/tos/chips/rf230/DefaultMacC.nc @@ -39,6 +39,8 @@ configuration DefaultMacC interface PacketField as PacketLinkQuality; interface PacketTimeStamp; + + interface PacketLastTouch; } } @@ -60,6 +62,9 @@ implementation PacketLinkQuality = DefaultPacketC.PacketLinkQuality; PacketTimeStamp = DefaultPacketC.PacketTimeStamp; + PacketLastTouch = DefaultPacketC; + RF230LayerC.lastTouch -> DefaultPacketC.lastTouch; + components ActiveMessageLayerC; components MessageBufferLayerC; components UniqueLayerC; diff --git a/tos/chips/rf230/DefaultMacP.nc b/tos/chips/rf230/DefaultMacP.nc index 1ab43da4..ddd131fb 100644 --- a/tos/chips/rf230/DefaultMacP.nc +++ b/tos/chips/rf230/DefaultMacP.nc @@ -295,5 +295,4 @@ implementation async command void DummyConfig.nothing() { } - } diff --git a/tos/chips/rf230/DefaultPacket.h b/tos/chips/rf230/DefaultPacket.h index 65ab1fe5..ff29c0e8 100644 --- a/tos/chips/rf230/DefaultPacket.h +++ b/tos/chips/rf230/DefaultPacket.h @@ -43,8 +43,9 @@ typedef nx_struct defpacket_metadata_t enum defpacket_metadata_flags { - DEFPACKET_WAS_ACKED = 0x01, - DEFPACKET_TIMESTAMP = 0x02, + DEFPACKET_WAS_ACKED = 0x01, // PacketAcknowledgements + DEFPACKET_TIMESTAMP = 0x02, // PacketTimeStamp + DEFPACKET_LAST_TOUCH = 0x04, // PacketLastTouch.touch DEFPACKET_CLEAR_METADATA = 0x00, }; diff --git a/tos/chips/rf230/DefaultPacketC.nc b/tos/chips/rf230/DefaultPacketC.nc index 3c32ee33..1658139d 100644 --- a/tos/chips/rf230/DefaultPacketC.nc +++ b/tos/chips/rf230/DefaultPacketC.nc @@ -34,6 +34,9 @@ configuration DefaultPacketC interface PacketField as PacketTransmitPower; interface PacketTimeStamp; + interface PacketLastTouch; + + async event void lastTouch(message_t* msg); } } @@ -48,5 +51,8 @@ implementation PacketAcknowledgements = DefaultPacketP; PacketLinkQuality = DefaultPacketP.PacketLinkQuality; PacketTransmitPower = DefaultPacketP.PacketTransmitPower; - PacketTimeStamp = DefaultPacketP.PacketTimeStamp; + PacketTimeStamp = DefaultPacketP; + + PacketLastTouch = DefaultPacketP; + lastTouch = DefaultPacketP; } diff --git a/tos/chips/rf230/DefaultPacketP.nc b/tos/chips/rf230/DefaultPacketP.nc index a0cb16f3..577ff252 100644 --- a/tos/chips/rf230/DefaultPacketP.nc +++ b/tos/chips/rf230/DefaultPacketP.nc @@ -33,6 +33,9 @@ module DefaultPacketP interface PacketField as PacketTransmitPower; interface PacketTimeStamp; + interface PacketLastTouch; + + async event void lastTouch(message_t* msg); } uses @@ -190,4 +193,31 @@ implementation flags |= FLAG_TXPOWER; transmitPower = value; } + +/*----------------- PacketLastTouch -----------------*/ + + async command void PacketLastTouch.request(message_t* msg) + { + getMeta(msg)->flags |= DEFPACKET_LAST_TOUCH; + } + + async command void PacketLastTouch.cancel(message_t* msg) + { + getMeta(msg)->flags &= ~DEFPACKET_LAST_TOUCH; + } + + async command bool PacketLastTouch.isPending(message_t* msg) + { + return getMeta(msg)->flags & DEFPACKET_LAST_TOUCH; + } + + async event void lastTouch(message_t* msg) + { + if( getMeta(msg)->flags & DEFPACKET_LAST_TOUCH ) + signal PacketLastTouch.touch(msg); + } + + default async event void PacketLastTouch.touch(message_t* msg) + { + } } diff --git a/tos/chips/rf230/PacketLastTouch.nc b/tos/chips/rf230/PacketLastTouch.nc index af51caf7..a090bcc9 100644 --- a/tos/chips/rf230/PacketLastTouch.nc +++ b/tos/chips/rf230/PacketLastTouch.nc @@ -34,6 +34,11 @@ interface PacketLastTouch */ async command void cancel(message_t* msg); + /** + * Returns TRUE if the touch callback is already scheduled. + */ + async command bool isPending(message_t* msg); + /** * This event is called by the MAC layer when the tranmission of the * message starts (the SFD byte is already transmitted and the packet diff --git a/tos/chips/rf230/PacketTimeSynch.nc b/tos/chips/rf230/PacketTimeSynch.nc deleted file mode 100644 index 42ff676e..00000000 --- a/tos/chips/rf230/PacketTimeSynch.nc +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 PacketTimeSynch -{ - /** - * The recveiver should call this method to ensure that the received - * message contains an embedded timestamp and that is correct (for the - * same reason as for PacketTimeStamp.isSet). If this method returns - * TRUE, then the eventTime returned by the get command is correct, - * and reflects the event time in the local clock of the receiver. - */ - async command bool isSet(message_t* msg); - - /** - * This command should be called by the receiver. The time stamp of the - * received message is added to the embedded time difference to get the - * eventTime as measured by the clock of the receiver. The caller should - * call the isSet command before to make sure that the returned time is - * correct. - */ - async command size_type get(message_t* msg); - - /** - * Clears the time stamp in the message. - */ - async command void clear(message_t* msg); - - /** - * This command should be called by the sender on packets used for sender- - * receiver time synchronization. The eventTime parameter should be as - * close to the current time as possible (precision and size of the stamp - * permitting) to avoid large time synchronization errors resulting from - * the time skew between the clocks of the sender and receiver. The - * time difference between the sending time and eventTime is stored in - * the message just before it is transmitted over the air. - */ - async command void set(message_t* msg, size_type eventTime); -} diff --git a/tos/chips/rf230/RF230Config.nc b/tos/chips/rf230/RF230Config.nc index 9f5f044c..0bd2e409 100644 --- a/tos/chips/rf230/RF230Config.nc +++ b/tos/chips/rf230/RF230Config.nc @@ -48,7 +48,9 @@ interface RF230Config /** * Gets the number of bytes we should read before the RadioReceive.header * event is fired. If the length of the packet is less than this amount, - * then that event is fired earlier. + * then that event is fired earlier. The last touch event is not signaled + * for packets whose length is less than or equal to this header length. + * The header length must be at least 1. */ async command uint8_t getHeaderLength(); diff --git a/tos/chips/rf230/RF230LayerC.nc b/tos/chips/rf230/RF230LayerC.nc index 7e12df94..3cd59d8a 100644 --- a/tos/chips/rf230/RF230LayerC.nc +++ b/tos/chips/rf230/RF230LayerC.nc @@ -37,6 +37,8 @@ configuration RF230LayerC interface PacketField as PacketLinkQuality; interface PacketField as PacketTransmitPower; interface PacketTimeStamp; + + async event void lastTouch(message_t* msg); } } @@ -69,6 +71,8 @@ implementation RF230LayerP.Tasklet -> TaskletC; RF230LayerP.BusyWait -> BusyWaitMicroC; + lastTouch = RF230LayerP.lastTouch; + #ifdef RF230_DEBUG components DiagMsgC; RF230LayerP.DiagMsg -> DiagMsgC; diff --git a/tos/chips/rf230/RF230LayerP.nc b/tos/chips/rf230/RF230LayerP.nc index 2796fd4e..153b9ee1 100644 --- a/tos/chips/rf230/RF230LayerP.nc +++ b/tos/chips/rf230/RF230LayerP.nc @@ -61,6 +61,8 @@ module RF230LayerP interface Tasklet; interface RadioAlarm; + async event void lastTouch(message_t* msg); + #ifdef RF230_DEBUG interface DiagMsg; #endif @@ -380,6 +382,7 @@ implementation uint16_t time; uint8_t length; uint8_t* data; + uint8_t header; if( cmd != CMD_NONE || state != STATE_RX_ON || ! isSpiAcquired() || radioIrq ) return EBUSY; @@ -427,9 +430,24 @@ implementation // length | data[0] ... data[length-3] | automatically generated FCS call HplRF230.spiSplitReadWrite(length); - // the FCS is atomatically generated + // the FCS is atomatically generated (2 bytes) length -= 2; + header = call RF230Config.getHeaderLength(); + if( header > length ) + header = length; + + length -= header; + + // first upload the header + do { + call HplRF230.spiSplitReadWrite(*(data++)); + } + while( --header != 0 ); + + call PacketTimeStamp.set(msg, time); + signal lastTouch(msg); + do { call HplRF230.spiSplitReadWrite(*(data++)); } @@ -537,8 +555,10 @@ implementation length -= read; - while( read-- != 0 ) + do { crc = call HplRF230.crcByte(crc, *(data++) = call HplRF230.spiSplitReadWrite(0)); + } + while( --read != 0 ); if( signal RadioReceive.header(rxMsg) ) { diff --git a/tos/chips/rf230/TimeSyncMessageC.nc b/tos/chips/rf230/TimeSyncMessageC.nc index 5876b0cf..79ad0867 100644 --- a/tos/chips/rf230/TimeSyncMessageC.nc +++ b/tos/chips/rf230/TimeSyncMessageC.nc @@ -30,7 +30,7 @@ configuration TimeSyncMessageC { interface TimeSyncSend as TimeSyncSendMicro[am_id_t id]; interface TimeSyncPacket as TimeSyncPacketMicro; - interface LocalTime as LocalTimeMicro; +// interface LocalTime as LocalTimeMicro; interface TimeSyncSend as TimeSyncSendMilli[am_id_t id]; interface TimeSyncPacket as TimeSyncPacketMilli; @@ -51,7 +51,7 @@ implementation TimeSyncSendMicro = TimeSyncMessageP; TimeSyncPacketMicro = TimeSyncMessageP; - LocalTimeMicro = ActiveMessageC; +// LocalTimeMicro = LocalTimeMicroC; TimeSyncSendMilli = TimeSyncMessageP; TimeSyncPacketMilli = TimeSyncMessageP; @@ -60,9 +60,12 @@ implementation Packet = TimeSyncMessageP; TimeSyncMessageP.SubSend -> ActiveMessageC.AMSend; TimeSyncMessageP.SubPacket -> ActiveMessageC.Packet; + TimeSyncMessageP.PacketTimeStamp -> ActiveMessageC; TimeSyncMessageP.LocalTimeMilli -> LocalTimeMilliC; + TimeSyncMessageP.PacketLastTouch -> ActiveMessageC; + SplitControl = ActiveMessageC; Receive = ActiveMessageC.Receive; Snoop = ActiveMessageC.Snoop; diff --git a/tos/chips/rf230/TimeSyncMessageP.nc b/tos/chips/rf230/TimeSyncMessageP.nc index 9a936c80..310a0974 100644 --- a/tos/chips/rf230/TimeSyncMessageP.nc +++ b/tos/chips/rf230/TimeSyncMessageP.nc @@ -38,7 +38,7 @@ module TimeSyncMessageP { interface AMSend as SubSend[uint8_t id]; interface Packet as SubPacket; - interface PacketTimeStamp; + interface PacketTimeStamp; // TODO: change this to 32-bit interface PacketLastTouch; interface LocalTime as LocalTimeMicro; @@ -55,6 +55,7 @@ implementation uint32_t event_time; // in microsec } timesync_local_t; + // TODO: change the Packet.payloadLength and Packet.maxPayloadLength commands to async inline timesync_footer_t* getFooter(message_t* msg) { return (timesync_footer_t*)(msg->data + call SubPacket.payloadLength(msg) - sizeof(timesync_footer_t)); @@ -101,7 +102,7 @@ implementation call PacketLastTouch.request(msg); - return call SubSend.send[id](addr, msg, len); + return call SubSend.send[id](addr, msg, len + sizeof(timesync_footer_t)); } command error_t TimeSyncSendMicro.cancel[am_id_t id](message_t* msg) @@ -137,7 +138,7 @@ implementation call PacketLastTouch.request(msg); - return call SubSend.send[id](addr, msg, len); + return call SubSend.send[id](addr, msg, len + sizeof(timesync_footer_t)); } command error_t TimeSyncSendMilli.cancel[am_id_t id](message_t* msg) diff --git a/tos/platforms/iris/ActiveMessageC.nc b/tos/platforms/iris/ActiveMessageC.nc index 3253e611..eda2370c 100644 --- a/tos/platforms/iris/ActiveMessageC.nc +++ b/tos/platforms/iris/ActiveMessageC.nc @@ -36,6 +36,7 @@ configuration ActiveMessageC interface PacketAcknowledgements; interface PacketField as PacketLinkQuality; interface PacketTimeStamp; + interface PacketLastTouch; } } @@ -53,4 +54,5 @@ implementation PacketAcknowledgements = MAC; PacketLinkQuality = MAC; PacketTimeStamp = MAC; + PacketLastTouch = MAC; } diff --git a/tos/platforms/iris/chips/rf230/HplRF230C.nc b/tos/platforms/iris/chips/rf230/HplRF230C.nc index 65459b40..113d47cd 100644 --- a/tos/platforms/iris/chips/rf230/HplRF230C.nc +++ b/tos/platforms/iris/chips/rf230/HplRF230C.nc @@ -36,7 +36,6 @@ configuration HplRF230C interface GpioCapture as IRQ; interface Alarm as Alarm; - interface LocalTime; interface HplRF230; } @@ -71,12 +70,4 @@ implementation components RealMainP; RealMainP.PlatformInit -> HplRF230P.PlatformInit; - - components CounterOne16C; - components new TransformCounterC(TRF230, uint32_t, TRF230, uint16_t, 0, uint32_t); - components new CounterToLocalTimeC(TRF230); - - LocalTime = CounterToLocalTimeC; - CounterToLocalTimeC.Counter -> TransformCounterC; - TransformCounterC.CounterFrom -> CounterOne16C; } -- 2.39.2