Loading...
Searching...
No Matches
ztimer64.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Inria
3 * 2021 Freie Universität Berlin
4 * 2021 Kaspar Schleiser <kaspar@schleiser.de>
5 *
6 * This file is subject to the terms and conditions of the GNU Lesser
7 * General Public License v2.1. See the file LICENSE in the top level
8 * directory for more details.
9 */
10
64#ifndef ZTIMER64_H
65#define ZTIMER64_H
66
67#include <stdint.h>
68
69#include "irq.h"
70#include "mutex.h"
71#include "msg.h"
72#include "ztimer.h"
73
74#ifdef __cplusplus
75extern "C" {
76#endif
77
86
94
101typedef struct {
103 void (*callback)(void *arg);
104 void *arg;
105} ztimer64_t;
106
114 uint64_t checkpoint;
115 uint16_t adjust_set;
116 uint16_t adjust_sleep;
118#if MODULE_PM_LAYERED || DOXYGEN
120#endif
121};
122
131
140static inline uint64_t ztimer64_offset2absolute(ztimer64_clock_t *clock,
141 uint64_t offset)
142{
143 unsigned state = irq_disable();
144 uint64_t result = ztimer64_now(clock) + offset;
145
146 irq_restore(state);
147 return result;
148}
149
164 uint64_t target);
165
179static inline void ztimer64_set(ztimer64_clock_t *clock, ztimer64_t *timer,
180 uint64_t offset)
181{
182 ztimer64_set_at(clock, timer,
183 ztimer64_offset2absolute(clock, offset));
184}
185
194unsigned ztimer64_is_set(const ztimer64_t *timer);
195
208
224 uint64_t target,
225 msg_t *msg, kernel_pid_t target_pid);
226
242static inline void ztimer64_set_msg(ztimer64_clock_t *clock, ztimer64_t *timer,
243 uint64_t offset,
244 msg_t *msg, kernel_pid_t target_pid)
245{
246 ztimer64_set_msg_at(clock, timer,
247 ztimer64_offset2absolute(clock, offset),
248 msg, target_pid);
249}
250
269 uint64_t target);
270
289 msg_t *msg,
290 uint64_t timeout)
291{
292 return ztimer64_msg_receive_until(clock, msg,
293 ztimer64_offset2absolute(clock, timeout));
294}
295
296#define MSG_ZTIMER64 0xc83f
318void ztimer64_periodic_wakeup(ztimer64_clock_t *clock, uint64_t *last_wakeup,
319 uint64_t period);
320
327void ztimer64_sleep_until(ztimer64_clock_t *clock, uint64_t target);
328
335static inline void ztimer64_sleep(ztimer64_clock_t *clock, uint64_t duration)
336{
337 ztimer64_sleep_until(clock, ztimer64_offset2absolute(clock, duration));
338}
339
348static inline void ztimer64_spin_until(ztimer64_clock_t *clock, uint64_t target)
349{
350 while (ztimer64_now(clock) <= target) {}
351}
352
365 uint64_t target,
366 kernel_pid_t pid);
367
379static inline void ztimer64_set_wakeup(ztimer64_clock_t *clock,
380 ztimer64_t *timer, uint64_t offset,
381 kernel_pid_t pid)
382{
383 ztimer64_set_wakeup_at(clock, timer,
384 ztimer64_offset2absolute(clock, offset), pid);
385}
386
398 uint64_t target);
399
411 ztimer64_t *timer,
412 uint64_t timeout)
413{
414 ztimer64_set_timeout_flag_at(clock, timer,
415 ztimer64_offset2absolute(clock, timeout));
416}
417
429 uint64_t target);
430
442 mutex_t *mutex,
443 uint64_t timeout)
444{
445 return ztimer64_mutex_lock_until(clock, mutex,
446 ztimer64_offset2absolute(clock, timeout));
447}
448
460 uint64_t target);
461
473 rmutex_t *rmutex,
474 uint64_t timeout)
475{
476 return ztimer64_rmutex_lock_until(clock, rmutex,
477 ztimer64_offset2absolute(clock, timeout));
478}
479
488
492void ztimer64_init(void);
493
500
501/* default ztimer virtual devices */
505extern ztimer64_clock_t *const ZTIMER64_USEC;
506
510extern ztimer64_clock_t *const ZTIMER64_MSEC;
511
515extern ztimer64_clock_t *const ZTIMER64_SEC;
516
528int64_t ztimer64_overhead(ztimer64_clock_t *clock, uint64_t base);
529
530#ifdef __cplusplus
531}
532#endif
533
534#endif /* ZTIMER64_H */
MAYBE_INLINE void irq_restore(unsigned state)
This function restores the IRQ disable bit in the status register to the value contained within passe...
MAYBE_INLINE unsigned irq_disable(void)
This function sets the IRQ disable bit in the status register.
int16_t kernel_pid_t
Unique process identifier.
Definition sched.h:139
void ztimer64_init(void)
Initialize the board-specific default ztimer configuration.
void ztimer64_set_wakeup_at(ztimer64_clock_t *clock, ztimer64_t *timer, uint64_t target, kernel_pid_t pid)
Set a timer that wakes up a thread (absolute version)
void ztimer64_clock_init(ztimer64_clock_t *clock, ztimer_clock_t *base_clock)
Initialize clock to be run from base_clock.
unsigned ztimer64_is_set(const ztimer64_t *timer)
Check if a timer is currently active.
static void ztimer64_set_wakeup(ztimer64_clock_t *clock, ztimer64_t *timer, uint64_t offset, kernel_pid_t pid)
Set a timer that wakes up a thread (relative version)
Definition ztimer64.h:379
void ztimer64_remove(ztimer64_clock_t *clock, ztimer64_t *timer)
Remove a timer from a clock.
static void ztimer64_set_timeout_flag(ztimer64_clock_t *clock, ztimer64_t *timer, uint64_t timeout)
Set timeout thread flag after timeout.
Definition ztimer64.h:410
int ztimer64_mutex_lock_until(ztimer64_clock_t *clock, mutex_t *mutex, uint64_t target)
Try to lock the given mutex, but give up at target time.
void ztimer64_sleep_until(ztimer64_clock_t *clock, uint64_t target)
Put the calling thread to sleep until the specified time.
void ztimer64_update_head_offset(ztimer64_clock_t *clock)
Update ztimer clock head list offset.
uint64_t ztimer64_now(ztimer64_clock_t *clock)
Get the current time from a clock.
static void ztimer64_set_msg(ztimer64_clock_t *clock, ztimer64_t *timer, uint64_t offset, msg_t *msg, kernel_pid_t target_pid)
Post a message after a delay (relative version)
Definition ztimer64.h:242
static int ztimer64_msg_receive_timeout(ztimer64_clock_t *clock, msg_t *msg, uint64_t timeout)
receive a message (blocking, with relative timeout)
Definition ztimer64.h:288
static int ztimer64_mutex_lock_timeout(ztimer64_clock_t *clock, mutex_t *mutex, uint64_t timeout)
Try to lock the given mutex, but give up after timeout.
Definition ztimer64.h:441
static void ztimer64_set(ztimer64_clock_t *clock, ztimer64_t *timer, uint64_t offset)
Set a timer on a clock (relative version)
Definition ztimer64.h:179
void ztimer64_periodic_wakeup(ztimer64_clock_t *clock, uint64_t *last_wakeup, uint64_t period)
Suspend the calling thread until the time (last_wakeup + period)
void ztimer64_set_timeout_flag_at(ztimer64_clock_t *clock, ztimer64_t *timer, uint64_t target)
Set timeout thread flag at target time.
static uint64_t ztimer64_offset2absolute(ztimer64_clock_t *clock, uint64_t offset)
Get absolute target time for a clock given offset.
Definition ztimer64.h:140
void ztimer64_set_at(ztimer64_clock_t *clock, ztimer64_t *timer, uint64_t target)
Set a timer on a clock (absolute version)
static void ztimer64_sleep(ztimer64_clock_t *clock, uint64_t duration)
Put the calling thread to sleep for the specified number of ticks.
Definition ztimer64.h:335
int ztimer64_msg_receive_until(ztimer64_clock_t *clock, msg_t *msg, uint64_t target)
receive a message (blocking, with absolute timeout)
static int ztimer64_rmutex_lock_timeout(ztimer64_clock_t *clock, rmutex_t *rmutex, uint64_t timeout)
Try to lock the given rmutex, but give up after timeout.
Definition ztimer64.h:472
ztimer64_clock_t *const ZTIMER64_USEC
Default ztimer microsecond clock.
int64_t ztimer64_overhead(ztimer64_clock_t *clock, uint64_t base)
Measure ztimer64 overhead.
void ztimer64_set_msg_at(ztimer64_clock_t *clock, ztimer64_t *timer, uint64_t target, msg_t *msg, kernel_pid_t target_pid)
Post a message at a specified time.
ztimer64_clock_t *const ZTIMER64_MSEC
Default ztimer millisecond clock.
ztimer64_clock_t *const ZTIMER64_SEC
Default ztimer second clock.
static void ztimer64_spin_until(ztimer64_clock_t *clock, uint64_t target)
Busy-wait until specified target time.
Definition ztimer64.h:348
int ztimer64_rmutex_lock_until(ztimer64_clock_t *clock, rmutex_t *rmutex, uint64_t target)
Try to lock the given rmutex, but give up at time.
IRQ driver interface.
Mutex for thread synchronization.
Describes a message object which can be sent between threads.
Definition msg.h:196
Mutex structure.
Definition mutex.h:146
Mutex structure.
Definition rmutex.h:38
Minimum information for each timer.
Definition ztimer64.h:90
ztimer64_base_t * next
next timer in list
Definition ztimer64.h:91
uint64_t target
absolute target time
Definition ztimer64.h:92
ztimer64 clock structure
Definition ztimer64.h:110
ztimer_t base_timer
32bit backend timer
Definition ztimer64.h:113
uint16_t adjust_sleep
will be subtracted on every sleep(), in addition to adjust_set
Definition ztimer64.h:116
uint8_t block_pm_mode
min.
Definition ztimer64.h:119
uint64_t checkpoint
lower timer checkpoint offset
Definition ztimer64.h:114
uint16_t adjust_set
will be subtracted on every set()
Definition ztimer64.h:115
ztimer64_base_t * first
list of active timers
Definition ztimer64.h:111
ztimer_clock_t * base_clock
32bit clock backend
Definition ztimer64.h:112
ztimer64 structure
Definition ztimer64.h:101
ztimer64_base_t base
clock list entry
Definition ztimer64.h:102
void * arg
timer callback argument
Definition ztimer64.h:104
ztimer device structure
Definition ztimer.h:369
ztimer structure
Definition ztimer.h:318
ztimer API