From 874772339261fa490b010d8fae4e409293dec9d4 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Tue, 25 Aug 2020 15:36:12 +0200 Subject: [PATCH] tests/periph_timer_periodic: remove need for TIMER_CHANNEL_NUMOF --- tests/periph_timer_periodic/main.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/periph_timer_periodic/main.c b/tests/periph_timer_periodic/main.c index 09fc0c2580..640b057a80 100644 --- a/tests/periph_timer_periodic/main.c +++ b/tests/periph_timer_periodic/main.c @@ -37,11 +37,16 @@ * as xtimer is not used in this test, we can use it and the fact that every board * provides a configuration for it. */ -#define TIMER_CYCL XTIMER_DEV -#define CYCLE_MS 25UL -#define CYCLES_MAX 10 +#define TIMER_CYCL (XTIMER_DEV) +#define CYCLE_MS (25UL) +#define CYCLES_MAX (10) +#ifdef TIMER_CHANNEL_NUMOF +#define MAX_CHANNELS (TIMER_CHANNEL_NUMOF) +#else +#define MAX_CHANNELS (10) +#endif -static unsigned count[TIMER_CHANNEL_NUMOF]; +static unsigned count[MAX_CHANNELS]; static void cb(void *arg, int chan) { @@ -85,7 +90,13 @@ int main(void) /* Only the first channel should trigger and reset the counter */ /* If subsequent channels trigger this is an error. */ - timer_set_periodic(TIMER_CYCL, 1, 2 * steps, TIM_FLAG_RESET_ON_SET); + unsigned channel_numof = 1; + for(unsigned i = 1; i < MAX_CHANNELS; i++) { + if(!timer_set_periodic(TIMER_CYCL, i, (1 + i) * steps, TIM_FLAG_RESET_ON_SET)) { + channel_numof = i; + break; + } + } timer_set_periodic(TIMER_CYCL, 0, steps, TIM_FLAG_RESET_ON_MATCH); mutex_lock(&lock); @@ -93,7 +104,7 @@ int main(void) puts("\nCycles:"); bool succeeded = true; - for (unsigned i = 0; i < TIMER_CHANNEL_NUMOF; ++i) { + for (unsigned i = 0; i < channel_numof; ++i) { printf("channel %u = %02u\t[%s]\n", i, count[i], _print_ok(i, &succeeded)); }