Index: /branches/streaming-rework/tests/test-cycletimer.cpp =================================================================== --- /branches/streaming-rework/tests/test-cycletimer.cpp (revision 393) +++ /branches/streaming-rework/tests/test-cycletimer.cpp (revision 394) @@ -196,8 +196,32 @@ subs=substractTicks(10, TICKS_PER_SECOND*128L + 12); if (subs != -2) { - debugOutput(DEBUG_LEVEL_NORMAL, " substractTicks(10, TICKS_PER_SECOND*128L + 12) != -2 : %ld\n", - subs); - failures++; - } + debugOutput(DEBUG_LEVEL_NORMAL, " substractTicks(10, TICKS_PER_SECOND*128L + 12) != -2 : %l011llu\n", + subs); + failures++; + } + + //--------- + // now = 10sec, 1380cy, 640ticks + + uint32_t st=sytRecvToFullTicks(0x1234, 1000, 0x14564280); + if (st != 248860212LLU) { + debugOutput(DEBUG_LEVEL_NORMAL, " sytToRecvFullTicks(0x1234, 1000, 0x14564280) != 248860212 : %011lu\n", + st); + failures++; + } + + st=sytRecvToFullTicks(0xB2B6, 7000, TICKS_TO_CYCLE_TIMER(3118082282LU)); + if (st != 3118089910LLU) { + debugOutput(DEBUG_LEVEL_NORMAL, " sytToRecvFullTicks(0x1234, 1000, %08X) != 3118089910 : %011lu\n", + TICKS_TO_CYCLE_TIMER(3118082282LU), st); + failures++; + } + + st=sytXmitToFullTicks(0xC4EA, 3000, TICKS_TO_CYCLE_TIMER(2958285668LU)); + if (st != 2958349546LLU) { + debugOutput(DEBUG_LEVEL_NORMAL, " sytToXmitFullTicks(0x1234, 1000, %08X) != 2958349546 : %011lu\n", + TICKS_TO_CYCLE_TIMER(2958285668LU), st); + failures++; + } if (failures) { Index: /branches/streaming-rework/src/libstreaming/StreamProcessor.h =================================================================== --- /branches/streaming-rework/src/libstreaming/StreamProcessor.h (revision 392) +++ /branches/streaming-rework/src/libstreaming/StreamProcessor.h (revision 394) @@ -140,10 +140,10 @@ public: /** - * @brief Can this StreamProcessor handle a nframes of frames? - * - * this function indicates if the streamprocessor can handle nframes - * of frames. It is used to detect underruns-to-be. - * - * @param nframes number of frames + * @brief Can this StreamProcessor handle a transfer of nframes frames? + * + * this function indicates if the streamprocessor can handle a transfer of + * nframes frames. It is used to detect underruns-to-be. + * + * @param nframes number of frames * @return true if the StreamProcessor can handle this amount of frames * false if it can't Index: /branches/streaming-rework/src/libstreaming/cycletimer.h =================================================================== --- /branches/streaming-rework/src/libstreaming/cycletimer.h (revision 393) +++ /branches/streaming-rework/src/libstreaming/cycletimer.h (revision 394) @@ -75,7 +75,6 @@ /** - * @brief Converts a SYT timestamp to a full timestamp in ticks. - * - * + * @brief Converts a received SYT timestamp to a full timestamp in ticks. + * * * @param syt_timestamp The SYT timestamp as present in the packet @@ -84,7 +83,10 @@ * @return */ -static inline uint32_t sytToFullTicks(uint32_t syt_timestamp, unsigned int rcv_cycle, uint32_t ctr_now) { +static inline uint32_t sytRecvToFullTicks(uint32_t syt_timestamp, unsigned int rcv_cycle, uint32_t ctr_now) { uint32_t timestamp; + debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"SYT=%08X CY=%04X CTR=%08X\n", + syt_timestamp,rcv_cycle,ctr_now); + // reconstruct the full cycle uint32_t cc_cycles=CYCLE_TIMER_GET_CYCLES(ctr_now); @@ -140,5 +142,101 @@ timestamp += CYCLE_TIMER_GET_OFFSET(syt_timestamp); + timestamp += cc_seconds * TICKS_PER_SECOND; + + #ifdef DEBUG + if(( TICKS_TO_CYCLE_TIMER(timestamp) & 0xFFFF) != syt_timestamp) { + debugWarning("back-converted timestamp not equal to SYT\n"); + debugWarning("TS=%011llu TSC=%08X SYT=%04X\n", + timestamp, TICKS_TO_CYCLE_TIMER(timestamp), syt_timestamp); + } + #endif + + return timestamp; +} + +/** + * @brief Converts a transmit SYT timestamp to a full timestamp in ticks. + * + * The difference between sytRecvToFullTicks and sytXmitToFullTicks is + * the way SYT cycle wraparound is detected: in the receive version, + * wraparound is present if rcv_cycle > current_cycle. In the xmit + * version this is when current_cycle > xmt_cycle. + * + * @param syt_timestamp The SYT timestamp as present in the packet + * @param xmt_cycle The cycle this timestamp was received on + * @param ctr_now The current value of the cycle timer ('now') + * @return + */ +static inline uint32_t sytXmitToFullTicks(uint32_t syt_timestamp, unsigned int xmt_cycle, uint32_t ctr_now) { + uint32_t timestamp; + + debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"SYT=%08X CY=%04X CTR=%08X\n", + syt_timestamp,xmt_cycle,ctr_now); + + // reconstruct the full cycle + uint32_t cc_cycles=CYCLE_TIMER_GET_CYCLES(ctr_now); + uint32_t cc_seconds=CYCLE_TIMER_GET_SECS(ctr_now); + + // the cycletimer has wrapped since this packet was received + // we want cc_seconds to reflect the 'seconds' at the point this + // is to be transmitted + if (xmt_cycle= 8000) { + debugWarning("insufficient unwrapping\n"); + } +#endif + timestamp = new_cycles * TICKS_PER_CYCLE; + // add one second due to wraparound + timestamp += TICKS_PER_SECOND; + } + + timestamp += CYCLE_TIMER_GET_OFFSET(syt_timestamp); + + timestamp += cc_seconds * TICKS_PER_SECOND; + + #ifdef DEBUG + if(( TICKS_TO_CYCLE_TIMER(timestamp) & 0xFFFF) != syt_timestamp) { + debugWarning("back-converted timestamp not equal to SYT\n"); + debugWarning("TS=%011llu TSC=%08X SYT=%04X\n", + timestamp, TICKS_TO_CYCLE_TIMER(timestamp), syt_timestamp); + } + #endif + return timestamp; } Index: /branches/streaming-rework/src/libstreaming/AmdtpStreamProcessor.cpp =================================================================== --- /branches/streaming-rework/src/libstreaming/AmdtpStreamProcessor.cpp (revision 393) +++ /branches/streaming-rework/src/libstreaming/AmdtpStreamProcessor.cpp (revision 394) @@ -235,6 +235,6 @@ #ifdef DEBUG if(!m_is_disabled) { - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, " > TS=%11llu, CTR=%11llu, FC=%5d\n", - timestamp, cycle_timer, fc + debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "R: TS=%011llu, NOW=%011llu, CYN=%04d, CYT=%04d\n", + timestamp, cycle_timer, now_cycles, cycle ); debugOutput(DEBUG_LEVEL_VERY_VERBOSE, " UTN=%11lld\n", @@ -246,5 +246,28 @@ } #endif - + + #ifdef DEBUG + if((cycle % 1000) == 0) { + uint32_t timestamp_u=timestamp; + uint32_t syt = TICKS_TO_SYT(addTicks(timestamp_u, TRANSMIT_TRANSFER_DELAY)); + uint32_t now=m_handler->getCycleTimer(); + uint32_t now_ticks=CYCLE_TIMER_TO_TICKS(now); + + uint32_t test_ts=sytXmitToFullTicks(syt, cycle, now); + + debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "T %04d: SYT=%08X, CY=%02d OFF=%04d\n", + cycle, syt, CYCLE_TIMER_GET_CYCLES(syt), CYCLE_TIMER_GET_OFFSET(syt) + ); + debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "T %04d: NOW=%011lu, SEC=%03u CY=%02u OFF=%04u\n", + cycle, now_ticks, CYCLE_TIMER_GET_SECS(now), CYCLE_TIMER_GET_CYCLES(now), CYCLE_TIMER_GET_OFFSET(now) + ); + debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "T %04d: TSS=%011lu, SEC=%03u CY=%02u OFF=%04u\n", + cycle, test_ts, TICKS_TO_SECS(test_ts), TICKS_TO_CYCLES(test_ts), TICKS_TO_OFFSET(test_ts) + ); + debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "T %04d: TSO=%011lu, SEC=%03u CY=%02u OFF=%04u\n", + cycle, timestamp_u, TICKS_TO_SECS(timestamp_u), TICKS_TO_CYCLES(timestamp_u), TICKS_TO_OFFSET(timestamp_u) + ); + } + #endif // don't process the stream when it is not enabled, not running // or when the next sample is not due yet. @@ -918,5 +941,5 @@ //=> convert the SYT to a full timestamp in ticks - m_last_timestamp=sytToFullTicks((uint32_t)ntohs(packet->syt), + m_last_timestamp=sytRecvToFullTicks((uint32_t)ntohs(packet->syt), cycle, m_handler->getCycleTimer()); @@ -1017,4 +1040,24 @@ return RAW1394_ISO_DEFER; } + + #ifdef DEBUG + if((cycle % 1000) == 0) { + uint32_t syt = (uint32_t)ntohs(packet->syt); + uint32_t now=m_handler->getCycleTimer(); + uint32_t now_ticks=CYCLE_TIMER_TO_TICKS(now); + + uint32_t test_ts=sytRecvToFullTicks(syt, cycle, now); + + debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "R %04d: SYT=%08X, CY=%02d OFF=%04d\n", + cycle, syt, CYCLE_TIMER_GET_CYCLES(syt), CYCLE_TIMER_GET_OFFSET(syt) + ); + debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "R %04d: NOW=%011lu, SEC=%03u CY=%02u OFF=%04u\n", + cycle, now_ticks, CYCLE_TIMER_GET_SECS(now), CYCLE_TIMER_GET_CYCLES(now), CYCLE_TIMER_GET_OFFSET(now) + ); + debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "R %04d: TSS=%011lu, SEC=%03u CY=%02u OFF=%04u\n", + cycle, test_ts, TICKS_TO_SECS(test_ts), TICKS_TO_CYCLES(test_ts), TICKS_TO_OFFSET(test_ts) + ); + } + #endif //=> process the packet Index: /branches/streaming-rework/src/libstreaming/IsoHandler.cpp =================================================================== --- /branches/streaming-rework/src/libstreaming/IsoHandler.cpp (revision 391) +++ /branches/streaming-rework/src/libstreaming/IsoHandler.cpp (revision 394) @@ -170,6 +170,6 @@ debugError("libraw1394 not compatible\n"); } else { - debugError("Could not get 1394 handle: %s", strerror(errno) ); - debugError("Are ieee1394 and raw1394 drivers loaded?"); + debugError("Could not get 1394 handle: %s\n", strerror(errno) ); + debugError("Are ieee1394 and raw1394 drivers loaded?\n"); } return false; @@ -183,6 +183,6 @@ debugError("libraw1394 not compatible\n"); } else { - debugError("Could not get 1394 handle: %s", strerror(errno) ); - debugError("Are ieee1394 and raw1394 drivers loaded?"); + debugError("Could not get 1394 handle: %s\n", strerror(errno) ); + debugError("Are ieee1394 and raw1394 drivers loaded?\n"); } @@ -340,5 +340,5 @@ err=raw1394_read_cycle_timer(m_handle_util, &ctr); if(err) { - debugWarning("raw1394_read_cycle_timer: %s", strerror(err)); + debugWarning("raw1394_read_cycle_timer: %s\n", strerror(err)); } return CYCLE_TIMER_TO_TICKS(ctr.cycle_timer); @@ -370,5 +370,5 @@ err=raw1394_read_cycle_timer(m_handle_util, &ctr); if(err) { - debugWarning("raw1394_read_cycle_timer: %s", strerror(err)); + debugWarning("raw1394_read_cycle_timer: %s\n", strerror(err)); } return ctr.cycle_timer; @@ -494,5 +494,5 @@ err=raw1394_read_cycle_timer(m_handle_util, &ctr); if(err) { - debugWarning("raw1394_read_cycle_timer: %s", strerror(err)); + debugWarning("raw1394_read_cycle_timer: %s\n", strerror(err)); } new_usecs=(freebob_microsecs_t)ctr.local_time; @@ -643,5 +643,5 @@ err=raw1394_read_cycle_timer(m_handle_util, &ctr); if(err) { - debugWarning("raw1394_read_cycle_timer: %s", strerror(err)); + debugWarning("raw1394_read_cycle_timer: %s\n", strerror(err)); } prev_usecs=(freebob_microsecs_t)ctr.local_time; @@ -665,5 +665,5 @@ err=raw1394_read_cycle_timer(m_handle_util, &ctr); if(err) { - debugWarning("raw1394_read_cycle_timer: %s", strerror(err)); + debugWarning("raw1394_read_cycle_timer: %s\n", strerror(err)); } new_usecs=(freebob_microsecs_t)ctr.local_time;