From c0af448efab8476d78cd88fa82c0dd69585d84a0 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Sun, 8 Feb 2015 17:59:20 +0000 Subject: [PATCH] uint64_t (even at 12MHz) isn't going to overflow any time soon, don't worry about wrapping. --- util.c | 9 ++------- util.h | 5 ++--- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/util.c b/util.c index d745c58..b66f7e1 100644 --- a/util.c +++ b/util.c @@ -63,14 +63,9 @@ uint64_t mstime(void) return mst; } -uint64_t receiveclock_ns_elapsed(uint64_t t1, uint64_t t2) +int64_t receiveclock_ns_elapsed(uint64_t t1, uint64_t t2) { - if (t2 < t1) { - // wrapped. - return (~(t1 - t2) + 1) * 1000U / 12U; - } else { - return (t2 - t1) * 1000U / 12U; - } + return (t2 - t1) * 1000U / 12U; } void normalize_timespec(struct timespec *ts) diff --git a/util.h b/util.h index 3cb022a..41ccbb1 100644 --- a/util.h +++ b/util.h @@ -26,10 +26,9 @@ uint64_t mstime(void); /* Returns the time elapsed, in nanoseconds, from t1 to t2, - * where t1 and t2 are 12MHz counters, - * accounting for wrapping. + * where t1 and t2 are 12MHz counters. */ -uint64_t receiveclock_ns_elapsed(uint64_t t1, uint64_t t2); +int64_t receiveclock_ns_elapsed(uint64_t t1, uint64_t t2); /* Normalize the value in ts so that ts->nsec lies in * [0,999999999]