RIOT icon indicating copy to clipboard operation
RIOT copied to clipboard

periph/rtc: add `rtc_pre_set_time()` and `rtc_post_set_time()`

Open fabian18 opened this issue 8 months ago • 2 comments

Contribution description

Add weak rtc_pre_set_time() and rtc_post_set_time() to let an application react to time changes.

Testing procedure

make -C tests/periph/rtc flash term

2025-04-06 15:39:33,496 # RIOT native interrupts/signals initialized.
2025-04-06 15:39:33,503 # RIOT native board initialized.
2025-04-06 15:39:33,504 # RIOT native hardware initialization complete.
2025-04-06 15:39:33,504 # 
2025-04-06 15:39:33,504 # main(): This is RIOT! (Version: 2025.04-devel-150-g7aa1c-pr/rtc_pre_post_set_time)
2025-04-06 15:39:33,504 # 
2025-04-06 15:39:33,504 # RIOT RTC low-level driver test
2025-04-06 15:39:33,504 # This test will display 'Alarm!' every 2 seconds for 4 times
2025-04-06 15:39:33,504 # Native RTC initialized.
2025-04-06 15:39:33,505 # Clock value is now   2025-04-06 15:39:32.498
2025-04-06 15:39:33,505 #   Setting clock to   2020-02-28 23:59:57
2025-04-06 15:39:33,505 # pre rtc_set_time: -161019575
2025-04-06 15:39:33,505 # post rtc_set_time: -161019575
2025-04-06 15:39:33,505 # Clock value is now   2020-02-28 23:59:57.499
2025-04-06 15:39:33,505 #   Setting alarm to   2020-02-28 23:59:59
2025-04-06 15:39:33,505 #    Alarm is set to   2020-02-28 23:59:59
2025-04-06 15:39:33,506 #   Alarm cleared at   2020-02-28 23:59:57.499
2025-04-06 15:39:34,499 #        No alarm at   2020-02-28 23:59:59.499
2025-04-06 15:39:34,500 #   Setting alarm to   2020-02-28 23:59:61
2025-04-06 15:39:34,500 # 
2025-04-06 15:39:36,499 # Alarm!
2025-04-06 15:39:38,500 # Alarm!
2025-04-06 15:39:40,500 # Alarm!
2025-04-06 15:39:42,500 # Alarm!
2025-04-06 15:39:42,501 # { "threads": [{ "name": "idle", "stack_size": 8192, "stack_used": 600 }]}
2025-04-06 15:39:42,501 # { "threads": [{ "name": "main", "stack_size": 12288, "stack_used": 2764 }]}
2025-04-06 15:49:23,640 # Exiting Pyterm

The -161019575 matches the difference between 2020-02-28 23:59 and 2025-04-06 15:39:32.

Issues/PRs references

A previous implementation: #17416

fabian18 avatar Apr 06 '25 14:04 fabian18

Murdock results

:heavy_check_mark: PASSED

9530c182f263619da03266ac2a4bf22ece7fd144 tests/periph/rtc: add rtc_{pre,post}_set_time

Success Failures Total Runtime
10275 0 10279 10m:11s

Artifacts

riot-ci avatar Apr 06 '25 14:04 riot-ci

I think applications shouldn't use the RTC API directly at all. Trying to make the low-level peripheral API more high level is just a path towards pain - let's rather add a high level API on top -> #21343

benpicco avatar Apr 07 '25 13:04 benpicco