Skip to content

Commit

Permalink
Merge pull request #18981 from maribu/backport/2022.10/cpu/atmega_com…
Browse files Browse the repository at this point in the history
…mon/periph_timer/spurious_irqs

cpu/atmega_common/periph_timer: fix spurious IRQs [backport 2022.10]
  • Loading branch information
aabadie authored Nov 27, 2022
2 parents 01952ef + ce60961 commit c3e83d0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cpu/atmega_common/periph/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c3e83d0

Please sign in to comment.