uses interface FrameUtility;
uses interface CC2420Config;
uses interface CC2420Ram as RXFIFO_RAM;
-
- uses interface Leds;
}
implementation {
SACK_HEADER_LENGTH = 3,
};
- ieee154_reftime_t m_timestamp_queue[ TIMESTAMP_QUEUE_SIZE ];
- ieee154_reftime_t m_timestamp;
+ ieee154_timestamp_t m_timestamp_queue[ TIMESTAMP_QUEUE_SIZE ];
+ ieee154_timestamp_t m_timestamp;
norace bool m_timestampValid;
uint8_t m_timestamp_head;
// because we don't own the SPI...
return FAIL;
}
- if (m_state != S_STOPPED){
- call Leds.led0On();
- return FAIL;
- }
+ ASSERT(m_state == S_STOPPED);
reset_state();
m_state = S_STARTED;
call InterruptFIFOP.enableFallingEdge(); // ready!
task void stopContinueTask()
{
- if (receivingPacket)
- call Leds.led0On();
+ ASSERT(receivingPacket != TRUE);
call SpiResource.release(); // may fail
atomic m_state = S_STOPPED;
signal AsyncSplitControl.stopDone(SUCCESS);
}
- void switchToUnbufferedMode()
- {
- uint16_t mdmctrol1;
- call CSN.set();
- call CSN.clr();
- call MDMCTRL1.read(&mdmctrol1);
- mdmctrol1 &= ~0x03;
- mdmctrol1 |= 0x01;
- call MDMCTRL1.write(mdmctrol1);
- call CSN.set();
- }
-
- void switchToBufferedMode()
- {
- uint16_t mdmctrol1;
- call CSN.set();
- call CSN.clr();
- call MDMCTRL1.read(&mdmctrol1);
- mdmctrol1 &= ~0x03;
- call MDMCTRL1.write(mdmctrol1);
- call CSN.set();
- }
-
/***************** CC2420Receive Commands ****************/
/**
* Start frame delimiter signifies the beginning/end of a packet
* See the CC2420 datasheet for details.
*/
- async command void CC2420Receive.sfd( ieee154_reftime_t *time ) {
+ async command void CC2420Receive.sfd( ieee154_timestamp_t *time ) {
if (m_state == S_STOPPED)
return;
if ( m_timestamp_size < TIMESTAMP_QUEUE_SIZE ) {
uint8_t tail = ( ( m_timestamp_head + m_timestamp_size ) %
TIMESTAMP_QUEUE_SIZE );
- memcpy(&m_timestamp_queue[ tail ], time, sizeof(ieee154_reftime_t) );
+ memcpy(&m_timestamp_queue[ tail ], time, sizeof(ieee154_timestamp_t) );
m_timestamp_size++;
}
}
atomic {
switch (m_state)
{
- case S_STOPPED: // this should never happen!
- call Leds.led0On();
- call SpiResource.release();
- break;
+ case S_STOPPED: ASSERT(0); break; // this should never happen!
default: receive();
}
}
}
- uint8_t mhrLength(uint8_t *fcf)
- {
- uint8_t idCompression;
- uint8_t len = MHR_INDEX_ADDRESS;
-
- if (fcf[MHR_INDEX_FC1] & FC1_SECURITY_ENABLED)
- return 0xFF; // not supported
- idCompression = (fcf[0] & FC1_PAN_ID_COMPRESSION);
- if (fcf[MHR_INDEX_FC2] & 0x08){ // short or ext. address
- len += 4; // pan id + short address
- if (fcf[MHR_INDEX_FC2] & 0x04) // ext. address
- len += 6; // diff to short address
- }
- if (fcf[MHR_INDEX_FC2] & 0x80){ // short or ext. address
- len += 2;
- if (!idCompression)
- len += 2;
- if (fcf[MHR_INDEX_FC2] & 0x40) // ext. address
- len += 6; // diff to short address
- }
- return len;
- }
-
-
/***************** RXFIFO Events ****************/
/**
* We received some bytes from the SPI bus. Process them in the context
}
if ( m_timestamp_size ) {
- if ( rxFrameLength > 10 ) {
+ if ( rxFrameLength > 4 ) {
//((ieee154_metadata_t*) m_rxFramePtr->metadata)->timestamp = m_timestamp_queue[ m_timestamp_head ];
- memcpy(&m_timestamp, &m_timestamp_queue[ m_timestamp_head ], sizeof(ieee154_reftime_t) );
+ memcpy(&m_timestamp, &m_timestamp_queue[ m_timestamp_head ], sizeof(ieee154_timestamp_t) );
m_timestampValid = TRUE;
m_timestamp_head = ( m_timestamp_head + 1 ) % TIMESTAMP_QUEUE_SIZE;
m_timestamp_size--;
uint8_t payloadLen = ((ieee154_header_t*) m_rxFramePtr->header)->length - m_mhrLen - 2;
ieee154_metadata_t *metadata = (ieee154_metadata_t*) m_rxFramePtr->metadata;
- atomic {
- if (m_state == S_STOPPED){
- call Leds.led0On();
- return;
- }
- }
+ atomic ASSERT(m_state != S_STOPPED);
((ieee154_header_t*) m_rxFramePtr->header)->length = m_rxFramePtr->data[payloadLen+1] & 0x7f; // temp. LQI
metadata->rssi = m_rxFramePtr->data[payloadLen];
metadata->linkQuality = ((ieee154_header_t*) m_rxFramePtr->header)->length; // copy back