evtimer.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2016-2017 Kaspar Schleiser <kaspar@schleiser.de>
3  * SPDX-FileCopyrightText: 2017 Freie Universität Berlin
4  * SPDX-License-Identifier: LGPL-2.1-only
5  */
6 
7 #pragma once
8 
40 #include <stdint.h>
41 #include "modules.h"
42 
43 #include "ztimer.h"
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
52 typedef struct evtimer_event {
53  struct evtimer_event *next;
54  uint32_t offset;
56 
61 
65 typedef struct {
67  uint32_t base;
71 } evtimer_t;
72 
83 void evtimer_init(evtimer_t *evtimer, evtimer_callback_t handler);
84 
92 
100 
106 void evtimer_print(const evtimer_t *evtimer);
107 
111 static inline uint32_t evtimer_now_msec(void)
112 {
113  return ztimer_now(ZTIMER_MSEC);
114 }
115 
116 #ifdef __cplusplus
117 }
118 #endif
119 
struct evtimer_event evtimer_event_t
Generic event.
void evtimer_print(const evtimer_t *evtimer)
Print overview of current state of an event timer.
void evtimer_init(evtimer_t *evtimer, evtimer_callback_t handler)
Initializes an event timer.
void(* evtimer_callback_t)(evtimer_event_t *event)
Event timer callback type.
Definition: evtimer.h:60
void evtimer_del(evtimer_t *evtimer, evtimer_event_t *event)
Removes an event from an event timer.
static uint32_t evtimer_now_msec(void)
Return the current system time in msec.
Definition: evtimer.h:111
void evtimer_add(evtimer_t *evtimer, evtimer_event_t *event)
Adds event to an event timer.
static ztimer_now_t ztimer_now(ztimer_clock_t *clock)
Get the current time from a clock.
Definition: ztimer.h:680
ztimer_clock_t *const ZTIMER_MSEC
Default ztimer millisecond clock.
Common macros and compiler attributes/pragmas configuration.
event structure
Definition: event.h:142
Generic event.
Definition: evtimer.h:52
uint32_t offset
offset in milliseconds from previous event
Definition: evtimer.h:54
struct evtimer_event * next
the next event in the queue
Definition: evtimer.h:53
Event timer.
Definition: evtimer.h:65
uint32_t base
Absolute time the first event is built on.
Definition: evtimer.h:67
evtimer_callback_t callback
Handler function for this evtimer's event type.
Definition: evtimer.h:68
ztimer_t timer
Timer.
Definition: evtimer.h:66
evtimer_event_t * events
Event queue.
Definition: evtimer.h:70
ztimer structure
Definition: ztimer.h:316
ztimer API