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

event_periodic_callback: add convenience wrapper for periodic callbacks #18598

Merged
merged 2 commits into from
Sep 19, 2022

Conversation

benpicco
Copy link
Contributor

@benpicco benpicco commented Sep 15, 2022

Contribution description

We have event_periodic to periodically trigger an event (callback in interrupt context) and we have event_callback to execute an event callback by the event thread.

Putting both together always requires some boilerplate and is not easy to discover - let's add a event_periodic_callback convenience module that ties it all together nicely.

Testing procedure

A new test case is provided with tests/event_periodic_callback.
Event callbacks are executed in thread context.

Issues/PRs references

@benpicco benpicco force-pushed the event_periodic_callback branch from 146d3d1 to 3aac88a Compare September 15, 2022 16:36
@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 Sep 15, 2022
@benpicco benpicco force-pushed the event_periodic_callback branch from 3aac88a to ba1de18 Compare September 17, 2022 11:47
Copy link
Member

@maribu maribu left a comment

Choose a reason for hiding this comment

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

ACK. Code looks good. I trust you have run the test application?

@benpicco
Copy link
Contributor Author

Sure and it will be run by CI too.

@maribu maribu added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Sep 19, 2022
@maribu maribu enabled auto-merge September 19, 2022 11:39
ifneq (,$(filter event_periodic_callback,$(USEMODULE)))
USEMODULE += event_callback
USEMODULE += event_periodic
USEMODULE += event_thread
Copy link
Member

Choose a reason for hiding this comment

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

What is this module needed for? From the code I don't see any obvious reason for this dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which of those modules do you mean?

Copy link
Member

Choose a reason for hiding this comment

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

event_thread. The module that's in the line I commented on...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need an event thread to execute the callbacks.

Copy link
Member

@miri64 miri64 Sep 19, 2022

Choose a reason for hiding this comment

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

Yes, but that's application code (you provide the queue to the init function). An application (or using module) might as well just use its own runner thread (which should remain an option anyways IMHO).


#include "event/callback.h"
#include "event/periodic.h"
#include "event/thread.h"
Copy link
Member

Choose a reason for hiding this comment

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

Same goes for this include btw. I am not sure what of event/thread.h is used here.

Comment on lines +34 to +36
event_periodic_callback_init(&a, ZTIMER_MSEC, EVENT_PRIO_MEDIUM, _event_cb, "event A");
event_periodic_callback_init(&b, ZTIMER_MSEC, EVENT_PRIO_MEDIUM, _event_cb, "event B");
event_periodic_callback_init(&c, ZTIMER_MSEC, EVENT_PRIO_MEDIUM, _event_cb, "event C");
Copy link
Member

Choose a reason for hiding this comment

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

You use the queues of event_thread here, but this is application code, so maybe you saw the link error and thought it was a missing dependency?

@maribu maribu merged commit 4b87a30 into RIOT-OS:master Sep 19, 2022
@benpicco benpicco deleted the event_periodic_callback branch September 19, 2022 18:52
@miri64
Copy link
Member

miri64 commented Sep 19, 2022

Mhhh... I darn, forgot to disable auto-merge 😅

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 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