Changeset 1090

Show
Ignore:
Timestamp:
05/02/08 03:23:59 (13 years ago)
Author:
ppalmers
Message:

fix CTR reconstruction bug

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/libieee1394/cycletimer.h

    r1038 r1090  
    202202    int diff = (int)x - (int)y; 
    203203 
    204     // the maximal difference we allow (64secs) 
     204    // the maximal difference we allow (4000 cycles) 
    205205    const int max=CYCLES_PER_SECOND/2; 
    206206 
  • trunk/libffado/src/libieee1394/IsoHandler.cpp

    r1046 r1090  
    374374    uint32_t now_secs = CYCLE_TIMER_GET_SECS(m_last_now); 
    375375    // causality results in the fact that 'now' is always after 'cycle' 
    376     if(CYCLE_TIMER_GET_CYCLES(m_last_now) < cycle) { 
     376    // except if additional packets are received between setting the 
     377    // m_last_now and the starting the iterate() loop. 
     378    // this causes the m_last_now to be set at a time before the last packet 
     379    // in this loop is received. however, it's not going to be >4000 cycles. 
     380    // hence: 
     381    // - if the m_last_now > cycle, there is no need to unwrap 
     382    //   both values are within the same second 
     383    // - if m_last_now < cycle it can mean two things: 
     384    //    * m_last_now has wrapped, but is still later than cycle 
     385    //      hence diffCycles(m_last_now, cycle) > 0. We should unwrap 
     386    //    * m_last_now has not wrapped, and cycle is ahead of m_last_now 
     387    //      this means that the cycle is more recent than the saved 
     388    //      m_last_now value 
     389    // . Hence if we calculate 
     390    // the unwrapped difference, and it's larger than 0, this means 
     391    // that m_last_now is after the current cycle. . 
     392    // it m_last_now is before the current cycle, we should not unwrap 
     393    // NOTE: another option is to reread the m_last_now 
     394    if( (CYCLE_TIMER_GET_CYCLES(m_last_now) < cycle) 
     395        && diffCycles(CYCLE_TIMER_GET_CYCLES(m_last_now), cycle) >= 0) { 
     396        debugOutputExtreme(DEBUG_LEVEL_VERBOSE, 
     397                           "unwrapping %d => %d, %d\n", 
     398                           CYCLE_TIMER_GET_CYCLES(m_last_now), 
     399                           cycle); 
    377400        // the cycle field has wrapped, substract one second 
    378401        if(now_secs == 0) { 
     
    382405        } 
    383406    } 
     407     
     408    #ifdef DEBUG 
     409    if( (CYCLE_TIMER_GET_CYCLES(m_last_now) < cycle) 
     410        && diffCycles(CYCLE_TIMER_GET_CYCLES(m_last_now), cycle) < 0) { 
     411        debugWarning("Special non-unwrapping happened\n"); 
     412    }     
     413    #endif 
     414     
    384415    pkt_ctr |= (now_secs & 0x7F) << 25; 
     416 
     417 
    385418 
    386419    #if ISOHANDLER_CHECK_CTR_RECONSTRUCTION 
     
    389422    uint32_t now_secs_ref = CYCLE_TIMER_GET_SECS(now); 
    390423    // causality results in the fact that 'now' is always after 'cycle' 
     424    // or at best, equal (if this handler was called within 125us after 
     425    // the packet was on the wire). 
    391426    if(CYCLE_TIMER_GET_CYCLES(now) < cycle) { 
    392427        // the cycle field has wrapped, substract one second 
     
    402437    if(pkt_ctr != pkt_ctr_ref) { 
    403438        debugWarning("reconstructed CTR counter discrepancy\n"); 
    404         pkt_ctr=pkt_ctr_ref; 
     439        debugWarning(" ingredients: %X, %lX, %lX, %lX, %lX, %ld, %ld\n", 
     440                       cycle, pkt_ctr_ref, pkt_ctr, now, m_last_now, now_secs_ref, now_secs); 
    405441    } 
    406442    #endif 
     
    461497    return RAW1394_ISO_OK; 
    462498} 
    463  
    464499 
    465500enum raw1394_iso_disposition