From 787884aa9539d19d482c77f0d03170ec4d48f2d0 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Fri, 25 Nov 2022 13:12:18 +0100 Subject: [PATCH] cpu/atmega_common/periph_timer: fix spurious IRQs --- cpu/atmega_common/periph/timer.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cpu/atmega_common/periph/timer.c b/cpu/atmega_common/periph/timer.c index dac8c57af8a7..81b68893abe7 100644 --- a/cpu/atmega_common/periph/timer.c +++ b/cpu/atmega_common/periph/timer.c @@ -158,7 +158,9 @@ int timer_set_absolute(tim_t tim, int channel, unsigned int value) unsigned state = irq_disable(); ctx[tim].dev->OCR[channel] = (uint16_t)value; - *ctx[tim].flag &= ~(1 << (channel + OCF1A)); + /* clear spurious IRQs, if any */ + *ctx[tim].flag = (1 << (channel + OCF1A)); + /* unmask IRQ */ *ctx[tim].mask |= (1 << (channel + OCIE1A)); set_oneshot(tim, channel); @@ -177,6 +179,9 @@ int timer_set(tim_t tim, int channel, unsigned int timeout) unsigned absolute = ctx[tim].dev->CNT + timeout; ctx[tim].dev->OCR[channel] = absolute; + /* clear spurious IRQs, if any */ + *ctx[tim].flag = (1 << (channel + OCF1A)); + /* unmask IRQ */ *ctx[tim].mask |= (1 << (channel + OCIE1A)); set_oneshot(tim, channel); @@ -210,7 +215,9 @@ int timer_set_periodic(tim_t tim, int channel, unsigned int value, uint8_t flags ctx[tim].dev->OCR[channel] = (uint16_t)value; - *ctx[tim].flag &= ~(1 << (channel + OCF1A)); + /* clear spurious IRQs, if any */ + *ctx[tim].flag = (1 << (channel + OCF1A)); + /* unmask IRQ */ *ctx[tim].mask |= (1 << (channel + OCIE1A)); clear_oneshot(tim, channel);