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

Provides functionality to trigger events after timeout. More...

Detailed Description

Provides functionality to trigger events after timeout.

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

Example:

event_timeout_t event_timeout;
printf("posting timed callback with timeout 1sec\n");
event_timeout_init(&event_timeout, &queue, (event_t*)&event);
event_timeout_set(&event_timeout, 1000000);
[...]
void event_timeout_set(event_timeout_t *event_timeout, uint32_t timeout)
Set a timeout.
void event_timeout_init(event_timeout_t *event_timeout, event_queue_t *queue, event_t *event)
Initialize timeout event object.
#define printf(...)
A wrapper for the printf() function that passes arguments through unmodified, but fails to compile if...
Definition stdio.h:60
Timeout Event structure.
Definition timeout.h:50
event structure
Definition event.h:148

Event Timeout API

Author
Kaspar Schleiser kaspa.nosp@m.r@sc.nosp@m.hleis.nosp@m.er.d.nosp@m.e

Definition in file timeout.h.

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

Go to the source code of this file.

Data Structures

struct  event_timeout_t
 Timeout Event structure. More...
 
void event_timeout_ztimer_init (event_timeout_t *event_timeout, ztimer_clock_t *clock, event_queue_t *queue, event_t *event)
 Initialize timeout event object.
 
void event_timeout_init (event_timeout_t *event_timeout, event_queue_t *queue, event_t *event)
 Initialize timeout event object.
 
void event_timeout_set (event_timeout_t *event_timeout, uint32_t timeout)
 Set a timeout.
 
void event_timeout_clear (event_timeout_t *event_timeout)
 Clear a timeout event.
 
static bool event_timeout_is_pending (const event_timeout_t *event_timeout)
 Check if a timeout event is scheduled to be executed in the future.
 

Function Documentation

◆ event_timeout_clear()

void event_timeout_clear ( event_timeout_t event_timeout)

Clear a 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.

Parameters
[in]event_timeoutevent_timeout context object to use

◆ event_timeout_init()

void event_timeout_init ( event_timeout_t event_timeout,
event_queue_t queue,
event_t event 
)

Initialize timeout event object.

Note
If ztimer is used the default time clock backend is ZTIMER_USEC
Parameters
[in]event_timeoutevent_timeout object to initialize
[in]queuequeue that the timed-out event will be added to
[in]eventevent to add to queue after timeout

◆ event_timeout_is_pending()

static bool event_timeout_is_pending ( const event_timeout_t event_timeout)
inlinestatic

Check if a timeout event is scheduled to be executed in the future.

Parameters
[in]event_timeoutevent_timout context object to use
Returns
true if the event is scheduled, false otherwise

Definition at line 116 of file timeout.h.

◆ event_timeout_set()

void event_timeout_set ( event_timeout_t event_timeout,
uint32_t  timeout 
)

Set a timeout.

This will make the event as configured in event_timeout be triggered after timeout microseconds (if using xtimer) or the ztimer_clock_t ticks.

Note
: the used event_timeout struct must stay valid until after the timeout event has been processed!
Parameters
[in]event_timeoutevent_timout context object to use
[in]timeouttimeout in microseconds or the ztimer_clock_t ticks units

◆ event_timeout_ztimer_init()

void event_timeout_ztimer_init ( event_timeout_t event_timeout,
ztimer_clock_t clock,
event_queue_t queue,
event_t event 
)

Initialize timeout event object.

Parameters
[in]event_timeoutevent_timeout object to initialize
[in]clockthe clock backend, eg: ZTIMER_USEC, ZTIMER_MSEC
[in]queuequeue that the timed-out event will be added to
[in]eventevent to add to queue after timeout