From: mmaroti Date: Tue, 7 Apr 2009 02:27:43 +0000 (+0000) Subject: reorganized packet header handling, added RF212Ieee154MessageC for BLIP X-Git-Tag: rc_6_tinyos_2_1_1~429 X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=commitdiff_plain;h=97e9cb5f12a8fcdd7537ddd0eec19ffe364af663 reorganized packet header handling, added RF212Ieee154MessageC for BLIP --- diff --git a/tos/chips/rf2xx/layers/ActiveMessageConfig.nc b/tos/chips/rf2xx/layers/ActiveMessageConfig.nc index d3dadd42..d9665af2 100755 --- a/tos/chips/rf2xx/layers/ActiveMessageConfig.nc +++ b/tos/chips/rf2xx/layers/ActiveMessageConfig.nc @@ -27,15 +27,10 @@ interface ActiveMessageConfig { /** * This command is called when the message first enters the radio stack - * via the Send.send command. This should clear the packet if the user - * forgot to do so (or return EINVAL to be strict). + * via the Send.send command. This command should return TRUE if the + * packet is deffinitely not cleared, FALSE otherwise. */ - command error_t checkPacket(message_t* msg); - - /** - * Returns a pointer to the ActiveMessage header field in the message - */ - command activemessage_header_t* getHeader(message_t* msg); + command bool forgotToClear(message_t* msg); /** Same as AMPacket.destination */ command am_addr_t destination(message_t* msg); diff --git a/tos/chips/rf2xx/layers/ActiveMessageLayerC.nc b/tos/chips/rf2xx/layers/ActiveMessageLayerC.nc index 055aaa72..5cc4afe6 100755 --- a/tos/chips/rf2xx/layers/ActiveMessageLayerC.nc +++ b/tos/chips/rf2xx/layers/ActiveMessageLayerC.nc @@ -21,13 +21,13 @@ * Author: Miklos Maroti */ -#include - configuration ActiveMessageLayerC { provides { + interface RadioPacket; interface AMPacket; + interface Packet; interface AMSend[am_id_t id]; interface Receive[am_id_t id]; interface Receive as Snoop[am_id_t id]; @@ -35,6 +35,7 @@ configuration ActiveMessageLayerC uses { + interface RadioPacket as SubPacket; interface Send as SubSend; interface Receive as SubReceive; interface ActiveMessageConfig as Config; @@ -46,11 +47,14 @@ implementation components ActiveMessageLayerP, ActiveMessageAddressC; ActiveMessageLayerP.ActiveMessageAddress -> ActiveMessageAddressC; + RadioPacket = ActiveMessageLayerP; AMPacket = ActiveMessageLayerP; + Packet = ActiveMessageLayerP; AMSend = ActiveMessageLayerP; Receive = ActiveMessageLayerP.Receive; Snoop = ActiveMessageLayerP.Snoop; + SubPacket = ActiveMessageLayerP; SubSend = ActiveMessageLayerP; SubReceive = ActiveMessageLayerP; Config = ActiveMessageLayerP; diff --git a/tos/chips/rf2xx/layers/ActiveMessageLayerP.nc b/tos/chips/rf2xx/layers/ActiveMessageLayerP.nc index 90406a94..c37c2bb8 100644 --- a/tos/chips/rf2xx/layers/ActiveMessageLayerP.nc +++ b/tos/chips/rf2xx/layers/ActiveMessageLayerP.nc @@ -21,11 +21,15 @@ * Author: Miklos Maroti */ +#include + module ActiveMessageLayerP { provides { + interface RadioPacket; interface AMPacket; + interface Packet; interface AMSend[am_id_t id]; interface Receive[am_id_t id]; interface Receive as Snoop[am_id_t id]; @@ -33,6 +37,7 @@ module ActiveMessageLayerP uses { + interface RadioPacket as SubPacket; interface Send as SubSend; interface Receive as SubReceive; interface ActiveMessageConfig as Config; @@ -42,15 +47,21 @@ module ActiveMessageLayerP implementation { + + activemessage_header_t* getHeader(message_t* msg) + { + return ((void*)msg) + call SubPacket.headerLength(msg); + } + /*----------------- Send -----------------*/ command error_t AMSend.send[am_id_t id](am_addr_t addr, message_t* msg, uint8_t len) { - error_t error; - - error = call Config.checkPacket(msg); - if( error != SUCCESS ) - return error; + if( call Config.forgotToClear(msg) ) + { + // return FAIL; + call Packet.clear(msg); + } call AMPacket.setSource(msg, call AMPacket.address()); call AMPacket.setGroup(msg, call AMPacket.localGroup()); @@ -147,12 +158,12 @@ implementation inline command am_id_t AMPacket.type(message_t* msg) { - return (call Config.getHeader(msg))->type; + return getHeader(msg)->type; } inline command void AMPacket.setType(message_t* msg, am_id_t type) { - (call Config.getHeader(msg))->type = type; + getHeader(msg)->type = type; } inline command am_group_t AMPacket.group(message_t* msg) @@ -168,4 +179,67 @@ implementation inline async event void ActiveMessageAddress.changed() { } + +/*----------------- RadioPacket -----------------*/ + + async command uint8_t RadioPacket.headerLength(message_t* msg) + { + return call SubPacket.headerLength(msg) + sizeof(activemessage_header_t); + } + + async command uint8_t RadioPacket.payloadLength(message_t* msg) + { + return call SubPacket.payloadLength(msg) - sizeof(activemessage_header_t); + } + + async command void RadioPacket.setPayloadLength(message_t* msg, uint8_t length) + { + call SubPacket.setPayloadLength(msg, length + sizeof(activemessage_header_t)); + } + + async command uint8_t RadioPacket.maxPayloadLength() + { + return call SubPacket.maxPayloadLength() - sizeof(activemessage_header_t); + } + + async command uint8_t RadioPacket.metadataLength(message_t* msg) + { + return call SubPacket.metadataLength(msg); + } + + async command void RadioPacket.clear(message_t* msg) + { + call SubPacket.clear(msg); + } + + +/*----------------- Packet -----------------*/ + + command void Packet.clear(message_t* msg) + { + call RadioPacket.clear(msg); + } + + command uint8_t Packet.payloadLength(message_t* msg) + { + return call RadioPacket.payloadLength(msg); + } + + command void Packet.setPayloadLength(message_t* msg, uint8_t len) + { + call RadioPacket.setPayloadLength(msg, len); + } + + command uint8_t Packet.maxPayloadLength() + { + return call RadioPacket.maxPayloadLength(); + } + + command void* Packet.getPayload(message_t* msg, uint8_t len) + { + if( len > call RadioPacket.maxPayloadLength() ) + return NULL; + + return ((void*)msg) + call RadioPacket.headerLength(msg); + } } diff --git a/tos/chips/rf2xx/layers/DummyLayerC.nc b/tos/chips/rf2xx/layers/DummyLayerC.nc index 3b76025d..a595974b 100644 --- a/tos/chips/rf2xx/layers/DummyLayerC.nc +++ b/tos/chips/rf2xx/layers/DummyLayerC.nc @@ -33,19 +33,22 @@ generic configuration DummyLayerC() interface RadioSend; interface RadioReceive; interface RadioCCA; + interface RadioPacket; interface DummyConfig as UnconnectedConfig; } uses { + interface SplitControl as SubControl; + interface Send as SubSend; + interface Receive as SubReceive; + interface RadioState as SubState; interface RadioSend as SubRadioSend; interface RadioReceive as SubRadioReceive; interface RadioCCA as SubRadioCCA; - interface SplitControl as SubControl; - interface Send as SubSend; - interface Receive as SubReceive; + interface RadioPacket as SubPacket; interface DummyConfig as Config; } @@ -57,6 +60,7 @@ implementation RadioSend = SubRadioSend; RadioReceive = SubRadioReceive; RadioCCA = SubRadioCCA; + RadioPacket = SubPacket; SplitControl = SubControl; Send = SubSend; diff --git a/tos/chips/rf2xx/layers/GenericTimeSyncMessageP.nc b/tos/chips/rf2xx/layers/GenericTimeSyncMessageP.nc index ba508ad7..3ebd71d5 100644 --- a/tos/chips/rf2xx/layers/GenericTimeSyncMessageP.nc +++ b/tos/chips/rf2xx/layers/GenericTimeSyncMessageP.nc @@ -92,7 +92,7 @@ implementation { *(timesync_absolute_t*)(msg->data + len) = event_time; - call PacketTimeSyncOffset.set(msg, len); + call PacketTimeSyncOffset.set(msg, offsetof(message_t, data) + len); return call SubSend.send[id](addr, msg, len + sizeof(timesync_relative_t)); } diff --git a/tos/chips/rf2xx/layers/IEEE154MessageConfig.nc b/tos/chips/rf2xx/layers/IEEE154MessageConfig.nc deleted file mode 100644 index c02bca44..00000000 --- a/tos/chips/rf2xx/layers/IEEE154MessageConfig.nc +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2009, 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 - */ - -#include - -interface IEEE154MessageConfig -{ - /** - * Returns a pointer to the IEEE 802.15.4 header fields in the message - */ - async command ieee154_header_t* getHeader(message_t* msg); -} diff --git a/tos/chips/rf2xx/layers/IEEE154MessageLayer.h b/tos/chips/rf2xx/layers/IEEE154MessageLayer.h index 9748012d..31ab0ea5 100644 --- a/tos/chips/rf2xx/layers/IEEE154MessageLayer.h +++ b/tos/chips/rf2xx/layers/IEEE154MessageLayer.h @@ -26,7 +26,6 @@ typedef nx_struct ieee154_header_t { - nxle_uint8_t length; nxle_uint16_t fcf; nxle_uint8_t dsn; nxle_uint16_t destpan; @@ -34,12 +33,6 @@ typedef nx_struct ieee154_header_t nxle_uint16_t src; } ieee154_header_t; -// the actual radio driver might not use this -typedef nx_struct ieee154_footer_t -{ - nxle_uint16_t crc; -} ieee154_footer_t; - enum ieee154_fcf_enums { IEEE154_FCF_FRAME_TYPE = 0, IEEE154_FCF_SECURITY_ENABLED = 3, diff --git a/tos/chips/rf2xx/layers/IEEE154MessageLayer.nc b/tos/chips/rf2xx/layers/IEEE154MessageLayer.nc index f1e34fd6..be98e1b9 100644 --- a/tos/chips/rf2xx/layers/IEEE154MessageLayer.nc +++ b/tos/chips/rf2xx/layers/IEEE154MessageLayer.nc @@ -33,16 +33,6 @@ */ interface IEEE154MessageLayer { - /** - * Returns the raw value (unadjusted) of the length field - */ - async command uint8_t getLength(message_t* msg); - - /** - * Sets the length field - */ - async command void setLength(message_t* msg, uint8_t length); - /** * Returns the frame control field. This method should not be used, * isDataFrame and isAckFrame should be used instead. diff --git a/tos/chips/rf2xx/layers/IEEE154MessageLayerC.nc b/tos/chips/rf2xx/layers/IEEE154MessageLayerC.nc index 2040739f..6ac1aa02 100644 --- a/tos/chips/rf2xx/layers/IEEE154MessageLayerC.nc +++ b/tos/chips/rf2xx/layers/IEEE154MessageLayerC.nc @@ -26,11 +26,16 @@ configuration IEEE154MessageLayerC provides { interface IEEE154MessageLayer; + interface RadioPacket; + interface Ieee154Packet; + interface Packet; + interface Ieee154Send; } uses { - interface IEEE154MessageConfig as Config; + interface RadioPacket as SubPacket; + interface Send as SubSend; } } @@ -40,5 +45,10 @@ implementation IEEE154MessageLayerP.ActiveMessageAddress -> ActiveMessageAddressC; IEEE154MessageLayer = IEEE154MessageLayerP; - Config = IEEE154MessageLayerP; + RadioPacket = IEEE154MessageLayerP; + SubPacket = IEEE154MessageLayerP; + Ieee154Packet = IEEE154MessageLayerP; + Packet = IEEE154MessageLayerP; + Ieee154Send = IEEE154MessageLayerP; + SubSend = IEEE154MessageLayerP; } diff --git a/tos/chips/rf2xx/layers/IEEE154MessageLayerP.nc b/tos/chips/rf2xx/layers/IEEE154MessageLayerP.nc index a9a82bb0..b806b96c 100644 --- a/tos/chips/rf2xx/layers/IEEE154MessageLayerP.nc +++ b/tos/chips/rf2xx/layers/IEEE154MessageLayerP.nc @@ -28,13 +28,17 @@ module IEEE154MessageLayerP provides { interface IEEE154MessageLayer; + interface RadioPacket; interface Ieee154Packet; + interface Packet; + interface Ieee154Send; } uses { interface ActiveMessageAddress; - interface IEEE154MessageConfig as Config; + interface RadioPacket as SubPacket; + interface Send as SubSend; } } @@ -54,24 +58,14 @@ implementation | (IEEE154_ADDR_SHORT << IEEE154_FCF_DEST_ADDR_MODE) | (IEEE154_ADDR_SHORT << IEEE154_FCF_SRC_ADDR_MODE), - IEEE154_ACK_FRAME_LENGTH = 5, // includes the FCF, DSN and FCS + IEEE154_ACK_FRAME_LENGTH = 3, // includes the FCF, DSN IEEE154_ACK_FRAME_MASK = (IEEE154_TYPE_MASK << IEEE154_FCF_FRAME_TYPE), IEEE154_ACK_FRAME_VALUE = (IEEE154_TYPE_ACK << IEEE154_FCF_FRAME_TYPE), }; ieee154_header_t* getHeader(message_t* msg) { - return call Config.getHeader(msg); - } - - async command uint8_t IEEE154MessageLayer.getLength(message_t* msg) - { - return getHeader(msg)->length; - } - - async command void IEEE154MessageLayer.setLength(message_t* msg, uint8_t length) - { - getHeader(msg)->length = length; + return ((void*)msg) + call SubPacket.headerLength(msg); } async command uint16_t IEEE154MessageLayer.getFCF(message_t* msg) @@ -101,17 +95,15 @@ implementation async command void IEEE154MessageLayer.createAckFrame(message_t* msg) { - ieee154_header_t* header = getHeader(msg); - - header->length = IEEE154_ACK_FRAME_LENGTH; - header->fcf = IEEE154_ACK_FRAME_VALUE; + call SubPacket.setPayloadLength(msg, IEEE154_ACK_FRAME_LENGTH); + getHeader(msg)->fcf = IEEE154_ACK_FRAME_VALUE; } async command void IEEE154MessageLayer.createAckReply(message_t* data, message_t* ack) { ieee154_header_t* header = getHeader(ack); + call SubPacket.setPayloadLength(ack, IEEE154_ACK_FRAME_LENGTH); - header->length = IEEE154_ACK_FRAME_LENGTH; header->fcf = IEEE154_ACK_FRAME_VALUE; header->dsn = getHeader(data)->dsn; } @@ -255,4 +247,107 @@ implementation { return call ActiveMessageAddress.amGroup(); } + +/*----------------- RadioPacket -----------------*/ + + async command uint8_t RadioPacket.headerLength(message_t* msg) + { + return call SubPacket.headerLength(msg) + sizeof(ieee154_header_t); + } + + async command uint8_t RadioPacket.payloadLength(message_t* msg) + { + return call SubPacket.payloadLength(msg) - sizeof(ieee154_header_t); + } + + async command void RadioPacket.setPayloadLength(message_t* msg, uint8_t length) + { + call SubPacket.setPayloadLength(msg, length + sizeof(ieee154_header_t)); + } + + async command uint8_t RadioPacket.maxPayloadLength() + { + return call SubPacket.maxPayloadLength() - sizeof(ieee154_header_t); + } + + async command uint8_t RadioPacket.metadataLength(message_t* msg) + { + return call SubPacket.metadataLength(msg); + } + + async command void RadioPacket.clear(message_t* msg) + { + call SubPacket.clear(msg); + call IEEE154MessageLayer.createDataFrame(msg); + } + +/*----------------- Packet -----------------*/ + + command void Packet.clear(message_t* msg) + { + call RadioPacket.clear(msg); + } + + command uint8_t Packet.payloadLength(message_t* msg) + { + return call RadioPacket.payloadLength(msg); + } + + command void Packet.setPayloadLength(message_t* msg, uint8_t len) + { + call RadioPacket.setPayloadLength(msg, len); + } + + command uint8_t Packet.maxPayloadLength() + { + return call RadioPacket.maxPayloadLength(); + } + + command void* Packet.getPayload(message_t* msg, uint8_t len) + { + if( len > call RadioPacket.maxPayloadLength() ) + return NULL; + + return ((void*)msg) + call RadioPacket.headerLength(msg); + } + +/*----------------- Ieee154Send -----------------*/ + + command void * Ieee154Send.getPayload(message_t* msg, uint8_t len) + { + return call Packet.getPayload(msg, len); + } + + command uint8_t Ieee154Send.maxPayloadLength() + { + return call Packet.maxPayloadLength(); + } + + command error_t Ieee154Send.cancel(message_t* msg) + { + return call SubSend.cancel(msg); + } + + command error_t Ieee154Send.send(ieee154_saddr_t addr, message_t* msg, uint8_t len) + { + ieee154_header_t* header = getHeader(msg); + + header->dest = addr; + header->destpan = call Ieee154Packet.localPan(); + header->src = call Ieee154Packet.address(); + + // Notifier (in original ActiveMessage) --> Not used in CC2420 + // signal SendNotifier.aboutToSend(addr, msg); + + return call SubSend.send(msg, len); + } + + event void SubSend.sendDone(message_t* msg, error_t error) + { + signal Ieee154Send.sendDone(msg, error); + } + + default event void Ieee154Send.sendDone(message_t* msg, error_t error) + { + } } diff --git a/tos/chips/rf2xx/layers/LowPowerListeningConfig.nc b/tos/chips/rf2xx/layers/LowPowerListeningConfig.nc index c0f2157a..e8bf31f7 100644 --- a/tos/chips/rf2xx/layers/LowPowerListeningConfig.nc +++ b/tos/chips/rf2xx/layers/LowPowerListeningConfig.nc @@ -21,22 +21,8 @@ * Author: Miklos Maroti */ -#include - interface LowPowerListeningConfig { - /** - * Returns a pointer to the low power listening metadata fields in - * the message - */ - async command lpl_metadata_t* metadata(message_t* msg); - - /** - * Clears the low power listening metadata fields in order to disable - * low power listening for the message - */ - async event void clear(message_t* msg); - /** * Returns TRUE if an acknowledgement is requested for this message. */ diff --git a/tos/chips/rf2xx/layers/LowPowerListeningDummyC.nc b/tos/chips/rf2xx/layers/LowPowerListeningDummyC.nc index fab03147..816710ec 100644 --- a/tos/chips/rf2xx/layers/LowPowerListeningDummyC.nc +++ b/tos/chips/rf2xx/layers/LowPowerListeningDummyC.nc @@ -28,6 +28,7 @@ configuration LowPowerListeningDummyC interface SplitControl; interface Send; interface Receive; + interface RadioPacket; interface LowPowerListening; } @@ -36,6 +37,7 @@ configuration LowPowerListeningDummyC interface SplitControl as SubControl; interface Send as SubSend; interface Receive as SubReceive; + interface RadioPacket as SubPacket; } } @@ -44,6 +46,7 @@ implementation SplitControl = SubControl; Send = SubSend; Receive = SubReceive; + RadioPacket = SubPacket; components LowPowerListeningDummyP; LowPowerListening = LowPowerListeningDummyP; diff --git a/tos/chips/rf2xx/layers/LowPowerListeningLayerC.nc b/tos/chips/rf2xx/layers/LowPowerListeningLayerC.nc index ddb2a38a..f6161678 100644 --- a/tos/chips/rf2xx/layers/LowPowerListeningLayerC.nc +++ b/tos/chips/rf2xx/layers/LowPowerListeningLayerC.nc @@ -21,8 +21,6 @@ * Author: Miklos Maroti */ -#include - #warning "*** USING LOW POWER LISTENING LAYER" configuration LowPowerListeningLayerC @@ -32,6 +30,7 @@ configuration LowPowerListeningLayerC interface SplitControl; interface Send; interface Receive; + interface RadioPacket; interface LowPowerListening; } @@ -40,6 +39,7 @@ configuration LowPowerListeningLayerC interface SplitControl as SubControl; interface Send as SubSend; interface Receive as SubReceive; + interface RadioPacket as SubPacket; interface LowPowerListeningConfig as Config; interface PacketAcknowledgements; @@ -53,11 +53,13 @@ implementation SplitControl = LowPowerListeningLayerP; Send = LowPowerListeningLayerP; Receive = LowPowerListeningLayerP; + RadioPacket = LowPowerListeningLayerP; LowPowerListening = LowPowerListeningLayerP; SubControl = LowPowerListeningLayerP; SubSend = LowPowerListeningLayerP; SubReceive = LowPowerListeningLayerP; + SubPacket = LowPowerListeningLayerP; Config = LowPowerListeningLayerP; PacketAcknowledgements = LowPowerListeningLayerP; diff --git a/tos/chips/rf2xx/layers/LowPowerListeningLayerP.nc b/tos/chips/rf2xx/layers/LowPowerListeningLayerP.nc index 4bdd79ee..eae77f1b 100644 --- a/tos/chips/rf2xx/layers/LowPowerListeningLayerP.nc +++ b/tos/chips/rf2xx/layers/LowPowerListeningLayerP.nc @@ -31,6 +31,7 @@ module LowPowerListeningLayerP interface SplitControl; interface Send; interface Receive; + interface RadioPacket; interface LowPowerListening; } @@ -40,6 +41,7 @@ module LowPowerListeningLayerP interface SplitControl as SubControl; interface Send as SubSend; interface Receive as SubReceive; + interface RadioPacket as SubPacket; interface PacketAcknowledgements; interface LowPowerListeningConfig as Config; @@ -358,6 +360,11 @@ implementation /*----------------- LowPowerListening -----------------*/ + lpl_metadata_t* getMeta(message_t* msg) + { + return ((void*)msg) + sizeof(message_t) - call RadioPacket.metadataLength(msg); + } + command uint16_t LowPowerListening.dutyCycleToSleepInterval(uint16_t dutyCycle) { if( dutyCycle >= 10000 ) @@ -418,12 +425,12 @@ implementation else if( interval > MAX_SLEEP ) interval = MAX_SLEEP; - (call Config.metadata(msg))->sleepint = interval; + getMeta(msg)->sleepint = interval; } command uint16_t LowPowerListening.getRxSleepInterval(message_t *msg) { - uint16_t sleepint = (call Config.metadata(msg))->sleepint; + uint16_t sleepint = getMeta(msg)->sleepint; return sleepint != 0 ? sleepint : sleepInterval; } @@ -440,8 +447,36 @@ implementation call LowPowerListening.getRxSleepInterval(msg)); } - async event void Config.clear(message_t* msg) +/*----------------- RadioPacket -----------------*/ + + async command uint8_t RadioPacket.headerLength(message_t* msg) + { + return call SubPacket.headerLength(msg); + } + + async command uint8_t RadioPacket.payloadLength(message_t* msg) + { + return call SubPacket.payloadLength(msg); + } + + async command void RadioPacket.setPayloadLength(message_t* msg, uint8_t length) + { + call SubPacket.setPayloadLength(msg, length); + } + + async command uint8_t RadioPacket.maxPayloadLength() + { + return call SubPacket.maxPayloadLength(); + } + + async command uint8_t RadioPacket.metadataLength(message_t* msg) + { + return call SubPacket.metadataLength(msg) + sizeof(lpl_metadata_t); + } + + async command void RadioPacket.clear(message_t* msg) { - (call Config.metadata(msg))->sleepint = 0; + getMeta(msg)->sleepint = 0; + call SubPacket.clear(msg); } } diff --git a/tos/chips/rf2xx/layers/LowpanNetworkConfig.nc b/tos/chips/rf2xx/layers/LowpanNetworkConfig.nc deleted file mode 100644 index 9159a1e3..00000000 --- a/tos/chips/rf2xx/layers/LowpanNetworkConfig.nc +++ /dev/null @@ -1,32 +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 - */ - -#include - -interface LowpanNetworkConfig -{ - /** - * Returns a pointer to the 6LowPAN header field in the message - */ - command lowpan_header_t* getHeader(message_t* msg); -} diff --git a/tos/chips/rf2xx/layers/LowpanNetworkLayerC.nc b/tos/chips/rf2xx/layers/LowpanNetworkLayerC.nc index f52c4d89..4f9a22e2 100644 --- a/tos/chips/rf2xx/layers/LowpanNetworkLayerC.nc +++ b/tos/chips/rf2xx/layers/LowpanNetworkLayerC.nc @@ -21,12 +21,15 @@ * Author: Miklos Maroti */ +#include + module LowpanNetworkLayerC { provides { interface Send; interface Receive; + interface RadioPacket; interface Receive as NonTinyosReceive[uint8_t network]; } @@ -35,7 +38,7 @@ module LowpanNetworkLayerC { interface Send as SubSend; interface Receive as SubReceive; - interface LowpanNetworkConfig as Config; + interface RadioPacket as SubPacket; } } @@ -45,9 +48,14 @@ implementation #define TINYOS_6LOWPAN_NETWORK_ID 0x3f #endif + lowpan_header_t* getHeader(message_t* msg) + { + return ((void*)msg) + call SubPacket.headerLength(msg); + } + command error_t Send.send(message_t* msg, uint8_t len) { - (call Config.getHeader(msg))->network = TINYOS_6LOWPAN_NETWORK_ID; + getHeader(msg)->network = TINYOS_6LOWPAN_NETWORK_ID; return call SubSend.send(msg, len); } @@ -73,7 +81,7 @@ implementation event message_t *SubReceive.receive(message_t *msg, void *payload, uint8_t len) { - uint8_t network = (call Config.getHeader(msg))->network; + uint8_t network = getHeader(msg)->network; if( network == TINYOS_6LOWPAN_NETWORK_ID ) return signal Receive.receive(msg, payload, len); else @@ -84,4 +92,36 @@ implementation { return msg; } + +/*----------------- RadioPacket -----------------*/ + + async command uint8_t RadioPacket.headerLength(message_t* msg) + { + return call SubPacket.headerLength(msg) + sizeof(lowpan_header_t); + } + + async command uint8_t RadioPacket.payloadLength(message_t* msg) + { + return call SubPacket.payloadLength(msg) - sizeof(lowpan_header_t); + } + + async command void RadioPacket.setPayloadLength(message_t* msg, uint8_t length) + { + call SubPacket.setPayloadLength(msg, length + sizeof(lowpan_header_t)); + } + + async command uint8_t RadioPacket.maxPayloadLength() + { + return call SubPacket.maxPayloadLength() - sizeof(lowpan_header_t); + } + + async command uint8_t RadioPacket.metadataLength(message_t* msg) + { + return call SubPacket.metadataLength(msg); + } + + async command void RadioPacket.clear(message_t* msg) + { + call SubPacket.clear(msg); + } } diff --git a/tos/chips/rf2xx/layers/MetadataFlagsLayerC.nc b/tos/chips/rf2xx/layers/MetadataFlagsLayerC.nc index dffafb0b..39b0beee 100644 --- a/tos/chips/rf2xx/layers/MetadataFlagsLayerC.nc +++ b/tos/chips/rf2xx/layers/MetadataFlagsLayerC.nc @@ -29,33 +29,41 @@ module MetadataFlagsLayerC provides { interface PacketFlag[uint8_t bit]; + interface RadioPacket; } uses { - interface PacketData as PacketFlagsMetadata; + interface RadioPacket as SubPacket; } } implementation { + flags_metadata_t* getMeta(message_t* msg) + { + return ((void*)msg) + sizeof(message_t) - call RadioPacket.metadataLength(msg); + } + +/*----------------- RadioPacket -----------------*/ + async command bool PacketFlag.get[uint8_t bit](message_t* msg) { - return (call PacketFlagsMetadata.get(msg))->flags & (1<flags & (1<flags |= (1<flags |= (1<flags &= ~(1<flags &= ~(1<flags = 0; + getMeta(msg)->flags = 0; + call SubPacket.clear(msg); } } diff --git a/tos/chips/rf2xx/layers/PacketLinkLayerC.nc b/tos/chips/rf2xx/layers/PacketLinkLayerC.nc index 5701af73..fb65fe60 100644 --- a/tos/chips/rf2xx/layers/PacketLinkLayerC.nc +++ b/tos/chips/rf2xx/layers/PacketLinkLayerC.nc @@ -65,11 +65,12 @@ configuration PacketLinkLayerC { provides { interface Send; interface PacketLink; + interface RadioPacket; } uses { interface Send as SubSend; - interface PacketData as PacketLinkMetadata; + interface RadioPacket as SubPacket; interface PacketAcknowledgements; } } @@ -78,10 +79,11 @@ implementation { components PacketLinkLayerP, new TimerMilliC() as DelayTimerC; PacketLink = PacketLinkLayerP; - Send = PacketLinkLayerP.Send; - SubSend = PacketLinkLayerP.SubSend; + Send = PacketLinkLayerP; + SubSend = PacketLinkLayerP; PacketAcknowledgements = PacketLinkLayerP; - PacketLinkMetadata = PacketLinkLayerP; + RadioPacket = PacketLinkLayerP; + SubPacket = PacketLinkLayerP; PacketLinkLayerP.DelayTimer -> DelayTimerC; } diff --git a/tos/chips/rf2xx/layers/PacketLinkLayerP.nc b/tos/chips/rf2xx/layers/PacketLinkLayerP.nc index 9418770d..1bf501f2 100644 --- a/tos/chips/rf2xx/layers/PacketLinkLayerP.nc +++ b/tos/chips/rf2xx/layers/PacketLinkLayerP.nc @@ -63,13 +63,14 @@ module PacketLinkLayerP { provides { interface Send; interface PacketLink; + interface RadioPacket; } uses { interface Send as SubSend; interface PacketAcknowledgements; interface Timer as DelayTimer; - interface PacketData as PacketLinkMetadata; + interface RadioPacket as SubPacket; } } @@ -91,6 +92,11 @@ implementation { /***************** PacketLink Commands ***************/ + + link_metadata_t* getMeta(message_t* msg) { + return ((void*)msg) + sizeof(message_t) - call RadioPacket.metadataLength(msg); + } + /** * Set the maximum number of times attempt message delivery * Default is 0 @@ -99,7 +105,7 @@ implementation { * the message */ command void PacketLink.setRetries(message_t *msg, uint16_t maxRetries) { - (call PacketLinkMetadata.get(msg))->maxRetries = maxRetries; + getMeta(msg)->maxRetries = maxRetries; } /** @@ -108,21 +114,21 @@ implementation { * @param retryDelay the delay betweeen retry attempts, in milliseconds */ command void PacketLink.setRetryDelay(message_t *msg, uint16_t retryDelay) { - (call PacketLinkMetadata.get(msg))->retryDelay = retryDelay; + getMeta(msg)->retryDelay = retryDelay; } /** * @return the maximum number of retry attempts for this message */ command uint16_t PacketLink.getRetries(message_t *msg) { - return (call PacketLinkMetadata.get(msg))->maxRetries; + return getMeta(msg)->maxRetries; } /** * @return the delay between retry attempts in ms for this message */ command uint16_t PacketLink.getRetryDelay(message_t *msg) { - return (call PacketLinkMetadata.get(msg))->retryDelay; + return getMeta(msg)->retryDelay; } /** @@ -132,10 +138,6 @@ implementation { return call PacketAcknowledgements.wasAcked(msg); } - async event void PacketLinkMetadata.clear(message_t* msg) { - (call PacketLinkMetadata.get(msg))->maxRetries = 0; - } - /***************** Send Commands ***************/ /** * Each call to this send command gives the message a single @@ -237,4 +239,30 @@ implementation { call PacketLink.setRetries(msg, totalRetries); signal Send.sendDone(msg, error); } + + /***************** Functions ***************/ + async command uint8_t RadioPacket.headerLength(message_t* msg) { + return call SubPacket.headerLength(msg); + } + + async command uint8_t RadioPacket.payloadLength(message_t* msg) { + return call SubPacket.payloadLength(msg); + } + + async command void RadioPacket.setPayloadLength(message_t* msg, uint8_t length) { + call SubPacket.setPayloadLength(msg, length); + } + + async command uint8_t RadioPacket.maxPayloadLength() { + return call SubPacket.maxPayloadLength(); + } + + async command uint8_t RadioPacket.metadataLength(message_t* msg) { + return call SubPacket.metadataLength(msg) + sizeof(link_metadata_t); + } + + async command void RadioPacket.clear(message_t* msg) { + getMeta(msg)->maxRetries = 0; + call SubPacket.clear(msg); + } } diff --git a/tos/chips/rf2xx/layers/SoftwareAckLayerC.nc b/tos/chips/rf2xx/layers/SoftwareAckLayerC.nc index 44e2cf06..775b9cdc 100755 --- a/tos/chips/rf2xx/layers/SoftwareAckLayerC.nc +++ b/tos/chips/rf2xx/layers/SoftwareAckLayerC.nc @@ -27,8 +27,10 @@ configuration SoftwareAckLayerC { interface RadioSend; interface RadioReceive; + interface PacketAcknowledgements; } + uses { interface RadioSend as SubSend; diff --git a/tos/chips/rf2xx/layers/SoftwareAckLayerP.nc b/tos/chips/rf2xx/layers/SoftwareAckLayerP.nc index 64324817..035c67b1 100644 --- a/tos/chips/rf2xx/layers/SoftwareAckLayerP.nc +++ b/tos/chips/rf2xx/layers/SoftwareAckLayerP.nc @@ -32,6 +32,7 @@ module SoftwareAckLayerP interface RadioReceive; interface PacketAcknowledgements; } + uses { interface RadioSend as SubSend; diff --git a/tos/chips/rf2xx/layers/TimeStampingLayerC.nc b/tos/chips/rf2xx/layers/TimeStampingLayerC.nc index a8aadeac..7bc5b0ca 100644 --- a/tos/chips/rf2xx/layers/TimeStampingLayerC.nc +++ b/tos/chips/rf2xx/layers/TimeStampingLayerC.nc @@ -27,12 +27,13 @@ configuration TimeStampingLayerC { interface PacketTimeStamp as PacketTimeStampMilli; interface PacketTimeStamp as PacketTimeStampRadio; + interface RadioPacket; } uses { interface LocalTime as LocalTimeRadio; - interface PacketData as PacketTimeStampMetadata; + interface RadioPacket as SubPacket; } } @@ -42,7 +43,8 @@ implementation PacketTimeStampMilli = TimeStampingLayerP; PacketTimeStampRadio = TimeStampingLayerP; - PacketTimeStampMetadata = TimeStampingLayerP.PacketTimeStampMetadata; + RadioPacket = TimeStampingLayerP.RadioPacket; + SubPacket = TimeStampingLayerP.SubPacket; LocalTimeRadio = TimeStampingLayerP; TimeStampingLayerP.LocalTimeMilli -> LocalTimeMilliC; diff --git a/tos/chips/rf2xx/layers/TimeStampingLayerP.nc b/tos/chips/rf2xx/layers/TimeStampingLayerP.nc index 33b14b8e..d0dec1e4 100644 --- a/tos/chips/rf2xx/layers/TimeStampingLayerP.nc +++ b/tos/chips/rf2xx/layers/TimeStampingLayerP.nc @@ -30,6 +30,7 @@ module TimeStampingLayerP { interface PacketTimeStamp as PacketTimeStampMilli; interface PacketTimeStamp as PacketTimeStampRadio; + interface RadioPacket; } uses @@ -39,12 +40,19 @@ module TimeStampingLayerP interface LocalTime as LocalTimeRadio; interface LocalTime as LocalTimeMilli; - interface PacketData as PacketTimeStampMetadata; + interface RadioPacket as SubPacket; } } implementation { + timestamp_metadata_t* getMeta(message_t* msg) + { + return ((void*)msg) + sizeof(message_t) - call RadioPacket.metadataLength(msg); + } + +/*----------------- PacketTimeStampRadio -----------------*/ + async command bool PacketTimeStampRadio.isValid(message_t* msg) { return call TimeStampFlag.get(msg); @@ -52,7 +60,7 @@ implementation async command uint32_t PacketTimeStampRadio.timestamp(message_t* msg) { - return (call PacketTimeStampMetadata.get(msg))->timestamp; + return getMeta(msg)->timestamp; } async command void PacketTimeStampRadio.clear(message_t* msg) @@ -63,12 +71,10 @@ implementation async command void PacketTimeStampRadio.set(message_t* msg, uint32_t value) { call TimeStampFlag.set(msg); - (call PacketTimeStampMetadata.get(msg))->timestamp = value; + getMeta(msg)->timestamp = value; } - async event void PacketTimeStampMetadata.clear(message_t* msg) - { - } +/*----------------- PacketTimeStampMilli -----------------*/ async command bool PacketTimeStampMilli.isValid(message_t* msg) { @@ -93,4 +99,37 @@ implementation call PacketTimeStampRadio.set(msg, offset + call LocalTimeRadio.get()); } + +/*----------------- RadioPacket -----------------*/ + + async command uint8_t RadioPacket.headerLength(message_t* msg) + { + return call SubPacket.headerLength(msg); + } + + async command uint8_t RadioPacket.payloadLength(message_t* msg) + { + return call SubPacket.payloadLength(msg); + } + + async command void RadioPacket.setPayloadLength(message_t* msg, uint8_t length) + { + call SubPacket.setPayloadLength(msg, length); + } + + async command uint8_t RadioPacket.maxPayloadLength() + { + return call SubPacket.maxPayloadLength(); + } + + async command uint8_t RadioPacket.metadataLength(message_t* msg) + { + return call SubPacket.metadataLength(msg) + sizeof(timestamp_metadata_t); + } + + async command void RadioPacket.clear(message_t* msg) + { + // all flags are automatically cleared + call SubPacket.clear(msg); + } } diff --git a/tos/chips/rf2xx/rf212/RF212ActiveMessage.h b/tos/chips/rf2xx/rf212/RF212ActiveMessage.h index 1f789e85..618d0489 100644 --- a/tos/chips/rf2xx/rf212/RF212ActiveMessage.h +++ b/tos/chips/rf2xx/rf212/RF212ActiveMessage.h @@ -35,6 +35,7 @@ typedef nx_struct rf212packet_header_t { + rf212_header_t rf212; ieee154_header_t ieee154; #ifndef TFRAMES_ENABLED lowpan_header_t lowpan; @@ -49,15 +50,15 @@ typedef nx_struct rf212packet_footer_t typedef struct rf212packet_metadata_t { - flags_metadata_t flags; - rf212_metadata_t rf212; - timestamp_metadata_t timestamp; #ifdef LOW_POWER_LISTENING lpl_metadata_t lpl; #endif #ifdef PACKET_LINK link_metadata_t link; #endif + timestamp_metadata_t timestamp; + flags_metadata_t flags; + rf212_metadata_t rf212; } rf212packet_metadata_t; #endif//__RF212ACTIVEMESSAGE_H__ diff --git a/tos/chips/rf2xx/rf212/RF212ActiveMessageC.nc b/tos/chips/rf2xx/rf212/RF212ActiveMessageC.nc index 18ffdf6a..f390303a 100644 --- a/tos/chips/rf2xx/rf212/RF212ActiveMessageC.nc +++ b/tos/chips/rf2xx/rf212/RF212ActiveMessageC.nc @@ -65,7 +65,8 @@ implementation RF212ActiveMessageP.IEEE154MessageLayer -> IEEE154MessageLayerC; RF212ActiveMessageP.RadioAlarm -> RadioAlarmC.RadioAlarm[unique("RadioAlarm")]; RF212ActiveMessageP.PacketTimeStamp -> TimeStampingLayerC; - Packet = RF212ActiveMessageP; + RF212ActiveMessageP.ActiveMessagePacket -> ActiveMessageLayerC; + RF212ActiveMessageP.RF212Packet -> RF212DriverLayerC; // -------- Active Message @@ -73,7 +74,9 @@ implementation ActiveMessageLayerC.Config -> RF212ActiveMessageP; ActiveMessageLayerC.SubSend -> LowpanNetworkLayerC; ActiveMessageLayerC.SubReceive -> LowpanNetworkLayerC; + ActiveMessageLayerC.SubPacket ->LowpanNetworkLayerC; AMSend = ActiveMessageLayerC; + Packet = ActiveMessageLayerC; Receive = ActiveMessageLayerC.Receive; Snoop = ActiveMessageLayerC.Snoop; AMPacket = ActiveMessageLayerC; @@ -84,15 +87,15 @@ implementation components new DummyLayerC() as LowpanNetworkLayerC; #else components LowpanNetworkLayerC; - LowpanNetworkLayerC.Config -> RF212ActiveMessageP; #endif LowpanNetworkLayerC.SubSend -> UniqueLayerC; LowpanNetworkLayerC.SubReceive -> LowPowerListeningLayerC; + LowpanNetworkLayerC.SubPacket -> IEEE154MessageLayerC; -// -------- IEEE154 Packet +// -------- IEEE154 Message components IEEE154MessageLayerC; - IEEE154MessageLayerC.Config -> RF212ActiveMessageP; + IEEE154MessageLayerC.SubPacket -> LowPowerListeningLayerC; // -------- UniqueLayer Send part (wired twice) @@ -112,6 +115,7 @@ implementation LowPowerListeningLayerC.SubControl -> MessageBufferLayerC; LowPowerListeningLayerC.SubSend -> PacketLinkLayerC; LowPowerListeningLayerC.SubReceive -> MessageBufferLayerC; + LowPowerListeningLayerC.SubPacket -> PacketLinkLayerC; SplitControl = LowPowerListeningLayerC; LowPowerListening = LowPowerListeningLayerC; @@ -120,17 +124,17 @@ implementation #ifdef PACKET_LINK components PacketLinkLayerC; PacketLink = PacketLinkLayerC; - PacketLinkLayerC.PacketLinkMetadata -> RF212ActiveMessageP; PacketLinkLayerC.PacketAcknowledgements -> SoftwareAckLayerC; #else components new DummyLayerC() as PacketLinkLayerC; #endif PacketLinkLayerC.SubSend -> MessageBufferLayerC; + PacketLinkLayerC.SubPacket -> TimeStampingLayerC; // -------- MessageBuffer components MessageBufferLayerC; - MessageBufferLayerC.Packet -> RF212ActiveMessageP; + MessageBufferLayerC.Packet -> ActiveMessageLayerC; MessageBufferLayerC.RadioSend -> TrafficMonitorLayerC; MessageBufferLayerC.RadioReceive -> UniqueLayerC; MessageBufferLayerC.RadioState -> TrafficMonitorLayerC; @@ -174,27 +178,26 @@ implementation CsmaLayerC -> RF212DriverLayerC.RadioSend; CsmaLayerC -> RF212DriverLayerC.RadioCCA; +// -------- TimeStamping + + components TimeStampingLayerC; + TimeStampingLayerC.LocalTimeRadio -> RF212DriverLayerC; + TimeStampingLayerC.SubPacket -> MetadataFlagsLayerC; + PacketTimeStampRadio = TimeStampingLayerC; + PacketTimeStampMilli = TimeStampingLayerC; + +// -------- MetadataFlags + + components MetadataFlagsLayerC; + MetadataFlagsLayerC.SubPacket -> RF212DriverLayerC; + // -------- RF212 Driver components RF212DriverLayerC; - RF212DriverLayerC.PacketRF212Metadata -> RF212ActiveMessageP; - RF212DriverLayerC.RF212DriverConfig -> RF212ActiveMessageP; + RF212DriverLayerC.Config -> RF212ActiveMessageP; RF212DriverLayerC.PacketTimeStamp -> TimeStampingLayerC; PacketTransmitPower = RF212DriverLayerC.PacketTransmitPower; PacketLinkQuality = RF212DriverLayerC.PacketLinkQuality; PacketRSSI = RF212DriverLayerC.PacketRSSI; LocalTimeRadio = RF212DriverLayerC; - -// -------- MetadataFlags - - components MetadataFlagsLayerC; - MetadataFlagsLayerC.PacketFlagsMetadata -> RF212ActiveMessageP; - -// -------- TimeStamping - - components TimeStampingLayerC; - TimeStampingLayerC.LocalTimeRadio -> RF212DriverLayerC; - TimeStampingLayerC.PacketTimeStampMetadata -> RF212ActiveMessageP; - PacketTimeStampRadio = TimeStampingLayerC; - PacketTimeStampMilli = TimeStampingLayerC; } diff --git a/tos/chips/rf2xx/rf212/RF212ActiveMessageP.nc b/tos/chips/rf2xx/rf212/RF212ActiveMessageP.nc index f304b53c..27dff12c 100644 --- a/tos/chips/rf2xx/rf212/RF212ActiveMessageP.nc +++ b/tos/chips/rf2xx/rf212/RF212ActiveMessageP.nc @@ -37,21 +37,10 @@ module RF212ActiveMessageP interface RandomCollisionConfig; interface SlottedCollisionConfig; interface ActiveMessageConfig; - interface LowpanNetworkConfig; - interface IEEE154MessageConfig; interface DummyConfig; - interface Packet; - - interface PacketData as PacketFlagsMetadata; - interface PacketData as PacketRF212Metadata; - interface PacketData as PacketTimeStampMetadata; - #ifdef LOW_POWER_LISTENING interface LowPowerListeningConfig; -#endif -#ifdef PACKET_LINK - interface PacketData as PacketLinkMetadata; #endif } @@ -59,6 +48,8 @@ module RF212ActiveMessageP { interface IEEE154MessageLayer; interface RadioAlarm; + interface RadioPacket as ActiveMessagePacket; + interface RadioPacket as RF212Packet; interface PacketTimeStamp; } @@ -66,45 +57,30 @@ module RF212ActiveMessageP implementation { - rf212packet_header_t* getHeader(message_t* msg) - { - return (rf212packet_header_t*)(msg->data - sizeof(rf212packet_header_t)); - } - - rf212packet_metadata_t* getMeta(message_t* msg) - { - return (rf212packet_metadata_t*)(msg->metadata); - } /*----------------- RF212DriverConfig -----------------*/ - async command uint8_t RF212DriverConfig.getLength(message_t* msg) + async command uint8_t RF212DriverConfig.headerLength(message_t* msg) { - return call IEEE154MessageLayer.getLength(msg); + return offsetof(message_t, data) - sizeof(rf212packet_header_t); } - async command void RF212DriverConfig.setLength(message_t* msg, uint8_t len) + async command uint8_t RF212DriverConfig.maxPayloadLength() { - call IEEE154MessageLayer.setLength(msg, len); + return sizeof(rf212packet_header_t) + TOSH_DATA_LENGTH; } - async command uint8_t* RF212DriverConfig.getPayload(message_t* msg) + async command uint8_t RF212DriverConfig.metadataLength(message_t* msg) { - return ((uint8_t*)(call IEEE154MessageConfig.getHeader(msg))) + 1; + return 0; } - async command uint8_t RF212DriverConfig.getHeaderLength() + async command uint8_t RF212DriverConfig.headerPreloadLength() { // we need the fcf, dsn, destpan and dest return 7; } - async command uint8_t RF212DriverConfig.getMaxLength() - { - // note, that the ieee154_footer_t is not stored, but we should include it here - return sizeof(rf212packet_header_t) - 1 + TOSH_DATA_LENGTH + sizeof(ieee154_footer_t); - } - async command bool RF212DriverConfig.requiresRssiCca(message_t* msg) { return call IEEE154MessageLayer.isDataFrame(msg); @@ -176,18 +152,9 @@ implementation /*----------------- ActiveMessageConfig -----------------*/ - command error_t ActiveMessageConfig.checkPacket(message_t* msg) - { - // the user forgot to call clear, we should return EINVAL - if( ! call IEEE154MessageLayer.isDataFrame(msg) ) - call Packet.clear(msg); - - return SUCCESS; - } - - command activemessage_header_t* ActiveMessageConfig.getHeader(message_t* msg) + command bool ActiveMessageConfig.forgotToClear(message_t* msg) { - return &(getHeader(msg)->am); + return ! call IEEE154MessageLayer.isDataFrame(msg); } command am_addr_t ActiveMessageConfig.destination(message_t* msg) @@ -249,7 +216,7 @@ implementation * ack required: 8-16 byte separation, 11 bytes airtime, 5-10 bytes separation */ - uint8_t len = call IEEE154MessageLayer.getLength(msg); + uint8_t len = call RF212Packet.payloadLength(msg); return call IEEE154MessageLayer.getAckRequired(msg) ? len + 6 + 16 + 11 + 10 : len + 6 + 10; } @@ -346,29 +313,10 @@ implementation { } -/*----------------- LowpanNetwork -----------------*/ - - command lowpan_header_t* LowpanNetworkConfig.getHeader(message_t* msg) - { - return &(getHeader(msg)->lowpan); - } - -/*----------------- IEEE154Message -----------------*/ - - async command ieee154_header_t* IEEE154MessageConfig.getHeader(message_t* msg) - { - return &(getHeader(msg)->ieee154); - } - /*----------------- LowPowerListening -----------------*/ #ifdef LOW_POWER_LISTENING - async command lpl_metadata_t* LowPowerListeningConfig.metadata(message_t* msg) - { - return &(getMeta(msg)->lpl); - } - async command bool LowPowerListeningConfig.getAckRequired(message_t* msg) { return call IEEE154MessageLayer.getAckRequired(msg); @@ -376,73 +324,4 @@ implementation #endif -/*----------------- Headers and Metadata -----------------*/ - - async command flags_metadata_t* PacketFlagsMetadata.get(message_t* msg) - { - return &(getMeta(msg)->flags); - } - - async command rf212_metadata_t* PacketRF212Metadata.get(message_t* msg) - { - return &(getMeta(msg)->rf212); - } - - async command timestamp_metadata_t* PacketTimeStampMetadata.get(message_t* msg) - { - return &(getMeta(msg)->timestamp); - } - -#ifdef PACKET_LINK - async command link_metadata_t* PacketLinkMetadata.get(message_t* msg) - { - return &(getMeta(msg)->link); - } -#endif - -/*----------------- Packet -----------------*/ - - enum - { - PACKET_LENGTH_INCREASE = - sizeof(rf212packet_header_t) - 1 // the 8-bit length field is not counted - + sizeof(ieee154_footer_t), // the CRC is not stored in memory - }; - - command void Packet.clear(message_t* msg) - { - signal PacketFlagsMetadata.clear(msg); - signal PacketRF212Metadata.clear(msg); - signal PacketTimeStampMetadata.clear(msg); -#ifdef LOW_POWER_LISTENING - signal LowPowerListeningConfig.clear(msg); -#endif -#ifdef PACKET_LINK - signal PacketLinkMetadata.clear(msg); -#endif - call IEEE154MessageLayer.createDataFrame(msg); - } - - command void Packet.setPayloadLength(message_t* msg, uint8_t len) - { - call IEEE154MessageLayer.setLength(msg, len + PACKET_LENGTH_INCREASE); - } - - command uint8_t Packet.payloadLength(message_t* msg) - { - return call IEEE154MessageLayer.getLength(msg) - PACKET_LENGTH_INCREASE; - } - - command uint8_t Packet.maxPayloadLength() - { - return TOSH_DATA_LENGTH; - } - - command void* Packet.getPayload(message_t* msg, uint8_t len) - { - if( len > TOSH_DATA_LENGTH ) - return NULL; - - return msg->data; - } } diff --git a/tos/chips/rf2xx/rf212/RF212DriverConfig.nc b/tos/chips/rf2xx/rf212/RF212DriverConfig.nc index 150b3424..98218bc3 100644 --- a/tos/chips/rf2xx/rf212/RF212DriverConfig.nc +++ b/tos/chips/rf2xx/rf212/RF212DriverConfig.nc @@ -21,41 +21,31 @@ * Author: Miklos Maroti */ -/** - * This interface needs to be implemented by the MAC to control the behaviour - * of the RF212DriverLayerC component. - */ interface RF212DriverConfig { /** - * Returns the length of the PHY payload (including the FCF field). - * This value must be in the range [3, 127]. + * Returns the length of a dummy header to align the payload properly. */ - async command uint8_t getLength(message_t* msg); + async command uint8_t headerLength(message_t* msg); /** - * Sets the length of the PHY payload. + * Returns the maximum length of the PHY payload including the + * length field but not counting the FCF field. */ - async command void setLength(message_t* msg, uint8_t len); + async command uint8_t maxPayloadLength(); /** - * Returns a pointer to the start of the PHY payload that contains - * getLength()-2 number of bytes. The FCF field (CRC-16) is not stored, - * but automatically appended / verified. + * Returns the length of a dummy metadata section to align the + * metadata section properly. */ - async command uint8_t* getPayload(message_t* msg); + async command uint8_t metadataLength(message_t* msg); /** * 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. The header length must be at least one. */ - async command uint8_t getHeaderLength(); - - /** - * Returns the maximum PHY length that can be set via the setLength command - */ - async command uint8_t getMaxLength(); + async command uint8_t headerPreloadLength(); /** * Returns TRUE if before sending this message we should make sure that diff --git a/tos/chips/rf2xx/rf212/RF212DriverLayer.h b/tos/chips/rf2xx/rf212/RF212DriverLayer.h index 0224247f..19f31515 100644 --- a/tos/chips/rf2xx/rf212/RF212DriverLayer.h +++ b/tos/chips/rf2xx/rf212/RF212DriverLayer.h @@ -24,6 +24,11 @@ #ifndef __RF212DRIVERLAYER_H__ #define __RF212DRIVERLAYER_H__ +typedef nx_struct rf212_header_t +{ + nxle_uint8_t length; +} rf212_header_t; + typedef struct rf212_metadata_t { uint8_t lqi; diff --git a/tos/chips/rf2xx/rf212/RF212DriverLayerC.nc b/tos/chips/rf2xx/rf212/RF212DriverLayerC.nc index 5197b694..73b6b5e3 100644 --- a/tos/chips/rf2xx/rf212/RF212DriverLayerC.nc +++ b/tos/chips/rf2xx/rf212/RF212DriverLayerC.nc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Vanderbilt University + * Copyright (c) 2007, Vanderbilt University * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its @@ -32,6 +32,7 @@ configuration RF212DriverLayerC interface RadioSend; interface RadioReceive; interface RadioCCA; + interface RadioPacket; interface PacketField as PacketTransmitPower; interface PacketField as PacketRSSI; @@ -43,9 +44,8 @@ configuration RF212DriverLayerC uses { - interface RF212DriverConfig; + interface RF212DriverConfig as Config; interface PacketTimeStamp; - interface PacketData as PacketRF212Metadata; } } @@ -57,11 +57,11 @@ implementation RadioSend = RF212DriverLayerP; RadioReceive = RF212DriverLayerP; RadioCCA = RF212DriverLayerP; + RadioPacket = RF212DriverLayerP; LocalTimeRadio = HplRF212C; - RF212DriverConfig = RF212DriverLayerP; - PacketRF212Metadata = RF212DriverLayerP; + Config = RF212DriverLayerP; PacketTransmitPower = RF212DriverLayerP.PacketTransmitPower; components new MetadataFlagC() as TransmitPowerFlagC; diff --git a/tos/chips/rf2xx/rf212/RF212DriverLayerP.nc b/tos/chips/rf2xx/rf212/RF212DriverLayerP.nc index 6950dd6f..1df169a2 100644 --- a/tos/chips/rf2xx/rf212/RF212DriverLayerP.nc +++ b/tos/chips/rf2xx/rf212/RF212DriverLayerP.nc @@ -38,6 +38,7 @@ module RF212DriverLayerP interface RadioSend; interface RadioReceive; interface RadioCCA; + interface RadioPacket; interface PacketField as PacketTransmitPower; interface PacketField as PacketRSSI; @@ -60,9 +61,8 @@ module RF212DriverLayerP interface BusyWait; interface LocalTime; - interface RF212DriverConfig; + interface RF212DriverConfig as Config; - interface PacketData as PacketRF212Metadata; interface PacketFlag as TransmitPowerFlag; interface PacketFlag as RSSIFlag; interface PacketFlag as TimeSyncFlag; @@ -80,6 +80,21 @@ module RF212DriverLayerP implementation { + rf212_header_t* getHeader(message_t* msg) + { + return ((void*)msg) + call Config.headerLength(msg); + } + + void* getPayload(message_t* msg) + { + return ((void*)msg) + call RadioPacket.headerLength(msg); + } + + rf212_metadata_t* getMeta(message_t* msg) + { + return ((void*)msg) + sizeof(message_t) - call RadioPacket.metadataLength(msg); + } + /*----------------- STATE -----------------*/ tasklet_norace uint8_t state; @@ -420,7 +435,7 @@ implementation writeRegister(RF212_PHY_TX_PWR, txPower); } - if( call RF212DriverConfig.requiresRssiCca(msg) + if( call Config.requiresRssiCca(msg) && (readRegister(RF212_PHY_RSSI) & RF212_RSSI_MASK) > ((rssiClear + rssiBusy) >> 3) ) return EBUSY; @@ -428,7 +443,7 @@ implementation // do something useful, just to wait a little time32 = call LocalTime.get(); - timesync = call PacketTimeSyncOffset.isSet(msg) ? msg->data + call PacketTimeSyncOffset.get(msg) : 0; + timesync = call PacketTimeSyncOffset.isSet(msg) ? ((void*)msg) + call PacketTimeSyncOffset.get(msg) : 0; // we have missed an incoming message in this short amount of time if( (readRegister(RF212_TRX_STATUS) & RF212_TRX_STATUS_MASK) != RF212_PLL_ON ) @@ -451,8 +466,8 @@ implementation call SELN.clr(); call FastSpiByte.splitWrite(RF212_CMD_FRAME_WRITE); - length = call RF212DriverConfig.getLength(msg); - data = call RF212DriverConfig.getPayload(msg); + data = getPayload(msg); + length = getHeader(msg)->length; // length | data[0] ... data[length-3] | automatically generated FCS call FastSpiByte.splitReadWrite(length); @@ -460,7 +475,7 @@ implementation // the FCS is atomatically generated (2 bytes) length -= 2; - header = call RF212DriverConfig.getHeaderLength(); + header = call Config.headerPreloadLength(); if( header > length ) header = length; @@ -504,12 +519,12 @@ implementation #ifdef RADIO_DEBUG_MESSAGES if( call DiagMsg.record() ) { - length = call RF212DriverConfig.getLength(msg); + length = getHeader(msg)->length; call DiagMsg.str("tx"); call DiagMsg.uint16(time); call DiagMsg.uint8(length); - call DiagMsg.hex8s(data, length - 2); + call DiagMsg.hex8s(getPayload(msg), length - 2); call DiagMsg.send(); } #endif @@ -563,7 +578,7 @@ implementation length = call FastSpiByte.write(0); // if correct length - if( length >= 3 && length <= call RF212DriverConfig.getMaxLength() ) + if( length >= 3 && length <= call RadioPacket.maxPayloadLength() + 2 ) { uint8_t read; uint8_t* data; @@ -571,14 +586,14 @@ implementation // initiate the reading call FastSpiByte.splitWrite(0); - call RF212DriverConfig.setLength(rxMsg, length); - data = call RF212DriverConfig.getPayload(rxMsg); + data = getPayload(rxMsg); + getHeader(rxMsg)->length = length; crc = 0; // we do not store the CRC field length -= 2; - read = call RF212DriverConfig.getHeaderLength(); + read = call Config.headerPreloadLength(); if( length < read ) read = length; @@ -609,14 +624,14 @@ implementation #ifdef RADIO_DEBUG_MESSAGES if( call DiagMsg.record() ) { - length = call RF212DriverConfig.getLength(rxMsg); + length = getHeader(rxMsg)->length; call DiagMsg.str("rx"); call DiagMsg.uint32(call PacketTimeStamp.isValid(rxMsg) ? call PacketTimeStamp.timestamp(rxMsg) : 0); call DiagMsg.uint16(call RadioAlarm.getNow()); - call DiagMsg.uint8(crc == 0); + call DiagMsg.uint8(crc != 0); call DiagMsg.uint8(length); - call DiagMsg.hex8s(call RF212DriverConfig.getPayload(rxMsg), length - 2); + call DiagMsg.hex8s(getPayload(rxMsg), length - 2); call DiagMsg.send(); } #endif @@ -823,13 +838,45 @@ implementation call SpiResource.release(); } -/*----------------- PACKET -----------------*/ +/*----------------- RadioPacket -----------------*/ + + async command uint8_t RadioPacket.headerLength(message_t* msg) + { + return call Config.headerLength(msg) + sizeof(rf212_header_t); + } + + async command uint8_t RadioPacket.payloadLength(message_t* msg) + { + return getHeader(msg)->length - 2; + } + + async command void RadioPacket.setPayloadLength(message_t* msg, uint8_t length) + { + ASSERT( 1 <= length && length <= 125 ); + ASSERT( call RadioPacket.headerLength(msg) + length + call RadioPacket.metadataLength(msg) <= sizeof(message_t) ); + + // we add the length of the CRC, which is automatically generated + getHeader(msg)->length = length + 2; + } - async event void PacketRF212Metadata.clear(message_t* msg) + async command uint8_t RadioPacket.maxPayloadLength() { + ASSERT( call Config.maxPayloadLength() <= 125 ); + + return call Config.maxPayloadLength() - sizeof(rf212_header_t); } -// --- TransmitPower + async command uint8_t RadioPacket.metadataLength(message_t* msg) + { + return call Config.metadataLength(msg) + sizeof(rf212_metadata_t); + } + + async command void RadioPacket.clear(message_t* msg) + { + // all flags are automatically cleared + } + +/*----------------- PacketTransmitPower -----------------*/ async command bool PacketTransmitPower.isSet(message_t* msg) { @@ -838,7 +885,7 @@ implementation async command uint8_t PacketTransmitPower.get(message_t* msg) { - return (call PacketRF212Metadata.get(msg))->power; + return getMeta(msg)->power; } async command void PacketTransmitPower.clear(message_t* msg) @@ -849,10 +896,10 @@ implementation async command void PacketTransmitPower.set(message_t* msg, uint8_t value) { call TransmitPowerFlag.set(msg); - (call PacketRF212Metadata.get(msg))->power = value; + getMeta(msg)->power = value; } -// --- RSSI +/*----------------- PacketRSSI -----------------*/ async command bool PacketRSSI.isSet(message_t* msg) { @@ -861,7 +908,7 @@ implementation async command uint8_t PacketRSSI.get(message_t* msg) { - return (call PacketRF212Metadata.get(msg))->rssi; + return getMeta(msg)->rssi; } async command void PacketRSSI.clear(message_t* msg) @@ -875,17 +922,10 @@ implementation call TransmitPowerFlag.clear(msg); call RSSIFlag.set(msg); - (call PacketRF212Metadata.get(msg))->rssi = value; + getMeta(msg)->rssi = value; } -// --- TimeSyncOffset - - enum - { - PACKET_LENGTH_INCREASE = - sizeof(rf212packet_header_t) - 1 // the 8-bit length field is not counted - + sizeof(ieee154_footer_t), // the CRC is not stored in memory - }; +/*----------------- PacketTimeSyncOffset -----------------*/ async command bool PacketTimeSyncOffset.isSet(message_t* msg) { @@ -894,7 +934,7 @@ implementation async command uint8_t PacketTimeSyncOffset.get(message_t* msg) { - return call RF212DriverConfig.getLength(msg) - PACKET_LENGTH_INCREASE - sizeof(timesync_absolute_t); + return call RadioPacket.headerLength(msg) + call RadioPacket.payloadLength(msg) - sizeof(timesync_absolute_t); } async command void PacketTimeSyncOffset.clear(message_t* msg) @@ -905,12 +945,12 @@ implementation async command void PacketTimeSyncOffset.set(message_t* msg, uint8_t value) { // we do not store the value, the time sync field is always the last 4 bytes - ASSERT( call RF212DriverConfig.getLength(msg) - PACKET_LENGTH_INCREASE - sizeof(timesync_absolute_t) == value ); + ASSERT( call PacketTimeSyncOffset.get(msg) == value ); call TimeSyncFlag.set(msg); } -// --- LinkQuality +/*----------------- PacketLinkQuality -----------------*/ async command bool PacketLinkQuality.isSet(message_t* msg) { @@ -919,7 +959,7 @@ implementation async command uint8_t PacketLinkQuality.get(message_t* msg) { - return (call PacketRF212Metadata.get(msg))->lqi; + return getMeta(msg)->lqi; } async command void PacketLinkQuality.clear(message_t* msg) @@ -928,6 +968,6 @@ implementation async command void PacketLinkQuality.set(message_t* msg, uint8_t value) { - (call PacketRF212Metadata.get(msg))->lqi = value; + getMeta(msg)->lqi = value; } } diff --git a/tos/chips/rf2xx/rf212/RF212Ieee154MessageC.nc b/tos/chips/rf2xx/rf212/RF212Ieee154MessageC.nc new file mode 100644 index 00000000..21eca29b --- /dev/null +++ b/tos/chips/rf2xx/rf212/RF212Ieee154MessageC.nc @@ -0,0 +1,174 @@ +/* + * 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 + */ + +#include + +configuration RF212Ieee154MessageC +{ + provides + { + interface SplitControl; + + interface Ieee154Send; + interface Receive as Ieee154Receive; + interface Ieee154Packet; + interface Packet; + interface PacketAcknowledgements; + interface LowPowerListening; + interface PacketLink; + + interface RadioChannel; + + interface PacketField as PacketLinkQuality; + interface PacketField as PacketTransmitPower; + interface PacketField as PacketRSSI; + + interface LocalTime as LocalTimeRadio; + interface PacketTimeStamp as PacketTimeStampRadio; + interface PacketTimeStamp as PacketTimeStampMilli; + } +} + +implementation +{ + components RF212ActiveMessageP, RadioAlarmC; + +#ifdef RADIO_DEBUG + components AssertC; +#endif + + RF212ActiveMessageP.IEEE154MessageLayer -> IEEE154MessageLayerC; + RF212ActiveMessageP.RadioAlarm -> RadioAlarmC.RadioAlarm[unique("RadioAlarm")]; + RF212ActiveMessageP.PacketTimeStamp -> TimeStampingLayerC; + RF212ActiveMessageP.RF212Packet -> RF212DriverLayerC; + +// -------- IEEE154 Message + + components IEEE154MessageLayerC; + IEEE154MessageLayerC.SubPacket -> LowPowerListeningLayerC; + IEEE154MessageLayerC.SubSend -> UniqueLayerC; + Ieee154Send = IEEE154MessageLayerC; + Packet = IEEE154MessageLayerC; + Ieee154Receive = LowPowerListeningLayerC; + Ieee154Packet = IEEE154MessageLayerC; + +// -------- UniqueLayer Send part (wired twice) + + components UniqueLayerC; + UniqueLayerC.Config -> RF212ActiveMessageP; + UniqueLayerC.SubSend -> LowPowerListeningLayerC; + +// -------- Low Power Listening + +#ifdef LOW_POWER_LISTENING + components LowPowerListeningLayerC; + LowPowerListeningLayerC.Config -> RF212ActiveMessageP; + LowPowerListeningLayerC.PacketAcknowledgements -> SoftwareAckLayerC; +#else + components LowPowerListeningDummyC as LowPowerListeningLayerC; +#endif + LowPowerListeningLayerC.SubControl -> MessageBufferLayerC; + LowPowerListeningLayerC.SubSend -> PacketLinkLayerC; + LowPowerListeningLayerC.SubReceive -> MessageBufferLayerC; + LowPowerListeningLayerC.SubPacket -> PacketLinkLayerC; + SplitControl = LowPowerListeningLayerC; + LowPowerListening = LowPowerListeningLayerC; + +// -------- Packet Link + + components PacketLinkLayerC; + PacketLink = PacketLinkLayerC; + PacketLinkLayerC.PacketAcknowledgements -> SoftwareAckLayerC; + PacketLinkLayerC.SubSend -> MessageBufferLayerC; + PacketLinkLayerC.SubPacket -> TimeStampingLayerC; + +// -------- MessageBuffer + + components MessageBufferLayerC; + MessageBufferLayerC.Packet -> IEEE154MessageLayerC; // to get the payload for the Ieee154Receive.receive + MessageBufferLayerC.RadioSend -> TrafficMonitorLayerC; + MessageBufferLayerC.RadioReceive -> UniqueLayerC; + MessageBufferLayerC.RadioState -> TrafficMonitorLayerC; + RadioChannel = MessageBufferLayerC; + +// -------- UniqueLayer receive part (wired twice) + + UniqueLayerC.SubReceive -> TrafficMonitorLayerC; + +// -------- Traffic Monitor + + components TrafficMonitorLayerC; + TrafficMonitorLayerC.Config -> RF212ActiveMessageP; + TrafficMonitorLayerC.SubSend -> CollisionAvoidanceLayerC; + TrafficMonitorLayerC.SubReceive -> CollisionAvoidanceLayerC; + TrafficMonitorLayerC.SubState -> RF212DriverLayerC; + +// -------- CollisionAvoidance + +#ifdef SLOTTED_MAC + components SlottedCollisionLayerC as CollisionAvoidanceLayerC; +#else + components RandomCollisionLayerC as CollisionAvoidanceLayerC; +#endif + CollisionAvoidanceLayerC.Config -> RF212ActiveMessageP; + CollisionAvoidanceLayerC.SubSend -> SoftwareAckLayerC; + CollisionAvoidanceLayerC.SubReceive -> SoftwareAckLayerC; + +// -------- SoftwareAcknowledgement + + components SoftwareAckLayerC; + SoftwareAckLayerC.Config -> RF212ActiveMessageP; + SoftwareAckLayerC.SubSend -> CsmaLayerC; + SoftwareAckLayerC.SubReceive -> RF212DriverLayerC; + PacketAcknowledgements = SoftwareAckLayerC; + +// -------- Carrier Sense + + components new DummyLayerC() as CsmaLayerC; + CsmaLayerC.Config -> RF212ActiveMessageP; + CsmaLayerC -> RF212DriverLayerC.RadioSend; + CsmaLayerC -> RF212DriverLayerC.RadioCCA; + +// -------- TimeStamping + + components TimeStampingLayerC; + TimeStampingLayerC.LocalTimeRadio -> RF212DriverLayerC; + TimeStampingLayerC.SubPacket -> MetadataFlagsLayerC; + PacketTimeStampRadio = TimeStampingLayerC; + PacketTimeStampMilli = TimeStampingLayerC; + +// -------- MetadataFlags + + components MetadataFlagsLayerC; + MetadataFlagsLayerC.SubPacket -> RF212DriverLayerC; + +// -------- RF212 Driver + + components RF212DriverLayerC; + RF212DriverLayerC.Config -> RF212ActiveMessageP; + RF212DriverLayerC.PacketTimeStamp -> TimeStampingLayerC; + PacketTransmitPower = RF212DriverLayerC.PacketTransmitPower; + PacketLinkQuality = RF212DriverLayerC.PacketLinkQuality; + PacketRSSI = RF212DriverLayerC.PacketRSSI; + LocalTimeRadio = RF212DriverLayerC; +} diff --git a/tos/chips/rf2xx/rf230/RF230ActiveMessage.h b/tos/chips/rf2xx/rf230/RF230ActiveMessage.h index 940da723..e91bf224 100644 --- a/tos/chips/rf2xx/rf230/RF230ActiveMessage.h +++ b/tos/chips/rf2xx/rf230/RF230ActiveMessage.h @@ -35,6 +35,7 @@ typedef nx_struct rf230packet_header_t { + rf230_header_t rf230; ieee154_header_t ieee154; #ifndef TFRAMES_ENABLED lowpan_header_t lowpan; @@ -49,15 +50,15 @@ typedef nx_struct rf230packet_footer_t typedef struct rf230packet_metadata_t { - flags_metadata_t flags; - rf230_metadata_t rf230; - timestamp_metadata_t timestamp; #ifdef LOW_POWER_LISTENING lpl_metadata_t lpl; #endif #ifdef PACKET_LINK link_metadata_t link; #endif + timestamp_metadata_t timestamp; + flags_metadata_t flags; + rf230_metadata_t rf230; } rf230packet_metadata_t; #endif//__RF230ACTIVEMESSAGE_H__ diff --git a/tos/chips/rf2xx/rf230/RF230ActiveMessageC.nc b/tos/chips/rf2xx/rf230/RF230ActiveMessageC.nc index aa5cffe0..a9c4b0f6 100644 --- a/tos/chips/rf2xx/rf230/RF230ActiveMessageC.nc +++ b/tos/chips/rf2xx/rf230/RF230ActiveMessageC.nc @@ -65,7 +65,8 @@ implementation RF230ActiveMessageP.IEEE154MessageLayer -> IEEE154MessageLayerC; RF230ActiveMessageP.RadioAlarm -> RadioAlarmC.RadioAlarm[unique("RadioAlarm")]; RF230ActiveMessageP.PacketTimeStamp -> TimeStampingLayerC; - Packet = RF230ActiveMessageP; + RF230ActiveMessageP.ActiveMessagePacket -> ActiveMessageLayerC; + RF230ActiveMessageP.RF230Packet -> RF230DriverLayerC; // -------- Active Message @@ -73,7 +74,9 @@ implementation ActiveMessageLayerC.Config -> RF230ActiveMessageP; ActiveMessageLayerC.SubSend -> LowpanNetworkLayerC; ActiveMessageLayerC.SubReceive -> LowpanNetworkLayerC; + ActiveMessageLayerC.SubPacket ->LowpanNetworkLayerC; AMSend = ActiveMessageLayerC; + Packet = ActiveMessageLayerC; Receive = ActiveMessageLayerC.Receive; Snoop = ActiveMessageLayerC.Snoop; AMPacket = ActiveMessageLayerC; @@ -84,15 +87,15 @@ implementation components new DummyLayerC() as LowpanNetworkLayerC; #else components LowpanNetworkLayerC; - LowpanNetworkLayerC.Config -> RF230ActiveMessageP; #endif LowpanNetworkLayerC.SubSend -> UniqueLayerC; LowpanNetworkLayerC.SubReceive -> LowPowerListeningLayerC; + LowpanNetworkLayerC.SubPacket -> IEEE154MessageLayerC; -// -------- IEEE154 Packet +// -------- IEEE154 Message components IEEE154MessageLayerC; - IEEE154MessageLayerC.Config -> RF230ActiveMessageP; + IEEE154MessageLayerC.SubPacket -> LowPowerListeningLayerC; // -------- UniqueLayer Send part (wired twice) @@ -112,6 +115,7 @@ implementation LowPowerListeningLayerC.SubControl -> MessageBufferLayerC; LowPowerListeningLayerC.SubSend -> PacketLinkLayerC; LowPowerListeningLayerC.SubReceive -> MessageBufferLayerC; + LowPowerListeningLayerC.SubPacket -> PacketLinkLayerC; SplitControl = LowPowerListeningLayerC; LowPowerListening = LowPowerListeningLayerC; @@ -120,17 +124,17 @@ implementation #ifdef PACKET_LINK components PacketLinkLayerC; PacketLink = PacketLinkLayerC; - PacketLinkLayerC.PacketLinkMetadata -> RF230ActiveMessageP; PacketLinkLayerC.PacketAcknowledgements -> SoftwareAckLayerC; #else components new DummyLayerC() as PacketLinkLayerC; #endif PacketLinkLayerC.SubSend -> MessageBufferLayerC; + PacketLinkLayerC.SubPacket -> TimeStampingLayerC; // -------- MessageBuffer components MessageBufferLayerC; - MessageBufferLayerC.Packet -> RF230ActiveMessageP; + MessageBufferLayerC.Packet -> ActiveMessageLayerC; MessageBufferLayerC.RadioSend -> TrafficMonitorLayerC; MessageBufferLayerC.RadioReceive -> UniqueLayerC; MessageBufferLayerC.RadioState -> TrafficMonitorLayerC; @@ -174,27 +178,26 @@ implementation CsmaLayerC -> RF230DriverLayerC.RadioSend; CsmaLayerC -> RF230DriverLayerC.RadioCCA; +// -------- TimeStamping + + components TimeStampingLayerC; + TimeStampingLayerC.LocalTimeRadio -> RF230DriverLayerC; + TimeStampingLayerC.SubPacket -> MetadataFlagsLayerC; + PacketTimeStampRadio = TimeStampingLayerC; + PacketTimeStampMilli = TimeStampingLayerC; + +// -------- MetadataFlags + + components MetadataFlagsLayerC; + MetadataFlagsLayerC.SubPacket -> RF230DriverLayerC; + // -------- RF230 Driver components RF230DriverLayerC; - RF230DriverLayerC.PacketRF230Metadata -> RF230ActiveMessageP; - RF230DriverLayerC.RF230DriverConfig -> RF230ActiveMessageP; + RF230DriverLayerC.Config -> RF230ActiveMessageP; RF230DriverLayerC.PacketTimeStamp -> TimeStampingLayerC; PacketTransmitPower = RF230DriverLayerC.PacketTransmitPower; PacketLinkQuality = RF230DriverLayerC.PacketLinkQuality; PacketRSSI = RF230DriverLayerC.PacketRSSI; LocalTimeRadio = RF230DriverLayerC; - -// -------- MetadataFlags - - components MetadataFlagsLayerC; - MetadataFlagsLayerC.PacketFlagsMetadata -> RF230ActiveMessageP; - -// -------- TimeStamping - - components TimeStampingLayerC; - TimeStampingLayerC.LocalTimeRadio -> RF230DriverLayerC; - TimeStampingLayerC.PacketTimeStampMetadata -> RF230ActiveMessageP; - PacketTimeStampRadio = TimeStampingLayerC; - PacketTimeStampMilli = TimeStampingLayerC; } diff --git a/tos/chips/rf2xx/rf230/RF230ActiveMessageP.nc b/tos/chips/rf2xx/rf230/RF230ActiveMessageP.nc index 3f1100a2..57fa1c22 100644 --- a/tos/chips/rf2xx/rf230/RF230ActiveMessageP.nc +++ b/tos/chips/rf2xx/rf230/RF230ActiveMessageP.nc @@ -37,21 +37,10 @@ module RF230ActiveMessageP interface RandomCollisionConfig; interface SlottedCollisionConfig; interface ActiveMessageConfig; - interface LowpanNetworkConfig; - interface IEEE154MessageConfig; interface DummyConfig; - interface Packet; - - interface PacketData as PacketFlagsMetadata; - interface PacketData as PacketRF230Metadata; - interface PacketData as PacketTimeStampMetadata; - #ifdef LOW_POWER_LISTENING interface LowPowerListeningConfig; -#endif -#ifdef PACKET_LINK - interface PacketData as PacketLinkMetadata; #endif } @@ -59,6 +48,8 @@ module RF230ActiveMessageP { interface IEEE154MessageLayer; interface RadioAlarm; + interface RadioPacket as ActiveMessagePacket; + interface RadioPacket as RF230Packet; interface PacketTimeStamp; } @@ -66,45 +57,30 @@ module RF230ActiveMessageP implementation { - rf230packet_header_t* getHeader(message_t* msg) - { - return (rf230packet_header_t*)(msg->data - sizeof(rf230packet_header_t)); - } - - rf230packet_metadata_t* getMeta(message_t* msg) - { - return (rf230packet_metadata_t*)(msg->metadata); - } /*----------------- RF230DriverConfig -----------------*/ - async command uint8_t RF230DriverConfig.getLength(message_t* msg) + async command uint8_t RF230DriverConfig.headerLength(message_t* msg) { - return call IEEE154MessageLayer.getLength(msg); + return offsetof(message_t, data) - sizeof(rf230packet_header_t); } - async command void RF230DriverConfig.setLength(message_t* msg, uint8_t len) + async command uint8_t RF230DriverConfig.maxPayloadLength() { - call IEEE154MessageLayer.setLength(msg, len); + return sizeof(rf230packet_header_t) + TOSH_DATA_LENGTH; } - async command uint8_t* RF230DriverConfig.getPayload(message_t* msg) + async command uint8_t RF230DriverConfig.metadataLength(message_t* msg) { - return ((uint8_t*)(call IEEE154MessageConfig.getHeader(msg))) + 1; + 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 IEEE154MessageLayer.isDataFrame(msg); @@ -176,18 +152,9 @@ implementation /*----------------- ActiveMessageConfig -----------------*/ - command error_t ActiveMessageConfig.checkPacket(message_t* msg) - { - // the user forgot to call clear, we should return EINVAL - if( ! call IEEE154MessageLayer.isDataFrame(msg) ) - call Packet.clear(msg); - - return SUCCESS; - } - - command activemessage_header_t* ActiveMessageConfig.getHeader(message_t* msg) + command bool ActiveMessageConfig.forgotToClear(message_t* msg) { - return &(getHeader(msg)->am); + return ! call IEEE154MessageLayer.isDataFrame(msg); } command am_addr_t ActiveMessageConfig.destination(message_t* msg) @@ -249,7 +216,7 @@ implementation * ack required: 8-16 byte separation, 11 bytes airtime, 5-10 bytes separation */ - uint8_t len = call IEEE154MessageLayer.getLength(msg); + uint8_t len = call RF230Packet.payloadLength(msg); return call IEEE154MessageLayer.getAckRequired(msg) ? len + 6 + 16 + 11 + 10 : len + 6 + 10; } @@ -346,29 +313,10 @@ implementation { } -/*----------------- LowpanNetwork -----------------*/ - - command lowpan_header_t* LowpanNetworkConfig.getHeader(message_t* msg) - { - return &(getHeader(msg)->lowpan); - } - -/*----------------- IEEE154Message -----------------*/ - - async command ieee154_header_t* IEEE154MessageConfig.getHeader(message_t* msg) - { - return &(getHeader(msg)->ieee154); - } - /*----------------- LowPowerListening -----------------*/ #ifdef LOW_POWER_LISTENING - async command lpl_metadata_t* LowPowerListeningConfig.metadata(message_t* msg) - { - return &(getMeta(msg)->lpl); - } - async command bool LowPowerListeningConfig.getAckRequired(message_t* msg) { return call IEEE154MessageLayer.getAckRequired(msg); @@ -376,73 +324,4 @@ implementation #endif -/*----------------- Headers and Metadata -----------------*/ - - async command flags_metadata_t* PacketFlagsMetadata.get(message_t* msg) - { - return &(getMeta(msg)->flags); - } - - async command rf230_metadata_t* PacketRF230Metadata.get(message_t* msg) - { - return &(getMeta(msg)->rf230); - } - - async command timestamp_metadata_t* PacketTimeStampMetadata.get(message_t* msg) - { - return &(getMeta(msg)->timestamp); - } - -#ifdef PACKET_LINK - async command link_metadata_t* PacketLinkMetadata.get(message_t* msg) - { - return &(getMeta(msg)->link); - } -#endif - -/*----------------- Packet -----------------*/ - - enum - { - PACKET_LENGTH_INCREASE = - sizeof(rf230packet_header_t) - 1 // the 8-bit length field is not counted - + sizeof(ieee154_footer_t), // the CRC is not stored in memory - }; - - command void Packet.clear(message_t* msg) - { - signal PacketFlagsMetadata.clear(msg); - signal PacketRF230Metadata.clear(msg); - signal PacketTimeStampMetadata.clear(msg); -#ifdef LOW_POWER_LISTENING - signal LowPowerListeningConfig.clear(msg); -#endif -#ifdef PACKET_LINK - signal PacketLinkMetadata.clear(msg); -#endif - call IEEE154MessageLayer.createDataFrame(msg); - } - - command void Packet.setPayloadLength(message_t* msg, uint8_t len) - { - call IEEE154MessageLayer.setLength(msg, len + PACKET_LENGTH_INCREASE); - } - - command uint8_t Packet.payloadLength(message_t* msg) - { - return call IEEE154MessageLayer.getLength(msg) - PACKET_LENGTH_INCREASE; - } - - command uint8_t Packet.maxPayloadLength() - { - return TOSH_DATA_LENGTH; - } - - command void* Packet.getPayload(message_t* msg, uint8_t len) - { - if( len > TOSH_DATA_LENGTH ) - return NULL; - - return msg->data; - } } diff --git a/tos/chips/rf2xx/rf230/RF230DriverConfig.nc b/tos/chips/rf2xx/rf230/RF230DriverConfig.nc index e6b05b3d..f67786d9 100644 --- a/tos/chips/rf2xx/rf230/RF230DriverConfig.nc +++ b/tos/chips/rf2xx/rf230/RF230DriverConfig.nc @@ -21,41 +21,31 @@ * Author: Miklos Maroti */ -/** - * This interface needs to be implemented by the MAC to control the behaviour - * of the RF230DriverLayerC component. - */ interface RF230DriverConfig { /** - * Returns the length of the PHY payload (including the FCF field). - * This value must be in the range [3, 127]. + * Returns the length of a dummy header to align the payload properly. */ - async command uint8_t getLength(message_t* msg); + async command uint8_t headerLength(message_t* msg); /** - * Sets the length of the PHY payload. + * Returns the maximum length of the PHY payload including the + * length field but not counting the FCF field. */ - async command void setLength(message_t* msg, uint8_t len); + async command uint8_t maxPayloadLength(); /** - * Returns a pointer to the start of the PHY payload that contains - * getLength()-2 number of bytes. The FCF field (CRC-16) is not stored, - * but automatically appended / verified. + * Returns the length of a dummy metadata section to align the + * metadata section properly. */ - async command uint8_t* getPayload(message_t* msg); + async command uint8_t metadataLength(message_t* msg); /** * 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. The header length must be at least one. */ - async command uint8_t getHeaderLength(); - - /** - * Returns the maximum PHY length that can be set via the setLength command - */ - async command uint8_t getMaxLength(); + async command uint8_t headerPreloadLength(); /** * Returns TRUE if before sending this message we should make sure that diff --git a/tos/chips/rf2xx/rf230/RF230DriverLayer.h b/tos/chips/rf2xx/rf230/RF230DriverLayer.h index c57969f8..1884d116 100644 --- a/tos/chips/rf2xx/rf230/RF230DriverLayer.h +++ b/tos/chips/rf2xx/rf230/RF230DriverLayer.h @@ -24,6 +24,11 @@ #ifndef __RF230DRIVERLAYER_H__ #define __RF230DRIVERLAYER_H__ +typedef nx_struct rf230_header_t +{ + nxle_uint8_t length; +} rf230_header_t; + typedef struct rf230_metadata_t { uint8_t lqi; diff --git a/tos/chips/rf2xx/rf230/RF230DriverLayerC.nc b/tos/chips/rf2xx/rf230/RF230DriverLayerC.nc index 8b58211d..b1bf4dd6 100644 --- a/tos/chips/rf2xx/rf230/RF230DriverLayerC.nc +++ b/tos/chips/rf2xx/rf230/RF230DriverLayerC.nc @@ -32,6 +32,7 @@ configuration RF230DriverLayerC interface RadioSend; interface RadioReceive; interface RadioCCA; + interface RadioPacket; interface PacketField as PacketTransmitPower; interface PacketField as PacketRSSI; @@ -43,9 +44,8 @@ configuration RF230DriverLayerC uses { - interface RF230DriverConfig; + interface RF230DriverConfig as Config; interface PacketTimeStamp; - interface PacketData as PacketRF230Metadata; } } @@ -57,11 +57,11 @@ implementation RadioSend = RF230DriverLayerP; RadioReceive = RF230DriverLayerP; RadioCCA = RF230DriverLayerP; + RadioPacket = RF230DriverLayerP; LocalTimeRadio = HplRF230C; - RF230DriverConfig = RF230DriverLayerP; - PacketRF230Metadata = RF230DriverLayerP; + Config = RF230DriverLayerP; PacketTransmitPower = RF230DriverLayerP.PacketTransmitPower; components new MetadataFlagC() as TransmitPowerFlagC; diff --git a/tos/chips/rf2xx/rf230/RF230DriverLayerP.nc b/tos/chips/rf2xx/rf230/RF230DriverLayerP.nc index 77e94ad2..6f74fb16 100644 --- a/tos/chips/rf2xx/rf230/RF230DriverLayerP.nc +++ b/tos/chips/rf2xx/rf230/RF230DriverLayerP.nc @@ -38,6 +38,7 @@ module RF230DriverLayerP interface RadioSend; interface RadioReceive; interface RadioCCA; + interface RadioPacket; interface PacketField as PacketTransmitPower; interface PacketField as PacketRSSI; @@ -60,9 +61,8 @@ module RF230DriverLayerP interface BusyWait; interface LocalTime; - interface RF230DriverConfig; + interface RF230DriverConfig as Config; - interface PacketData as PacketRF230Metadata; interface PacketFlag as TransmitPowerFlag; interface PacketFlag as RSSIFlag; interface PacketFlag as TimeSyncFlag; @@ -80,6 +80,21 @@ module RF230DriverLayerP implementation { + rf230_header_t* getHeader(message_t* msg) + { + return ((void*)msg) + call Config.headerLength(msg); + } + + void* getPayload(message_t* msg) + { + return ((void*)msg) + call RadioPacket.headerLength(msg); + } + + rf230_metadata_t* getMeta(message_t* msg) + { + return ((void*)msg) + sizeof(message_t) - call RadioPacket.metadataLength(msg); + } + /*----------------- STATE -----------------*/ tasklet_norace uint8_t state; @@ -420,7 +435,7 @@ implementation writeRegister(RF230_PHY_TX_PWR, RF230_TX_AUTO_CRC_ON | txPower); } - if( call RF230DriverConfig.requiresRssiCca(msg) + if( call Config.requiresRssiCca(msg) && (readRegister(RF230_PHY_RSSI) & RF230_RSSI_MASK) > ((rssiClear + rssiBusy) >> 3) ) return EBUSY; @@ -428,7 +443,7 @@ implementation // do something useful, just to wait a little time32 = call LocalTime.get(); - timesync = call PacketTimeSyncOffset.isSet(msg) ? msg->data + call PacketTimeSyncOffset.get(msg) : 0; + timesync = call PacketTimeSyncOffset.isSet(msg) ? ((void*)msg) + call PacketTimeSyncOffset.get(msg) : 0; // we have missed an incoming message in this short amount of time if( (readRegister(RF230_TRX_STATUS) & RF230_TRX_STATUS_MASK) != RF230_PLL_ON ) @@ -453,8 +468,8 @@ implementation call SELN.clr(); call FastSpiByte.splitWrite(RF230_CMD_FRAME_WRITE); - length = call RF230DriverConfig.getLength(msg); - data = call RF230DriverConfig.getPayload(msg); + data = getPayload(msg); + length = getHeader(msg)->length; // length | data[0] ... data[length-3] | automatically generated FCS call FastSpiByte.splitReadWrite(length); @@ -462,7 +477,7 @@ implementation // the FCS is atomatically generated (2 bytes) length -= 2; - header = call RF230DriverConfig.getHeaderLength(); + header = call Config.headerPreloadLength(); if( header > length ) header = length; @@ -515,12 +530,12 @@ implementation #ifdef RADIO_DEBUG_MESSAGES if( call DiagMsg.record() ) { - length = call RF230DriverConfig.getLength(msg); + length = getHeader(msg)->length; call DiagMsg.str("tx"); call DiagMsg.uint16(time); call DiagMsg.uint8(length); - call DiagMsg.hex8s(data, length - 2); + call DiagMsg.hex8s(getPayload(msg), length - 2); call DiagMsg.send(); } #endif @@ -574,7 +589,7 @@ implementation length = call FastSpiByte.write(0); // if correct length - if( length >= 3 && length <= call RF230DriverConfig.getMaxLength() ) + if( length >= 3 && length <= call RadioPacket.maxPayloadLength() + 2 ) { uint8_t read; uint8_t* data; @@ -582,14 +597,14 @@ implementation // initiate the reading call FastSpiByte.splitWrite(0); - call RF230DriverConfig.setLength(rxMsg, length); - data = call RF230DriverConfig.getPayload(rxMsg); + data = getPayload(rxMsg); + getHeader(rxMsg)->length = length; crc = 0; // we do not store the CRC field length -= 2; - read = call RF230DriverConfig.getHeaderLength(); + read = call Config.headerPreloadLength(); if( length < read ) read = length; @@ -622,14 +637,14 @@ implementation #ifdef RADIO_DEBUG_MESSAGES if( call DiagMsg.record() ) { - length = call RF230DriverConfig.getLength(rxMsg); + length = getHeader(rxMsg)->length; call DiagMsg.str("rx"); call DiagMsg.uint32(call PacketTimeStamp.isValid(rxMsg) ? call PacketTimeStamp.timestamp(rxMsg) : 0); call DiagMsg.uint16(call RadioAlarm.getNow()); call DiagMsg.uint8(crc != 0); call DiagMsg.uint8(length); - call DiagMsg.hex8s(call RF230DriverConfig.getPayload(rxMsg), length - 2); + call DiagMsg.hex8s(getPayload(rxMsg), length - 2); call DiagMsg.send(); } #endif @@ -836,13 +851,45 @@ implementation call SpiResource.release(); } -/*----------------- PACKET -----------------*/ +/*----------------- RadioPacket -----------------*/ + + async command uint8_t RadioPacket.headerLength(message_t* msg) + { + return call Config.headerLength(msg) + sizeof(rf230_header_t); + } + + async command uint8_t RadioPacket.payloadLength(message_t* msg) + { + return getHeader(msg)->length - 2; + } + + async command void RadioPacket.setPayloadLength(message_t* msg, uint8_t length) + { + ASSERT( 1 <= length && length <= 125 ); + ASSERT( call RadioPacket.headerLength(msg) + length + call RadioPacket.metadataLength(msg) <= sizeof(message_t) ); + + // we add the length of the CRC, which is automatically generated + getHeader(msg)->length = length + 2; + } - async event void PacketRF230Metadata.clear(message_t* msg) + async command uint8_t RadioPacket.maxPayloadLength() { + ASSERT( call Config.maxPayloadLength() <= 125 ); + + return call Config.maxPayloadLength() - sizeof(rf230_header_t); } -// --- TransmitPower + async command uint8_t RadioPacket.metadataLength(message_t* msg) + { + return call Config.metadataLength(msg) + sizeof(rf230_metadata_t); + } + + async command void RadioPacket.clear(message_t* msg) + { + // all flags are automatically cleared + } + +/*----------------- PacketTransmitPower -----------------*/ async command bool PacketTransmitPower.isSet(message_t* msg) { @@ -851,7 +898,7 @@ implementation async command uint8_t PacketTransmitPower.get(message_t* msg) { - return (call PacketRF230Metadata.get(msg))->power; + return getMeta(msg)->power; } async command void PacketTransmitPower.clear(message_t* msg) @@ -862,10 +909,10 @@ implementation async command void PacketTransmitPower.set(message_t* msg, uint8_t value) { call TransmitPowerFlag.set(msg); - (call PacketRF230Metadata.get(msg))->power = value; + getMeta(msg)->power = value; } -// --- RSSI +/*----------------- PacketRSSI -----------------*/ async command bool PacketRSSI.isSet(message_t* msg) { @@ -874,7 +921,7 @@ implementation async command uint8_t PacketRSSI.get(message_t* msg) { - return (call PacketRF230Metadata.get(msg))->rssi; + return getMeta(msg)->rssi; } async command void PacketRSSI.clear(message_t* msg) @@ -888,17 +935,10 @@ implementation call TransmitPowerFlag.clear(msg); call RSSIFlag.set(msg); - (call PacketRF230Metadata.get(msg))->rssi = value; + getMeta(msg)->rssi = value; } -// --- TimeSyncOffset - - enum - { - PACKET_LENGTH_INCREASE = - sizeof(rf230packet_header_t) - 1 // the 8-bit length field is not counted - + sizeof(ieee154_footer_t), // the CRC is not stored in memory - }; +/*----------------- PacketTimeSyncOffset -----------------*/ async command bool PacketTimeSyncOffset.isSet(message_t* msg) { @@ -907,7 +947,7 @@ implementation async command uint8_t PacketTimeSyncOffset.get(message_t* msg) { - return call RF230DriverConfig.getLength(msg) - PACKET_LENGTH_INCREASE - sizeof(timesync_absolute_t); + return call RadioPacket.headerLength(msg) + call RadioPacket.payloadLength(msg) - sizeof(timesync_absolute_t); } async command void PacketTimeSyncOffset.clear(message_t* msg) @@ -918,12 +958,12 @@ implementation async command void PacketTimeSyncOffset.set(message_t* msg, uint8_t value) { // we do not store the value, the time sync field is always the last 4 bytes - ASSERT( call RF230DriverConfig.getLength(msg) - PACKET_LENGTH_INCREASE - sizeof(timesync_absolute_t) == value ); + ASSERT( call PacketTimeSyncOffset.get(msg) == value ); call TimeSyncFlag.set(msg); } -// --- LinkQuality +/*----------------- PacketLinkQuality -----------------*/ async command bool PacketLinkQuality.isSet(message_t* msg) { @@ -932,7 +972,7 @@ implementation async command uint8_t PacketLinkQuality.get(message_t* msg) { - return (call PacketRF230Metadata.get(msg))->lqi; + return getMeta(msg)->lqi; } async command void PacketLinkQuality.clear(message_t* msg) @@ -941,6 +981,6 @@ implementation async command void PacketLinkQuality.set(message_t* msg, uint8_t value) { - (call PacketRF230Metadata.get(msg))->lqi = value; + getMeta(msg)->lqi = value; } } diff --git a/tos/chips/rf2xx/util/PacketData.nc b/tos/chips/rf2xx/util/PacketData.nc deleted file mode 100644 index b3338280..00000000 --- a/tos/chips/rf2xx/util/PacketData.nc +++ /dev/null @@ -1,37 +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 PacketData -{ - /** - * This command returns a pointer to a set of packet fields (in the header, footer - * or metadata) with the given data type. - */ - async command data_t* get(message_t* msg); - - /** - * This event is signalled, when the these fields should be reset to their default - * value (usually called from Packet.clear) - */ - async event void clear(message_t* msg); -} diff --git a/tos/chips/rf2xx/util/RadioPacket.nc b/tos/chips/rf2xx/util/RadioPacket.nc new file mode 100644 index 00000000..17979eab --- /dev/null +++ b/tos/chips/rf2xx/util/RadioPacket.nc @@ -0,0 +1,60 @@ +/* + * 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 RadioPacket +{ + /** + * This command returns the length of the header. The header + * starts at the first byte of the message_t structure + * (some layers may add dummy bytes to allign the payload to + * the msg->data section). + */ + async command uint8_t headerLength(message_t* msg); + + /** + * Returns the length of the payload. The payload starts right + * after th header. + */ + async command uint8_t payloadLength(message_t* msg); + + /** + * Sets the length of the payload. + */ + async command void setPayloadLength(message_t* msg, uint8_t length); + + /** + * Returns the maximum length that can be set for this message. + */ + async command uint8_t maxPayloadLength(); + + /** + * Returns the length of the metadata section. The metadata section + * is at the very end of the message_t structure and grows downwards. + */ + async command uint8_t metadataLength(message_t* msg); + + /** + * Clears all metadata and sets all default values in the headers. + */ + async command void clear(message_t* msg); +}