From da76ca68db7001221f068cd07e4858f387a14d06 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Thu, 7 Jan 2021 10:22:56 +0100 Subject: [PATCH 01/11] sys/ztimer: add ZTIMER_SEC wire up ZTIMER_SEC to the existing RTC backend, or RTT backend, or periph_timer backend (in this order of preference). Update sys/ztimer/auto_init.c Co-authored-by: Leandro Lanzieri --- sys/include/ztimer.h | 5 ++++ sys/ztimer/Makefile.dep | 4 ++++ sys/ztimer/auto_init.c | 53 ++++++++++++++++++++++++++++++++++++----- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/sys/include/ztimer.h b/sys/include/ztimer.h index 6c6068dcbc..9e327a77cc 100644 --- a/sys/include/ztimer.h +++ b/sys/include/ztimer.h @@ -595,6 +595,11 @@ extern ztimer_clock_t *const ZTIMER_USEC; */ extern ztimer_clock_t *const ZTIMER_MSEC; +/** + * @brief Default ztimer second clock + */ +extern ztimer_clock_t *const ZTIMER_SEC; + /** * @brief Base ztimer for the microsecond clock (ZTIMER_USEC) * diff --git a/sys/ztimer/Makefile.dep b/sys/ztimer/Makefile.dep index c72b3c3828..681102f7a8 100644 --- a/sys/ztimer/Makefile.dep +++ b/sys/ztimer/Makefile.dep @@ -66,6 +66,10 @@ ifneq (,$(filter ztimer_periph_timer,$(USEMODULE))) FEATURES_REQUIRED += periph_timer endif +ifneq (,$(filter ztimer_periph_rtc,$(USEMODULE))) + FEATURES_REQUIRED += periph_rtc +endif + ifneq (,$(filter ztimer_periph_rtt,$(USEMODULE))) FEATURES_REQUIRED += periph_rtt endif diff --git a/sys/ztimer/auto_init.c b/sys/ztimer/auto_init.c index 139d95c11f..8a36ec4fd7 100644 --- a/sys/ztimer/auto_init.c +++ b/sys/ztimer/auto_init.c @@ -43,6 +43,7 @@ #include "ztimer/convert_muldiv64.h" #include "ztimer/periph_timer.h" #include "ztimer/periph_rtt.h" +#include "ztimer/periph_rtc.h" #include "ztimer/config.h" #include "log.h" @@ -52,6 +53,7 @@ #define FREQ_1MHZ 1000000LU #define FREQ_250KHZ 250000LU #define FREQ_1KHZ 1000LU +#define FREQ_1HZ 1LU #if MODULE_ZTIMER_USEC # if CONFIG_ZTIMER_USEC_TYPE_PERIPH_TIMER @@ -74,18 +76,23 @@ ztimer_clock_t *const ZTIMER_USEC = &_ztimer_convert_frac_usec.super.super; # endif #endif +/* use RTT for ZTIMER_MSEC, if used. Use RTT also for ZTIMER_USEC, + unless module ztimer_periph_rtc is explicitly used by application */ +#if MODULE_ZTIMER_PERIPH_RTT && (MODULE_ZTIMER_MSEC || (MODULE_ZTIMER_SEC && !MODULE_ZTIMER_PERIPH_RTC)) +static ztimer_periph_rtt_t _ztimer_periph_timer_rtt_msec_sec; +# define ZTIMER_RTT_INIT (&_ztimer_periph_timer_rtt_msec_sec) +#endif + #if MODULE_ZTIMER_MSEC # if MODULE_ZTIMER_PERIPH_RTT -static ztimer_periph_rtt_t _ztimer_periph_timer_rtt_msec; -ztimer_clock_t *const ZTIMER_MSEC_BASE = &_ztimer_periph_timer_rtt_msec; -# define ZTIMER_RTT_INIT (ZTIMER_MSEC_BASE) +ztimer_clock_t *const ZTIMER_MSEC_BASE = &_ztimer_periph_timer_rtt_msec_sec; # if RTT_FREQUENCY != FREQ_1KHZ static ztimer_convert_frac_t _ztimer_convert_frac_msec; -ztimer_clock_t *const ZTIMER_MSEC = &_ztimer_convert_frac_msec.super.super; +ztimer_clock_t *const ZTIMER_MSEC = &_ztimer_convert_frac_msec_sec.super.super; # define ZTIMER_MSEC_CONVERT_LOWER_FREQ RTT_FREQUENCY -# define ZTIMER_MSEC_CONVERT_LOWER (&_ztimer_periph_timer_rtt_msec) +# define ZTIMER_MSEC_CONVERT_LOWER (&_ztimer_periph_timer_rtt_msec_sec) # else -ztimer_clock_t *const ZTIMER_MSEC = &_ztimer_periph_timer_rtt_msec; +ztimer_clock_t *const ZTIMER_MSEC = &_ztimer_periph_timer_rtt_msec_sec; # endif # elif MODULE_ZTIMER_USEC static ztimer_convert_frac_t _ztimer_convert_frac_msec; @@ -98,6 +105,27 @@ ztimer_clock_t *const ZTIMER_MSEC_BASE = &_ztimer_periph_timer_usec.super; # endif #endif +#if MODULE_ZTIMER_SEC +# if MODULE_ZTIMER_PERIPH_RTC +static ztimer_periph_rtc_t _ztimer_periph_timer_rtc_sec; +ztimer_clock_t *const ZTIMER_SEC = &_ztimer_periph_timer_rtc_sec; +# elif MODULE_ZTIMER_PERIPH_RTT +static ztimer_convert_frac_t _ztimer_convert_frac_sec; +ztimer_clock_t *const ZTIMER_SEC = &_ztimer_convert_frac_sec.super.super; +ztimer_clock_t *const ZTIMER_SEC_BASE = &_ztimer_periph_timer_msec_sec.super; +# define ZTIMER_SEC_CONVERT_LOWER (&_ztimer_periph_timer_rtt_msec_sec) +# define ZTIMER_SEC_CONVERT_LOWER_FREQ RTT_FREQUENCY +# elif MODULE_ZTIMER_USEC +static ztimer_convert_frac_t _ztimer_convert_frac_sec; +ztimer_clock_t *const ZTIMER_SEC = &_ztimer_convert_frac_sec.super.super; +ztimer_clock_t *const ZTIMER_SEC_BASE = &_ztimer_periph_timer_usec.super; +# define ZTIMER_SEC_CONVERT_LOWER ZTIMER_USEC_BASE +# define ZTIMER_SEC_CONVERT_LOWER_FREQ CONFIG_ZTIMER_USEC_BASE_FREQ +# else +# error No suitable ZTIMER_SEC config. Maybe add USEMODULE += ztimer_usec? +# endif +#endif + void ztimer_init(void) { #if MODULE_ZTIMER_USEC @@ -166,4 +194,17 @@ void ztimer_init(void) ZTIMER_MSEC->required_pm_mode = CONFIG_ZTIMER_MSEC_REQUIRED_PM_MODE; # endif #endif + +#if MODULE_ZTIMER_SEC +# if MODULE_ZTIMER_PERIPH_RTC + LOG_DEBUG("ztimer_init(): initializing rtc\n"); + ztimer_periph_rtc_init(&_ztimer_periph_timer_rtc_sec); +# else + LOG_DEBUG("ztimer_init(): ZTIMER_SEC convert_frac from %lu to 1000\n", + (long unsigned)ZTIMER_SEC_CONVERT_LOWER_FREQ); + ztimer_convert_frac_init(&_ztimer_convert_frac_sec, + ZTIMER_SEC_CONVERT_LOWER, + FREQ_1HZ, ZTIMER_SEC_CONVERT_LOWER_FREQ); +# endif +#endif } From cc92a0aea31bc94f24e5a7bba2604c2fbaf96ae2 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Thu, 7 Jan 2021 10:26:33 +0100 Subject: [PATCH 02/11] tests/ztimer_msg: Allow testing ZTIMER_SEC --- tests/ztimer_msg/Makefile | 3 +++ tests/ztimer_msg/main.c | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/ztimer_msg/Makefile b/tests/ztimer_msg/Makefile index e198e2c38e..7289b23ccd 100644 --- a/tests/ztimer_msg/Makefile +++ b/tests/ztimer_msg/Makefile @@ -5,4 +5,7 @@ USEMODULE += ztimer_usec # uncomment this to test using ztimer msec on rtt #USEMODULE += ztimer_msec ztimer_periph_rtt +# uncomment this to test using ztimer sec on rtc +#USEMODULE += ztimer_sec ztimer_periph_rtc + include $(RIOTBASE)/Makefile.include diff --git a/tests/ztimer_msg/main.c b/tests/ztimer_msg/main.c index f4bbf1fce8..24e52a0bcb 100644 --- a/tests/ztimer_msg/main.c +++ b/tests/ztimer_msg/main.c @@ -31,7 +31,10 @@ #include "test_utils/expect.h" -#ifdef MODULE_ZTIMER_MSEC +#ifdef MODULE_ZTIMER_SEC +#define ZTIMER ZTIMER_SEC +#define TICKS_PER_SEC 1 +#elif MODULE_ZTIMER_MSEC #define ZTIMER ZTIMER_MSEC #define TICKS_PER_SEC MS_PER_SEC #else @@ -71,11 +74,14 @@ void *timer_thread(void *arg) msg_receive(&m); struct timer_msg *tmsg = m.content.ptr; uint32_t now = ztimer_now(ZTIMER); - printf("now=%lu:%lu -> every %lu.%lus: %s\n", - (now / TICKS_PER_SEC), - (now % TICKS_PER_SEC), - tmsg->interval / TICKS_PER_SEC, - tmsg->interval % TICKS_PER_SEC, + /* casts are needed to solve for sometimes TICKS_PER_SEC being UL + * result of / and % of uint32_t will always fit into uint32_t + */ + printf("now=%"PRIu32":%"PRIu32" -> every %"PRIu32".%"PRIu32"s: %s\n", + (uint32_t)(now / TICKS_PER_SEC), + (uint32_t)(now % TICKS_PER_SEC), + (uint32_t)(tmsg->interval / TICKS_PER_SEC), + (uint32_t)(tmsg->interval % TICKS_PER_SEC), tmsg->text); tmsg->msg.type = 12345; From fc3e0b60555b66dba84b0b59d2e910a903a84a7e Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Thu, 7 Jan 2021 10:29:41 +0100 Subject: [PATCH 03/11] tests/ztimer_underflow: allow testing ZTIMER_SEC --- tests/ztimer_underflow/Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/ztimer_underflow/Makefile b/tests/ztimer_underflow/Makefile index 63098523a7..2a44cfd641 100644 --- a/tests/ztimer_underflow/Makefile +++ b/tests/ztimer_underflow/Makefile @@ -12,6 +12,10 @@ ifeq ($(TEST_ZTIMER_CLOCK), ZTIMER_MSEC) KCONFIG_ADD_CONFIG += $(APPDIR)/app.config.msec.test endif endif +ifeq ($(TEST_ZTIMER_CLOCK), ZTIMER_SEC) + USEMODULE += ztimer_sec + USEMODULE += ztimer_periph_rtc +endif CFLAGS += -DTEST_ZTIMER_CLOCK=$(TEST_ZTIMER_CLOCK) From aa770fdd8c97751513d72c24d0729ad87d17b112 Mon Sep 17 00:00:00 2001 From: Karl Fessel Date: Thu, 4 Feb 2021 13:23:08 +0100 Subject: [PATCH 04/11] ztimer/auto_init: restructure for flexibitily, pm for ZTIMER_SEC MSEC and SEC are now usable on TIMER(0) without having USEC pm is configured by used hardware OLD configuration values are translated for backward compatibility prefer rtt for ZTIMER_SEC avoid doing partial ztimer setup if auto_init_ztimer is disabled before this patch some const pointers might have been definend to values that a user who disables auto_init for ztimer does not like. --- sys/include/ztimer/config.h | 31 +++- sys/ztimer/auto_init.c | 281 ++++++++++++++++++++++++------------ 2 files changed, 213 insertions(+), 99 deletions(-) diff --git a/sys/include/ztimer/config.h b/sys/include/ztimer/config.h index 87770b1067..2240d7e2ee 100644 --- a/sys/include/ztimer/config.h +++ b/sys/include/ztimer/config.h @@ -104,17 +104,36 @@ extern "C" { #endif /* MODULE_ZTIMER_PERIPH_RTT */ /** - * @brief The minimum pm mode required for ZTIMER_USEC to run. + * @brief The minimum pm mode required for ZTIMER_TIMER to run. */ -#ifndef CONFIG_ZTIMER_USEC_REQUIRED_PM_MODE -#define CONFIG_ZTIMER_USEC_REQUIRED_PM_MODE ZTIMER_CLOCK_NO_REQUIRED_PM_MODE +#ifndef CONFIG_ZTIMER_TIMER_BLOCK_PM_MODE +# ifdef CONFIG_ZTIMER_USEC_REQUIRED_PM_MODE +# define CONFIG_ZTIMER_TIMER_BLOCK_PM_MODE CONFIG_ZTIMER_USEC_REQUIRED_PM_MODE +# else +# define CONFIG_ZTIMER_TIMER_BLOCK_PM_MODE ZTIMER_CLOCK_NO_REQUIRED_PM_MODE +# endif #endif /** - * @brief The minimum pm mode required for ZTIMER_MSEC to run + * @brief The minimum pm mode required for ZTIMER_RTT to run */ -#ifndef CONFIG_ZTIMER_MSEC_REQUIRED_PM_MODE -#define CONFIG_ZTIMER_MSEC_REQUIRED_PM_MODE ZTIMER_CLOCK_NO_REQUIRED_PM_MODE +#ifndef CONFIG_ZTIMER_RTT_BLOCK_PM_MODE +# ifdef CONFIG_ZTIMER_MSEC_REQUIRED_PM_MODE +# define CONFIG_ZTIMER_RTT_BLOCK_PM_MODE CONFIG_ZTIMER_MSEC_REQUIRED_PM_MODE +# else +# define CONFIG_ZTIMER_RTT_BLOCK_PM_MODE ZTIMER_CLOCK_NO_REQUIRED_PM_MODE +# endif +#endif + +/** + * @brief The minimum pm mode required for ZTIMER_RTC to run + */ +#ifndef CONFIG_ZTIMER_RTC_BLOCK_PM_MODE +# ifdef CONFIG_ZTIMER_SEC_REQUIRED_PM_MODE +# define CONFIG_ZTIMER_RTC_BLOCK_PM_MODE CONFIG_ZTIMER_SEC_REQUIRED_PM_MODE +# else +# define CONFIG_ZTIMER_RTC_BLOCK_PM_MODE ZTIMER_CLOCK_NO_REQUIRED_PM_MODE +# endif #endif #ifdef __cplusplus diff --git a/sys/ztimer/auto_init.c b/sys/ztimer/auto_init.c index 8a36ec4fd7..ed1b8d8b28 100644 --- a/sys/ztimer/auto_init.c +++ b/sys/ztimer/auto_init.c @@ -36,6 +36,9 @@ * @} */ +#include "kernel_defines.h" +#if IS_USED(MODULE_AUTO_INIT_ZTIMER) + #include "board.h" #include "ztimer.h" #include "ztimer/convert_frac.h" @@ -55,103 +58,214 @@ #define FREQ_1KHZ 1000LU #define FREQ_1HZ 1LU -#if MODULE_ZTIMER_USEC -# if CONFIG_ZTIMER_USEC_TYPE_PERIPH_TIMER -static ztimer_periph_timer_t _ztimer_periph_timer_usec = { - .min = CONFIG_ZTIMER_USEC_MIN -}; +/* Step 0: define available ztimer-periphery by activated modules */ -ztimer_clock_t *const ZTIMER_USEC_BASE = &_ztimer_periph_timer_usec.super; -# if CONFIG_ZTIMER_USEC_BASE_FREQ == FREQ_1MHZ -ztimer_clock_t *const ZTIMER_USEC = &_ztimer_periph_timer_usec.super; -# elif CONFIG_ZTIMER_USEC_BASE_FREQ == 250000LU -static ztimer_convert_shift_t _ztimer_convert_shift_usec; -ztimer_clock_t *const ZTIMER_USEC = &_ztimer_convert_shift_usec.super.super; -# else -static ztimer_convert_frac_t _ztimer_convert_frac_usec; -ztimer_clock_t *const ZTIMER_USEC = &_ztimer_convert_frac_usec.super.super; -# endif -# else -# error ztimer_usec selected, but no configuration available! +/* #if CONFIG_ZTIMER_USEC_TYPE_PERIPH_TIMER + * replaces #if MODULE_ZTIMER_PERIPH_TIMER + * the ztimer_periph_timer is always available + * having an (1) config defined in ztimer/config.h + */ + +#if CONFIG_ZTIMER_USEC_TYPE_PERIPH_TIMER +# define ZTIMER_TIMER _ztimer_periph_timer +# define ZTIMER_TIMER_CLK _ztimer_periph_timer.super +# define ZTIMER_TIMER_FREQ CONFIG_ZTIMER_USEC_BASE_FREQ +#endif + +#if MODULE_ZTIMER_PERIPH_RTT +# define ZTIMER_RTT _ztimer_periph_timer_rtt +# define ZTIMER_RTT_CLK _ztimer_periph_timer_rtt +# define ZTIMER_RTT_FREQ RTT_FREQUENCY +#endif + +#if MODULE_ZTIMER_PERIPH_RTC +# define ZTIMER_RTC _ztimer_periph_timer_rtc +# define ZTIMER_RTC_CLK _ztimer_periph_timer_rtc +# define ZTIMER_RTC_FREQ FREQ_1HZ +#endif + +/* Step 1: select which periphery to use for the higher level ZTIMER_*SEC + * selected periphery is marked for initialisation (INIT_ZTIMER_ + * prepare defines for ztimer initialization + */ + +/* ZTIMER_USEC always uses the basic timer + * basic timer is available on all boards */ +#if MODULE_ZTIMER_USEC +# ifndef INIT_ZTIMER_TIMER +# define INIT_ZTIMER_TIMER 1 # endif #endif -/* use RTT for ZTIMER_MSEC, if used. Use RTT also for ZTIMER_USEC, - unless module ztimer_periph_rtc is explicitly used by application */ -#if MODULE_ZTIMER_PERIPH_RTT && (MODULE_ZTIMER_MSEC || (MODULE_ZTIMER_SEC && !MODULE_ZTIMER_PERIPH_RTC)) -static ztimer_periph_rtt_t _ztimer_periph_timer_rtt_msec_sec; -# define ZTIMER_RTT_INIT (&_ztimer_periph_timer_rtt_msec_sec) +/* ZTIMER_MSEC prefers ZTIMER_RTT (ztimer_periph_rtt) + * if it is available and runs at a frequency > 1kHz + * if not it falls back to use the basic timer */ +#if MODULE_ZTIMER_MSEC +# if defined(ZTIMER_RTT) && ZTIMER_RTT_FREQ >= FREQ_1KHZ +# define ZTIMER_MSEC_RTT 1 +# ifndef INIT_ZTIMER_RTT +# define INIT_ZTIMER_RTT 1 +# endif +# if ZTIMER_RTT_FREQ != FREQ_1KHZ +# define ZTIMER_MSEC_CONVERT_LOWER_FREQ ZTIMER_RTT_FREQ +# endif +# else +# define ZTIMER_MSEC_TIMER 1 +# ifndef INIT_ZTIMER_TIMER +# define INIT_ZTIMER_TIMER 1 +# endif +# define ZTIMER_MSEC_CONVERT_LOWER_FREQ ZTIMER_TIMER_FREQ +# endif +#endif + +/* ZTIMER_SEC prefers ZTIMER_RTT (ztimer_periph_rtt) if it is available + * if not it prefers ZTIMER_RTC (ztimer_periph_rtc) if it is available + * if not it falls back to use the basic timer */ +#if MODULE_ZTIMER_SEC +# ifdef ZTIMER_RTT +# define ZTIMER_SEC_RTT +# ifndef INIT_ZTIMER_RTT +# define INIT_ZTIMER_RTT 1 +# endif +# define ZTIMER_SEC_CONVERT_LOWER_FREQ ZTIMER_RTT_FREQ +# else +# ifdef ZTIMER_RTC +# define ZTIMER_SEC_RTC +# ifndef INIT_ZTIMER_RTC +# define INIT_ZTIMER_RTC 1 +# endif +# else +# define ZTIMER_SEC_TIMER +# ifndef INIT_ZTIMER_TIMER +# define INIT_ZTIMER_TIMER 1 +# endif +# define ZTIMER_SEC_CONVERT_LOWER_FREQ ZTIMER_TIMER_FREQ +# endif +# endif +#endif + +/* Step 2: setup static memory for used ztimer-periphery */ + +#if INIT_ZTIMER_TIMER +static ztimer_periph_timer_t ZTIMER_TIMER = { + .min = CONFIG_ZTIMER_USEC_MIN +}; +#endif + +#if INIT_ZTIMER_RTT +static ztimer_periph_rtt_t ZTIMER_RTT; +#endif + +#if INIT_ZTIMER_RTC +static ztimer_periph_rtc_t ZTIMER_RTC; +#endif + +/* Step 3: setup constants for ztimers and memory for converters */ + +#if MODULE_ZTIMER_USEC +# ifdef ZTIMER_TIMER +ztimer_clock_t *const ZTIMER_USEC_BASE = &ZTIMER_TIMER_CLK; +# else +# error No suitable ZTIMER_USEC config. Basic timer configuration missing? +# endif +# if ZTIMER_TIMER_FREQ == FREQ_1MHZ +ztimer_clock_t *const ZTIMER_USEC = &ZTIMER_TIMER_CLK; +# elif ZTIMER_TIMER_FREQ == 250000LU +static ztimer_convert_shift_t _ztimer_convert_shift_usec; +ztimer_clock_t *const ZTIMER_USEC = &_ztimer_convert_shift_usec.super.super; +# else +static ztimer_convert_frac_t _ztimer_convert_frac_usec; +ztimer_clock_t *const ZTIMER_USEC = &_ztimer_convert_frac_usec.super.super; +# endif #endif #if MODULE_ZTIMER_MSEC -# if MODULE_ZTIMER_PERIPH_RTT -ztimer_clock_t *const ZTIMER_MSEC_BASE = &_ztimer_periph_timer_rtt_msec_sec; -# if RTT_FREQUENCY != FREQ_1KHZ -static ztimer_convert_frac_t _ztimer_convert_frac_msec; -ztimer_clock_t *const ZTIMER_MSEC = &_ztimer_convert_frac_msec_sec.super.super; -# define ZTIMER_MSEC_CONVERT_LOWER_FREQ RTT_FREQUENCY -# define ZTIMER_MSEC_CONVERT_LOWER (&_ztimer_periph_timer_rtt_msec_sec) -# else -ztimer_clock_t *const ZTIMER_MSEC = &_ztimer_periph_timer_rtt_msec_sec; -# endif -# elif MODULE_ZTIMER_USEC +# ifdef ZTIMER_MSEC_RTT +ztimer_clock_t *const ZTIMER_MSEC_BASE = &ZTIMER_RTT_CLK; +# elif defined(ZTIMER_MSEC_TIMER) +ztimer_clock_t *const ZTIMER_MSEC_BASE = &ZTIMER_TIMER_CLK; +# else +# error No suitable ZTIMER_MSEC config. No rtt or basic timer? +# endif +# ifdef ZTIMER_MSEC_CONVERT_LOWER_FREQ static ztimer_convert_frac_t _ztimer_convert_frac_msec; ztimer_clock_t *const ZTIMER_MSEC = &_ztimer_convert_frac_msec.super.super; -ztimer_clock_t *const ZTIMER_MSEC_BASE = &_ztimer_periph_timer_usec.super; -# define ZTIMER_MSEC_CONVERT_LOWER ZTIMER_USEC_BASE -# define ZTIMER_MSEC_CONVERT_LOWER_FREQ CONFIG_ZTIMER_USEC_BASE_FREQ # else -# error No suitable ZTIMER_MSEC config. Maybe add USEMODULE += ztimer_usec? -# endif +ztimer_clock_t *const ZTIMER_MSEC = &ZTIMER_RTT_CLK; +# endif #endif #if MODULE_ZTIMER_SEC -# if MODULE_ZTIMER_PERIPH_RTC -static ztimer_periph_rtc_t _ztimer_periph_timer_rtc_sec; -ztimer_clock_t *const ZTIMER_SEC = &_ztimer_periph_timer_rtc_sec; -# elif MODULE_ZTIMER_PERIPH_RTT -static ztimer_convert_frac_t _ztimer_convert_frac_sec; -ztimer_clock_t *const ZTIMER_SEC = &_ztimer_convert_frac_sec.super.super; -ztimer_clock_t *const ZTIMER_SEC_BASE = &_ztimer_periph_timer_msec_sec.super; -# define ZTIMER_SEC_CONVERT_LOWER (&_ztimer_periph_timer_rtt_msec_sec) -# define ZTIMER_SEC_CONVERT_LOWER_FREQ RTT_FREQUENCY -# elif MODULE_ZTIMER_USEC -static ztimer_convert_frac_t _ztimer_convert_frac_sec; -ztimer_clock_t *const ZTIMER_SEC = &_ztimer_convert_frac_sec.super.super; -ztimer_clock_t *const ZTIMER_SEC_BASE = &_ztimer_periph_timer_usec.super; -# define ZTIMER_SEC_CONVERT_LOWER ZTIMER_USEC_BASE -# define ZTIMER_SEC_CONVERT_LOWER_FREQ CONFIG_ZTIMER_USEC_BASE_FREQ +# ifdef ZTIMER_SEC_RTC +ztimer_clock_t *const ZTIMER_SEC_BASE = &ZTIMER_RTC_CLK; +ztimer_clock_t *const ZTIMER_SEC = &ZTIMER_RTC_CLK; +# elif defined(ZTIMER_SEC_RTT) +ztimer_clock_t *const ZTIMER_SEC_BASE = &ZTIMER_RTT_CLK; +# elif defined(ZTIMER_SEC_TIMER) +ztimer_clock_t *const ZTIMER_SEC_BASE = &ZTIMER_TIMER_CLK; # else -# error No suitable ZTIMER_SEC config. Maybe add USEMODULE += ztimer_usec? +# error No suitable ZTIMER_SEC config. No rtc, rtt or basic timer? +# endif + +# ifdef ZTIMER_SEC_CONVERT_LOWER_FREQ +static ztimer_convert_frac_t _ztimer_convert_frac_sec; +ztimer_clock_t *const ZTIMER_SEC = &_ztimer_convert_frac_sec.super.super; # endif #endif void ztimer_init(void) { -#if MODULE_ZTIMER_USEC -# if CONFIG_ZTIMER_USEC_TYPE_PERIPH_TIMER +/* Step 4: initialize used ztimer-periphery */ +#if INIT_ZTIMER_TIMER LOG_DEBUG( - "ztimer_init(): ZTIMER_USEC using periph timer %u, freq %lu, width %u\n", + "ztimer_init(): ZTIMER_TIMER using periph timer %u, freq %lu, width %u\n", CONFIG_ZTIMER_USEC_DEV, CONFIG_ZTIMER_USEC_BASE_FREQ, CONFIG_ZTIMER_USEC_WIDTH); - - ztimer_periph_timer_init(&_ztimer_periph_timer_usec, CONFIG_ZTIMER_USEC_DEV, - CONFIG_ZTIMER_USEC_BASE_FREQ, - WIDTH_TO_MAXVAL(CONFIG_ZTIMER_USEC_WIDTH)); + ztimer_periph_timer_init(&ZTIMER_TIMER, CONFIG_ZTIMER_USEC_DEV, + ZTIMER_TIMER_FREQ, WIDTH_TO_MAXVAL(CONFIG_ZTIMER_USEC_WIDTH)); +# ifdef MODULE_PM_LAYERED + LOG_DEBUG("ztimer_init(): ZTIMER_TIMER setting required_pm_mode to %i\n", + CONFIG_ZTIMER_TIMER_BLOCK_PM_MODE); + ZTIMER_TIMER_CLK.required_pm_mode = CONFIG_ZTIMER_TIMER_BLOCK_PM_MODE; # endif -# if CONFIG_ZTIMER_USEC_BASE_FREQ != FREQ_1MHZ -# if CONFIG_ZTIMER_USEC_BASE_FREQ == FREQ_250KHZ +#endif + +#if INIT_ZTIMER_RTT + LOG_DEBUG("ztimer_init(): initializing rtt\n"); + ztimer_periph_rtt_init(&ZTIMER_RTT); +# ifdef MODULE_PM_LAYERED + LOG_DEBUG("ztimer_init(): ZTIMER_RTT setting required_pm_mode to %i\n", + CONFIG_ZTIMER_RTT_BLOCK_PM_MODE); + ZTIMER_RTT_CLK.required_pm_mode = CONFIG_ZTIMER_RTT_BLOCK_PM_MODE; +# endif +#endif + +#if INIT_ZTIMER_RTC + LOG_DEBUG("ztimer_init(): initializing rtc\n"); + ztimer_periph_rtc_init(&ZTIMER_RTC); +# ifdef MODULE_PM_LAYERED + LOG_DEBUG("ztimer_init(): ZTIMER_RTC setting required_pm_mode to %i\n", + CONFIG_ZTIMER_RTC_BLOCK_PM_MODE); + ZTIMER_RTC_CLK.required_pm_mode = CONFIG_ZTIMER_RTC_BLOCK_PM_MODE; +# endif +#endif + +/* Step 5: initialize ztimers requested */ +#if MODULE_ZTIMER_USEC +# if ZTIMER_TIMER_FREQ != FREQ_1MHZ +# if ZTIMER_TIMER_FREQ == FREQ_250KHZ LOG_DEBUG("ztimer_init(): ZTIMER_USEC convert_shift %lu to 1000000\n", - CONFIG_ZTIMER_USEC_BASE_FREQ); + ZTIMER_TIMER_FREQ); ztimer_convert_shift_up_init(&_ztimer_convert_shift_usec, - &_ztimer_periph_timer_usec.super, 2); + ZTIMER_USEC_BASE, 2); # else LOG_DEBUG("ztimer_init(): ZTIMER_USEC convert_frac %lu to 1000000\n", - CONFIG_ZTIMER_USEC_BASE_FREQ); - ztimer_convert_frac_init(&_ztimer_convert_frac_usec, - &_ztimer_periph_timer_usec.super, - FREQ_1MHZ, CONFIG_ZTIMER_USEC_BASE_FREQ); + ZTIMER_TIMER_FREQ); + ztimer_convert_frac_init(&_ztimer_convert_frac_usec, ZTIMER_USEC_BASE, + FREQ_1MHZ, ZTIMER_TIMER_FREQ); # endif +# else + LOG_DEBUG("ztimer_init(): ZTIMER_USEC without conversion\n"); # endif # ifdef CONFIG_ZTIMER_USEC_ADJUST_SET LOG_DEBUG("ztimer_init(): ZTIMER_USEC setting adjust_set value to %i\n", @@ -163,24 +277,13 @@ void ztimer_init(void) CONFIG_ZTIMER_USEC_ADJUST_SLEEP ); ZTIMER_USEC->adjust_sleep = CONFIG_ZTIMER_USEC_ADJUST_SLEEP; # endif -# ifdef MODULE_PM_LAYERED - LOG_DEBUG("ztimer_init(): ZTIMER_USEC setting required_pm_mode to %i\n", - CONFIG_ZTIMER_USEC_REQUIRED_PM_MODE); - ZTIMER_USEC->required_pm_mode = CONFIG_ZTIMER_USEC_REQUIRED_PM_MODE; -# endif -#endif - -#ifdef ZTIMER_RTT_INIT - LOG_DEBUG("ztimer_init(): initializing rtt\n"); - ztimer_periph_rtt_init(ZTIMER_RTT_INIT); #endif #if MODULE_ZTIMER_MSEC # if ZTIMER_MSEC_CONVERT_LOWER_FREQ LOG_DEBUG("ztimer_init(): ZTIMER_MSEC convert_frac from %lu to 1000\n", (long unsigned)ZTIMER_MSEC_CONVERT_LOWER_FREQ); - ztimer_convert_frac_init(&_ztimer_convert_frac_msec, - ZTIMER_MSEC_CONVERT_LOWER, + ztimer_convert_frac_init(&_ztimer_convert_frac_msec, ZTIMER_MSEC_BASE, FREQ_1KHZ, ZTIMER_MSEC_CONVERT_LOWER_FREQ); # endif # ifdef CONFIG_ZTIMER_MSEC_ADJUST @@ -188,23 +291,15 @@ void ztimer_init(void) CONFIG_ZTIMER_MSEC_ADJUST); ZTIMER_MSEC->adjust = CONFIG_ZTIMER_MSEC_ADJUST; # endif -# ifdef MODULE_PM_LAYERED - LOG_DEBUG("ztimer_init(): ZTIMER_MSEC setting required_pm_mode to %i\n", - CONFIG_ZTIMER_MSEC_REQUIRED_PM_MODE); - ZTIMER_MSEC->required_pm_mode = CONFIG_ZTIMER_MSEC_REQUIRED_PM_MODE; -# endif #endif #if MODULE_ZTIMER_SEC -# if MODULE_ZTIMER_PERIPH_RTC - LOG_DEBUG("ztimer_init(): initializing rtc\n"); - ztimer_periph_rtc_init(&_ztimer_periph_timer_rtc_sec); -# else - LOG_DEBUG("ztimer_init(): ZTIMER_SEC convert_frac from %lu to 1000\n", +# if ZTIMER_SEC_CONVERT_LOWER_FREQ + LOG_DEBUG("ztimer_init(): ZTIMER_SEC convert_frac from %lu to 1\n", (long unsigned)ZTIMER_SEC_CONVERT_LOWER_FREQ); - ztimer_convert_frac_init(&_ztimer_convert_frac_sec, - ZTIMER_SEC_CONVERT_LOWER, + ztimer_convert_frac_init(&_ztimer_convert_frac_sec, ZTIMER_SEC_BASE, FREQ_1HZ, ZTIMER_SEC_CONVERT_LOWER_FREQ); # endif #endif } +#endif /* IS_USED(MODULE_AUTO_INIT_ZTIMER) */ From c9e17196def8837f8fac404f433310ae9c608463 Mon Sep 17 00:00:00 2001 From: Karl Fessel Date: Mon, 29 Mar 2021 17:15:57 +0200 Subject: [PATCH 05/11] sys/ztimer: enhance periph selection documentation provide more information about the selection procedure to Doxygen --- sys/include/ztimer.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sys/include/ztimer.h b/sys/include/ztimer.h index 9e327a77cc..947d1819fc 100644 --- a/sys/include/ztimer.h +++ b/sys/include/ztimer.h @@ -182,12 +182,20 @@ * * For now, there are: * - * ZTIMER_USEC: clock providing microsecond ticks + * ZTIMER_USEC: clock providing microsecond ticks, always uses a basic timer + * (ztimer_periph_timer) * - * ZTIMER_MSEC: clock providing millisecond ticks, using a low power timer if - * available on the platform + * ZTIMER_MSEC: clock providing millisecond ticks, using a low power timer + * (ztimer_periph_rtt) if it is available on the platform + * and it running at 1kHz or above else it uses the same + * basic timer as ZTIMER_USEC does. * - * ZTIMER_SEC: clock providing second time, possibly using epoch semantics + * ZTIMER_SEC: clock providing second time, possibly using epoch semantics, + * it will use a low power timer (ztimer_periph_rtt) + * if it is available on the platform alternately it uses + * ztimer_periph_rtc if it is available and configured + * if if these are missing it will use same basic timer + * as ZTIMER_USEC does. * * These pointers are defined in `ztimer.h` and can be used like this: * From febfa5bc627a4fe0908a4448e8f56945591e73c5 Mon Sep 17 00:00:00 2001 From: Karl Fessel Date: Tue, 30 Mar 2021 13:55:13 +0200 Subject: [PATCH 06/11] tests/ztimer_xsec: add a simple high level ztimer test --- tests/ztimer_xsec/Makefile | 8 ++++ tests/ztimer_xsec/Makefile.ci | 11 +++++ tests/ztimer_xsec/README.md | 12 +++++ tests/ztimer_xsec/app.config.test | 7 +++ tests/ztimer_xsec/main.c | 77 +++++++++++++++++++++++++++++++ tests/ztimer_xsec/tests/01-run.py | 23 +++++++++ 6 files changed, 138 insertions(+) create mode 100644 tests/ztimer_xsec/Makefile create mode 100644 tests/ztimer_xsec/Makefile.ci create mode 100644 tests/ztimer_xsec/README.md create mode 100644 tests/ztimer_xsec/app.config.test create mode 100644 tests/ztimer_xsec/main.c create mode 100755 tests/ztimer_xsec/tests/01-run.py diff --git a/tests/ztimer_xsec/Makefile b/tests/ztimer_xsec/Makefile new file mode 100644 index 0000000000..baa0f6980e --- /dev/null +++ b/tests/ztimer_xsec/Makefile @@ -0,0 +1,8 @@ +include ../Makefile.tests_common + +USEMODULE += ztimer +USEMODULE += ztimer_usec +USEMODULE += ztimer_msec +USEMODULE += ztimer_sec + +include $(RIOTBASE)/Makefile.include diff --git a/tests/ztimer_xsec/Makefile.ci b/tests/ztimer_xsec/Makefile.ci new file mode 100644 index 0000000000..d220123487 --- /dev/null +++ b/tests/ztimer_xsec/Makefile.ci @@ -0,0 +1,11 @@ +BOARD_INSUFFICIENT_MEMORY := \ + arduino-duemilanove \ + arduino-leonardo \ + arduino-nano \ + arduino-uno \ + atmega328p \ + atmega328p-xplained-mini\ + nucleo-f031k6 \ + nucleo-l011k4 \ + stm32f030f4-demo \ + # diff --git a/tests/ztimer_xsec/README.md b/tests/ztimer_xsec/README.md new file mode 100644 index 0000000000..5887a0242d --- /dev/null +++ b/tests/ztimer_xsec/README.md @@ -0,0 +1,12 @@ +# Introduction + +This application tests the high abstraction level ztimer clocks usec, msec and sec +by locking three mutexes and waiting for them to +be unlocked by ZTIMER_USEC, ZTIMER_MSEC and ZTIMER_SEC +The tests succeeds if the board running the test does not get stuck. + +ZTIMER_MSEC and ZTIMER_SEC will be configured following the rules described +in the ztimer documentation (one may want to use extra ztimer_perih_*). +Timing information is provided for human analysis it is not checked by automatic +testing, since they are system and runtime dependent, there are other tests +that (partially) cover the accuracy of timers. diff --git a/tests/ztimer_xsec/app.config.test b/tests/ztimer_xsec/app.config.test new file mode 100644 index 0000000000..d39df143ba --- /dev/null +++ b/tests/ztimer_xsec/app.config.test @@ -0,0 +1,7 @@ +# this file enables modules defined in Kconfig. Do not use this file for +# application configuration. This is only needed during migration. +CONFIG_MODULE_ZTIMER=y +CONFIG_MODULE_ZTIMER_PERIPH_TIMER=y +CONFIG_MODULE_ZTIMER_USEC=y +CONFIG_MODULE_ZTIMER_MSEC=y +CONFIG_MODULE_ZTIMER_SEC=y diff --git a/tests/ztimer_xsec/main.c b/tests/ztimer_xsec/main.c new file mode 100644 index 0000000000..993edfa344 --- /dev/null +++ b/tests/ztimer_xsec/main.c @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2021 TUBA Freiberg + * + * 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 tests + * @{ + * + * @file + * @brief high level ztimer test application + * + * @author Karl Fessel + * + * + * @} + */ + +#include + +#include "ztimer.h" +#include "mutex.h" + +/* only header information is used we do not need to use MODULE_TIMEX */ +#include "timex.h" + +typedef struct named_lock { + char *name; + mutex_t mut; + uint32_t release_time; +} named_lock_t; + +void release(void *arg); + +static named_lock_t sec_lock = { .name = "SEC", .mut = MUTEX_INIT_LOCKED }; +static named_lock_t msec_lock = { .name = "MSEC", .mut = MUTEX_INIT_LOCKED }; +static named_lock_t usec_lock = { .name = "USEC", .mut = MUTEX_INIT_LOCKED }; + +static ztimer_t sec_tim = { .callback = release, .arg = &sec_lock }; +static ztimer_t msec_tim = { .callback = release, .arg = &msec_lock }; +static ztimer_t usec_tim = { .callback = release, .arg = &usec_lock }; + +void release(void *arg) +{ + named_lock_t *e = arg; + + e->release_time = (uint32_t)ztimer_now(ZTIMER_USEC); + puts(e->name); + mutex_unlock(&e->mut); +} + +int main(void) +{ + puts("starting ztimers"); + /* start a timer on each high level ztimer*/ + ztimer_set(ZTIMER_SEC, &sec_tim, 1); + ztimer_set(ZTIMER_MSEC, &msec_tim, 200); + ztimer_set(ZTIMER_USEC, &usec_tim, 100 * US_PER_MS); + + printf("time %s:\t%" PRIu32 "\n", "Wait", (uint32_t)ztimer_now(ZTIMER_USEC)); + + puts("waiting for locks"); + /* wait for mutexes */ + mutex_lock(&sec_lock.mut); + mutex_lock(&msec_lock.mut); + mutex_lock(&usec_lock.mut); + + printf("time %s:\t%" PRIu32 "\n", sec_lock.name, sec_lock.release_time); + printf("time %s:\t%" PRIu32 "\n", msec_lock.name, msec_lock.release_time); + printf("time %s:\t%" PRIu32 "\n", usec_lock.name, usec_lock.release_time); + + printf("SUCCESS!\n"); + return 0; +} diff --git a/tests/ztimer_xsec/tests/01-run.py b/tests/ztimer_xsec/tests/01-run.py new file mode 100755 index 0000000000..4d365cec82 --- /dev/null +++ b/tests/ztimer_xsec/tests/01-run.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2021 TUBA Freiberg +# +# 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. + +import sys +from testrunner import run + + +def testfunc(child): + child.expect_exact("starting ztimers") + child.expect_exact("waiting for locks") + child.expect_exact("USEC") + child.expect_exact("MSEC") + child.expect_exact("SEC") + child.expect_exact("SUCCESS!") + + +if __name__ == "__main__": + sys.exit(run(testfunc)) From 72213ec99a230f3e44e452f3b66ba341adf4b86d Mon Sep 17 00:00:00 2001 From: Karl Fessel Date: Wed, 31 Mar 2021 23:51:48 +0200 Subject: [PATCH 07/11] native/rtc: avoid dealing with DST --- cpu/native/periph/rtc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cpu/native/periph/rtc.c b/cpu/native/periph/rtc.c index 0b2835efcd..bc2960beab 100644 --- a/cpu/native/periph/rtc.c +++ b/cpu/native/periph/rtc.c @@ -154,6 +154,9 @@ int rtc_get_time(struct tm *ttime) } _native_syscall_leave(); + /* riot does not handle dst */ + ttime->tm_isdst=0; + return 0; } From 0b5709a853624bbe32273ce96bdae596ad17bac6 Mon Sep 17 00:00:00 2001 From: Karl Fessel Date: Thu, 1 Apr 2021 00:03:47 +0200 Subject: [PATCH 08/11] ztimer/periph_rtc: count months from 0 contrary to the western civilised world struct tm requires us to count months from 0 --- sys/ztimer/periph_rtc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sys/ztimer/periph_rtc.c b/sys/ztimer/periph_rtc.c index bab81b856f..68656ea7b2 100644 --- a/sys/ztimer/periph_rtc.c +++ b/sys/ztimer/periph_rtc.c @@ -35,6 +35,9 @@ static uint32_t _gmt_civil_to_timestamp(unsigned y, unsigned m, unsigned d, unsigned h, unsigned mi, unsigned s) { + /* struct tm counts months from 0 to 11 */ + m += 1; + if (m <= 2) { y -= 1; m += 12; @@ -71,6 +74,9 @@ void _timestamp_to_gmt_civil(struct tm *_tm, uint32_t epoch) .tm_hour = h, .tm_min = m, .tm_sec = s }; *_tm = tmp; } + + /* struct tm counts months starting from 0 */ + _tm->tm_mon -= 1; } static void _ztimer_periph_rtc_callback(void *arg) From 9e7f1d0097f9df51c90d27ef7b858e8e5cf079e0 Mon Sep 17 00:00:00 2001 From: Karl Fessel Date: Thu, 1 Apr 2021 12:01:05 +0200 Subject: [PATCH 09/11] sys/ztimer: add ZTIMER_SEC to Kconfig --- sys/ztimer/Kconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sys/ztimer/Kconfig b/sys/ztimer/Kconfig index 63d264dbe5..a533b912c5 100644 --- a/sys/ztimer/Kconfig +++ b/sys/ztimer/Kconfig @@ -44,6 +44,10 @@ config MODULE_ZTIMER_MSEC bool "Milliseconds" depends on MODULE_ZTIMER_PERIPH_TIMER || MODULE_ZTIMER_PERIPH_RTT +config MODULE_ZTIMER_SEC + bool "Seconds" + depends on MODULE_ZTIMER_PERIPH_TIMER || MODULE_ZTIMER_PERIPH_RTT || MODULE_ZTIMER_PERIPH_RTC + endmenu # Clocks From 15f2d0008abf9186f9796713a83af38b950f0527 Mon Sep 17 00:00:00 2001 From: Karl Fessel Date: Thu, 1 Apr 2021 15:21:17 +0200 Subject: [PATCH 10/11] native/rtc: ensure no struct tm extra information is used --- cpu/native/periph/rtc.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/cpu/native/periph/rtc.c b/cpu/native/periph/rtc.c index bc2960beab..30f84fdcba 100644 --- a/cpu/native/periph/rtc.c +++ b/cpu/native/periph/rtc.c @@ -53,6 +53,19 @@ static void _native_rtc_cb(void *arg) { _native_rtc_alarm_callback = NULL; } +/* RIOT does not expect DST or TZ information */ +static void _remove_struct_tm_extra( struct tm * t ){ + struct tm tmp = {.tm_year = t->tm_year, + .tm_mon = t->tm_mon, + .tm_mday = t->tm_mday, + .tm_hour = t->tm_hour, + .tm_min = t->tm_min, + .tm_sec = t->tm_sec, + .tm_wday = t->tm_wday + }; + *t = tmp; +} + void rtc_init(void) { DEBUG("rtc_init\n"); @@ -115,8 +128,14 @@ int rtc_set_time(struct tm *ttime) warnx("rtc_set_time: not powered on"); return -1; } + /* ensure there is no accidental extra information */ + struct tm itime = *ttime; + _remove_struct_tm_extra(&itime); + + /* mktime() and localtime are only inverse functions if tm_isdst == -1 */ + itime.tm_isdst = -1; + time_t tnew = mktime(&itime); - time_t tnew = mktime(ttime); if (tnew == -1) { warnx("rtc_set_time: out of time_t range"); return -1; @@ -154,8 +173,8 @@ int rtc_get_time(struct tm *ttime) } _native_syscall_leave(); - /* riot does not handle dst */ - ttime->tm_isdst=0; + /* RIOT does not handle DST or TZ information */ + _remove_struct_tm_extra(ttime); return 0; } @@ -174,7 +193,13 @@ int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg) struct tm now; rtc_get_time(&now); - time_t tdiff_secs = mktime(time) - mktime(&now); + /* ensure there is no accidental extra information */ + struct tm intime = *time; + _remove_struct_tm_extra(&intime); + + /* tm_idst are ignored for these mktime calls since + * both times carry the same (00) timezone information */ + time_t tdiff_secs = mktime(&intime) - mktime(&now); if (_native_rtc_alarm_callback) { xtimer_remove(&_native_rtc_timer); From 3f66735bde26c382f065d70fdd4c9c507fc8e10b Mon Sep 17 00:00:00 2001 From: Karl Fessel Date: Thu, 1 Apr 2021 15:24:52 +0200 Subject: [PATCH 11/11] ztimer/periph_rtc: intialize struct tm to avoid TZ and IDST problems { .elem = 0 } initializes the complete struct to 0 {} is not ISO C conform --- sys/ztimer/periph_rtc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sys/ztimer/periph_rtc.c b/sys/ztimer/periph_rtc.c index 68656ea7b2..7144706d1a 100644 --- a/sys/ztimer/periph_rtc.c +++ b/sys/ztimer/periph_rtc.c @@ -46,7 +46,7 @@ static uint32_t _gmt_civil_to_timestamp(unsigned y, unsigned m, unsigned d, 719561) * 86400 + 3600 * h + 60 * mi + s; } -void _timestamp_to_gmt_civil(struct tm *_tm, uint32_t epoch) +static void _timestamp_to_gmt_civil(struct tm *_tm, uint32_t epoch) { uint32_t s = epoch % 86400; @@ -88,7 +88,7 @@ static uint32_t _ztimer_periph_rtc_now(ztimer_clock_t *clock) { (void)clock; - struct tm time; + struct tm time = { .tm_year = 0 }; rtc_get_time(&time); @@ -110,7 +110,7 @@ static void _ztimer_periph_rtc_set(ztimer_clock_t *clock, uint32_t val) target = now + val; - struct tm _tm; + struct tm _tm = { .tm_year = 0 }; _timestamp_to_gmt_civil(&_tm, target); /* TODO: ensure this doesn't underflow */