All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
deferred_callback.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 ML!PA Consulting GmbH
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
25#ifndef EVENT_DEFERRED_CALLBACK_H
26#define EVENT_DEFERRED_CALLBACK_H
27
28#include <assert.h>
29#include "event/callback.h"
30#include "ztimer.h"
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
44
49static inline void _event_deferred_post(void *arg)
50{
51 event_deferred_callback_t *event_timeout = arg;
52
53 event_post(event_timeout->queue, arg);
54}
55
69 event_queue_t *queue,
70 ztimer_clock_t *clock, uint32_t timeout,
71 void (*callback)(void *), void *arg)
72{
73 event->event = (event_callback_t) {
74 .super.handler = _event_callback_handler,
75 .callback = callback,
76 .arg = arg,
77 };
78 event->timer = (ztimer_t) {
79 .callback = _event_deferred_post,
80 .arg = event,
81 };
82 event->queue = queue;
83
84 ztimer_set(clock, &event->timer, timeout);
85}
86
94 ztimer_clock_t *clock)
95{
96 ztimer_remove(clock, &event->timer);
97 event_cancel(event->queue, (event_t *)event);
98}
99
100#ifdef __cplusplus
101}
102#endif
103#endif /* EVENT_DEFERRED_CALLBACK_H */
POSIX.1-2008 compliant version of the assert macro.
Provides a callback-with-argument event type.
void _event_callback_handler(event_t *event)
event callback handler function (used internally)
static void _event_deferred_post(void *arg)
Internal helper function for ztimer callback.
static void event_deferred_callback_cancel(event_deferred_callback_t *event, ztimer_clock_t *clock)
Cancel a callback function if it has not been executed yet.
static void event_deferred_callback_post(event_deferred_callback_t *event, event_queue_t *queue, ztimer_clock_t *clock, uint32_t timeout, void(*callback)(void *), void *arg)
Execute a callback function in the event thread after a timeout.
void event_post(event_queue_t *queue, event_t *event)
Queue an event.
void event_cancel(event_queue_t *queue, event_t *event)
Cancel a queued event.
uint32_t ztimer_set(ztimer_clock_t *clock, ztimer_t *timer, uint32_t val)
Set a timer on a clock.
bool ztimer_remove(ztimer_clock_t *clock, ztimer_t *timer)
Remove a timer from a clock.
event queue structure
Definition event.h:156
Callback Event structure definition.
Definition callback.h:49
Deferred Callback Event structure.
ztimer_t timer
ztimer object used for timeout
event_callback_t event
callback event portion
event_queue_t * queue
event queue to post event to
event structure
Definition event.h:148
ztimer device structure
Definition ztimer.h:370
ztimer structure
Definition ztimer.h:319
ztimer API