From d0e8d3aa248ca36d97b685ac61585d58a4619819 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Mon, 6 Sep 2021 11:00:54 +0200 Subject: [PATCH] pkg/uwb-core: allow using event-thread --- pkg/uwb-core/Kconfig | 4 ++++ pkg/uwb-core/Makefile.dep | 4 ++++ pkg/uwb-core/contrib/uwb_core.c | 26 ++++++++++---------------- pkg/uwb-core/contrib/uwb_core_init.c | 2 -- pkg/uwb-core/include/uwb_core.h | 26 ++++++++++++++++++-------- 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/pkg/uwb-core/Kconfig b/pkg/uwb-core/Kconfig index 13d69aa280..92acdb1a58 100644 --- a/pkg/uwb-core/Kconfig +++ b/pkg/uwb-core/Kconfig @@ -74,6 +74,10 @@ config MODULE_UWB-CORE_UWBCFG bool "uwb-core configuration module" select MODULE_UWB-CORE_CONFIG +config MODULE_UWB-CORE_EVENT_THREAD + bool "Use event-thread loop as uwb-core's event loop" + select MODULE_UWB-CORE_CONFIG + config MODULE_UWB-CORE_CONFIG bool diff --git a/pkg/uwb-core/Makefile.dep b/pkg/uwb-core/Makefile.dep index fd59855a7a..589ce0fb53 100644 --- a/pkg/uwb-core/Makefile.dep +++ b/pkg/uwb-core/Makefile.dep @@ -30,6 +30,10 @@ ifneq (,$(filter uwb-core_dpl,$(USEMODULE))) endif endif +ifneq (,$(filter uwb-core_event_thread,$(USEMODULE))) + USEMODULE += event_thread +endif + # Some stdlib functions used by the pkg are not in avr-gcc FEATURES_BLACKLIST += arch_avr8 # uwb-core has specific compilation sources when compiling kernel diff --git a/pkg/uwb-core/contrib/uwb_core.c b/pkg/uwb-core/contrib/uwb_core.c index dfde98d1dc..c444da7541 100644 --- a/pkg/uwb-core/contrib/uwb_core.c +++ b/pkg/uwb-core/contrib/uwb_core.c @@ -19,43 +19,37 @@ #include "thread.h" #include "event.h" -#include "event/callback.h" #include "uwb_core.h" -#include "os/os_cputime.h" -#include "hal/hal_timer.h" - -#ifndef UWB_CORE_STACKSIZE -#define UWB_CORE_STACKSIZE (THREAD_STACKSIZE_LARGE) -#endif -#ifndef UWB_CORE_PRIO -#define UWB_CORE_PRIO (THREAD_PRIORITY_MAIN - 5) -#endif - -static char _stack_uwb_core[UWB_CORE_STACKSIZE]; - +#if !IS_USED(MODULE_UWB_CORE_EVENT_THREAD) static event_queue_t _queue; - +static char _stack_uwb_core[UWB_CORE_STACKSIZE]; static void *_uwb_core_thread(void *arg) { (void)arg; - event_queue_init(&_queue); event_loop(&_queue); /* never reached */ return NULL; } +#endif event_queue_t *uwb_core_get_eventq(void) { +#if !IS_USED(MODULE_UWB_CORE_EVENT_THREAD) return &_queue; +#else + return UWB_CORE_EVENT_THREAD_QUEUE; +#endif } void uwb_core_riot_init(void) { +#if !IS_USED(MODULE_UWB_CORE_EVENT_THREAD) thread_create(_stack_uwb_core, sizeof(_stack_uwb_core), UWB_CORE_PRIO, THREAD_CREATE_STACKTEST, _uwb_core_thread, NULL, - "uwb_core"); + "uwb_core_event"); +#endif } diff --git a/pkg/uwb-core/contrib/uwb_core_init.c b/pkg/uwb-core/contrib/uwb_core_init.c index d6b8ad0815..6581714b48 100644 --- a/pkg/uwb-core/contrib/uwb_core_init.c +++ b/pkg/uwb-core/contrib/uwb_core_init.c @@ -53,13 +53,11 @@ void uwb_core_init(void) extern void uwb_rng_pkg_init(void); uwb_rng_pkg_init(); #endif - /* uwb configuration module */ #if IS_USED(MODULE_UWB_CORE_UWBCFG) extern int uwbcfg_pkg_init(void); uwbcfg_pkg_init(); #endif - /* ranging algorithms */ #if IS_USED(MODULE_UWB_CORE_TWR_SS) twr_ss_pkg_init(); diff --git a/pkg/uwb-core/include/uwb_core.h b/pkg/uwb-core/include/uwb_core.h index 19550aab9e..e286de5c20 100644 --- a/pkg/uwb-core/include/uwb_core.h +++ b/pkg/uwb-core/include/uwb_core.h @@ -21,23 +21,33 @@ #include #include "event.h" +#if IS_USED(MODULE_UWB_CORE_EVENT_THREAD) +#include "event/thread" +#endif #ifdef __cplusplus extern "C" { #endif /** - * @brief Priority used for + * @brief The event queue if uwb_core_event_thread is used */ -#ifndef UWB_CORE__PRIO -#define UWB_CORE__PRIO (THREAD_PRIORITY_MAIN - 2) +#ifndef UWB_CORE_EVENT_THREAD_QUEUE +#define UWB_CORE_EVENT_THREAD_QUEUE EVENT_PRIO_MEDIUM #endif /** - * @brief Stacksize used for + * @brief Priority used for uwb-core event queue */ -#ifndef UWB_CORE__STACKSIZE -#define UWB_CORE__STACKSIZE (THREAD_STACKSIZE_DEFAULT) +#ifndef UWB_CORE_PRIO +#define UWB_CORE_PRIO (THREAD_PRIORITY_MAIN - 2) +#endif + +/** + * @brief Stacksize used for uwb-core event queue + */ +#ifndef UWB_CORE_STACKSIZE +#define UWB_CORE_STACKSIZE (THREAD_STACKSIZE_LARGE) #endif /** @@ -48,8 +58,8 @@ void uwb_core_riot_init(void); /** * @brief Retrieves the default event queue. * - * As there is no default event queue in RIOT, uwb-core will start and - * handle a default event queue. + * if uwb_core_event_thread is used then the event_thread module queue will be + * used. Otherwise uwb-core will start and handle its own event queue. * * @return the default event queue. */