-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cpu/atmega_common/periph_timer: fix spurious IRQs #18978
cpu/atmega_common/periph_timer: fix spurious IRQs #18978
Conversation
cpu/atmega_common/periph/timer.c
Outdated
@@ -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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*ctx[tim].flag |= (1 << (channel + OCF1A)); | |
*ctx[tim].flag = (1 << (channel + OCF1A)); |
I think this should also work. @kfessel: You're the AVR expert, do I read the datasheet correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, "would also work" is incorrect: The current version would unset all flags and is buggy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was about to write that:
doc tmega328p:
"Alternatively, can be cleared by writing a logic one to its bit location."
so if you flags = flags
it will clear all flags that are 1.
*ctx[tim].flag |= (1 << (channel + OCF1A));
will clear all flags that are read as 1 and OCF1A
in any case.
but the compiler should make *ctx[tim].flag |= (1 << (channel + OCF1A));
work anyway since all flags are placed in io-address-space -> it will become SBI <FLAGSioaddres>, (channel + OCF1A)
writing a one to that specific bit location.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see inline
7d4815f
to
787884a
Compare
Thx :) |
Backport provided in #18981 |
Contribution description
As the tile says
Testing procedure
tests/periph_timer
from #18963 andtests/periph_timer_periodic
should pass. (They do on thearduino-mega2560
.)Issues/PRs references
#18976