periph/rtc: normalize struct tm before usage#11413
Conversation
01147d2 to
2d69d84
Compare
fjmolinas
left a comment
There was a problem hiding this comment.
Nice catch, the current tests don't take this into account since only 4 alarms are triggered there never is an overflow. I tested your changes with and without normalizing on nucleo-l073rz, without this PR it just triggers one alarm and with this PR it works as expected. I also tested that there was no regression for samr21-xpro.
Everything looks good, I would just add a comment on rtc_set_alarm and rtc_set_time that states that the input time structure gets normalized.
I don't have any board using the other CPU's @maribu has a msba2 according to the wiki and @kaspar030 has a chronos, maybe they can test for those cpu's?
|
I tested with the MSB-A2. The I checked the manpage of I'll have a look at the broken +1 for merging this without having it tested on the MSB-A2 (but on the other three implementations). This fixes a real issue for the other CPU-families and should not be stalled IMO due to an unrelated bug. Also, this PR is not really scary and very unlikely to break anything. |
da98ddd to
15748e7
Compare
|
Well it turns out not every platform has I've now introduced a Calculating For before: after: after with |
9379591 to
97667fc
Compare
|
Code looks good. |
|
For chronos rtc code size has almost doubled with this addition. But I still think we should include this. Timing is important enough to spend the memory on getting it correctly, I might want to check if we can optimize it a bit though. |
|
Using |
83ae633 to
a605c44
Compare
|
Tests are still passing for me. Changes are looking good to, thanks for the unit-test addition. @kaspar030 can you find time to test on chronos? If not I think we should just move forward with the PR. |
maribu
left a comment
There was a problem hiding this comment.
OK, codewise I'd ACK. With the PR not changing hardware interactions, I think there is no reason to test it on every board, but testing on one should be more that enough.
Some of the code is pretty magic, which needs more explanation. I marked those sections inline and tried to already suggest comments that could explain the magic. Afterwards, I will ACK.
|
Btw: Please squash right away (including the added comments). |
|
@maribu thank you for the comments! I added them all except the inline one inside the array members , that one just adds clutter imho and the logic is already explained above. |
A naive implementation may set a RTC alarm in 30s by calling struct tm now; rtc_get_time(&now); now.tm_sec += 30; rtc_set_alarm(&now, _cb, NULL); This works for RTC implementations that use a RTT internally and call mktime() to convert the struct tm to a unix timestamp, as mktime() will normalize the struct in the process. Call rtc_tm_normalize() when the RTC uses separate registers for time / date components to ensure it is normalized. This also modifies tests/periph_rtc to exercise this case.
1858467 to
b1724a7
Compare
Contribution description
A naive implementation may set a RTC alarm in 30s by calling
This works for RTC implementations that use a RTT internally and call mktime() to convert the struct tm to a unix timestamp, as mktime() will normalize the struct in the process.
On a RTC implementation where there is a separate register for minutes / seconds the alarm will never trigger if the current seconds are > 30.
Always call mktime() even when the RTC uses separate registers for time / date components to ensure it is normalized.
This also modifies tests/periph_rtc to exercise this case.
Testing procedure
Run
tests/periph_rtcon a board with RTC.4
Alarm!s should be triggered.[ ] Board with CPU(Broken anyway)lpc2387(@maribu)[ ] Board withNot neededcc430-CPU (@kaspar030)