X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fchips%2Fcc2420%2Ftransmit%2FCC2420TransmitP.nc;h=a8367e54c99f0342df952fd65fda1dc59baf2e5c;hb=fbde8e8b590651b32583d9250bb4921d5b6ab1a3;hp=5e45f8d769ae85f345f5db511eeba0c7b12f65a3;hpb=31bef23ef3377514af595000d2fa2cce07bd4531;p=tinyos-2.x.git diff --git a/tos/chips/cc2420/transmit/CC2420TransmitP.nc b/tos/chips/cc2420/transmit/CC2420TransmitP.nc index 5e45f8d7..a8367e54 100644 --- a/tos/chips/cc2420/transmit/CC2420TransmitP.nc +++ b/tos/chips/cc2420/transmit/CC2420TransmitP.nc @@ -257,6 +257,7 @@ implementation { */ async event void CaptureSFD.captured( uint16_t time ) { uint32_t time32; + uint8_t sfd_state = 0; atomic { time32 = getTime32(time); switch( m_state ) { @@ -264,6 +265,9 @@ implementation { case S_SFD: m_state = S_EFD; sfdHigh = TRUE; + // in case we got stuck in the receive SFD interrupts, we can reset + // the state here since we know that we are not receiving anymore + m_receiving = FALSE; call CaptureSFD.captureFallingEdge(); call PacketTimeStamp.set(m_msg, time32); if (call PacketTimeSyncOffset.isSet(m_msg)) { @@ -274,6 +278,8 @@ implementation { call CSN.clr(); call TXFIFO_RAM.write( absOffset, (uint8_t*)timesync, sizeof(timesync_radio_t) ); call CSN.set(); + //restoring the event time to the original value + *timesync += time32; } if ( (call CC2420PacketBody.getHeader( m_msg ))->fcf & ( 1 << IEEE154_FCF_ACK_REQ ) ) { @@ -305,9 +311,12 @@ implementation { /** Fall Through because the next interrupt was already received */ default: + /* 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; @@ -315,13 +324,23 @@ 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 } if ( sfdHigh == TRUE ) { sfdHigh = FALSE; call CaptureSFD.captureRisingEdge(); m_receiving = FALSE; - if ( time - m_prev_time < 10 ) { + /* 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);