Index: /branches/streaming-rework/src/libstreaming/cycletimer.h =================================================================== --- /branches/streaming-rework/src/libstreaming/cycletimer.h (revision 394) +++ /branches/streaming-rework/src/libstreaming/cycletimer.h (revision 397) @@ -46,7 +46,7 @@ #define USECS_PER_CYCLE (125U) -#define CYCLE_TIMER_GET_SECS(x) ((((x) & 0xFE000000U) >> 25)) -#define CYCLE_TIMER_GET_CYCLES(x) ((((x) & 0x01FFF000U) >> 12)) -#define CYCLE_TIMER_GET_OFFSET(x) ((((x) & 0x00000FFFU))) +#define CYCLE_TIMER_GET_SECS(x) ((((x) & 0xFE000000UL) >> 25)) +#define CYCLE_TIMER_GET_CYCLES(x) ((((x) & 0x01FFF000UL) >> 12)) +#define CYCLE_TIMER_GET_OFFSET(x) ((((x) & 0x00000FFFUL))) #define CYCLE_TIMER_TO_TICKS(x) ((CYCLE_TIMER_GET_SECS(x) * TICKS_PER_SECOND) +\ (CYCLE_TIMER_GET_CYCLES(x) * TICKS_PER_CYCLE ) +\ @@ -73,4 +73,107 @@ DECLARE_GLOBAL_DEBUG_MODULE; + +/** + * @brief Wraps x to the maximum number of ticks + * + * The input value is wrapped to the maximum value of the cycle + * timer, in ticks (128sec * 24576000 ticks/sec). + * + * @param x time to wrap + * @return wrapped time + */ +static inline uint32_t wrapAtMaxTicks(uint64_t x) { + if (x >= TICKS_PER_SECOND * 128L) { + x -= TICKS_PER_SECOND * 128L; + } + +#ifdef DEBUG + if (x >= TICKS_PER_SECOND * 128L) { + debugWarning("insufficient wrapping: %llu\n",x); + } +#endif + + return x; +} + +/** + * @brief Wraps both at minimum and maximum value for ticks + * @param x value to wrap + * @return wrapped value + */ +static inline uint32_t wrapAtMinMaxTicks(int64_t x) { + + if (x < 0) { + x += TICKS_PER_SECOND * 128L; + } else if (x >= TICKS_PER_SECOND * 128L) { + x -= TICKS_PER_SECOND * 128L; + } + +#ifdef DEBUG + if (x >= TICKS_PER_SECOND * 128L) { + debugWarning("insufficient wrapping (max): %llu\n",x); + } + if (x < 0) { + debugWarning("insufficient wrapping (min): %lld\n",x); + } +#endif + return x; + +} + +/** + * @brief Computes a difference between timestamps + * + * This function computes a difference between timestamps + * such that it respects wrapping. + * + * If x wraps around, but y doesn't, the result of x-y is + * negative and very large. However the real difference is + * not large. It can be calculated by unwrapping x and then + * calculating x-y. + * + * @param x First timestamp + * @param y Second timestamp + * @return the difference x-y, unwrapped + */ +static inline int32_t substractTicks(uint32_t x, uint32_t y) { + int64_t diff=(int64_t)x - (int64_t)y; + + // the maximal difference we allow (64secs) + const int64_t max=TICKS_PER_SECOND*64L; + + if(diff > max) { + // this means that y has wrapped, but + // x has not. we should unwrap y + // by adding TICKS_PER_SECOND*128L, meaning that we should substract + // this value from diff + diff -= TICKS_PER_SECOND*128L; + } else if (diff < -max) { + // this means that x has wrapped, but + // y has not. we should unwrap x + // by adding TICKS_PER_SECOND*128L, meaning that we should add + // this value to diff + diff += TICKS_PER_SECOND*128L; + } + + return (int32_t)diff; + +} + +/** + * @brief Computes a sum of timestamps + * + * This function computes a sum of timestamps in ticks, + * wrapping the result if nescessary. + * + * @param x First timestamp + * @param y Second timestamp + * @return the sum x+y, wrapped + */ +static inline uint32_t addTicks(uint32_t x, uint32_t y) { + uint64_t sum=x+y; + + return wrapAtMaxTicks(sum); +} /** @@ -143,5 +246,5 @@ timestamp += CYCLE_TIMER_GET_OFFSET(syt_timestamp); - timestamp += cc_seconds * TICKS_PER_SECOND; + timestamp = addTicks(timestamp, cc_seconds * TICKS_PER_SECOND); #ifdef DEBUG @@ -229,5 +332,5 @@ timestamp += CYCLE_TIMER_GET_OFFSET(syt_timestamp); - timestamp += cc_seconds * TICKS_PER_SECOND; + timestamp = addTicks(timestamp, cc_seconds * TICKS_PER_SECOND); #ifdef DEBUG @@ -243,107 +346,4 @@ /** - * @brief Wraps x to the maximum number of ticks - * - * The input value is wrapped to the maximum value of the cycle - * timer, in ticks (128sec * 24576000 ticks/sec). - * - * @param x time to wrap - * @return wrapped time - */ -static inline uint32_t wrapAtMaxTicks(uint64_t x) { - if (x >= TICKS_PER_SECOND * 128L) { - x -= TICKS_PER_SECOND * 128L; - } - -#ifdef DEBUG - if (x >= TICKS_PER_SECOND * 128L) { - debugWarning("insufficient wrapping: %llu\n",x); - } -#endif - - return x; -} - -/** - * @brief Wraps both at minimum and maximum value for ticks - * @param x value to wrap - * @return wrapped value - */ -static inline uint32_t wrapAtMinMaxTicks(int64_t x) { - - if (x < 0) { - x += TICKS_PER_SECOND * 128L; - } else if (x >= TICKS_PER_SECOND * 128L) { - x -= TICKS_PER_SECOND * 128L; - } - -#ifdef DEBUG - if (x >= TICKS_PER_SECOND * 128L) { - debugWarning("insufficient wrapping (max): %llu\n",x); - } - if (x < 0) { - debugWarning("insufficient wrapping (min): %lld\n",x); - } -#endif - return x; - -} - -/** - * @brief Computes a difference between timestamps - * - * This function computes a difference between timestamps - * such that it respects wrapping. - * - * If x wraps around, but y doesn't, the result of x-y is - * negative and very large. However the real difference is - * not large. It can be calculated by unwrapping x and then - * calculating x-y. - * - * @param x First timestamp - * @param y Second timestamp - * @return the difference x-y, unwrapped - */ -static inline int32_t substractTicks(uint32_t x, uint32_t y) { - int64_t diff=(int64_t)x - (int64_t)y; - - // the maximal difference we allow (64secs) - const int64_t max=TICKS_PER_SECOND*64L; - - if(diff > max) { - // this means that y has wrapped, but - // x has not. we should unwrap y - // by adding TICKS_PER_SECOND*128L, meaning that we should substract - // this value from diff - diff -= TICKS_PER_SECOND*128L; - } else if (diff < -max) { - // this means that x has wrapped, but - // y has not. we should unwrap x - // by adding TICKS_PER_SECOND*128L, meaning that we should add - // this value to diff - diff += TICKS_PER_SECOND*128L; - } - - return (int32_t)diff; - -} - -/** - * @brief Computes a sum of timestamps - * - * This function computes a sum of timestamps in ticks, - * wrapping the result if nescessary. - * - * @param x First timestamp - * @param y Second timestamp - * @return the sum x+y, wrapped - */ -static inline uint32_t addTicks(uint32_t x, uint32_t y) { - uint64_t sum=x+y; - - return wrapAtMaxTicks(sum); -} - -/** * @brief Computes a difference between cycles * Index: /branches/streaming-rework/src/libstreaming/AmdtpStreamProcessor.cpp =================================================================== --- /branches/streaming-rework/src/libstreaming/AmdtpStreamProcessor.cpp (revision 396) +++ /branches/streaming-rework/src/libstreaming/AmdtpStreamProcessor.cpp (revision 397) @@ -36,5 +36,5 @@ #include -#define RECEIVE_PROCESSING_DELAY (0U) +#define RECEIVE_PROCESSING_DELAY (TICKS_PER_CYCLE * 2) // in ticks Index: /branches/streaming-rework/src/libstreaming/IsoHandlerManager.cpp =================================================================== --- /branches/streaming-rework/src/libstreaming/IsoHandlerManager.cpp (revision 391) +++ /branches/streaming-rework/src/libstreaming/IsoHandlerManager.cpp (revision 397) @@ -35,5 +35,5 @@ -#define MINIMUM_INTERRUPTS_PER_PERIOD 4U +#define MINIMUM_INTERRUPTS_PER_PERIOD 2U #define PACKETS_PER_INTERRUPT 4U @@ -323,12 +323,12 @@ unsigned int packets_per_period=stream->getPacketsPerPeriod(); -#if 0 +#if 1 // hardware interrupts occur when one DMA block is full, and the size of one DMA - // block = PAGE_SIZE. Setting the max_packet_size makes sure that the HW irq is + // block = PAGE_SIZE. Setting the max_packet_size makes sure that the HW irq // occurs at a period boundary (optimal CPU use) // NOTE: try and use MINIMUM_INTERRUPTS_PER_PERIOD hardware interrupts // per period for better latency. - unsigned int max_packet_size=MINIMUM_INTERRUPTS_PER_PERIOD * getpagesize() / packets_per_period; + unsigned int max_packet_size=(MINIMUM_INTERRUPTS_PER_PERIOD * getpagesize()) / packets_per_period; if (max_packet_size < stream->getMaxPacketSize()) { max_packet_size=stream->getMaxPacketSize(); Index: /branches/streaming-rework/src/libstreaming/IsoHandler.cpp =================================================================== --- /branches/streaming-rework/src/libstreaming/IsoHandler.cpp (revision 394) +++ /branches/streaming-rework/src/libstreaming/IsoHandler.cpp (revision 397) @@ -342,5 +342,5 @@ debugWarning("raw1394_read_cycle_timer: %s\n", strerror(err)); } - return CYCLE_TIMER_TO_TICKS(ctr.cycle_timer); + return CYCLE_TIMER_TO_TICKS((uint32_t)ctr.cycle_timer); #else Index: /branches/streaming-rework/src/libstreaming/StreamProcessor.cpp =================================================================== --- /branches/streaming-rework/src/libstreaming/StreamProcessor.cpp (revision 396) +++ /branches/streaming-rework/src/libstreaming/StreamProcessor.cpp (revision 397) @@ -227,5 +227,5 @@ const int64_t max=(int64_t)(TICKS_PER_SECOND/2); - int64_t diff=m_cycle_to_enable_at-now_cycles; + int64_t diff=(int64_t)m_cycle_to_enable_at-(int64_t)now_cycles; if (diff > max) { @@ -236,5 +236,5 @@ if (diff<0) { - debugWarning("Request to enable streamprocessor %d cycles ago (now=%llu, cy=%llu).\n", + debugWarning("Request to enable streamprocessor %lld cycles ago (now=%llu, cy=%llu).\n", diff,now_cycles,time_to_enable_at); } Index: /branches/streaming-rework/src/libutil/TimestampedBuffer.cpp =================================================================== --- /branches/streaming-rework/src/libutil/TimestampedBuffer.cpp (revision 395) +++ /branches/streaming-rework/src/libutil/TimestampedBuffer.cpp (revision 397) @@ -259,8 +259,8 @@ // init the DLL - m_dll_e2=m_nominal_rate * (double)m_update_period; - - m_dll_b=((double)(0.877)); - m_dll_c=((double)(0.384)); + m_dll_e2=m_nominal_rate * (float)m_update_period; + + m_dll_b=((float)(0.877)); + m_dll_c=((float)(0.384)); return true; @@ -548,8 +548,8 @@ if (diff < 0) diff += m_wrap_at; - double rate; + float rate; if (diff) { - rate=(double)diff / (double)m_update_period; + rate=(float)diff / (float)m_update_period; } else { rate=m_nominal_rate; @@ -579,5 +579,5 @@ m_dll_e2=m_update_period * m_nominal_rate; - m_buffer_next_tail_timestamp = (uint64_t)((double)m_buffer_tail_timestamp + m_dll_e2); + m_buffer_next_tail_timestamp = (uint64_t)((float)m_buffer_tail_timestamp + m_dll_e2); pthread_mutex_unlock(&m_framecounter_lock); @@ -639,5 +639,5 @@ if (diff < 0) diff += m_wrap_at; - double rate=(double)diff / (double)m_update_period; + float rate=(float)diff / (float)m_update_period; int64_t timestamp; @@ -709,5 +709,5 @@ if (diff < 0) diff += m_wrap_at; - double rate=(double)diff / (double)m_update_period; + float rate=(float)diff / (float)m_update_period; int64_t ts=new_timestamp; @@ -758,5 +758,5 @@ } - double err=diff; + float err=diff; debugOutputShort(DEBUG_LEVEL_VERY_VERBOSE, "diff2=%lld err=%f\n", Index: /branches/streaming-rework/src/libutil/TimestampedBuffer.h =================================================================== --- /branches/streaming-rework/src/libutil/TimestampedBuffer.h (revision 395) +++ /branches/streaming-rework/src/libutil/TimestampedBuffer.h (revision 397) @@ -172,7 +172,7 @@ // tracking DLL variables - double m_dll_e2; - double m_dll_b; - double m_dll_c; + float m_dll_e2; + float m_dll_b; + float m_dll_c; float m_nominal_rate;