evtimer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-17 Kaspar Schleiser <kaspar@schleiser.de>
3  * 2017 Freie Universit├Ąt Berlin
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
45 #ifndef EVTIMER_H
46 #define EVTIMER_H
47 
48 #include <stdint.h>
49 #include "kernel_defines.h"
50 
51 #if IS_USED(MODULE_EVTIMER_ON_ZTIMER)
52 #include "ztimer.h"
53 #else
54 #include "xtimer.h"
55 #endif
56 
57 #include "timex.h"
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
66 typedef struct evtimer_event {
67  struct evtimer_event *next;
68  uint32_t offset;
70 
75 
79 typedef struct {
80 #if IS_USED(MODULE_EVTIMER_ON_ZTIMER)
81  ztimer_t timer;
82  uint32_t base;
83 #else
85 #endif
89 } evtimer_t;
90 
101 void evtimer_init(evtimer_t *evtimer, evtimer_callback_t handler);
102 
110 
118 
124 void evtimer_print(const evtimer_t *evtimer);
125 
129 static inline uint32_t evtimer_now_msec(void)
130 {
131 #if IS_USED(MODULE_EVTIMER_ON_ZTIMER)
132  return ztimer_now(ZTIMER_MSEC);
133 #else
134  return xtimer_now_usec64() / US_PER_MS;
135 #endif
136 }
137 
141 static inline uint32_t evtimer_now_min(void)
142 {
143 #if IS_USED(MODULE_EVTIMER_ON_ZTIMER)
145 #else
147 #endif
148 }
149 
150 #ifdef __cplusplus
151 }
152 #endif
153 
154 #endif /* EVTIMER_H */
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.
static uint32_t evtimer_now_min(void)
Return the current system time in minutes.
Definition: evtimer.h:141
void(* evtimer_callback_t)(evtimer_event_t *event)
Event timer callback type.
Definition: evtimer.h:74
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:129
void evtimer_add(evtimer_t *evtimer, evtimer_event_t *event)
Adds event to an event timer.
#define US_PER_MS
The number of microseconds per millisecond.
Definition: timex.h:53
#define US_PER_SEC
The number of microseconds per second.
Definition: timex.h:33
#define MS_PER_SEC
The number of milliseconds per second.
Definition: timex.h:48
#define SEC_PER_MIN
The number of seconds per minute.
Definition: timex.h:38
static uint64_t xtimer_now_usec64(void)
get the current system time in microseconds since start
static ztimer_now_t ztimer_now(ztimer_clock_t *clock)
Get the current time from a clock.
Definition: ztimer.h:452
ztimer_clock_t *const ZTIMER_MSEC
Default ztimer millisecond clock.
Common macros and compiler attributes/pragmas configuration.
event structure
Definition: event.h:147
Generic event.
Definition: evtimer.h:66
uint32_t offset
offset in milliseconds from previous event
Definition: evtimer.h:68
struct evtimer_event * next
the next event in the queue
Definition: evtimer.h:67
Event timer.
Definition: evtimer.h:79
xtimer_t timer
Timer.
Definition: evtimer.h:84
evtimer_callback_t callback
Handler function for this evtimer's event type.
Definition: evtimer.h:86
evtimer_event_t * events
Event queue.
Definition: evtimer.h:88
xtimer timer structure
Definition: xtimer.h:81
ztimer structure
Definition: ztimer.h:294
Utility library for comparing and computing timestamps.
xtimer interface definitions
ztimer API