Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys/ztimer: initial import #11874

Merged
merged 15 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@
/sys/usb/ @bergzand @dylad @aabadie
/sys/xtimer/ @kaspar030 @MichelRottleuthner

/sys/include/ztimer.h @kaspar030 @bergzand
/sys/include/ztimer/ @kaspar030 @bergzand
kaspar030 marked this conversation as resolved.
Show resolved Hide resolved
/sys/ztimer/ @kaspar030 @bergzand

/tests/ @smlng @leandrolanzieri @aabadie @MichelRottleuthner @fjmolinas
/tests/emb6* @miri64
/tests/gnrc* @miri64
Expand Down
28 changes: 22 additions & 6 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,6 @@ ifneq (,$(filter arduino_pwm,$(FEATURES_USED)))
FEATURES_REQUIRED += periph_pwm
endif

ifneq (,$(filter xtimer,$(USEMODULE)))
DEFAULT_MODULE += auto_init_xtimer
FEATURES_REQUIRED += periph_timer
USEMODULE += div
endif

ifneq (,$(filter saul,$(USEMODULE)))
USEMODULE += phydat
endif
Expand Down Expand Up @@ -1013,6 +1007,28 @@ ifneq (,$(filter periph_uart_nonblocking,$(USEMODULE)))
FEATURES_REQUIRED += periph_uart
endif
maribu marked this conversation as resolved.
Show resolved Hide resolved

