diff --git a/tests/periph_timer/main.c b/tests/periph_timer/main.c index 04cf3a4315f89e8b7916c919f1deddeb5ea80204..ad75ea662a4800d8cf7c305118a8efc83438d06f 100644 --- a/tests/periph_timer/main.c +++ b/tests/periph_timer/main.c @@ -34,15 +34,17 @@ #define MAX_CHANNELS (10U) #define TIM_SPEED (1000000ul) /* try to run with 1MHz */ #define CHAN_OFFSET (5000U) /* fire every 5ms */ +#define COOKIE (100U) /* for checking if arg is passed */ static volatile int fired; static volatile uint32_t sw_count; static volatile uint32_t timeouts[MAX_CHANNELS]; +static volatile unsigned args[MAX_CHANNELS]; static void cb(void *arg, int chan) { - (void)arg; timeouts[chan] = sw_count; + args[chan] = (unsigned)arg + chan; fired++; } @@ -55,10 +57,11 @@ static int test_timer(unsigned num) fired = 0; for (unsigned i = 0; i < MAX_CHANNELS; i++) { timeouts[i] = 0; + args[i] = UINT_MAX; } /* initialize and halt timer */ - if (timer_init(TIMER_DEV(num), TIM_SPEED, cb, NULL) < 0) { + if (timer_init(TIMER_DEV(num), TIM_SPEED, cb, (void *)(COOKIE * num)) < 0) { printf("TIMER_%u: ERROR on initialization - skipping\n\n", num); return 0; } @@ -91,6 +94,10 @@ static int test_timer(unsigned num) } while (fired != set); /* collect results */ for (int i = 0; i < fired; i++) { + if (args[i] != ((COOKIE * num) + i)) { + printf("TIMER_%u: ERROR callback argument mismatch\n\n", num); + return 0; + } printf("TIMER_%u: channel %i fired at SW count %8u", num, i, (unsigned)timeouts[i]); if (i == 0) {