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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
sys/event: add event_periodic_start_now()
fabian18 committed Oct 14, 2024
commit 90473c62f060ff92b99f1e97636a9658c3e3fa2c
1 change: 0 additions & 1 deletion sys/event/periodic.c
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@
static bool _event_periodic_callback(void *arg)
{
event_periodic_t *event_periodic = (event_periodic_t *)arg;

event_post(event_periodic->queue, event_periodic->event);

if (event_periodic->count && --event_periodic->count == 0) {
22 changes: 22 additions & 0 deletions sys/include/event/periodic.h
Original file line number Diff line number Diff line change
@@ -72,6 +72,28 @@ typedef struct {
void event_periodic_init(event_periodic_t *event_periodic, ztimer_clock_t *clock,
event_queue_t *queue, event_t *event);

/**
* @brief Starts a periodic timeout without delay for the first occurrence
*
* This will make the event as configured in @p event_periodic be triggered
* at every interval ticks (based on event_periodic->clock).
*
* @note: the used event_periodic struct must stay valid until after the timeout
* event has been processed!
*
* @note: this function does not touch the current count value.
*
* @note: the periodic event will start without delay.
*
* @param[in] event_periodic event_timout context object to use
* @param[in] interval period length for the event
*/
static inline void event_periodic_start_now(event_periodic_t *event_periodic, uint32_t interval)
{
event_periodic->timer.interval = interval;
ztimer_periodic_start_now(&event_periodic->timer);
}

/**
* @brief Starts a periodic timeout
*