mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/ztimer: introduce xtimer wrapper
This commit is contained in:
parent
eccb6e89ed
commit
616daff945
25
Makefile.dep
25
Makefile.dep
@ -676,9 +676,18 @@ ifneq (,$(filter arduino_pwm,$(FEATURES_USED)))
|
||||
endif
|
||||
|
||||
ifneq (,$(filter xtimer,$(USEMODULE)))
|
||||
DEFAULT_MODULE += auto_init_xtimer
|
||||
FEATURES_REQUIRED += periph_timer
|
||||
ifeq (,$(filter ztimer,$(USEMODULE)))
|
||||
DEFAULT_MODULE += auto_init_xtimer
|
||||
FEATURES_REQUIRED += periph_timer
|
||||
USEMODULE += div
|
||||
else
|
||||
USEMODULE += ztimer_xtimer_compat
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
|
||||
USEMODULE += div
|
||||
PSEUDOMODULES += xtimer
|
||||
endif
|
||||
|
||||
ifneq (,$(filter saul,$(USEMODULE)))
|
||||
@ -1013,15 +1022,22 @@ ifneq (,$(filter periph_uart_nonblocking,$(USEMODULE)))
|
||||
FEATURES_REQUIRED += periph_uart
|
||||
endif
|
||||
|
||||
ifneq (,$(filter xtimer_on_ztimer%,$(USEMODULE)))
|
||||
#
|
||||
# ztimer dependencies
|
||||
#
|
||||
ifneq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
|
||||
USEMODULE += ztimer_usec
|
||||
endif
|
||||
|
||||
ifneq (,$(filter ztimer_%,$(USEMODULE)))
|
||||
USEMODULE += ztimer
|
||||
USEMODULE += ztimer_core
|
||||
USEMODULE += ztimer_extend
|
||||
endif
|
||||
|
||||
ifneq (,$(filter ztimer_convert_%,$(USEMODULE)))
|
||||
USEMODULE += ztimer_convert
|
||||
endif
|
||||
|
||||
ifneq (,$(filter ztimer_periph,$(USEMODULE)))
|
||||
FEATURES_REQUIRED += periph_timer
|
||||
endif
|
||||
@ -1035,6 +1051,7 @@ ifneq (,$(filter ztimer_convert_frac,$(USEMODULE)))
|
||||
endif
|
||||
|
||||
ifneq (,$(filter ztimer,$(USEMODULE)))
|
||||
# this is the default module for ztimer
|
||||
USEMODULE += ztimer_auto_init
|
||||
USEMODULE += ztimer_core
|
||||
USEMODULE += ztimer_convert_frac
|
||||
|
@ -76,8 +76,8 @@ endif
|
||||
ifneq (,$(filter log_%,$(USEMODULE)))
|
||||
DIRS += log
|
||||
endif
|
||||
ifneq (,$(filter xtimer,$(USEMODULE)))
|
||||
DIRS += xtimer
|
||||
ifneq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
|
||||
FILTER += xtimer
|
||||
endif
|
||||
ifneq (,$(filter cpp11-compat,$(USEMODULE)))
|
||||
DIRS += cpp11-compat
|
||||
@ -163,7 +163,10 @@ endif
|
||||
ifneq (,$(filter netif,$(USEMODULE)))
|
||||
DIRS += net/netif
|
||||
endif
|
||||
ifneq (,$(filter ztimer_core,$(USEMODULE)))
|
||||
DIRS += ztimer
|
||||
endif
|
||||
|
||||
DIRS += $(dir $(wildcard $(addsuffix /Makefile, $(USEMODULE))))
|
||||
DIRS += $(dir $(wildcard $(addsuffix /Makefile, $(filter-out $(FILTER), $(USEMODULE)))))
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
|
@ -397,7 +397,8 @@ void auto_init(void)
|
||||
void ztimer_init(void);
|
||||
ztimer_init();
|
||||
}
|
||||
if (IS_USED(MODULE_AUTO_INIT_XTIMER)) {
|
||||
if (IS_USED(MODULE_AUTO_INIT_XTIMER) &&
|
||||
!IS_USED(MODULE_ZTIMER_XTIMER_COMPAT)) {
|
||||
LOG_DEBUG("Auto init xtimer.\n");
|
||||
extern void xtimer_init(void);
|
||||
xtimer_init();
|
||||
|
@ -38,6 +38,10 @@
|
||||
#include "mutex.h"
|
||||
#include "kernel_types.h"
|
||||
|
||||
#ifdef MODULE_ZTIMER_XTIMER_COMPAT
|
||||
#include "ztimer/xtimer_compat.h"
|
||||
#else
|
||||
|
||||
#include "board.h"
|
||||
#include "periph_conf.h"
|
||||
|
||||
@ -617,5 +621,7 @@ static inline int xtimer_msg_receive_timeout64(msg_t *msg, uint64_t timeout);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MODULE_XTIMER_ON_ZTIMER */
|
||||
|
||||
/** @} */
|
||||
#endif /* XTIMER_H */
|
||||
|
178
sys/include/ztimer/xtimer_compat.h
Normal file
178
sys/include/ztimer/xtimer_compat.h
Normal file
@ -0,0 +1,178 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup sys_ztimer_util
|
||||
* @{
|
||||
* @file
|
||||
* @brief ztimer xtimer wrapper interface
|
||||
*
|
||||
* Please check out xtimer's documentation for usage.
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*/
|
||||
#ifndef ZTIMER_XTIMER_COMPAT_H
|
||||
#define ZTIMER_XTIMER_COMPAT_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "div.h"
|
||||
#include "timex.h"
|
||||
#ifdef MODULE_CORE_MSG
|
||||
#include "msg.h"
|
||||
#endif /* MODULE_CORE_MSG */
|
||||
#include "mutex.h"
|
||||
#include "kernel_types.h"
|
||||
|
||||
#include "ztimer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* the xtimer API is documented elsewhere. This is just an (incomplete) wrapper,
|
||||
* so skip doxygen.
|
||||
*/
|
||||
#ifndef DOXYGEN
|
||||
|
||||
typedef ztimer_t xtimer_t;
|
||||
typedef uint32_t xtimer_ticks32_t;
|
||||
typedef uint64_t xtimer_ticks64_t;
|
||||
|
||||
static inline xtimer_ticks32_t xtimer_now(void)
|
||||
{
|
||||
return ztimer_now(ZTIMER_USEC);
|
||||
}
|
||||
|
||||
static inline xtimer_ticks64_t xtimer_now64(void)
|
||||
{
|
||||
return ztimer_now(ZTIMER_USEC);
|
||||
}
|
||||
|
||||
/*static void xtimer_now_timex(timex_t *out) {
|
||||
}*/
|
||||
|
||||
static inline uint32_t xtimer_now_usec(void)
|
||||
{
|
||||
return ztimer_now(ZTIMER_USEC);
|
||||
}
|
||||
|
||||
static inline uint64_t xtimer_now_usec64(void)
|
||||
{
|
||||
return ztimer_now(ZTIMER_USEC);
|
||||
}
|
||||
|
||||
static inline void xtimer_sleep(uint32_t seconds)
|
||||
{
|
||||
/* TODO: use ZTIMER_SEC */
|
||||
ztimer_sleep(ZTIMER_USEC, seconds * 1000000LU);
|
||||
}
|
||||
|
||||
static inline void xtimer_usleep(uint32_t microseconds)
|
||||
{
|
||||
ztimer_sleep(ZTIMER_USEC, microseconds);
|
||||
}
|
||||
|
||||
static inline void xtimer_nanosleep(uint32_t nanoseconds)
|
||||
{
|
||||
ztimer_sleep(ZTIMER_USEC, nanoseconds / NS_PER_US);
|
||||
}
|
||||
|
||||
static inline void xtimer_set(xtimer_t *timer, uint32_t offset)
|
||||
{
|
||||
ztimer_set(ZTIMER_USEC, timer, offset);
|
||||
}
|
||||
|
||||
static inline void xtimer_remove(xtimer_t *timer)
|
||||
{
|
||||
ztimer_remove(ZTIMER_USEC, timer);
|
||||
}
|
||||
|
||||
static inline void xtimer_set_msg(xtimer_t *timer, uint32_t offset, msg_t *msg,
|
||||
kernel_pid_t target_pid)
|
||||
{
|
||||
ztimer_set_msg(ZTIMER_USEC, timer, offset, msg, target_pid);
|
||||
}
|
||||
|
||||
static inline void xtimer_periodic_wakeup(xtimer_ticks32_t *last_wakeup,
|
||||
uint32_t period)
|
||||
{
|
||||
ztimer_periodic_wakeup(ZTIMER_USEC, last_wakeup, period);
|
||||
}
|
||||
|
||||
static inline uint32_t xtimer_usec_from_ticks(xtimer_ticks32_t ticks)
|
||||
{
|
||||
return ticks;
|
||||
}
|
||||
|
||||
static inline xtimer_ticks32_t xtimer_ticks_from_usec(uint32_t usec)
|
||||
{
|
||||
return usec;
|
||||
}
|
||||
|
||||
static inline void xtimer_now_timex(timex_t *out)
|
||||
{
|
||||
uint64_t now = xtimer_now_usec64();
|
||||
|
||||
out->seconds = div_u64_by_1000000(now);
|
||||
out->microseconds = now - (out->seconds * US_PER_SEC);
|
||||
}
|
||||
|
||||
static inline int xtimer_msg_receive_timeout(msg_t *msg, uint32_t timeout)
|
||||
{
|
||||
return ztimer_msg_receive_timeout(ZTIMER_USEC, msg, timeout);
|
||||
}
|
||||
|
||||
static inline void xtimer_set_wakeup(xtimer_t *timer, uint32_t offset,
|
||||
kernel_pid_t pid)
|
||||
{
|
||||
ztimer_set_wakeup(ZTIMER_USEC, timer, offset, pid);
|
||||
}
|
||||
|
||||
/*
|
||||
static inline void xtimer_set64(xtimer_t *timer, uint64_t offset_us);
|
||||
static inline void xtimer_tsleep32(xtimer_ticks32_t ticks);
|
||||
static inline void xtimer_tsleep64(xtimer_ticks64_t ticks);
|
||||
static inline void xtimer_spin(xtimer_ticks32_t ticks);
|
||||
static inline void xtimer_periodic_wakeup(xtimer_ticks32_t *last_wakeup,
|
||||
uint32_t period);
|
||||
static inline void xtimer_set_wakeup64(xtimer_t *timer, uint64_t offset,
|
||||
kernel_pid_t pid);
|
||||
static inline xtimer_ticks32_t xtimer_ticks_from_usec(uint32_t usec);
|
||||
static inline xtimer_ticks64_t xtimer_ticks_from_usec64(uint64_t usec);
|
||||
static inline uint32_t xtimer_usec_from_ticks(xtimer_ticks32_t ticks);
|
||||
static inline uint64_t xtimer_usec_from_ticks64(xtimer_ticks64_t ticks);
|
||||
static inline xtimer_ticks32_t xtimer_ticks(uint32_t ticks);
|
||||
static inline xtimer_ticks64_t xtimer_ticks64(uint64_t ticks);
|
||||
static inline xtimer_ticks32_t xtimer_diff(xtimer_ticks32_t a,
|
||||
xtimer_ticks32_t b);
|
||||
static inline xtimer_ticks64_t xtimer_diff64(xtimer_ticks64_t a,
|
||||
xtimer_ticks64_t b);
|
||||
static inline xtimer_ticks32_t xtimer_diff32_64(xtimer_ticks64_t a,
|
||||
xtimer_ticks64_t b);
|
||||
static inline bool xtimer_less(xtimer_ticks32_t a, xtimer_ticks32_t b);
|
||||
static inline bool xtimer_less64(xtimer_ticks64_t a, xtimer_ticks64_t b);
|
||||
int xtimer_mutex_lock_timeout(mutex_t *mutex, uint64_t us);
|
||||
void xtimer_set_timeout_flag(xtimer_t *t, uint32_t timeout);
|
||||
|
||||
#if defined(MODULE_CORE_MSG) || defined(DOXYGEN)
|
||||
static inline void xtimer_set_msg64(xtimer_t *timer, uint64_t offset,
|
||||
msg_t *msg, kernel_pid_t target_pid);
|
||||
static inline int xtimer_msg_receive_timeout64(msg_t *msg, uint64_t timeout);
|
||||
#endif
|
||||
*/
|
||||
|
||||
#endif /* DOXYGEN */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif /* ZTIMER_XTIMER_COMPAT_H */
|
Loading…
Reference in New Issue
Block a user