# include ztimer dependencies
ifneq (,$(filter ztimer%,$(USEMODULE)))
include $(RIOTBASE)/sys/ztimer/Makefile.dep
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
ifneq (,$(filter periph_gpio_irq,$(USEMODULE)))
FEATURES_REQUIRED += periph_gpio
Expand Down
10 changes: 10 additions & 0 deletions boards/common/arduino-atmega/include/board_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ extern "C" {
#define XTIMER_BACKOFF (40)
/** @} */

/**
* @name ztimer configuration values
* @{
*/
#define CONFIG_ZTIMER_USEC_TYPE ZTIMER_TYPE_PERIPH_TIMER
#define CONFIG_ZTIMER_USEC_DEV (TIMER_DEV(0))
#define CONFIG_ZTIMER_USEC_FREQ (250000LU)
#define CONFIG_ZTIMER_USEC_WIDTH (16)
/** @} */

/**
* @name Configuration parameters for the W5100 driver
* @{
Expand Down
9 changes: 9 additions & 0 deletions boards/ek-lm4f120xl/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ extern "C" {
#define LED2_TOGGLE (LED_PORT ^= LED2_MASK)
/* @} */

/**
* @name ztimer configuration
* @{
*/
#define CONFIG_ZTIMER_USEC_TYPE ZTIMER_TYPE_PERIPH_TIMER
#define CONFIG_ZTIMER_USEC_DEV TIMER_DEV(0)
#define CONFIG_ZTIMER_USEC_MIN (8)
/** @} */

/**
* @brief Initialize board specific hardware, including clock, LEDs and std-IO
*/
Expand Down
8 changes: 8 additions & 0 deletions boards/frdm-kw41z/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ extern "C"
#endif
/** @} */

/**
* @name ztimer configuration
* @{
*/
#define CONFIG_ZTIMER_USEC_TYPE ZTIMER_TYPE_PERIPH_TIMER
#define CONFIG_ZTIMER_USEC_DEV (TIMER_PIT_DEV(0))
/** @} */

/**
* @name NOR flash hardware configuration
* @{
Expand Down
10 changes: 10 additions & 0 deletions boards/native/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ static const motor_driver_config_t motor_driver_config[] = {
#define MOTOR_DRIVER_NUMOF ARRAY_SIZE(motor_driver_config)
/** @} */

/**
* @name ztimer configuration
* @{
*/
#define CONFIG_ZTIMER_USEC_TYPE ZTIMER_TYPE_PERIPH_TIMER
#define CONFIG_ZTIMER_USEC_DEV TIMER_DEV(0)
/* on native, anything can happen... */
#define CONFIG_ZTIMER_USEC_MIN (64)
/** @} */

#endif /* __cplusplus */

#ifdef __cplusplus
Expand Down
8 changes: 8 additions & 0 deletions boards/phynode-kw41z/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ extern "C"
#endif
/** @} */

/**
* @name ztimer configuration
* @{
*/
#define CONFIG_ZTIMER_USEC_TYPE ZTIMER_TYPE_PERIPH_TIMER
#define CONFIG_ZTIMER_USEC_DEV (TIMER_PIT_DEV(0))
/** @} */

/**
* @name Define the interface for the CCS811 gas sensors
* @{
Expand Down
9 changes: 9 additions & 0 deletions boards/samr21-xpro/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ extern "C" {
#define XTIMER_CHAN (0)
/** @} */

/**
* @name ztimer configuration
* @{
*/
#define CONFIG_ZTIMER_USEC_TYPE ZTIMER_TYPE_PERIPH_TIMER
#define CONFIG_ZTIMER_USEC_DEV TIMER_DEV(1)
#define CONFIG_ZTIMER_USEC_MIN (8)
/** @} */

/**
* @name AT86RF233 configuration
*
Expand Down
10 changes: 10 additions & 0 deletions boards/usb-kw41z/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ extern "C"
#endif
/** @} */

/**
* @name ztimer configuration
* @{
*/
#define CONFIG_ZTIMER_USEC_TYPE ZTIMER_TYPE_PERIPH_TIMER
#define CONFIG_ZTIMER_USEC_DEV (TIMER_PIT_DEV(0))
#define CONFIG_ZTIMER_USEC_FREQ (1000000LU)
#define CONFIG_ZTIMER_USEC_WIDTH (32)
/** @} */

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions makefiles/pseudomodules.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ PSEUDOMODULES += stdio_uart_rx
PSEUDOMODULES += suit_%
PSEUDOMODULES += wakaama_objects_%
PSEUDOMODULES += zptr
PSEUDOMODULES += ztimer%

# ztimer's main module is called "ztimer_core"
NO_PSEUDOMODULES += ztimer_core

# handle suit_v4 being a distinct module
NO_PSEUDOMODULES += suit_v4
Expand Down
9 changes: 6 additions & 3 deletions sys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
8 changes: 7 additions & 1 deletion sys/auto_init/auto_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,13 @@ void auto_init(void)
extern void auto_init_random(void);
auto_init_random();
}
if (IS_USED(MODULE_AUTO_INIT_XTIMER)) {
if (IS_USED(MODULE_AUTO_INIT_ZTIMER)) {
LOG_DEBUG("Auto init ztimer.\n");
void ztimer_init(void);
ztimer_init();
}
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();
Expand Down
8 changes: 8 additions & 0 deletions sys/include/xtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@
#include "mutex.h"
#include "kernel_types.h"

#ifdef MODULE_ZTIMER_XTIMER_COMPAT
#include "ztimer/xtimer_compat.h"
#else

#ifndef MODULE_XTIMER_ON_ZTIMER
#include "board.h"
#include "periph_conf.h"
#endif

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -617,5 +623,7 @@ static inline int xtimer_msg_receive_timeout64(msg_t *msg, uint64_t timeout);
}
#endif

#endif /* MODULE_XTIMER_ON_ZTIMER */

/** @} */
#endif /* XTIMER_H */
11 changes: 11 additions & 0 deletions sys/include/xtimer/implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@
#error "Do not include this file directly! Use xtimer.h instead"
#endif

#ifdef MODULE_XTIMER_ON_ZTIMER
#include "ztimer.h"
#else
#include "periph/timer.h"
#endif

#include "irq.h"


#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -46,7 +52,12 @@ extern volatile uint64_t _xtimer_current_time;
*/
static inline uint32_t _xtimer_lltimer_now(void)
{
#ifndef MODULE_XTIMER_ON_ZTIMER
return timer_read(XTIMER_DEV);
#else
return ztimer_now(ZTIMER_USEC);
#endif

}

/**
Expand Down
Loading