X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fchips%2Frf2xx%2Frf230%2FRF230ActiveMessageP.nc;h=0842b5af1ae456795ebf0a75aa9c39d4cb87ff31;hb=fb06e38f2c4372980a983a3d79f584221d475a36;hp=9c8044cd34a704c34e6e17c2a52c5956b01ffc5b;hpb=a3ebb402bf00465e45f4420fb0c472e03432cca9;p=tinyos-2.x.git diff --git a/tos/chips/rf2xx/rf230/RF230ActiveMessageP.nc b/tos/chips/rf2xx/rf230/RF230ActiveMessageP.nc index 9c8044cd..0842b5af 100644 --- a/tos/chips/rf2xx/rf230/RF230ActiveMessageP.nc +++ b/tos/chips/rf2xx/rf230/RF230ActiveMessageP.nc @@ -21,7 +21,7 @@ * Author: Miklos Maroti */ -#include +#include #include #include @@ -38,13 +38,27 @@ module RF230ActiveMessageP interface SlottedCollisionConfig; interface ActiveMessageConfig; interface DummyConfig; + + interface Packet; + + interface PacketData as PacketFlagsMetadata; + interface PacketData as PacketRF230Metadata; + interface PacketData as PacketTimeStampMetadata; + +#ifdef LOW_POWER_LISTENING + interface PacketData as PacketLplMetadata; +#endif +#ifdef PACKET_LINK + interface PacketData as PacketLinkMetadata; +#endif } uses { - interface IEEE154Packet2; - interface Packet; + interface IEEE154PacketLayer; interface RadioAlarm; + + interface PacketTimeStamp; } } @@ -54,22 +68,17 @@ implementation async command uint8_t RF230DriverConfig.getLength(message_t* msg) { - return call IEEE154Packet2.getLength(msg); + return call IEEE154PacketLayer.getLength(msg); } async command void RF230DriverConfig.setLength(message_t* msg, uint8_t len) { - call IEEE154Packet2.setLength(msg, len); + call IEEE154PacketLayer.setLength(msg, len); } async command uint8_t* RF230DriverConfig.getPayload(message_t* msg) { - return ((uint8_t*)(call IEEE154Packet2.getHeader(msg))) + 1; - } - - inline rf230packet_metadata_t* getMeta(message_t* msg) - { - return (rf230packet_metadata_t*)(msg->metadata); + return ((uint8_t*)(call IEEE154PacketLayer.getHeader(msg))) + 1; } async command uint8_t RF230DriverConfig.getHeaderLength() @@ -86,42 +95,39 @@ implementation async command bool RF230DriverConfig.requiresRssiCca(message_t* msg) { - return call IEEE154Packet2.isDataFrame(msg); + return call IEEE154PacketLayer.isDataFrame(msg); } /*----------------- SoftwareAckConfig -----------------*/ async command bool SoftwareAckConfig.requiresAckWait(message_t* msg) { - return call IEEE154Packet2.requiresAckWait(msg); + return call IEEE154PacketLayer.requiresAckWait(msg); } async command bool SoftwareAckConfig.isAckPacket(message_t* msg) { - return call IEEE154Packet2.isAckFrame(msg); + return call IEEE154PacketLayer.isAckFrame(msg); } async command bool SoftwareAckConfig.verifyAckPacket(message_t* data, message_t* ack) { - return call IEEE154Packet2.verifyAckReply(data, ack); + return call IEEE154PacketLayer.verifyAckReply(data, ack); } - async command bool SoftwareAckConfig.requiresAckReply(message_t* msg) + async command void SoftwareAckConfig.setAckRequired(message_t* msg, bool ack) { - return call IEEE154Packet2.requiresAckReply(msg); + call IEEE154PacketLayer.setAckRequired(msg, ack); } - async command void SoftwareAckConfig.createAckPacket(message_t* data, message_t* ack) + async command bool SoftwareAckConfig.requiresAckReply(message_t* msg) { - call IEEE154Packet2.createAckReply(data, ack); + return call IEEE154PacketLayer.requiresAckReply(msg); } - async command void SoftwareAckConfig.setAckReceived(message_t* msg, bool acked) + async command void SoftwareAckConfig.createAckPacket(message_t* data, message_t* ack) { - if( acked ) - getMeta(msg)->flags |= RF230PACKET_WAS_ACKED; - else - getMeta(msg)->flags &= ~RF230PACKET_WAS_ACKED; + call IEEE154PacketLayer.createAckReply(data, ack); } async command uint16_t SoftwareAckConfig.getAckTimeout() @@ -138,17 +144,17 @@ implementation async command uint8_t UniqueConfig.getSequenceNumber(message_t* msg) { - return call IEEE154Packet2.getDSN(msg); + return call IEEE154PacketLayer.getDSN(msg); } async command void UniqueConfig.setSequenceNumber(message_t* msg, uint8_t dsn) { - call IEEE154Packet2.setDSN(msg, dsn); + call IEEE154PacketLayer.setDSN(msg, dsn); } async command am_addr_t UniqueConfig.getSender(message_t* msg) { - return call IEEE154Packet2.getSrcAddr(msg); + return call IEEE154PacketLayer.getSrcAddr(msg); } tasklet_async command void UniqueConfig.reportChannelError() @@ -161,7 +167,7 @@ implementation command error_t ActiveMessageConfig.checkPacket(message_t* msg) { // the user forgot to call clear, we should return EINVAL - if( ! call IEEE154Packet2.isDataFrame(msg) ) + if( ! call IEEE154PacketLayer.isDataFrame(msg) ) call Packet.clear(msg); return SUCCESS; @@ -171,7 +177,7 @@ implementation async command bool CsmaConfig.requiresSoftwareCCA(message_t* msg) { - return call IEEE154Packet2.isDataFrame(msg); + return call IEEE154PacketLayer.isDataFrame(msg); } /*----------------- TrafficMonitorConfig -----------------*/ @@ -196,13 +202,13 @@ implementation * ack required: 8-16 byte separation, 11 bytes airtime, 5-10 bytes separation */ - uint8_t len = call IEEE154Packet2.getLength(msg); - return call IEEE154Packet2.getAckRequired(msg) ? len + 6 + 16 + 11 + 10 : len + 6 + 10; + uint8_t len = call IEEE154PacketLayer.getLength(msg); + return call IEEE154PacketLayer.getAckRequired(msg) ? len + 6 + 16 + 11 + 10 : len + 6 + 10; } async command am_addr_t TrafficMonitorConfig.getSender(message_t* msg) { - return call IEEE154Packet2.getSrcAddr(msg); + return call IEEE154PacketLayer.getSrcAddr(msg); } tasklet_async command void TrafficMonitorConfig.timerTick() @@ -244,7 +250,7 @@ implementation time = call RadioAlarm.getNow(); // estimated response time (download the message, etc) is 5-8 bytes - if( call IEEE154Packet2.requiresAckReply(msg) ) + if( call IEEE154PacketLayer.requiresAckReply(msg) ) time += (uint16_t)(32 * (-5 + 16 + 11 + 5) * RADIO_ALARM_MICROSEC); else time += (uint16_t)(32 * (-5 + 5) * RADIO_ALARM_MICROSEC); @@ -269,13 +275,13 @@ implementation async command uint16_t SlottedCollisionConfig.getTransmitTime(message_t* msg) { // TODO: check if the timestamp is correct - return getMeta(msg)->timestamp; + return call PacketTimeStamp.timestamp(msg); } async command uint16_t SlottedCollisionConfig.getCollisionWindowStart(message_t* msg) { // the preamble (4 bytes), SFD (1 byte), plus two extra for safety - return getMeta(msg)->timestamp - (uint16_t)(7 * 32 * RADIO_ALARM_MICROSEC); + return (call PacketTimeStamp.timestamp(msg)) - (uint16_t)(7 * 32 * RADIO_ALARM_MICROSEC); } async command uint16_t SlottedCollisionConfig.getCollisionWindowLength(message_t* msg) @@ -290,4 +296,86 @@ implementation async command void DummyConfig.nothing() { } + +/*----------------- Metadata -----------------*/ + + inline rf230packet_metadata_t* getMeta(message_t* msg) + { + return (rf230packet_metadata_t*)(msg->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 LOW_POWER_LISTENING + async command lpl_metadata_t* PacketLplMetadata.get(message_t* msg) + { + return &(getMeta(msg)->lpl); + } +#endif + +#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 PacketLplMetadata.clear(msg); +#endif +#ifdef PACKET_LINK + signal PacketLinkMetadata.clear(msg); +#endif + call IEEE154PacketLayer.createDataFrame(msg); + } + + inline command void Packet.setPayloadLength(message_t* msg, uint8_t len) + { + call IEEE154PacketLayer.setLength(msg, len + PACKET_LENGTH_INCREASE); + } + + inline command uint8_t Packet.payloadLength(message_t* msg) + { + return call IEEE154PacketLayer.getLength(msg) - PACKET_LENGTH_INCREASE; + } + + inline 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; + } }