Skip to content

Commit

Permalink
Merge pull request RIOT-OS#13571 from kaspar030/ztimer_overhead_signed
Browse files Browse the repository at this point in the history
sys/ztimer: make ztimer_overhead() return signed result
  • Loading branch information
bergzand authored Mar 10, 2020
2 parents 741b9d3 + 90ca4f3 commit 0edfce8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion sys/include/ztimer/overhead.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
/** @} */
2 changes: 1 addition & 1 deletion sys/ztimer/overhead.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 8 additions & 5 deletions tests/ztimer_overhead/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

#include "ztimer.h"
Expand All @@ -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;
}
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion tests/ztimer_overhead/tests/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


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__":
Expand Down

0 comments on commit 0edfce8

Please sign in to comment.