1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Merge pull request #13571 from kaspar030/ztimer_overhead_signed

sys/ztimer: make ztimer_overhead() return signed result
This commit is contained in:
Koen Zandberg 2020-03-10 14:39:03 +01:00 committed by GitHub
commit 0edfce82e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 8 deletions

View File

@ -41,7 +41,7 @@ extern "C" {
* @param[in] base base interval to use * @param[in] base base interval to use
* @return (time from ztimer_set() until callback) - base * @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 */ #endif /* ZTIMER_OVERHEAD_H */
/** @} */ /** @} */

View File

@ -35,7 +35,7 @@ static void _callback(void *arg)
*callback_arg->val = ztimer_now(callback_arg->clock); *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; volatile uint32_t after = 0;
uint32_t pre; uint32_t pre;

View File

@ -20,6 +20,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <inttypes.h> #include <inttypes.h>
#include "ztimer.h" #include "ztimer.h"
@ -32,16 +33,17 @@ int main(void)
{ {
uint32_t total = 0; uint32_t total = 0;
uint16_t min = 0xFFFF; int32_t min = INT32_MAX;
uint16_t max = 0; int32_t max = INT32_MIN;
/* unset configured adjustment */ /* unset configured adjustment */
/* ZTIMER_USEC->adjust = 0; */ /* ZTIMER_USEC->adjust = 0; */
printf("ZTIMER_USEC->adjust = %" PRIu32 "\n", ZTIMER_USEC->adjust);
unsigned n = SAMPLES; unsigned n = SAMPLES;
while (n--) { while (n--) {
unsigned overhead = ztimer_overhead(ZTIMER_USEC, BASE); int32_t overhead = ztimer_overhead(ZTIMER_USEC, BASE);
total += overhead; total += labs(overhead);
if (overhead < min) { if (overhead < min) {
min = overhead; 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; return 0;
} }

View File

@ -11,7 +11,7 @@ from testrunner import run
def testfunc(child): 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__": if __name__ == "__main__":