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

Provides functionality to trigger periodic events. More...

Detailed Description

Provides functionality to trigger periodic events.

event_periodic intentionally doesn't extend event structures in order to support events that are integrated in larger structs intrusively.

Example:

event_periodic_t event_periodic;
printf("posting timed callback every 1sec\n");
event_periodic_init(&event_periodic, ZTIMER_USEC, &queue, (event_t*)&event);
event_periodic_start(&event_periodic, 1000000);
[...]
static void event_periodic_start(event_periodic_t *event_periodic, uint32_t interval)
Starts a periodic timeout.
Definition periodic.h:111
void event_periodic_init(event_periodic_t *event_periodic, ztimer_clock_t *clock, event_queue_t *queue, event_t *event)
Initialize a periodic event timeout.
#define printf(...)
A wrapper for the printf() function that passes arguments through unmodified, but fails to compile if...
Definition stdio.h:60
ztimer_clock_t *const ZTIMER_USEC
Default ztimer microsecond clock.
Timeout Event structure.
Definition periodic.h:54
event structure
Definition event.h:148

Event Periodic API

Author
Francisco Molina franc.nosp@m.ois-.nosp@m.xavie.nosp@m.r.mo.nosp@m.lina@.nosp@m.inri.nosp@m.a.fr

Definition in file periodic.h.

#include "event.h"
#include "ztimer/periodic.h"
+ Include dependency graph for periodic.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  event_periodic_t
 Timeout Event structure. More...
 
#define EVENT_PERIODIC_FOREVER   0
 Run the periodic event forever.
 
void event_periodic_init (event_periodic_t *event_periodic, ztimer_clock_t *clock, event_queue_t *queue, event_t *event)
 Initialize a periodic event timeout.
 
static void event_periodic_start_now (event_periodic_t *event_periodic, uint32_t interval)
 Starts a periodic timeout without delay for the first occurrence.
 
static void event_periodic_start (event_periodic_t *event_periodic, uint32_t interval)
 Starts a periodic timeout.
 
static void event_periodic_set_count (event_periodic_t *event_periodic, uint32_t count)
 Set the amount of times the periodic event should repeat itself.
 
static void event_periodic_stop (event_periodic_t *event_periodic)
 Stop a periodic timeout event.
 

Macro Definition Documentation

◆ EVENT_PERIODIC_FOREVER

#define EVENT_PERIODIC_FOREVER   0

Run the periodic event forever.

Definition at line 49 of file periodic.h.

Function Documentation

◆ event_periodic_init()

void event_periodic_init ( event_periodic_t event_periodic,
ztimer_clock_t clock,
event_queue_t queue,
event_t event 
)

Initialize a periodic event timeout.

Note
: On init the periodic event is to to run forever.
Parameters
[in]event_periodicevent_periodic object to initialize
[in]clockthe clock to configure this timer on
[in]queuequeue that the timed-out event will be added to
[in]eventevent to add to queue after timeout

◆ event_periodic_set_count()

static void event_periodic_set_count ( event_periodic_t event_periodic,
uint32_t  count 
)
inlinestatic

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

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

Definition at line 124 of file periodic.h.

◆ event_periodic_start()

static void event_periodic_start ( event_periodic_t event_periodic,
uint32_t  interval 
)
inlinestatic

Starts a periodic timeout.

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

Definition at line 111 of file periodic.h.

◆ event_periodic_start_now()

static void event_periodic_start_now ( event_periodic_t event_periodic,
uint32_t  interval 
)
inlinestatic

Starts a periodic timeout without delay for the first occurrence.

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

Definition at line 91 of file periodic.h.

◆ event_periodic_stop()

static void event_periodic_stop ( event_periodic_t event_periodic)
inlinestatic

Stop a periodic timeout 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]event_periodicevent_periodic_timeout context object to use

Definition at line 146 of file periodic.h.