Loading...
Searching...
No Matches
periodic_callback.h File Reference

Provides functionality to trigger periodic event callbacks. More...

Detailed Description

Provides functionality to trigger periodic event callbacks.

This provides convenience functions to trigger periodic event callbacks executed by the event thread.

Event Periodic Callback API

Author
Benjamin Valentin benja.nosp@m.min..nosp@m.valen.nosp@m.tin@.nosp@m.ml-pa.nosp@m..com

Definition in file periodic_callback.h.

#include <assert.h>
#include "event/callback.h"
#include "event/periodic.h"
+ Include dependency graph for periodic_callback.h:

Go to the source code of this file.

Data Structures

struct  event_periodic_callback_t
 Periodic Callback Event structure. More...
 
static void * event_periodic_callback_get_arg (event_periodic_callback_t *event)
 Get user context from Periodic Callback Event.
 
static void event_periodic_callback_init (event_periodic_callback_t *event, ztimer_clock_t *clock, event_queue_t *queue, void(*callback)(void *), void *arg)
 Initialize a periodic callback event.
 
static void event_periodic_callback_start (event_periodic_callback_t *event, uint32_t interval)
 Starts a periodic callback event.
 
static void event_periodic_callback_create (event_periodic_callback_t *event, ztimer_clock_t *clock, uint32_t interval, event_queue_t *queue, void(*callback)(void *), void *arg)
 Initialize and start a periodic callback event.
 
static uint32_t event_periodic_callback_get_interval (const event_periodic_callback_t *event)
 Get the interval in which the periodic callback event repeats.
 
static void event_periodic_callback_set_count (event_periodic_callback_t *event, uint32_t count)
 Set the amount of times the periodic callback event should repeat itself.
 
static uint32_t event_periodic_callback_get_count (const event_periodic_callback_t *event)
 Get the amount of times the periodic callback event should repeat itself.
 
static void event_periodic_callback_stop (event_periodic_callback_t *event)
 Stop a periodic callback event.
 

Function Documentation

◆ event_periodic_callback_create()

static void event_periodic_callback_create ( event_periodic_callback_t event,
ztimer_clock_t clock,
uint32_t  interval,
event_queue_t queue,
void(*)(void *)  callback,
void *  arg 
)
inlinestatic

Initialize and start a periodic callback event.

This is a convenience function that combines event_periodic_callback_init and event_periodic_callback_start

Parameters
[out]eventevent_periodic_callback object to initialize
[in]clockthe clock to configure this timer on
[in]intervalperiod length for the event
[in]queuequeue that the timed-out event will be added to
[in]callbackcallback to set up
[in]argcallback argument to set up

Definition at line 115 of file periodic_callback.h.

◆ event_periodic_callback_get_arg()

static void * event_periodic_callback_get_arg ( event_periodic_callback_t event)
inlinestatic

Get user context from Periodic Callback Event.

Parameters
[in]eventevent_periodic_callback object to initialize
Returns
User supplied argument to the event

Definition at line 50 of file periodic_callback.h.

◆ event_periodic_callback_get_count()

static uint32_t event_periodic_callback_get_count ( const event_periodic_callback_t event)
inlinestatic

Get the amount of times the periodic callback event should repeat itself.

Parameters
[in]eventevent_periodic_callback context object to use
Returns
times the event should repeat itself, EVENT_PERIODIC_FOREVER if it will repeat forever or is exhausted

Definition at line 156 of file periodic_callback.h.

◆ event_periodic_callback_get_interval()

static uint32_t event_periodic_callback_get_interval ( const event_periodic_callback_t event)
inlinestatic

Get the interval in which the periodic callback event repeats.

Parameters
[in]eventevent_periodic_callback context object to use
Returns
The interval of the underlying timer in which the event repeats

Definition at line 131 of file periodic_callback.h.

◆ event_periodic_callback_init()

static void event_periodic_callback_init ( event_periodic_callback_t event,
ztimer_clock_t clock,
event_queue_t queue,
void(*)(void *)  callback,
void *  arg 
)
inlinestatic

Initialize a periodic callback event.

Note
: On init the periodic event is configured to run forever.
Parameters
[in]eventevent_periodic_callback object to initialize
[in]clockthe clock to configure this timer on
[in]queuequeue that the timed-out event will be added to
[in]callbackcallback to set up
[in]argcallback argument to set up

Definition at line 66 of file periodic_callback.h.

◆ event_periodic_callback_set_count()

static void event_periodic_callback_set_count ( event_periodic_callback_t event,
uint32_t  count 
)
inlinestatic

Set the amount of times the periodic callback event should repeat itself.

Parameters
[in]eventevent_periodic_callback context object to use
[in]counttimes the event should repeat itself, EVENT_PERIODIC_FOREVER to run for ever.

Definition at line 143 of file periodic_callback.h.

◆ event_periodic_callback_start()

static void event_periodic_callback_start ( event_periodic_callback_t event,
uint32_t  interval 
)
inlinestatic

Starts a periodic callback event.

If the event is already started, it's interval will be updated and it will be scheduled with the new interval.

This will make the event as configured in event 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!
: this function does not touch the current count value.
Parameters
[in]eventevent_periodic_callback context object to use
[in]intervalperiod length for the event

Definition at line 95 of file periodic_callback.h.

◆ event_periodic_callback_stop()

static void event_periodic_callback_stop ( event_periodic_callback_t event)
inlinestatic

Stop a periodic callback event.

Calling this function will cancel the timeout by removing its underlying timer. If the timer has already fired before calling this function, the connected event will be put already into the given event queue and this function does not have any effect.

Note
Calling this function does not touch event_periodic->count, if the periodic event was not set to run for ever and did run until expiration, then count will be != 0 after this function is called.
Parameters
[in]eventevent_periodic_callback context object to use

Definition at line 175 of file periodic_callback.h.