bool hwAutoAckDefault;
+ bool addressRecognition;
+
norace cc2420_control_state_t m_state = S_VREG_STOPPED;
/***************** Prototypes ****************/
hwAutoAckDefault = FALSE;
#endif
+#if defined(CC2420_NO_ADDRESS_RECOGNITION)
+ addressRecognition = FALSE;
+#else
+ addressRecognition = TRUE;
+#endif
+
return SUCCESS;
}
atomic m_channel = channel;
}
- command uint16_t CC2420Config.getShortAddr() {
+ async command uint16_t CC2420Config.getShortAddr() {
atomic return m_short_addr;
}
atomic m_short_addr = addr;
}
- command uint16_t CC2420Config.getPanAddr() {
- return m_pan;
+ async command uint16_t CC2420Config.getPanAddr() {
+ atomic return m_pan;
}
command void CC2420Config.setPanAddr( uint16_t pan ) {
return SUCCESS;
}
+ /**
+ * @param on TRUE to turn address recognition on, FALSE to turn it off
+ */
+ command void CC2420Config.setAddressRecognition(bool on) {
+ atomic addressRecognition = on;
+ }
+
+ /**
+ * @return TRUE if address recognition is enabled
+ */
+ async command bool CC2420Config.isAddressRecognitionEnabled() {
+ atomic return addressRecognition;
+ }
+
+
/**
* Sync must be called for acknowledgement changes to take effect
* @param enableAutoAck TRUE to enable auto acknowledgements
* acks are the default
*/
async command bool CC2420Config.isHwAutoAckDefault() {
- bool isHwAck;
- atomic {
- isHwAck = hwAutoAckDefault;
- }
- return isHwAck;
+ atomic return hwAutoAckDefault;
}
/**
* @return TRUE if auto acks are enabled
*/
async command bool CC2420Config.isAutoAckEnabled() {
- bool isAckEnabled;
- atomic {
- isAckEnabled = autoAckEnabled;
- }
- return isAckEnabled;
+ atomic return autoAckEnabled;
}
/***************** ReadRssi Commands ****************/
void writeMdmctrl0() {
atomic {
call MDMCTRL0.write( ( 1 << CC2420_MDMCTRL0_RESERVED_FRAME_MODE ) |
- ( 1 << CC2420_MDMCTRL0_ADR_DECODE ) |
+ ( addressRecognition << CC2420_MDMCTRL0_ADR_DECODE ) |
( 2 << CC2420_MDMCTRL0_CCA_HYST ) |
( 3 << CC2420_MDMCTRL0_CCA_MOD ) |
( 1 << CC2420_MDMCTRL0_AUTOCRC ) |
/**
* Change the short address of the radio.
*/
- command uint16_t getShortAddr();
+ async command uint16_t getShortAddr();
command void setShortAddr( uint16_t address );
/**
* Change the PAN address of the radio.
*/
- command uint16_t getPanAddr();
+ async command uint16_t getPanAddr();
command void setPanAddr( uint16_t address );
+ /**
+ * @param on TRUE to turn address recognition on, FALSE to turn it off
+ */
+ command void setAddressRecognition(bool on);
+
+ /**
+ * @return TRUE if address recognition is enabled
+ */
+ async command bool isAddressRecognitionEnabled();
+
/**
* Sync must be called for acknowledgement changes to take effect
* @param enableAutoAck TRUE to enable auto acknowledgements
components MainC;
components CC2420ReceiveP;
components CC2420PacketC;
- components ActiveMessageAddressC;
components new CC2420SpiC() as Spi;
components CC2420ControlC;
enum {
RXFIFO_SIZE = 128,
TIMESTAMP_QUEUE_SIZE = 8,
- FCF_LENGTH = 2,
+ SACK_HEADER_LENGTH = 7,
};
uint16_t m_timestamp_queue[ TIMESTAMP_QUEUE_SIZE ];
}
return SUCCESS;
}
-
-
command error_t StdControl.stop() {
atomic {
if(rxFrameLength <= MAC_PACKET_SIZE) {
if(rxFrameLength > 0) {
- if(rxFrameLength > FCF_LENGTH) {
+ if(rxFrameLength > SACK_HEADER_LENGTH) {
// This packet has an FCF byte plus at least one more byte to read
- call RXFIFO.continueRead(buf + 1, FCF_LENGTH);
+ call RXFIFO.continueRead(buf + 1, SACK_HEADER_LENGTH);
} else {
// This is really a bad packet, skip FCF and get it out of here.
case S_RX_FCF:
m_state = S_RX_PAYLOAD;
+
+ /*
+ * The destination address check here is not completely optimized. If you
+ * are seeing issues with dropped acknowledgements, try removing
+ * the address check and decreasing SACK_HEADER_LENGTH to 2.
+ * The length byte and the FCF byte are the only two bytes required
+ * to know that the packet is valid and requested an ack. The destination
+ * address is useful when we want to sniff packets from other transmitters
+ * while acknowledging packets that were destined for our local address.
+ */
if(call CC2420Config.isAutoAckEnabled() && !call CC2420Config.isHwAutoAckDefault()) {
if (((( header->fcf >> IEEE154_FCF_ACK_REQ ) & 0x01) == 1)
+ && (header->dest == call CC2420Config.getShortAddr())
&& ((( header->fcf >> IEEE154_FCF_FRAME_TYPE ) & 7) == IEEE154_TYPE_DATA)) {
// CSn flippage cuts off our FIFO; SACK and begin reading again
call CSN.set();
call SACK.strobe();
call CSN.set();
call CSN.clr();
- call RXFIFO.beginRead(buf + 1 + FCF_LENGTH,
- rxFrameLength - FCF_LENGTH);
+ call RXFIFO.beginRead(buf + 1 + SACK_HEADER_LENGTH,
+ rxFrameLength - SACK_HEADER_LENGTH);
return;
}
}
// Didn't flip CSn, we're ok to continue reading.
- call RXFIFO.continueRead(buf + 1 + FCF_LENGTH,
- rxFrameLength - FCF_LENGTH);
+ call RXFIFO.continueRead(buf + 1 + SACK_HEADER_LENGTH,
+ rxFrameLength - SACK_HEADER_LENGTH);
break;
case S_RX_PAYLOAD:
atomic receivingPacket = FALSE;
waitForNextPacket();
}
-
+
/****************** CC2420Config Events ****************/
event void CC2420Config.syncDone( error_t error ) {
}