sys/ztimer: add xtimer_on_ztimer
This commit adds logic to make xtimer use ztimer_usec as backend (instead of periph_timer). This allows ztimer_usec and xtimer to coexist. It also allows xtimer to profit from eventually implemented power mode blocking in ztimer's periph_timer backend.
This commit is contained in:
parent
21613b0aa6
commit
dd218333c2
26
Makefile.dep
26
Makefile.dep
@ -675,14 +675,6 @@ ifneq (,$(filter arduino_pwm,$(FEATURES_USED)))
|
|||||||
FEATURES_REQUIRED += periph_pwm
|
FEATURES_REQUIRED += periph_pwm
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter xtimer,$(USEMODULE)))
|
|
||||||
ifeq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
|
|
||||||
DEFAULT_MODULE += auto_init_xtimer
|
|
||||||
FEATURES_REQUIRED += periph_timer
|
|
||||||
USEMODULE += div
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq (,$(filter saul,$(USEMODULE)))
|
ifneq (,$(filter saul,$(USEMODULE)))
|
||||||
USEMODULE += phydat
|
USEMODULE += phydat
|
||||||
endif
|
endif
|
||||||
@ -1015,10 +1007,28 @@ ifneq (,$(filter periph_uart_nonblocking,$(USEMODULE)))
|
|||||||
FEATURES_REQUIRED += periph_uart
|
FEATURES_REQUIRED += periph_uart
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# include ztimer dependencies
|
||||||
ifneq (,$(filter ztimer%,$(USEMODULE)))
|
ifneq (,$(filter ztimer%,$(USEMODULE)))
|
||||||
include $(RIOTBASE)/sys/ztimer/Makefile.dep
|
include $(RIOTBASE)/sys/ztimer/Makefile.dep
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# handle xtimer's deps. Needs to be done *after* ztimer
|
||||||
|
ifneq (,$(filter xtimer,$(USEMODULE)))
|
||||||
|
ifeq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
|
||||||
|
# xtimer is used, ztimer xtimer wrapper is not
|
||||||
|
DEFAULT_MODULE += auto_init_xtimer
|
||||||
|
USEMODULE += div
|
||||||
|
ifeq (,$(filter xtimer_on_ztimer,$(USEMODULE)))
|
||||||
|
# ztimer is not used, so use *periph_timer as low-level timer*.
|
||||||
|
FEATURES_REQUIRED += periph_timer
|
||||||
|
else
|
||||||
|
# will use *ztimer_usec as low-level timer*
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
# ztimer_xtimer_compat is used, all of *xtimer's API will be mapped on ztimer.*
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
# Enable periph_gpio when periph_gpio_irq is enabled
|
# Enable periph_gpio when periph_gpio_irq is enabled
|
||||||
ifneq (,$(filter periph_gpio_irq,$(USEMODULE)))
|
ifneq (,$(filter periph_gpio_irq,$(USEMODULE)))
|
||||||
FEATURES_REQUIRED += periph_gpio
|
FEATURES_REQUIRED += periph_gpio
|
||||||
|
|||||||
@ -42,8 +42,10 @@
|
|||||||
#include "ztimer/xtimer_compat.h"
|
#include "ztimer/xtimer_compat.h"
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
#ifndef MODULE_XTIMER_ON_ZTIMER
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "periph_conf.h"
|
#include "periph_conf.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|||||||
@ -27,9 +27,15 @@
|
|||||||
#error "Do not include this file directly! Use xtimer.h instead"
|
#error "Do not include this file directly! Use xtimer.h instead"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODULE_XTIMER_ON_ZTIMER
|
||||||
|
#include "ztimer.h"
|
||||||
|
#else
|
||||||
#include "periph/timer.h"
|
#include "periph/timer.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "irq.h"
|
#include "irq.h"
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -46,7 +52,12 @@ extern volatile uint64_t _xtimer_current_time;
|
|||||||
*/
|
*/
|
||||||
static inline uint32_t _xtimer_lltimer_now(void)
|
static inline uint32_t _xtimer_lltimer_now(void)
|
||||||
{
|
{
|
||||||
|
#ifndef MODULE_XTIMER_ON_ZTIMER
|
||||||
return timer_read(XTIMER_DEV);
|
return timer_read(XTIMER_DEV);
|
||||||
|
#else
|
||||||
|
return ztimer_now(ZTIMER_USEC);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -24,9 +24,12 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifndef MODULE_XTIMER_ON_ZTIMER
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "periph/timer.h"
|
#include "periph/timer.h"
|
||||||
#include "periph_conf.h"
|
#include "periph_conf.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "xtimer.h"
|
#include "xtimer.h"
|
||||||
#include "irq.h"
|
#include "irq.h"
|
||||||
@ -50,12 +53,20 @@ static inline void _update_long_timers(uint64_t *now);
|
|||||||
static inline void _schedule_earliest_lltimer(uint32_t now);
|
static inline void _schedule_earliest_lltimer(uint32_t now);
|
||||||
|
|
||||||
static void _timer_callback(void);
|
static void _timer_callback(void);
|
||||||
|
|
||||||
|
#ifndef MODULE_XTIMER_ON_ZTIMER
|
||||||
static void _periph_timer_callback(void *arg, int chan);
|
static void _periph_timer_callback(void *arg, int chan);
|
||||||
|
#else
|
||||||
|
static void _ztimer_callback(void *arg);
|
||||||
|
static ztimer_t _ztimer = { .callback=_ztimer_callback };
|
||||||
|
#endif
|
||||||
|
|
||||||
void xtimer_init(void)
|
void xtimer_init(void)
|
||||||
{
|
{
|
||||||
|
#ifndef MODULE_XTIMER_ON_ZTIMER
|
||||||
/* initialize low-level timer */
|
/* initialize low-level timer */
|
||||||
timer_init(XTIMER_DEV, XTIMER_HZ, _periph_timer_callback, NULL);
|
timer_init(XTIMER_DEV, XTIMER_HZ, _periph_timer_callback, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* register initial overflow tick */
|
/* register initial overflow tick */
|
||||||
_schedule_earliest_lltimer(_xtimer_now());
|
_schedule_earliest_lltimer(_xtimer_now());
|
||||||
@ -107,12 +118,20 @@ void _xtimer_set64(xtimer_t *timer, uint32_t offset, uint32_t long_offset)
|
|||||||
irq_restore(state);
|
irq_restore(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef MODULE_XTIMER_ON_ZTIMER
|
||||||
static void _periph_timer_callback(void *arg, int chan)
|
static void _periph_timer_callback(void *arg, int chan)
|
||||||
{
|
{
|
||||||
(void)arg;
|
(void)arg;
|
||||||
(void)chan;
|
(void)chan;
|
||||||
_timer_callback();
|
_timer_callback();
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
static void _ztimer_callback(void *arg)
|
||||||
|
{
|
||||||
|
(void)arg;
|
||||||
|
_timer_callback();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void _shoot(xtimer_t *timer)
|
static void _shoot(xtimer_t *timer)
|
||||||
{
|
{
|
||||||
@ -141,7 +160,11 @@ static inline void _schedule_earliest_lltimer(uint32_t now)
|
|||||||
}
|
}
|
||||||
|
|
||||||
DEBUG("_schedule_earliest_lltimer(): setting %" PRIu32 "\n", _xtimer_lltimer_mask(target));
|
DEBUG("_schedule_earliest_lltimer(): setting %" PRIu32 "\n", _xtimer_lltimer_mask(target));
|
||||||
|
#ifndef MODULE_XTIMER_ON_ZTIMER
|
||||||
timer_set_absolute(XTIMER_DEV, XTIMER_CHAN, _xtimer_lltimer_mask(target));
|
timer_set_absolute(XTIMER_DEV, XTIMER_CHAN, _xtimer_lltimer_mask(target));
|
||||||
|
#else
|
||||||
|
ztimer_set(ZTIMER_USEC, &_ztimer, target - ztimer_now(ZTIMER_USEC));
|
||||||
|
#endif
|
||||||
_lltimer_ongoing = true;
|
_lltimer_ongoing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
# ztimer dependencies
|
# ztimer dependencies
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
# "ztimer" is the default meta-module of ztimer
|
# "ztimer" is the default meta-module of ztimer
|
||||||
ifneq (,$(filter ztimer,$(USEMODULE)))
|
ifneq (,$(filter ztimer,$(USEMODULE)))
|
||||||
USEMODULE += ztimer_core
|
USEMODULE += ztimer_core
|
||||||
@ -24,8 +23,23 @@ ifneq (,$(filter ztimer,$(USEMODULE)))
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# unless ztimer_xtimer_compat is used, make xtimer use ztimer as backend.
|
||||||
|
ifneq (,$(filter ztimer,$(USEMODULE)))
|
||||||
|
ifneq (,$(filter xtimer,$(USEMODULE)))
|
||||||
|
ifeq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
|
||||||
|
USEMODULE += xtimer_on_ztimer
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
# make xtimer use ztimer_usec as low level timer
|
||||||
|
ifneq (,$(filter xtimer_on_ztimer,$(USEMODULE)))
|
||||||
|
USEMODULE += ztimer_usec
|
||||||
|
PSEUDOMODULES += xtimer_on_ztimer
|
||||||
|
endif
|
||||||
|
|
||||||
# "ztimer_xtimer_compat" is a wrapper of the xtimer API on ztimer_used
|
# "ztimer_xtimer_compat" is a wrapper of the xtimer API on ztimer_used
|
||||||
# (it is currently incomplete)
|
# (it is currently incomplete). Unless doing testing, use "xtimer_on_ztimer".
|
||||||
ifneq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
|
ifneq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
|
||||||
USEMODULE += div
|
USEMODULE += div
|
||||||
USEMODULE += ztimer_usec
|
USEMODULE += ztimer_usec
|
||||||
@ -41,11 +55,11 @@ ifneq (,$(filter ztimer_convert_%,$(USEMODULE)))
|
|||||||
USEMODULE += ztimer_convert
|
USEMODULE += ztimer_convert
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter ztimer_periph,$(USEMODULE)))
|
ifneq (,$(filter ztimer_periph_timer,$(USEMODULE)))
|
||||||
FEATURES_REQUIRED += periph_timer
|
FEATURES_REQUIRED += periph_timer
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter ztimer_rtt,$(USEMODULE)))
|
ifneq (,$(filter ztimer_periph_rtt,$(USEMODULE)))
|
||||||
FEATURES_REQUIRED += periph_rtt
|
FEATURES_REQUIRED += periph_rtt
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -55,7 +69,7 @@ endif
|
|||||||
|
|
||||||
ifneq (,$(filter ztimer_usec,$(USEMODULE)))
|
ifneq (,$(filter ztimer_usec,$(USEMODULE)))
|
||||||
USEMODULE += ztimer
|
USEMODULE += ztimer
|
||||||
USEMODULE += ztimer_periph
|
USEMODULE += ztimer_periph_timer
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter ztimer_msec,$(USEMODULE)))
|
ifneq (,$(filter ztimer_msec,$(USEMODULE)))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user