timeout.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2017 Inria
3  * SPDX-FileCopyrightText: 2017 Freie Universität Berlin
4  * SPDX-FileCopyrightText: 2017 Kaspar Schleiser <kaspar@schleiser.de>
5  * SPDX-License-Identifier: LGPL-2.1-only
6  */
7 
8 #pragma once
9 
36 #include "event.h"
37 #include "ztimer.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
46 typedef struct {
52 
62  event_queue_t *queue, event_t *event);
63 
64 #if IS_USED(MODULE_EVENT_TIMEOUT) || DOXYGEN
74 void event_timeout_init(event_timeout_t *event_timeout, event_queue_t *queue,
75  event_t *event);
76 #endif
77 
92 void event_timeout_set(event_timeout_t *event_timeout, uint32_t timeout);
93 
105 
112 static inline bool event_timeout_is_pending(const event_timeout_t *event_timeout)
113 {
114  if (event_timeout->clock == NULL || event_timeout->queue == NULL ||
115  event_timeout->event == NULL) {
116  return false;
117  }
118 
119  return ztimer_is_set(event_timeout->clock, &event_timeout->timer)
120  || event_is_queued(event_timeout->queue, event_timeout->event);
121 }
122 
123 #ifdef __cplusplus
124 }
125 #endif
bool event_is_queued(const event_queue_t *queue, const event_t *event)
Check if an event is already queued.
unsigned ztimer_is_set(const ztimer_clock_t *clock, const ztimer_t *timer)
Check if a timer is currently active.
event queue structure
Definition: event.h:150
Timeout Event structure.
Definition: timeout.h:46
ztimer_t timer
ztimer object used for timeout
Definition: timeout.h:48
event_t * event
event to post after timeout
Definition: timeout.h:50
event_queue_t * queue
event queue to post event to
Definition: timeout.h:49
ztimer_clock_t * clock
ztimer clock to use
Definition: timeout.h:47
event structure
Definition: event.h:142
ztimer device structure
Definition: ztimer.h:367
ztimer structure
Definition: ztimer.h:316
void event_timeout_set(event_timeout_t *event_timeout, uint32_t timeout)
Set a timeout.
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.
Definition: timeout.h:112
void event_timeout_init(event_timeout_t *event_timeout, event_queue_t *queue, event_t *event)
Initialize timeout event object.
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_clear(event_timeout_t *event_timeout)
Clear a timeout event.
ztimer API