From abf95d14a69b9fb91fa167fa49bd990c43b29e37 Mon Sep 17 00:00:00 2001 From: chrysn Date: Thu, 17 Aug 2023 13:42:03 +0200 Subject: [PATCH] cpu/nrf5x: Tolerate NULL callback in timers timer_set has no documented restriction on this being not null, other implementations explicitly tolerate it (rpx0xx checks inside the ISR, but doing it at init time keeps the ISR slim). This is useful when using a timer just to read, without any action when it triggers (the action is taken depending on read values, eg. in a thread context). --- cpu/nrf5x_common/periph/timer.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cpu/nrf5x_common/periph/timer.c b/cpu/nrf5x_common/periph/timer.c index 556ead9b63..ae944867d5 100644 --- a/cpu/nrf5x_common/periph/timer.c +++ b/cpu/nrf5x_common/periph/timer.c @@ -111,7 +111,9 @@ int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg) } /* enable interrupts */ - NVIC_EnableIRQ(timer_config[tim].irqn); + if (cb != NULL) { + NVIC_EnableIRQ(timer_config[tim].irqn); + } /* start the timer */ dev(tim)->TASKS_START = 1;