Show
Ignore:
Timestamp:
02/14/07 01:31:54 (17 years ago)
Author:
pieterpalmers
Message:

- fixed SYT timestamp to ticks conversion

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/streaming-rework/src/libstreaming/AmdtpStreamProcessor.cpp

    r393 r394  
    235235#ifdef DEBUG 
    236236    if(!m_is_disabled) { 
    237         debugOutput(DEBUG_LEVEL_VERY_VERBOSE, " > TS=%11llu, CTR=%11llu, FC=%5d\n", 
    238             timestamp, cycle_timer, fc 
     237        debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "R: TS=%011llu, NOW=%011llu, CYN=%04d, CYT=%04d\n", 
     238            timestamp, cycle_timer, now_cycles, cycle 
    239239            ); 
    240240        debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "    UTN=%11lld\n", 
     
    246246    } 
    247247#endif 
    248      
     248 
     249    #ifdef DEBUG 
     250    if((cycle % 1000) == 0) { 
     251        uint32_t timestamp_u=timestamp; 
     252        uint32_t syt = TICKS_TO_SYT(addTicks(timestamp_u, TRANSMIT_TRANSFER_DELAY)); 
     253        uint32_t now=m_handler->getCycleTimer(); 
     254        uint32_t now_ticks=CYCLE_TIMER_TO_TICKS(now); 
     255         
     256        uint32_t test_ts=sytXmitToFullTicks(syt, cycle, now); 
     257 
     258        debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "T %04d: SYT=%08X,            CY=%02d OFF=%04d\n", 
     259            cycle, syt, CYCLE_TIMER_GET_CYCLES(syt), CYCLE_TIMER_GET_OFFSET(syt) 
     260            ); 
     261        debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "T %04d: NOW=%011lu, SEC=%03u CY=%02u OFF=%04u\n", 
     262            cycle, now_ticks, CYCLE_TIMER_GET_SECS(now), CYCLE_TIMER_GET_CYCLES(now), CYCLE_TIMER_GET_OFFSET(now) 
     263            ); 
     264        debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "T %04d: TSS=%011lu, SEC=%03u CY=%02u OFF=%04u\n", 
     265            cycle, test_ts, TICKS_TO_SECS(test_ts), TICKS_TO_CYCLES(test_ts), TICKS_TO_OFFSET(test_ts) 
     266            ); 
     267        debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "T %04d: TSO=%011lu, SEC=%03u CY=%02u OFF=%04u\n", 
     268            cycle, timestamp_u, TICKS_TO_SECS(timestamp_u), TICKS_TO_CYCLES(timestamp_u), TICKS_TO_OFFSET(timestamp_u) 
     269            ); 
     270    } 
     271    #endif 
    249272    // don't process the stream when it is not enabled, not running 
    250273    // or when the next sample is not due yet. 
     
    918941 
    919942        //=> convert the SYT to a full timestamp in ticks 
    920         m_last_timestamp=sytToFullTicks((uint32_t)ntohs(packet->syt),  
     943        m_last_timestamp=sytRecvToFullTicks((uint32_t)ntohs(packet->syt),  
    921944                                        cycle, m_handler->getCycleTimer()); 
    922945 
     
    10171040            return RAW1394_ISO_DEFER; 
    10181041        } 
     1042         
     1043        #ifdef DEBUG 
     1044        if((cycle % 1000) == 0) { 
     1045            uint32_t syt = (uint32_t)ntohs(packet->syt); 
     1046            uint32_t now=m_handler->getCycleTimer(); 
     1047            uint32_t now_ticks=CYCLE_TIMER_TO_TICKS(now); 
     1048             
     1049            uint32_t test_ts=sytRecvToFullTicks(syt, cycle, now); 
     1050 
     1051            debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "R %04d: SYT=%08X,            CY=%02d OFF=%04d\n", 
     1052                cycle, syt, CYCLE_TIMER_GET_CYCLES(syt), CYCLE_TIMER_GET_OFFSET(syt) 
     1053                ); 
     1054            debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "R %04d: NOW=%011lu, SEC=%03u CY=%02u OFF=%04u\n", 
     1055                cycle, now_ticks, CYCLE_TIMER_GET_SECS(now), CYCLE_TIMER_GET_CYCLES(now), CYCLE_TIMER_GET_OFFSET(now) 
     1056                ); 
     1057            debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "R %04d: TSS=%011lu, SEC=%03u CY=%02u OFF=%04u\n", 
     1058                cycle, test_ts, TICKS_TO_SECS(test_ts), TICKS_TO_CYCLES(test_ts), TICKS_TO_OFFSET(test_ts) 
     1059                ); 
     1060        } 
     1061        #endif 
    10191062         
    10201063        //=> process the packet 
  • branches/streaming-rework/src/libstreaming/cycletimer.h

    r393 r394  
    7575 
    7676/** 
    77  * @brief Converts a SYT timestamp to a full timestamp in ticks. 
    78  * 
    79  *  
     77 * @brief Converts a received SYT timestamp to a full timestamp in ticks. 
     78 * 
    8079 * 
    8180 * @param syt_timestamp The SYT timestamp as present in the packet 
     
    8483 * @return  
    8584 */ 
    86 static inline uint32_t sytToFullTicks(uint32_t syt_timestamp, unsigned int rcv_cycle, uint32_t ctr_now) { 
     85static inline uint32_t sytRecvToFullTicks(uint32_t syt_timestamp, unsigned int rcv_cycle, uint32_t ctr_now) { 
    8786    uint32_t timestamp; 
    8887     
     88    debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"SYT=%08X CY=%04X CTR=%08X\n", 
     89        syt_timestamp,rcv_cycle,ctr_now); 
     90         
    8991    // reconstruct the full cycle 
    9092    uint32_t cc_cycles=CYCLE_TIMER_GET_CYCLES(ctr_now); 
     
    140142     
    141143    timestamp += CYCLE_TIMER_GET_OFFSET(syt_timestamp); 
     144     
    142145    timestamp += cc_seconds * TICKS_PER_SECOND; 
     146     
     147    #ifdef DEBUG 
     148        if(( TICKS_TO_CYCLE_TIMER(timestamp) & 0xFFFF) != syt_timestamp) { 
     149            debugWarning("back-converted timestamp not equal to SYT\n"); 
     150            debugWarning("TS=%011llu TSC=%08X SYT=%04X\n", 
     151                  timestamp, TICKS_TO_CYCLE_TIMER(timestamp), syt_timestamp); 
     152        } 
     153    #endif 
     154     
     155    return timestamp; 
     156} 
     157 
     158/** 
     159 * @brief Converts a transmit SYT timestamp to a full timestamp in ticks. 
     160 * 
     161 * The difference between sytRecvToFullTicks and sytXmitToFullTicks is 
     162 * the way SYT cycle wraparound is detected: in the receive version,  
     163 * wraparound is present if rcv_cycle > current_cycle. In the xmit 
     164 * version this is when current_cycle > xmt_cycle. 
     165 * 
     166 * @param syt_timestamp The SYT timestamp as present in the packet 
     167 * @param xmt_cycle The cycle this timestamp was received on 
     168 * @param ctr_now The current value of the cycle timer ('now') 
     169 * @return  
     170 */ 
     171static inline uint32_t sytXmitToFullTicks(uint32_t syt_timestamp, unsigned int xmt_cycle, uint32_t ctr_now) { 
     172    uint32_t timestamp; 
     173     
     174    debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"SYT=%08X CY=%04X CTR=%08X\n", 
     175        syt_timestamp,xmt_cycle,ctr_now); 
     176         
     177    // reconstruct the full cycle 
     178    uint32_t cc_cycles=CYCLE_TIMER_GET_CYCLES(ctr_now); 
     179    uint32_t cc_seconds=CYCLE_TIMER_GET_SECS(ctr_now); 
     180     
     181    // the cycletimer has wrapped since this packet was received 
     182    // we want cc_seconds to reflect the 'seconds' at the point this  
     183    // is to be transmitted 
     184    if (xmt_cycle<cc_cycles) { 
     185        if (cc_seconds) { 
     186            cc_seconds--; 
     187        } else { 
     188            // seconds has wrapped around, so we'd better not substract 1 
     189            // the good value is 127 
     190            cc_seconds=127; 
     191        } 
     192    } 
     193     
     194    // reconstruct the top part of the timestamp using the current cycle number 
     195    uint32_t xmt_cycle_masked=xmt_cycle & 0xF; 
     196    uint32_t syt_cycle=CYCLE_TIMER_GET_CYCLES(syt_timestamp); 
     197     
     198    // if this is true, wraparound has occurred, undo this wraparound 
     199    if(syt_cycle<xmt_cycle_masked) syt_cycle += 0x10; 
     200     
     201    // this is the difference in cycles wrt the cycle the 
     202    // timestamp was received 
     203    uint32_t delta_cycles=syt_cycle-xmt_cycle_masked; 
     204     
     205    // reconstruct the cycle part of the timestamp 
     206    uint32_t new_cycles=xmt_cycle + delta_cycles; 
     207     
     208    // if the cycles cause a wraparound of the cycle timer, 
     209    // perform this wraparound 
     210    // and convert the timestamp into ticks 
     211    if(new_cycles<8000) { 
     212        timestamp  = new_cycles * TICKS_PER_CYCLE; 
     213    } else { 
     214        debugOutput(DEBUG_LEVEL_VERY_VERBOSE, 
     215            "Detected wraparound: %d + %d = %d\n", 
     216            xmt_cycle,delta_cycles,new_cycles); 
     217         
     218        new_cycles-=8000; // wrap around 
     219#ifdef DEBUG 
     220        if (new_cycles >= 8000) { 
     221            debugWarning("insufficient unwrapping\n"); 
     222        } 
     223#endif 
     224        timestamp  = new_cycles * TICKS_PER_CYCLE; 
     225        // add one second due to wraparound 
     226        timestamp += TICKS_PER_SECOND; 
     227    } 
     228     
     229    timestamp += CYCLE_TIMER_GET_OFFSET(syt_timestamp); 
     230     
     231    timestamp += cc_seconds * TICKS_PER_SECOND; 
     232     
     233    #ifdef DEBUG 
     234        if(( TICKS_TO_CYCLE_TIMER(timestamp) & 0xFFFF) != syt_timestamp) { 
     235            debugWarning("back-converted timestamp not equal to SYT\n"); 
     236            debugWarning("TS=%011llu TSC=%08X SYT=%04X\n", 
     237                  timestamp, TICKS_TO_CYCLE_TIMER(timestamp), syt_timestamp); 
     238        } 
     239    #endif 
     240     
    143241    return timestamp; 
    144242} 
  • branches/streaming-rework/src/libstreaming/IsoHandler.cpp

    r391 r394  
    170170            debugError("libraw1394 not compatible\n"); 
    171171        } else { 
    172             debugError("Could not get 1394 handle: %s", strerror(errno) ); 
    173             debugError("Are ieee1394 and raw1394 drivers loaded?"); 
     172            debugError("Could not get 1394 handle: %s\n", strerror(errno) ); 
     173            debugError("Are ieee1394 and raw1394 drivers loaded?\n"); 
    174174        } 
    175175        return false; 
     
    183183            debugError("libraw1394 not compatible\n"); 
    184184        } else { 
    185             debugError("Could not get 1394 handle: %s", strerror(errno) ); 
    186             debugError("Are ieee1394 and raw1394 drivers loaded?"); 
     185            debugError("Could not get 1394 handle: %s\n", strerror(errno) ); 
     186            debugError("Are ieee1394 and raw1394 drivers loaded?\n"); 
    187187        } 
    188188         
     
    340340    err=raw1394_read_cycle_timer(m_handle_util, &ctr); 
    341341    if(err) { 
    342         debugWarning("raw1394_read_cycle_timer: %s", strerror(err)); 
     342        debugWarning("raw1394_read_cycle_timer: %s\n", strerror(err)); 
    343343    } 
    344344    return CYCLE_TIMER_TO_TICKS(ctr.cycle_timer); 
     
    370370    err=raw1394_read_cycle_timer(m_handle_util, &ctr); 
    371371    if(err) { 
    372         debugWarning("raw1394_read_cycle_timer: %s", strerror(err)); 
     372        debugWarning("raw1394_read_cycle_timer: %s\n", strerror(err)); 
    373373    } 
    374374    return ctr.cycle_timer; 
     
    494494    err=raw1394_read_cycle_timer(m_handle_util, &ctr); 
    495495    if(err) { 
    496         debugWarning("raw1394_read_cycle_timer: %s", strerror(err)); 
     496        debugWarning("raw1394_read_cycle_timer: %s\n", strerror(err)); 
    497497    } 
    498498    new_usecs=(freebob_microsecs_t)ctr.local_time; 
     
    643643        err=raw1394_read_cycle_timer(m_handle_util, &ctr); 
    644644        if(err) { 
    645             debugWarning("raw1394_read_cycle_timer: %s", strerror(err)); 
     645            debugWarning("raw1394_read_cycle_timer: %s\n", strerror(err)); 
    646646        } 
    647647        prev_usecs=(freebob_microsecs_t)ctr.local_time; 
     
    665665        err=raw1394_read_cycle_timer(m_handle_util, &ctr); 
    666666        if(err) { 
    667             debugWarning("raw1394_read_cycle_timer: %s", strerror(err)); 
     667            debugWarning("raw1394_read_cycle_timer: %s\n", strerror(err)); 
    668668        } 
    669669        new_usecs=(freebob_microsecs_t)ctr.local_time; 
  • branches/streaming-rework/src/libstreaming/StreamProcessor.h

    r392 r394  
    140140    public: 
    141141        /** 
    142          * @brief Can this StreamProcessor handle a nframes of frames? 
    143          * 
    144          * this function indicates if the streamprocessor can handle nframes 
    145          * of frames. It is used to detect underruns-to-be. 
    146          * 
    147          * @param nframes number of frames  
     142         * @brief Can this StreamProcessor handle a transfer of nframes frames? 
     143         * 
     144         * this function indicates if the streamprocessor can handle a transfer of  
     145         * nframes frames. It is used to detect underruns-to-be. 
     146         * 
     147         * @param nframes number of frames 
    148148         * @return true if the StreamProcessor can handle this amount of frames 
    149149         *         false if it can't 
  • branches/streaming-rework/tests/test-cycletimer.cpp

    r393 r394  
    196196    subs=substractTicks(10, TICKS_PER_SECOND*128L + 12); 
    197197    if (subs != -2) { 
    198          debugOutput(DEBUG_LEVEL_NORMAL, "  substractTicks(10, TICKS_PER_SECOND*128L + 12) != -2 : %ld\n", 
    199             subs); 
    200         failures++;    
    201     }     
     198         debugOutput(DEBUG_LEVEL_NORMAL, "  substractTicks(10, TICKS_PER_SECOND*128L + 12) != -2 : %l011llu\n", 
     199            subs); 
     200        failures++; 
     201    } 
     202     
     203    //--------- 
     204    // now = 10sec, 1380cy, 640ticks 
     205     
     206    uint32_t st=sytRecvToFullTicks(0x1234, 1000, 0x14564280); 
     207    if (st != 248860212LLU) { 
     208         debugOutput(DEBUG_LEVEL_NORMAL, "  sytToRecvFullTicks(0x1234, 1000, 0x14564280) != 248860212 : %011lu\n", 
     209            st); 
     210        failures++;    
     211    } 
     212     
     213    st=sytRecvToFullTicks(0xB2B6, 7000, TICKS_TO_CYCLE_TIMER(3118082282LU)); 
     214    if (st != 3118089910LLU) { 
     215         debugOutput(DEBUG_LEVEL_NORMAL, "  sytToRecvFullTicks(0x1234, 1000, %08X) != 3118089910 : %011lu\n", 
     216            TICKS_TO_CYCLE_TIMER(3118082282LU), st); 
     217        failures++;    
     218    } 
     219     
     220    st=sytXmitToFullTicks(0xC4EA, 3000, TICKS_TO_CYCLE_TIMER(2958285668LU)); 
     221    if (st != 2958349546LLU) { 
     222         debugOutput(DEBUG_LEVEL_NORMAL, "  sytToXmitFullTicks(0x1234, 1000, %08X) != 2958349546 : %011lu\n", 
     223            TICKS_TO_CYCLE_TIMER(2958285668LU), st); 
     224        failures++;    
     225    } 
    202226     
    203227    if (failures) {