23#ifndef XTIMER_IMPLEMENTATION_H
24#define XTIMER_IMPLEMENTATION_H
27#error "Do not include this file directly! Use xtimer.h instead"
30#ifdef MODULE_XTIMER_ON_ZTIMER
42extern volatile uint64_t _xtimer_current_time;
47#define MSG_XTIMER 12345
54#ifndef MODULE_XTIMER_ON_ZTIMER
69 return val & ~XTIMER_MASK;
80void _xtimer_set64(
xtimer_t *timer, uint32_t offset, uint32_t long_offset);
81void _xtimer_periodic_wakeup(uint32_t *last_wakeup, uint32_t period);
85int _xtimer_msg_receive_timeout(
msg_t *msg, uint32_t ticks);
86int _xtimer_msg_receive_timeout64(
msg_t *msg, uint64_t ticks);
97#ifndef XTIMER_MIN_SPIN
101#define XTIMER_MIN_SPIN _xtimer_usec_from_ticks(1)
107static inline uint64_t _xtimer_now64(
void)
109 uint32_t now, elapsed;
116 _xtimer_current_time += (uint64_t)elapsed;
118 elapsed = now - ((uint32_t)_xtimer_current_time & 0xFFFFFFFF);
119 _xtimer_current_time += (uint64_t)elapsed;
123 return _xtimer_current_time;
150static inline void _xtimer_spin(uint32_t offset) {
160static inline void _xtimer_tsleep32(uint32_t ticks)
165static inline void _xtimer_tsleep64(uint64_t ticks)
176 _xtimer_tsleep64(_xtimer_ticks_from_usec64(milliseconds *
US_PER_MS));
181 _xtimer_tsleep32(_xtimer_ticks_from_usec(microseconds));
186 _xtimer_tsleep64(_xtimer_ticks_from_usec64(microseconds));
191 _xtimer_tsleep64(_xtimer_ticks_from_usec64((uint64_t)seconds *
US_PER_SEC));
196 _xtimer_tsleep32(_xtimer_ticks_from_usec(nanoseconds /
NS_PER_US));
201 _xtimer_tsleep32(ticks.
ticks32);
206 _xtimer_tsleep64(ticks.
ticks64);
211 _xtimer_periodic_wakeup(&last_wakeup->
ticks32, _xtimer_ticks_from_usec(period));
216 _xtimer_set_wakeup(timer, _xtimer_ticks_from_usec(offset), pid);
221 _xtimer_set_wakeup64(timer, _xtimer_ticks_from_usec64(offset), pid);
226 _xtimer_set64(timer, _xtimer_ticks_from_usec(offset), 0);
231 uint64_t ticks = _xtimer_ticks_from_usec64(period_us);
232 _xtimer_set64(timer, ticks, ticks >> 32);
235#ifdef MODULE_CORE_MSG
238 return _xtimer_msg_receive_timeout(msg, _xtimer_ticks_from_usec(timeout));
243 return _xtimer_msg_receive_timeout64(msg, _xtimer_ticks_from_usec64(timeout));
248 _xtimer_set_msg(timer, _xtimer_ticks_from_usec(offset), msg, target_pid);
253 _xtimer_set_msg64(timer, _xtimer_ticks_from_usec64(offset), msg, target_pid);
260 ticks.
ticks32 = _xtimer_ticks_from_usec(usec);
267 ticks.
ticks64 = _xtimer_ticks_from_usec64(usec);
273 return _xtimer_usec_from_ticks(ticks.
ticks32);
278 return _xtimer_usec_from_ticks64(ticks.
ticks64);
Low-level timer peripheral driver interface definitions.
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.
unsigned int timer_read(tim_t dev)
Read the current value of the given timer device.
#define US_PER_MS
The number of microseconds per millisecond.
#define US_PER_SEC
The number of microseconds per second.
#define NS_PER_US
The number of nanoseconds per microsecond.
static void xtimer_usleep(uint32_t microseconds)
Pause the execution of a thread for some microseconds.
static xtimer_ticks32_t xtimer_diff(xtimer_ticks32_t a, xtimer_ticks32_t b)
Compute difference between two xtimer time stamps.
static uint32_t xtimer_now_usec(void)
get the current system time in microseconds since start
static xtimer_ticks64_t xtimer_ticks_from_usec64(uint64_t usec)
Convert microseconds to xtimer ticks, 64 bit version.
static void xtimer_set_msg64(xtimer_t *timer, uint64_t offset, msg_t *msg, kernel_pid_t target_pid)
Set a timer that sends a message, 64bit version.
static void xtimer_set_wakeup64(xtimer_t *timer, uint64_t offset, kernel_pid_t pid)
Set a timer that wakes up a thread, 64bit version.
static bool xtimer_less64(xtimer_ticks64_t a, xtimer_ticks64_t b)
Compare two xtimer time stamps, 64 bit version.
static xtimer_ticks64_t xtimer_now64(void)
get the current system time as 64bit time stamp
static void xtimer_set64(xtimer_t *timer, uint64_t offset_us)
Set a timer to execute a callback at some time in the future, 64bit version.
static void xtimer_tsleep32(xtimer_ticks32_t ticks)
Stop execution of a thread for some time, 32bit version.
static void xtimer_msleep(uint32_t milliseconds)
Pause the execution of a thread for some milliseconds.
static void xtimer_sleep(uint32_t seconds)
Pause the execution of a thread for some seconds.
static xtimer_ticks32_t xtimer_diff32_64(xtimer_ticks64_t a, xtimer_ticks64_t b)
Compute 32 bit difference between two 64 bit xtimer time stamps.
static xtimer_ticks64_t xtimer_ticks64(uint64_t ticks)
Create an xtimer time stamp, 64 bit version.
static void xtimer_periodic_wakeup(xtimer_ticks32_t *last_wakeup, uint32_t period)
will cause the calling thread to be suspended until the absolute time (last_wakeup + period).
static void xtimer_set_msg(xtimer_t *timer, uint32_t offset, msg_t *msg, kernel_pid_t target_pid)
Set a timer that sends a message.
static bool xtimer_less(xtimer_ticks32_t a, xtimer_ticks32_t b)
Compare two xtimer time stamps.
static uint32_t xtimer_usec_from_ticks(xtimer_ticks32_t ticks)
Convert xtimer ticks to microseconds.
static xtimer_ticks64_t xtimer_diff64(xtimer_ticks64_t a, xtimer_ticks64_t b)
Compute difference between two xtimer time stamps, 64 bit version.
static void xtimer_usleep64(uint64_t microseconds)
Pause the execution of a thread for some microseconds.
static int xtimer_msg_receive_timeout(msg_t *msg, uint32_t timeout)
receive a message blocking but with timeout
static void xtimer_tsleep64(xtimer_ticks64_t ticks)
Stop execution of a thread for some time, 64bit version.
static void xtimer_nanosleep(uint32_t nanoseconds)
Stop execution of a thread for some time.
static void xtimer_set_wakeup(xtimer_t *timer, uint32_t offset, kernel_pid_t pid)
Set a timer that wakes up a thread.
static void xtimer_spin(xtimer_ticks32_t ticks)
Stop execution of a thread for some time, blocking.
static uint64_t xtimer_now_usec64(void)
get the current system time in microseconds since start
static void xtimer_set(xtimer_t *timer, uint32_t offset)
Set a timer to execute a callback at some time in the future.
static xtimer_ticks32_t xtimer_ticks_from_usec(uint32_t usec)
Convert microseconds to xtimer ticks.
static xtimer_ticks32_t xtimer_ticks(uint32_t ticks)
Create an xtimer time stamp.
static xtimer_ticks32_t xtimer_now(void)
get the current system time as 32bit time stamp value
static bool xtimer_is_set(const xtimer_t *timer)
state if an xtimer is currently set (waiting to be expired)
static uint64_t xtimer_usec_from_ticks64(xtimer_ticks64_t ticks)
Convert xtimer ticks to microseconds, 64 bit version.
static int xtimer_msg_receive_timeout64(msg_t *msg, uint64_t timeout)
receive a message blocking but with timeout, 64bit version
ztimer_clock_t *const ZTIMER_USEC
Default ztimer microsecond clock.
static ztimer_now_t ztimer_now(ztimer_clock_t *clock)
Get the current time from a clock.
uint32_t _xtimer_now(void)
xtimer internal stuff
static uint32_t _xtimer_lltimer_mask(uint32_t val)
drop bits of a value that don't fit into the low-level timer.
void _xtimer_tsleep(uint32_t offset, uint32_t long_offset)
Sleep for the given number of ticks.
static uint32_t _xtimer_lltimer_now(void)
returns the (masked) low-level timer counter value.
Describes a message object which can be sent between threads.
xtimer timestamp (32 bit)
uint32_t ticks32
Tick count.
xtimer timestamp (64 bit)
uint64_t ticks64
Tick count.
uint32_t long_offset
upper 32bit offset time
uint32_t offset
lower 32bit offset time