From cbde66f61049e1753a027665beabeb693ec3aae3 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Fri, 17 Mar 2023 12:04:44 +0100 Subject: [PATCH 1/7] sys/trickle: Remove xtimer and only use ztimer --- sys/Makefile.dep | 7 +------ sys/include/trickle.h | 9 --------- sys/trickle/trickle.c | 11 +---------- 3 files changed, 2 insertions(+), 25 deletions(-) diff --git a/sys/Makefile.dep b/sys/Makefile.dep index 896156eb99f0..28a256232cfb 100644 --- a/sys/Makefile.dep +++ b/sys/Makefile.dep @@ -225,12 +225,7 @@ endif ifneq (,$(filter trickle,$(USEMODULE))) USEMODULE += random - ifeq (,$(filter ztimer_msec,$(USEMODULE))) - USEMODULE += xtimer - ifneq (,$(filter ztimer_xtimer_compat,$(USEMODULE))) - USEMODULE += ztimer_msec - endif - endif + USEMODULE += ztimer_msec endif ifneq (,$(filter eui_provider,$(USEMODULE))) diff --git a/sys/include/trickle.h b/sys/include/trickle.h index 95cf2208724e..d001a9c9e7d5 100644 --- a/sys/include/trickle.h +++ b/sys/include/trickle.h @@ -33,11 +33,7 @@ #endif #include "thread.h" -#if IS_USED(MODULE_ZTIMER_MSEC) #include "ztimer.h" -#else -#include "xtimer.h" -#endif /** * @brief Trickle callback function with arguments @@ -63,13 +59,8 @@ typedef struct { trickle_callback_t callback; /**< callback function and parameter that trickle calls after each interval */ msg_t msg; /**< the msg_t to use for intervals */ -#if IS_USED(MODULE_ZTIMER_MSEC) ztimer_t msg_timer; /**< timer to send a msg_t to the target thread for a new interval */ -#else - xtimer_t msg_timer; /**< xtimer to send a msg_t to the target - thread for a new interval */ -#endif } trickle_t; /** diff --git a/sys/trickle/trickle.c b/sys/trickle/trickle.c index ab37140d10cb..c6ff5cf15c80 100644 --- a/sys/trickle/trickle.c +++ b/sys/trickle/trickle.c @@ -19,6 +19,7 @@ #include "inttypes.h" #include "random.h" #include "trickle.h" +#include "ztimer.h" #define ENABLE_DEBUG 0 #include "debug.h" @@ -53,14 +54,8 @@ void trickle_interval(trickle_t *trickle) /* old_interval == trickle->I / 2 */ trickle->t = random_uint32_range(old_interval, trickle->I); -#if IS_USED(MODULE_ZTIMER_MSEC) ztimer_set_msg(ZTIMER_MSEC, &trickle->msg_timer, (trickle->t + diff), &trickle->msg, trickle->pid); -#else - uint64_t msg_time = (trickle->t + diff) * US_PER_MS; - xtimer_set_msg64(&trickle->msg_timer, msg_time, &trickle->msg, - trickle->pid); -#endif } void trickle_reset_timer(trickle_t *trickle) @@ -93,11 +88,7 @@ void trickle_start(kernel_pid_t pid, trickle_t *trickle, uint16_t msg_type, void trickle_stop(trickle_t *trickle) { -#if IS_USED(MODULE_ZTIMER_MSEC) ztimer_remove(ZTIMER_MSEC, &trickle->msg_timer); -#else - xtimer_remove(&trickle->msg_timer); -#endif } void trickle_increment_counter(trickle_t *trickle) From c309f21e977fb522d06819c37f75ab7682d159c2 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Fri, 17 Mar 2023 12:09:01 +0100 Subject: [PATCH 2/7] sys/trickle: Model kconfig --- sys/Kconfig | 1 + sys/trickle/Kconfig | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 sys/trickle/Kconfig diff --git a/sys/Kconfig b/sys/Kconfig index 2de4c83e50b9..5f986c5c4bdc 100644 --- a/sys/Kconfig +++ b/sys/Kconfig @@ -101,6 +101,7 @@ rsource "test_utils/Kconfig" rsource "timex/Kconfig" rsource "tiny_strerror/Kconfig" rsource "trace/Kconfig" +rsource "trickle/Kconfig" rsource "tsrb/Kconfig" rsource "uri_parser/Kconfig" rsource "usb/Kconfig" diff --git a/sys/trickle/Kconfig b/sys/trickle/Kconfig new file mode 100644 index 000000000000..cd0ad475a863 --- /dev/null +++ b/sys/trickle/Kconfig @@ -0,0 +1,12 @@ +# Copyright (c) 2023 HAW Hamburg +# +# 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. +# + +config MODULE_TRICKLE + bool "Trickle Algorithm (RFC 6206)" + depends on TEST_KCONFIG + select ZTIMER_MSEC + select MODULE_RANDOM From 3e3dc7698acdce88f52b843223f184f86ba14218 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Fri, 17 Mar 2023 12:11:52 +0100 Subject: [PATCH 3/7] tests/trickle: Remove xtimer and use ztimer --- tests/trickle/Makefile | 1 + tests/trickle/main.c | 10 +--------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/tests/trickle/Makefile b/tests/trickle/Makefile index da98e5784e3f..bf78a682582e 100644 --- a/tests/trickle/Makefile +++ b/tests/trickle/Makefile @@ -1,6 +1,7 @@ include ../Makefile.tests_common USEMODULE += trickle +USEMODULE += ztimer_msec # microbit qemu lacks rtt TEST_ON_CI_BLACKLIST += microbit diff --git a/tests/trickle/main.c b/tests/trickle/main.c index d5a246d79446..af4f06220598 100644 --- a/tests/trickle/main.c +++ b/tests/trickle/main.c @@ -23,11 +23,8 @@ #include "trickle.h" #include "thread.h" #include "msg.h" -#if IS_USED(MODULE_ZTIMER_MSEC) #include "ztimer.h" -#else -#include "xtimer.h" -#endif + #define TRICKLE_MSG (0xfeef) #define TR_IMIN (8) @@ -50,12 +47,7 @@ static trickle_t trickle = { .callback = { .func = &callback, static void callback(void *args) { (void) args; -#if IS_USED(MODULE_ZTIMER_MSEC) uint32_t now = ztimer_now(ZTIMER_MSEC); -#else - uint32_t now = xtimer_now_usec(); -#endif - printf("now = %" PRIu32 ", t = %" PRIu32 "\n", now, trickle.t); /* previous `t` is chosen from a smaller interval [I/2, I). From bdd8819e7f42fbde700b37c69a29610106ab6a66 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Fri, 17 Mar 2023 12:15:45 +0100 Subject: [PATCH 4/7] tests/trickle: Model kconfig --- tests/trickle/app.config.test | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/trickle/app.config.test diff --git a/tests/trickle/app.config.test b/tests/trickle/app.config.test new file mode 100644 index 000000000000..6ef900d1d026 --- /dev/null +++ b/tests/trickle/app.config.test @@ -0,0 +1,3 @@ +CONFIG_MODULE_TRICKLE=y +CONFIG_MODULE_ZTIMER=y +CONFIG_MODULE_ZTIMER_MSEC=y From 664b209e7aa2281273edf967979c6f61095e5b3d Mon Sep 17 00:00:00 2001 From: chrysn Date: Fri, 17 Mar 2023 13:02:20 +0100 Subject: [PATCH 5/7] cpu/efm32: pwm_init errors are zeros --- cpu/efm32/periph/pwm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpu/efm32/periph/pwm.c b/cpu/efm32/periph/pwm.c index f8c2f2432e26..ea940a3b5a5b 100644 --- a/cpu/efm32/periph/pwm.c +++ b/cpu/efm32/periph/pwm.c @@ -33,7 +33,7 @@ uint32_t pwm_init(pwm_t dev, pwm_mode_t mode, uint32_t freq, uint16_t res) { /* check if device is valid */ if (dev >= PWM_NUMOF) { - return -1; + return 0; } /* enable clocks */ @@ -46,7 +46,7 @@ uint32_t pwm_init(pwm_t dev, pwm_mode_t mode, uint32_t freq, uint16_t res) freq_timer); if (prescaler > timerPrescale1024) { - return -2; + return 0; } /* reset and initialize peripheral */ From 6c8d1ebc9805fb8b8cf9f0845ce975282b4d3b69 Mon Sep 17 00:00:00 2001 From: chrysn Date: Fri, 17 Mar 2023 13:09:57 +0100 Subject: [PATCH 6/7] tests/periph_pwm: wording fix, s/initiate/initialize/ --- tests/periph_pwm/main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/periph_pwm/main.c b/tests/periph_pwm/main.c index a615eaba0268..092e136da0c1 100644 --- a/tests/periph_pwm/main.c +++ b/tests/periph_pwm/main.c @@ -42,7 +42,7 @@ #define OSC_STEPS (256U) #define PWR_SLEEP (1U) -static uint32_t initiated; +static uint32_t initialized; static unsigned _get_dev(const char *dev_str) { @@ -94,11 +94,11 @@ static int _init(int argc, char** argv) (uint16_t)atoi(argv[4])); if (pwm_freq != 0) { printf("The pwm frequency is set to %" PRIu32 "\n", pwm_freq); - initiated |= (1 << dev); + initialized |= (1 << dev); return 0; } - puts("Error: device is not initiated"); + puts("Error: device is not initialized"); return 1; } @@ -117,8 +117,8 @@ static int _set(int argc, char**argv) return 1; } - if ((initiated & (1 << dev)) == 0) { - puts("Error: pwm is not initiated.\n"); + if ((initialized & (1 << dev)) == 0) { + puts("Error: pwm is not initialized.\n"); puts("Execute init function first.\n"); return 1; } @@ -245,7 +245,7 @@ static const shell_command_t shell_commands[] = { int main(void) { puts("PWM peripheral driver test\n"); - initiated = 0; + initialized = 0; char line_buf[SHELL_DEFAULT_BUFSIZE]; shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE); From 72107a08735324222ba6ab1296539605de8db33f Mon Sep 17 00:00:00 2001 From: Jan Mohr Date: Fri, 17 Mar 2023 10:05:23 +0100 Subject: [PATCH 7/7] sys/net/gnrc/netif: fixing no global address wait --- sys/net/gnrc/netif/gnrc_netif.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/sys/net/gnrc/netif/gnrc_netif.c b/sys/net/gnrc/netif/gnrc_netif.c index 51639946ce56..d92b522a7ad9 100644 --- a/sys/net/gnrc/netif/gnrc_netif.c +++ b/sys/net/gnrc/netif/gnrc_netif.c @@ -1372,6 +1372,15 @@ static void _netif_bus_detach(gnrc_netif_t *netif, msg_bus_entry_t *sub) msg_bus_detach(bus, sub); } +static void _netif_bus_msg_global(gnrc_netif_t *netif, msg_t* m, bool *has_global) +{ + msg_bus_t* bus = gnrc_netif_get_bus(netif, GNRC_NETIF_BUS_IPV6); + if (msg_is_from_bus(bus, m) && ipv6_addr_is_global(m->content.ptr)) { + DEBUG_PUTS("gnrc_netif: got global address"); + *has_global = true; + } +} + bool gnrc_netif_ipv6_wait_for_global_address(gnrc_netif_t *netif, uint32_t timeout_ms) { @@ -1385,7 +1394,7 @@ bool gnrc_netif_ipv6_wait_for_global_address(gnrc_netif_t *netif, msg_bus_entry_t subs[netif_numof]; bool has_global = false; - if (netif) { + if (netif != NULL) { if (_has_global_addr(netif)) { return true; } @@ -1406,17 +1415,27 @@ bool gnrc_netif_ipv6_wait_for_global_address(gnrc_netif_t *netif, /* wait for global address */ msg_t m; + ztimer_now_t t_stop = ztimer_now(ZTIMER_MSEC) + timeout_ms; while (!has_global) { + /* stop if timeout reached */ + if (ztimer_now(ZTIMER_MSEC) > t_stop) { + DEBUG_PUTS("gnrc_netif: timeout reached"); + break; + } + /* waiting for any message */ if (ztimer_msg_receive_timeout(ZTIMER_MSEC, &m, timeout_ms) < 0) { DEBUG_PUTS("gnrc_netif: timeout waiting for prefix"); break; } - if (ipv6_addr_is_link_local(m.content.ptr)) { - DEBUG_PUTS("gnrc_netif: got link-local address"); + if (netif != NULL) { + _netif_bus_msg_global(netif, &m, &has_global); } else { - DEBUG_PUTS("gnrc_netif: got global address"); - has_global = true; + /* scan all interfaces */ + gnrc_netif_t *_netif = NULL; + while ((_netif = gnrc_netif_iter(_netif))) { + _netif_bus_msg_global(_netif, &m, &has_global); + } } } @@ -1738,7 +1757,7 @@ static void _send_queued_pkt(gnrc_netif_t *netif) } static void _tx_done(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt, - gnrc_pktsnip_t *tx_sync , int res, bool push_back) + gnrc_pktsnip_t *tx_sync, int res, bool push_back) { (void)push_back; /* only used with IS_USED(MODULE_GNRC_NETIF_PKTQ) */