Hi,
I'm have some problem understanding the following places in CC2420ReceiveP,
can anyone help? Thanks in advance.
async event void RXFIFO.readDone( uint8_t* rx_buf, uint8_t rx_len,
error_t error ) {
cc2420_header_t* header = call CC2420PacketBody.getHeader( m_p_rx_buf );
uint8_t tmpLen __DEPUTY_UNUSED__ = sizeof(message_t) -
(offsetof(message_t, data) - sizeof(cc2420_header_t));
uint8_t* COUNT(tmpLen) buf = TCAST(uint8_t* COUNT(tmpLen), header);
rxFrameLength = buf[ 0 ];
switch( m_state ) {
case S_RX_LENGTH:
m_state = S_RX_FCF;
if ( rxFrameLength + 1 > m_bytes_left ) {
// Length of this packet is bigger than the RXFIFO, flush it out.
flush();
} else {
//XL: what does the following sentence mean?
if ( !call FIFO.get() && !call FIFOP.get() ) {
m_bytes_left -= rxFrameLength + 1;
}
if(rxFrameLength <= MAC_PACKET_SIZE) {
if(rxFrameLength > 0) {
//XL: what is happening here?
if(rxFrameLength > SACK_HEADER_LENGTH) {
// This packet has an FCF byte plus at least one more byte to
read
call RXFIFO.continueRead(buf + 1, SACK_HEADER_LENGTH);
} else {
// This is really a bad packet, skip FCF and get it out of
here.
m_state = S_RX_PAYLOAD;
call RXFIFO.continueRead(buf + 1, rxFrameLength);
}
} else {
// Length == 0; start reading the next packet
atomic receivingPacket = FALSE;
call CSN.set();
call SpiResource.release();
waitForNextPacket();
}
} else {
// Length is too large; we have to flush the entire Rx FIFO
flush();
}
}
break;
..........
case S_RX_PAYLOAD:
call CSN.set();
//XL: why is SPI released if no packet is missed?
if(!m_missed_packets) {
// Release the SPI only if there are no more frames to download
call SpiResource.release();
}
//XL: why is time stamp needed here?
if ( m_timestamp_size ) {
if ( rxFrameLength > 10 ) {
call PacketTimeStamp.set(m_p_rx_buf, m_timestamp_queue[
m_timestamp_head ]);
m_timestamp_head = ( m_timestamp_head + 1 ) %
TIMESTAMP_QUEUE_SIZE;
m_timestamp_size--;
}
} else {
call PacketTimeStamp.clear(m_p_rx_buf);
}
// We may have received an ack that should be processed by Transmit
// buf[rxFrameLength] >> 7 checks the CRC
if ( ( buf[ rxFrameLength ] >> 7 ) && rx_buf ) {
uint8_t type = ( header->fcf >> IEEE154_FCF_FRAME_TYPE ) & 7;
//XL: is ACK also passed to upper layer via event Receive.receive()
?
signal CC2420Receive.receive( type, m_p_rx_buf );
if ( type == IEEE154_TYPE_DATA ) {
post receiveDone_task();
return;
}
}
.....
}
--
-Xiaohui Liu
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help