X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fchips%2Fcc2420%2Ftransmit%2FCC2420TransmitP.nc;h=a8367e54c99f0342df952fd65fda1dc59baf2e5c;hb=aa7578fd1472c62c1d22d0801fe0f55b36093bdf;hp=17653d6584c4b471d366a52e2c06ef6b999dbf48;hpb=0ab1429a57148045a74254930442ecddd47d63a3;p=tinyos-2.x.git diff --git a/tos/chips/cc2420/transmit/CC2420TransmitP.nc b/tos/chips/cc2420/transmit/CC2420TransmitP.nc index 17653d65..a8367e54 100644 --- a/tos/chips/cc2420/transmit/CC2420TransmitP.nc +++ b/tos/chips/cc2420/transmit/CC2420TransmitP.nc @@ -41,7 +41,7 @@ #include "crc.h" #include "message.h" -module CC2420TransmitP { +module CC2420TransmitP @safe() { provides interface Init; provides interface StdControl; @@ -236,12 +236,10 @@ implementation { } - inline uint32_t time16to32(uint16_t time, uint32_t recent_time) + inline uint32_t getTime32(uint16_t time) { - if ((recent_time&0xFFFF)fcf & ( 1 << IEEE154_FCF_ACK_REQ ) ) { @@ -283,16 +289,11 @@ implementation { releaseSpiResource(); call BackoffTimer.stop(); - - if ( ( ( (call CC2420PacketBody.getHeader( m_msg ))->fcf >> IEEE154_FCF_FRAME_TYPE ) & 7 ) == IEEE154_TYPE_DATA ) { - call PacketTimeStamp.set(m_msg, time32); - } - if ( call SFD.get() ) { break; } /** Fall Through because the next interrupt was already received */ - + case S_EFD: sfdHigh = FALSE; call CaptureSFD.captureRisingEdge(); @@ -310,9 +311,12 @@ implementation { /** Fall Through because the next interrupt was already received */ default: - if ( !m_receiving ) { + /* this is the SFD for received messages */ + if ( !m_receiving && sfdHigh == FALSE ) { sfdHigh = TRUE; call CaptureSFD.captureFallingEdge(); + // safe the SFD pin status for later use + sfd_state = call SFD.get(); call CC2420Receive.sfd( time32 ); m_receiving = TRUE; m_prev_time = time; @@ -320,17 +324,29 @@ implementation { // wait for the next interrupt before moving on return; } + // if SFD.get() = 0, then an other interrupt happened since we + // reconfigured CaptureSFD! Fall through } - sfdHigh = FALSE; - call CaptureSFD.captureRisingEdge(); - m_receiving = FALSE; - if ( time - m_prev_time < 10 ) { - call CC2420Receive.sfd_dropped(); - call PacketTimeStamp.clear(m_msg); + if ( sfdHigh == TRUE ) { + sfdHigh = FALSE; + call CaptureSFD.captureRisingEdge(); + m_receiving = FALSE; + /* if sfd_state is 1, then we fell through, but at the time of + * saving the time stamp the SFD was still high. Thus, the timestamp + * is valid. + * if the sfd_state is 0, then either we fell through and SFD + * was low while we safed the time stamp, or we didn't fall through. + * Thus, we check for the time between the two interrupts. + * FIXME: Why 10 tics? Seams like some magic number... + */ + if ((sfd_state == 0) && (time - m_prev_time < 10) ) { + call CC2420Receive.sfd_dropped(); + if (m_msg) + call PacketTimeStamp.clear(m_msg); + } + break; } - break; - } } } @@ -355,7 +371,7 @@ implementation { uint8_t* ack_buf; uint8_t length; - if ( type == IEEE154_TYPE_ACK ) { + if ( type == IEEE154_TYPE_ACK && m_msg) { ack_header = call CC2420PacketBody.getHeader( ack_msg ); msg_header = call CC2420PacketBody.getHeader( m_msg );