diff --git a/sys/include/ztimer/overhead.h b/sys/include/ztimer/overhead.h index 86637fc32e..521667053c 100644 --- a/sys/include/ztimer/overhead.h +++ b/sys/include/ztimer/overhead.h @@ -41,7 +41,7 @@ extern "C" { * @param[in] base base interval to use * @return (time from ztimer_set() until callback) - base */ -uint32_t ztimer_overhead(ztimer_clock_t *clock, uint32_t base); +int32_t ztimer_overhead(ztimer_clock_t *clock, uint32_t base); #endif /* ZTIMER_OVERHEAD_H */ /** @} */ diff --git a/sys/ztimer/overhead.c b/sys/ztimer/overhead.c index 6502f49cc3..c8d792a0cb 100644 --- a/sys/ztimer/overhead.c +++ b/sys/ztimer/overhead.c @@ -35,7 +35,7 @@ static void _callback(void *arg) *callback_arg->val = ztimer_now(callback_arg->clock); } -uint32_t ztimer_overhead(ztimer_clock_t *clock, uint32_t base) +int32_t ztimer_overhead(ztimer_clock_t *clock, uint32_t base) { volatile uint32_t after = 0; uint32_t pre; diff --git a/tests/ztimer_overhead/main.c b/tests/ztimer_overhead/main.c index 9e2723e2a8..03f258e635 100644 --- a/tests/ztimer_overhead/main.c +++ b/tests/ztimer_overhead/main.c @@ -20,6 +20,7 @@ #include #include +#include #include #include "ztimer.h" @@ -32,16 +33,17 @@ int main(void) { uint32_t total = 0; - uint16_t min = 0xFFFF; - uint16_t max = 0; + int32_t min = INT32_MAX; + int32_t max = INT32_MIN; /* unset configured adjustment */ /* ZTIMER_USEC->adjust = 0; */ + printf("ZTIMER_USEC->adjust = %" PRIu32 "\n", ZTIMER_USEC->adjust); unsigned n = SAMPLES; while (n--) { - unsigned overhead = ztimer_overhead(ZTIMER_USEC, BASE); - total += overhead; + int32_t overhead = ztimer_overhead(ZTIMER_USEC, BASE); + total += labs(overhead); if (overhead < min) { min = overhead; } @@ -50,7 +52,8 @@ int main(void) } } - printf("min=%u max=%u avg=%" PRIu32 "\n", min, max, (total / SAMPLES)); + printf("min=%" PRIi32 " max=%" PRIi32 " avg_diff=%" PRIi32 "\n", min, max, + (total / SAMPLES)); return 0; } diff --git a/tests/ztimer_overhead/tests/01-run.py b/tests/ztimer_overhead/tests/01-run.py index 8430a94fea..d838f7a72d 100755 --- a/tests/ztimer_overhead/tests/01-run.py +++ b/tests/ztimer_overhead/tests/01-run.py @@ -11,7 +11,7 @@ from testrunner import run def testfunc(child): - child.expect(r"min=\d+ max=\d+ avg=\d+\r\n") + child.expect(r"min=-?\d+ max=-?\d+ avg_diff=\d+\r\n") if __name__ == "__main__":