Skip to content
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

sys/event: add API to start periodic event without initial delay #20911

Merged
merged 3 commits into from
Oct 16, 2024

Conversation

fabian18
Copy link
Contributor

Contribution description

Depending on what you want, a periodic event could happen the first time after the first interval, or without initial delay.
Only the first variant is implemented in RIOT so far. This adds an API to start it without delay.

Currently I am misusing the timed events for that. I initialize them with 0 delay and in their callback I re-initialize and add them again with actual delay. The reinit is an invitation for race conditions if the event could also be added from another thread as the event thread.

Testing procedure

I added a call to the new API in tests/sys/event_ztimer.

Help: Press s to start test, r to print it is ready
s
START
main(): This is RIOT! (Version: 2024.10-devel-292-gb6d800-pr/event_periodic_no_delay)
posting periodic timed callback with timeout 1sec
waiting for periodic callback to be triggered 4 times
trigger 1 of periodic timeout, elapsed time: 1000547 us
trigger 2 of periodic timeout, elapsed time: 1000076 us
stop periodic event
resume periodic event, 2 triggers remaining
trigger 3 of periodic timeout, elapsed time: 663 us
trigger 4 of periodic timeout, elapsed time: 999972 us
posting periodic timed callback with timeout 1sec and no delay
waiting for periodic callback to be triggered 4 times
trigger 1 of periodic timeout, elapsed time: 406 us
trigger 2 of periodic timeout, elapsed time: 1000223 us
stop periodic event
resume periodic event, 2 triggers remaining
trigger 3 of periodic timeout, elapsed time: 682 us
trigger 4 of periodic timeout, elapsed time: 1000017 us
posting timed callback with timeout 0.5sec, clear right after
posting timed callback with timeout 1sec
waiting for timed callback to trigger
triggered timed callback after 1000794us
[SUCCESS]
{ "threads": [{ "name": "idle", "stack_size": 8192, "stack_used": 600 }]}
{ "threads": [{ "name": "main", "stack_size": 12288, "stack_used": 2452 }]}

Issues/PRs references

@github-actions github-actions bot added Area: tests Area: tests and testing framework Area: timers Area: timer subsystems Area: sys Area: System labels Oct 14, 2024
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Oct 15, 2024
@riot-ci
Copy link

riot-ci commented Oct 15, 2024

Murdock results

✔️ PASSED

d4cd708 tests/sys/event_ztimer: add event_periodic_start_now() to test

Success Failures Total Runtime
10215 0 10215 17m:31s

Artifacts

@benpicco benpicco added this pull request to the merge queue Oct 15, 2024
Merged via the queue into RIOT-OS:master with commit 9123b5e Oct 16, 2024
27 checks passed
@fabian18
Copy link
Contributor Author

Thank you for quick approval!

@benpicco benpicco added this to the Release 2024.10 milestone Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: sys Area: System Area: tests Area: tests and testing framework Area: timers Area: timer subsystems CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants