X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fchips%2Fcc2420%2FCC2420ActiveMessageP.nc;h=0db2423c7b83167d7bf41b4797e85c117b52cb8f;hb=42b450d2e6d5eda17245d38f4d2bceb6b60e5400;hp=35fb1c03345e4b5bdc4f542965613fe9a2de18e0;hpb=bf9b9a71bbe1b62dfb69216f90c3bd50ee87dc53;p=tinyos-2.x.git diff --git a/tos/chips/cc2420/CC2420ActiveMessageP.nc b/tos/chips/cc2420/CC2420ActiveMessageP.nc index 35fb1c03..0db2423c 100644 --- a/tos/chips/cc2420/CC2420ActiveMessageP.nc +++ b/tos/chips/cc2420/CC2420ActiveMessageP.nc @@ -1,4 +1,4 @@ -/* tab:4 +/* * "Copyright (c) 2005 Stanford University. All rights reserved. * * Permission to use, copy, modify, and distribute this software and @@ -34,7 +34,7 @@ #include "CC2420.h" -module CC2420ActiveMessageP { +module CC2420ActiveMessageP @safe() { provides { interface AMSend[am_id_t id]; interface Receive[am_id_t id]; @@ -42,6 +42,7 @@ module CC2420ActiveMessageP { interface AMPacket; interface Packet; interface SendNotifier[am_id_t id]; + interface RadioBackoff[am_id_t id]; } uses { @@ -51,26 +52,29 @@ module CC2420ActiveMessageP { interface CC2420PacketBody; interface CC2420Config; interface ActiveMessageAddress; + interface RadioBackoff as SubBackoff; } } implementation { - enum { - CC2420_SIZE = MAC_HEADER_SIZE + MAC_FOOTER_SIZE, - }; - /***************** AMSend Commands ****************/ command error_t AMSend.send[am_id_t id](am_addr_t addr, message_t* msg, uint8_t len) { cc2420_header_t* header = call CC2420PacketBody.getHeader( msg ); + + if (len > call Packet.maxPayloadLength()) { + return ESIZE; + } + header->type = id; header->dest = addr; header->destpan = call CC2420Config.getPanAddr(); + header->src = call AMPacket.address(); signal SendNotifier.aboutToSend[id](addr, msg); - return call SubSend.send( msg, len + CC2420_SIZE ); + return call SubSend.send( msg, len ); } command error_t AMSend.cancel[am_id_t id](message_t* msg) { @@ -176,10 +180,10 @@ implementation { } if (call AMPacket.isForMe(msg)) { - return signal Receive.receive[call AMPacket.type(msg)](msg, payload, len - CC2420_SIZE); + return signal Receive.receive[call AMPacket.type(msg)](msg, payload, len); } else { - return signal Snoop.receive[call AMPacket.type(msg)](msg, payload, len - CC2420_SIZE); + return signal Snoop.receive[call AMPacket.type(msg)](msg, payload, len); } } @@ -192,6 +196,48 @@ implementation { event void CC2420Config.syncDone( error_t error ) { } + + /***************** RadioBackoff ***********************/ + + async event void SubBackoff.requestInitialBackoff(message_t *msg) { + signal RadioBackoff.requestInitialBackoff[(TCAST(cc2420_header_t* ONE, + (uint8_t*)msg + offsetof(message_t, data) - sizeof(cc2420_header_t)))->type](msg); + } + + async event void SubBackoff.requestCongestionBackoff(message_t *msg) { + signal RadioBackoff.requestCongestionBackoff[(TCAST(cc2420_header_t* ONE, + (uint8_t*)msg + offsetof(message_t, data) - sizeof(cc2420_header_t)))->type](msg); + } + async event void SubBackoff.requestCca(message_t *msg) { + // Lower layers than this do not configure the CCA settings + signal RadioBackoff.requestCca[(TCAST(cc2420_header_t* ONE, + (uint8_t*)msg + offsetof(message_t, data) - sizeof(cc2420_header_t)))->type](msg); + } + + async command void RadioBackoff.setInitialBackoff[am_id_t amId](uint16_t backoffTime) { + call SubBackoff.setInitialBackoff(backoffTime); + } + + /** + * Must be called within a requestCongestionBackoff event + * @param backoffTime the amount of time in some unspecified units to backoff + */ + async command void RadioBackoff.setCongestionBackoff[am_id_t amId](uint16_t backoffTime) { + call SubBackoff.setCongestionBackoff(backoffTime); + } + + + /** + * Enable CCA for the outbound packet. Must be called within a requestCca + * event + * @param ccaOn TRUE to enable CCA, which is the default. + */ + async command void RadioBackoff.setCca[am_id_t amId](bool useCca) { + call SubBackoff.setCca(useCca); + } + + + /***************** Defaults ****************/ default event message_t* Receive.receive[am_id_t id](message_t* msg, void* payload, uint8_t len) { return msg; @@ -206,5 +252,16 @@ implementation { default event void SendNotifier.aboutToSend[am_id_t amId](am_addr_t addr, message_t *msg) { } + default async event void RadioBackoff.requestInitialBackoff[am_id_t id]( + message_t *msg) { + } + + default async event void RadioBackoff.requestCongestionBackoff[am_id_t id]( + message_t *msg) { + } + + default async event void RadioBackoff.requestCca[am_id_t id]( + message_t *msg) { + } }