Skip to content

periph/rtc: add rtc_pre_set_time() and rtc_post_set_time()#21366

Closed
fabian18 wants to merge 3 commits intoRIOT-OS:masterfrom
fabian18:pr/rtc_pre_post_set_time
Closed

periph/rtc: add rtc_pre_set_time() and rtc_post_set_time()#21366
fabian18 wants to merge 3 commits intoRIOT-OS:masterfrom
fabian18:pr/rtc_pre_post_set_time

Conversation

@fabian18
Copy link
Copy Markdown
Contributor

@fabian18 fabian18 commented Apr 6, 2025

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

@github-actions github-actions bot added Platform: native Platform: This PR/issue effects the native platform Platform: ARM Platform: This PR/issue effects ARM-based platforms Area: tests Area: tests and testing framework Platform: AVR Platform: This PR/issue effects AVR-based platforms Area: drivers Area: Device drivers Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms Area: cpu Area: CPU/MCU ports labels Apr 6, 2025
@fabian18 fabian18 force-pushed the pr/rtc_pre_post_set_time branch from 5d28390 to 9530c18 Compare April 6, 2025 14:04
void rtc_init(void);

/**
* @brief Hook to be implemented by the application to prepare for a time travel
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's always good to be prepared for time travel.

But on a serious note: It would be good to add some more information on why an application would need/want this.

@crasbe crasbe added Type: new feature The issue requests / The PR implemements a new feature for RIOT CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Apr 6, 2025
@riot-ci
Copy link
Copy Markdown

riot-ci commented Apr 6, 2025

Murdock results

✔️ PASSED

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

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

Artifacts

@benpicco
Copy link
Copy Markdown
Contributor

benpicco commented Apr 7, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: cpu Area: CPU/MCU ports Area: drivers Area: Device drivers Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Platform: AVR Platform: This PR/issue effects AVR-based platforms Platform: native Platform: This PR/issue effects the native platform Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants