1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tests/periph_timer_short_relative_set: fix diff calculation for non 32 bit timers

This commit is contained in:
Michel Rottleuthner 2019-12-02 11:28:26 +01:00
parent 920884dd00
commit 29c11c9963
2 changed files with 11 additions and 2 deletions

View File

@ -8,8 +8,9 @@ USEMODULE += core_thread_flags
# TEST_TIMER_DEV takes a 0-based index to the periph_timer instance defined in
# the board's periph_conf.h. TEST_TIMER_FREQ as an integer number which will
# be used as "freq" parameter in the timer_init() call.
# TEST_TIMER_WIDTH defines the timer width in number of bits.
# Note: not all implementations support arbitrary frequencies.
#CFLAGS += -DTEST_TIMER_DEV=foo -DTEST_TIMER_FREQ=bar
#CFLAGS += -DTEST_TIMER_DEV=foo -DTEST_TIMER_FREQ=bar -DTEST_TIMER_WIDTH=n
# this test currently fails all CI boards and native
TEST_ON_CI_BLACKLIST += all

View File

@ -32,6 +32,7 @@
# include "xtimer.h"
# define TEST_TIMER_DEV XTIMER_DEV
# define TEST_TIMER_FREQ XTIMER_HZ
# define TEST_TIMER_WIDTH XTIMER_WIDTH
#else
# ifndef TEST_TIMER_FREQ
# define TEST_TIMER_FREQ (1000000LU)
@ -42,6 +43,12 @@
#define TEST_MAX_DIFF (1000LU)
#endif
#if TEST_TIMER_WIDTH == 32
# define TEST_TIMER_MAX (0xFFFFFFFFLU)
#else
# define TEST_TIMER_MAX ((1UL << TEST_TIMER_WIDTH) - 1)
#endif
static void cb(void *arg, int chan)
{
(void)chan;
@ -65,7 +72,8 @@ int main(void)
uint32_t before = timer_read(TEST_TIMER_DEV);
timer_set(TEST_TIMER_DEV, 0, interval);
while(!thread_flags_clear(1)) {
uint32_t diff = timer_read(TEST_TIMER_DEV) - before;
uint32_t diff = (timer_read(TEST_TIMER_DEV) - before)
& TEST_TIMER_MAX;
if (diff > TEST_MAX_DIFF) {
printf("ERROR: too long delay, aborted after %" PRIu32
" (TEST_MAX_DIFF=%lu)\n"