cpu/atmega_common: RTT support#12815
Conversation
maribu
left a comment
There was a problem hiding this comment.
Code contains a data race, see inline explanation. But trivial to fix :-)
maribu
left a comment
There was a problem hiding this comment.
With the current implementation the returned time could be up to 255 ticks lower than correct in a race condition. See inline comment
maribu
left a comment
There was a problem hiding this comment.
Two more suggestions to get _safe_cnt_get() race-free (at least unless I didn't overlook anything).
|
I'll test tonight. |
|
(If noone does so sooner ;-)) |
|
Sorry, I'm too tired to think straight now. I'll test tomorrow. |
|
Don't worry, there is no ticking clock 😆 |
|
OK. I hooked up a 32.768kHz and two 10 pF capacitors to TOSC1 and TOSC2 as pictured in the schematic in the data sheet to an ATmega1284P. Seems to work as advertised :-) Output of
|
maribu
left a comment
There was a problem hiding this comment.
Please squash. (Also, please squash the fix for the nitpick right away.)
cpu/atmega_common/periph/rtt.c
Outdated
| /* Overflow occurred just after we read `TCNT2` | ||
| so it has overflown back to zero now */ | ||
| if (cnt == 255) { | ||
| cnt = 0; | ||
| } |
There was a problem hiding this comment.
Nitpick: The comment should be moved inside the body of the if. (Or reword the comment, e.g."Check if overflow occurred just after reading TCNT2, in which case it will now have a value of zero and update cnt to correspondingly.)
The RTT on ATmega only works if the board provides a 32kHz oscillator.
maribu
left a comment
There was a problem hiding this comment.
ACK. The code is well written and documented, it worked as expected during testing, and I gave my best to check that the code is race free.
|
Thank you for the thorough review & suggestions w.r.t. race conditions! |
Contribution description
This is just the RTT commit split off from the RTT/RTC PR by @ZetaR60.
I made small adjustments & cleanups to make it compile with the latest master branch and made the RTT frequency configurable.
Without the RTC emulation I hope this should be less controversial.
The RTT requires a 32kHz oscillator to be present on the board.
The only boards I know where this is the case are
mega-xplained,atmega256rfr2-xproandavr-rss2. It's possible that I missed some.#12799 will add two more.
Testing procedure
Run
tests/periph_rtt.The RTT on ATmega will only work if the board is equipped with a 32kHz crystal.
Issues/PRs references
split off from #8842 which is based on #7604