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 
109 void evtimer_add(evtimer_t *evtimer, evtimer_event_t *event);
110 
117 void evtimer_del(evtimer_t *evtimer, evtimer_event_t *event);
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 */
155 
SEC_PER_MIN
#define SEC_PER_MIN
The number of seconds per minute.
Definition: timex.h:39
xtimer
xtimer timer structure
Definition: xtimer.h:81
evtimer_t
Event timer.
Definition: evtimer.h:79
evtimer_add
void evtimer_add(evtimer_t *evtimer, evtimer_event_t *event)
Adds event to an event timer.
kernel_defines.h
Common macros and compiler attributes/pragmas configuration.
ztimer.h
ztimer API
evtimer_t::timer
xtimer_t timer
Timer.
Definition: evtimer.h:84
event
event structure
Definition: event.h:142
evtimer_del
void evtimer_del(evtimer_t *evtimer, evtimer_event_t *event)
Removes an event from an event timer.
evtimer_callback_t
void(* evtimer_callback_t)(evtimer_event_t *event)
Event timer callback type.
Definition: evtimer.h:74
evtimer_now_msec
static uint32_t evtimer_now_msec(void)
Return the current system time in msec.
Definition: evtimer.h:129
ztimer_t
ztimer structure
Definition: ztimer.h:279
MS_PER_SEC
#define MS_PER_SEC
The number of milliseconds per second.
Definition: timex.h:49
ZTIMER_MSEC
ztimer_clock_t *const ZTIMER_MSEC
Default ztimer millisecond clock.
evtimer_t::events
evtimer_event_t * events
Event queue.
Definition: evtimer.h:88
timex.h
Utility library for comparing and computing timestamps.
evtimer_print
void evtimer_print(const evtimer_t *evtimer)
Print overview of current state of an event timer.
evtimer_t::callback
evtimer_callback_t callback
Handler function for this evtimer's event type.
Definition: evtimer.h:86
evtimer_event_t
struct evtimer_event evtimer_event_t
Generic event.
evtimer_now_min
static uint32_t evtimer_now_min(void)
Return the current system time in minutes.
Definition: evtimer.h:141
evtimer_event::offset
uint32_t offset
offset in milliseconds from previous event
Definition: evtimer.h:68
evtimer_event
Generic event.
Definition: evtimer.h:66
US_PER_MS
#define US_PER_MS
The number of microseconds per millisecond.
Definition: timex.h:54
ztimer_now
static ztimer_now_t ztimer_now(ztimer_clock_t *clock)
Get the current time from a clock.
Definition: ztimer.h:422
xtimer_now_usec64
static uint64_t xtimer_now_usec64(void)
get the current system time in microseconds since start
xtimer.h
xtimer interface definitions
evtimer_init
void evtimer_init(evtimer_t *evtimer, evtimer_callback_t handler)
Initializes an event timer.
evtimer_event::next
struct evtimer_event * next
the next event in the queue
Definition: evtimer.h:67
US_PER_SEC
#define US_PER_SEC
The number of microseconds per second.
Definition: timex.h:34