diff --git a/examples/twr_aloha/Makefile b/examples/twr_aloha/Makefile index 9a03b53c5f..88f6a82a0f 100644 --- a/examples/twr_aloha/Makefile +++ b/examples/twr_aloha/Makefile @@ -28,6 +28,7 @@ USEMODULE += uwb-core_twr_ds_ext USEMODULE += shell USEMODULE += shell_commands USEMODULE += ps +USEMODULE += ztimer_usec # Set the device role: 0x0 for tag, 0x4 for an anchor DW1000_ROLE ?= 0x00 diff --git a/examples/twr_aloha/control.c b/examples/twr_aloha/control.c index 492584cbb6..c0cba17926 100644 --- a/examples/twr_aloha/control.c +++ b/examples/twr_aloha/control.c @@ -29,7 +29,6 @@ #include "shell_commands.h" #include "shell.h" -#include "xtimer.h" static struct dpl_callout _rng_req_callout; static uint8_t _ranging_enabled_flag; @@ -46,7 +45,7 @@ static int _range_cli_cmd(int argc, char **argv) if (!strcmp(argv[1], "start")) { printf("Start ranging\n"); - dpl_callout_reset(&_rng_req_callout, RANGE_REQUEST_T_US); + dpl_callout_reset(&_rng_req_callout, RANGE_REQUEST_T_MS); _ranging_enabled_flag = 1; } else if (!strcmp(argv[1], "stop")) { @@ -150,12 +149,12 @@ static void _slot_complete_cb(struct dpl_event *ev) } /** - * @brief An event callback to send range request every RANGE_REQUEST_T_US. + * @brief An event callback to send range request every RANGE_REQUEST_T_MS. * On every request it will switch the used ranging algorithm. */ static void uwb_ev_cb(struct dpl_event *ev) { - struct uwb_rng_instance *rng = (struct uwb_rng_instance *)ev->arg; + struct uwb_rng_instance *rng = (struct uwb_rng_instance *)ev->ev.arg; struct uwb_dev *inst = rng->dev_inst; if (inst->role & UWB_ROLE_ANCHOR) { @@ -195,7 +194,7 @@ static void uwb_ev_cb(struct dpl_event *ev) /* reset the callback if ranging is enabled */ if (_ranging_enabled_flag) { - dpl_callout_reset(&_rng_req_callout, RANGE_REQUEST_T_US); + dpl_callout_reset(&_rng_req_callout, RANGE_REQUEST_T_MS); } } @@ -211,7 +210,7 @@ void init_ranging(void) _uwb_mac_cbs.inst_ptr = rng; uwb_mac_append_interface(udev, &_uwb_mac_cbs); - uint32_t utime = xtimer_now_usec(); + uint32_t utime = ztimer_now(ZTIMER_USEC); printf("{\"utime\": %" PRIu32 ",\"exec\": \"%s\"}\n", utime, __FILE__); printf("{\"device_id\"=\"%" PRIx32 "\"", udev->device_id); @@ -235,7 +234,7 @@ void init_ranging(void) dpl_callout_init(&_rng_req_callout, dpl_eventq_dflt_get(), uwb_ev_cb, rng); - dpl_callout_reset(&_rng_req_callout, RANGE_REQUEST_T_US); + dpl_callout_reset(&_rng_req_callout, RANGE_REQUEST_T_MS); dpl_event_init(&_slot_event, _slot_complete_cb, rng); /* Apply config */ diff --git a/examples/twr_aloha/control.h b/examples/twr_aloha/control.h index 2c3e467d91..1d5557b4a3 100644 --- a/examples/twr_aloha/control.h +++ b/examples/twr_aloha/control.h @@ -37,8 +37,8 @@ extern "C" { /** * @brief Range request period */ -#ifndef RANGE_REQUEST_T_US -#define RANGE_REQUEST_T_US (40 * US_PER_MS) +#ifndef RANGE_REQUEST_T_MS +#define RANGE_REQUEST_T_MS (40) #endif /** diff --git a/pkg/mynewt-core/Makefile b/pkg/mynewt-core/Makefile new file mode 100644 index 0000000000..f45bcb2425 --- /dev/null +++ b/pkg/mynewt-core/Makefile @@ -0,0 +1,46 @@ +PKG_NAME=mynewt-core +PKG_URL=https://github.com/apache/mynewt-core.git +PKG_VERSION=de203365f207dda658657a7525253e02f68503a1 +PKG_LICENSE=Apache-2.0 + +include $(RIOTBASE)/pkg/pkg.mk + +CFLAGS += -Wno-unused-parameter +CFLAGS += -Wno-unused-but-set-variable +CFLAGS += -Wno-sign-compare + +MYNEWT_CORE_MODULES := mynewt-core_os \ + mynewt-core_util \ + mynewt-core_nrf5x_hal \ + # + +MYNEWT_CORE_PATH_util = util/mem/src +MYNEWT_CORE_PATH_os = kernel/os/src + +ifneq (,$(filter nrf52,$(CPU))) + MYNEWT_CORE_PATH_nrf5x_hal = hw/mcu/nordic/nrf52xxx/src/ +endif +ifneq (,$(filter nrf51,$(CPU))) + MYNEWT_CORE_PATH_nrf5x_hal = hw/mcu/nordic/nrf51xxx/src/ +endif + +.PHONY: rm_riot_provided_headers + +all: $(filter $(MYNEWT_CORE_MODULES),$(USEMODULE)) + @true + +mynewt-core_%: rm_riot_provided_headers + "$(MAKE)" -C $(PKG_SOURCE_DIR)/$(MYNEWT_CORE_PATH_$*) -f $(RIOTPKG)/$(PKG_NAME)/$@.mk MODULE=$@ + +# The following mynewt-core headers are provided by RIOT, remove them from +# mynewt-core include paths to avoid header conflicts +MYNEWT_CORE_HAL_HEADERS = hal_gpio.h hal_spi.h +MYNEWT_CORE_OS_HEADERS = os.h mynewt.h os_dev.h os_eventq.h os_time.h +MYNEWT_CORE_HAL_HEADERS_PATH = hw/hal/include/hal +MYNEWT_CORE_OS_HEADERS_PATH = kernel/os/include/os/os_time + +rm_riot_provided_headers: + $(Q)for i in $(MYNEWT_CORE_OS_HEADERS); \ + do rm -f "$(PKG_SOURCE_DIR)/$(MYNEWT_CORE_OS_HEADERS_PATH)/$$i"; done + $(Q)for i in $(MYNEWT_CORE_HAL_HEADERS); \ + do rm -f "$(PKG_SOURCE_DIR)/$(MYNEWT_CORE_HAL_HEADERS_PATH)/$$i"; done diff --git a/pkg/mynewt-core/Makefile.dep b/pkg/mynewt-core/Makefile.dep new file mode 100644 index 0000000000..31480b59b3 --- /dev/null +++ b/pkg/mynewt-core/Makefile.dep @@ -0,0 +1,17 @@ +USEMODULE += event_callback +USEMODULE += sema +USEMODULE += ztimer +USEMODULE += ztimer_msec + +USEMODULE += mynewt-core + +DEFAULT_MODULE += auto_init_mynewt-core + +# MyNewt `os_hw_is_in_critical` function needs to know whether ISR are masked +# of if the function is being called in ISR context. There is no such function +# in RIOT except for arm (__get_PRIMASK), therefore unless a similar function +# is provided for other arch, this port is currently only enabled for those arch. +# Note: that this should not be a hindrance since nimble only works on nordic +# and uwb-core breakouts are all arm. +FEATURES_REQUIRED += arch_arm +FEATURES_BLACKLIST += arch_arm7 diff --git a/pkg/mynewt-core/Makefile.include b/pkg/mynewt-core/Makefile.include new file mode 100644 index 0000000000..3defd3ce4c --- /dev/null +++ b/pkg/mynewt-core/Makefile.include @@ -0,0 +1,16 @@ +INCLUDES += -I$(RIOTPKG)/mynewt-core/include \ + -I$(PKGDIRBASE)/mynewt-core/kernel/os/include \ + -I$(PKGDIRBASE)/mynewt-core/hw/hal/include \ + -I$(PKGDIRBASE)/mynewt-core/util/mem/include \ + -I$(PKGDIRBASE)/mynewt-core/sys/stats/stub/include \ + # + +DIRS += $(RIOTPKG)/mynewt-core/contrib \ + # + +ifneq (,$(filter nrf5%,$(CPU))) + # OS_CPUTIME is set to 32.767 Hz + CFLAGS += -DMYNEWT_VAL_OS_CPUTIME_FREQ=32768 +else + CFLAGS += -DMYNEWT_VAL_OS_CPUTIME_FREQ=CONFIG_ZTIMER_MSEC_BASE_FREQ +endif diff --git a/pkg/mynewt-core/contrib/Makefile b/pkg/mynewt-core/contrib/Makefile new file mode 100644 index 0000000000..0bb65a903f --- /dev/null +++ b/pkg/mynewt-core/contrib/Makefile @@ -0,0 +1,12 @@ +MODULE = mynewt-core + +# exclude submodule sources from *.c wildcard source selection +SRC := $(filter-out nrf5x_isr.c cputime.c,$(wildcard *.c)) + +ifneq (,$(filter nrf%,$(CPU))) + SRC += nrf5x_isr.c +else + SRC += cputime.c +endif + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/mynewt-core/contrib/callout.c b/pkg/mynewt-core/contrib/callout.c new file mode 100644 index 0000000000..c6d9414edb --- /dev/null +++ b/pkg/mynewt-core/contrib/callout.c @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2020 Inria + * + * 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 pkg_mynewt_core + * @{ + * + * @file + * @brief mynewt-core callout + * + * @author Francisco Molina + * @} + */ + +#include + +#include "ztimer.h" +#include "os/os.h" +#include "os/os_callout.h" + +static void _os_callout_timer_cb(void* arg) +{ + struct os_callout *c = (struct os_callout *) arg; + assert(c); + + /* post the event if there is a queue, otherwise call the callback + here */ + if (c->c_evq) { + os_eventq_put(c->c_evq, &c->c_ev); + } else { + c->c_ev.e.callback(&c->c_ev); + } +} + +void os_callout_init(struct os_callout *c, struct os_eventq *q, + os_event_fn *e_cb, void *e_arg) +{ + os_event_init(&c->c_ev, e_cb, e_arg); + c->c_evq = q; + c->timer.callback = _os_callout_timer_cb; + c->timer.arg = (void*) c; +} + +int os_callout_reset(struct os_callout *c, os_time_t ticks) +{ + ztimer_set(ZTIMER_MSEC, &c->timer, ticks); + return OS_OK; +} + +void os_callout_stop(struct os_callout *c) +{ + ztimer_remove(ZTIMER_MSEC, &(c->timer)); +} diff --git a/pkg/mynewt-core/contrib/core.c b/pkg/mynewt-core/contrib/core.c new file mode 100644 index 0000000000..9dc9e11ada --- /dev/null +++ b/pkg/mynewt-core/contrib/core.c @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2021 Inria + * + * 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 pkg_mynewt_core + * @{ + * + * @file + * @brief mynewt-core bootstrapping functions + * + * @author Francisco Molina + * @} + */ + +#include + +#include "os/os_cputime.h" +#include "hal/hal_timer.h" + +void mynewt_core_init(void) +{ +#if (MYNEWT_VAL_OS_CPUTIME_TIMER_NUM >= 0) && (defined(CPU_NRF51) || defined(CPU_NRF52)) + int rc = hal_timer_init(5, NULL); + assert(rc == 0); + rc = os_cputime_init(MYNEWT_VAL_OS_CPUTIME_FREQ); + assert(rc == 0); + (void) rc; +#endif +} diff --git a/pkg/mynewt-core/contrib/cputime.c b/pkg/mynewt-core/contrib/cputime.c new file mode 100644 index 0000000000..52382936ba --- /dev/null +++ b/pkg/mynewt-core/contrib/cputime.c @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2020 Inria + * + * 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 pkg_mynewt_core + * @{ + * + * @file + * @brief cputime implementation for non nrf5x BOARDs + * + * @author Francisco Molina + * @} + */ + +#include "os/os_cputime.h" +#include "ztimer.h" +#include "hal/hal_timer.h" + +uint32_t os_cputime_get32(void) +{ + return ztimer_now(ZTIMER_MSEC_BASE); +} + +void os_cputime_delay_ticks(uint32_t ticks) +{ + ztimer_sleep(ZTIMER_MSEC_BASE, ticks); +} + +void os_cputime_delay_usecs(uint32_t usecs) +{ + ztimer_sleep(ZTIMER_MSEC_BASE, os_cputime_usecs_to_ticks(usecs)); +} + +int os_cputime_init(uint32_t clock_freq) +{ + (void)clock_freq; + return 0; +} + +void os_cputime_timer_init(struct hal_timer *timer, hal_timer_cb fp, + void *arg) +{ + timer->timer.callback = fp; + timer->timer.arg = arg; +} + +int os_cputime_timer_start(struct hal_timer *timer, uint32_t cputime) +{ + uint32_t now = ztimer_now(ZTIMER_MSEC_BASE); + + /* taken from mynewt-core 'hal_timer' implementations, this will + only work with timeouts at most 2**32-1 away, so it will have the same + limitations as their implementation does */ + if ((int32_t)(cputime - now) <= 0) { + ztimer_set(ZTIMER_MSEC_BASE, &timer->timer, 0); + } + else { + ztimer_set(ZTIMER_MSEC_BASE, &timer->timer, cputime - now); + } + return 0; +} + +int os_cputime_timer_relative(struct hal_timer *timer, uint32_t usecs) +{ + ztimer_set(ZTIMER_MSEC_BASE, &timer->timer, os_cputime_usecs_to_ticks(usecs)); + return 0; +} + +void os_cputime_timer_stop(struct hal_timer *timer) +{ + ztimer_remove(ZTIMER_MSEC_BASE, &timer->timer); +} diff --git a/pkg/uwb-core/dpl/dpl_mutex.c b/pkg/mynewt-core/contrib/mutex.c similarity index 62% rename from pkg/uwb-core/dpl/dpl_mutex.c rename to pkg/mynewt-core/contrib/mutex.c index 40a4ec9542..a8f8b684d1 100644 --- a/pkg/uwb-core/dpl/dpl_mutex.c +++ b/pkg/mynewt-core/contrib/mutex.c @@ -7,7 +7,7 @@ */ /** - * @ingroup pkg_uwb_core + * @ingroup pkg_mynewt_core * @{ * * @file @@ -17,34 +17,33 @@ * @} */ -#include "mutex.h" -#include "dpl/dpl_mutex.h" +#include "os/os_mutex.h" -dpl_error_t dpl_mutex_init(struct dpl_mutex *mu) +os_error_t os_mutex_init(struct os_mutex *mu) { if (!mu) { - return DPL_INVALID_PARAM; + return OS_INVALID_PARM; } mutex_init(&mu->mutex); - return DPL_OK; + return OS_OK; } -dpl_error_t dpl_mutex_release(struct dpl_mutex *mu) +os_error_t os_mutex_release(struct os_mutex *mu) { if (!mu) { - return DPL_INVALID_PARAM; + return OS_INVALID_PARM; } mutex_unlock(&mu->mutex); - return DPL_OK; + return OS_OK; } -dpl_error_t dpl_mutex_pend(struct dpl_mutex *mu, uint32_t timeout) +os_error_t os_mutex_pend(struct os_mutex *mu, uint32_t timeout) { - int rc = DPL_OK; + int rc = OS_OK; if (!mu) { - return DPL_INVALID_PARAM; + return OS_INVALID_PARM; } if (!timeout) { diff --git a/pkg/mynewt-core/contrib/nrf5x_isr.c b/pkg/mynewt-core/contrib/nrf5x_isr.c new file mode 100644 index 0000000000..23260f19a5 --- /dev/null +++ b/pkg/mynewt-core/contrib/nrf5x_isr.c @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2021 Freie Universität Berlin + * + * 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 pkg_mynewt_core + * @{ + * + * @file + * @brief mynewt-core isr mapping + * + * @author Hauke Petersen + * @} + */ + + +#include "mcu/mcu.h" +#include "cpu.h" + +static void (*radio_isr_addr)(void); +static void (*rng_isr_addr)(void); +static void (*rtc0_isr_addr)(void); + +void isr_radio(void) +{ + radio_isr_addr(); +} + +void isr_rng(void) +{ + rng_isr_addr(); +} + +void isr_rtc0(void) +{ + rtc0_isr_addr(); +} + +void nrf5x_hw_set_isr(int irqn, void (*addr)(void)) +{ + switch (irqn) { + case RADIO_IRQn: + radio_isr_addr = addr; + break; + case RNG_IRQn: + rng_isr_addr = addr; + break; + case RTC0_IRQn: + rtc0_isr_addr = addr; + break; + } +} diff --git a/pkg/mynewt-core/contrib/sem.c b/pkg/mynewt-core/contrib/sem.c new file mode 100644 index 0000000000..c15fc2d019 --- /dev/null +++ b/pkg/mynewt-core/contrib/sem.c @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2020 Inria + * + * 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 pkg_mynewt_core + * @{ + * + * @file + * @brief Decawave Porting Layer semaphore RIOT wrapper + * + * @author Francisco Molina + * @} + */ + +#include + +#include "irq.h" +#include "os/os_sem.h" + +os_error_t os_sem_init(struct os_sem *sem, uint16_t tokens) +{ + sema_create(&sem->sema, tokens); + return OS_OK; +} + +os_error_t os_sem_release(struct os_sem *sem) +{ + int ret = sema_post(&sem->sema); + return (ret) ? OS_ERROR : OS_OK; +} + +os_error_t os_sem_pend(struct os_sem *sem, os_time_t timeout) +{ + int ret = sema_wait_timed_ztimer(&sem->sema, ZTIMER_MSEC, timeout); + return (ret) ? OS_ERROR : OS_OK; +} diff --git a/pkg/uwb-core/dpl/dpl_task.c b/pkg/mynewt-core/contrib/task.c similarity index 65% rename from pkg/uwb-core/dpl/dpl_task.c rename to pkg/mynewt-core/contrib/task.c index eba30fc540..f4d7bad184 100644 --- a/pkg/uwb-core/dpl/dpl_task.c +++ b/pkg/mynewt-core/contrib/task.c @@ -7,7 +7,7 @@ */ /** - * @ingroup pkg_uwb_core + * @ingroup pkg_mynewt_core * @{ * * @file @@ -17,8 +17,8 @@ * @} */ -#include "dpl/dpl_error.h" -#include "dpl/dpl_tasks.h" +#include "os/os_error.h" +#include "os/os_task.h" #include "thread.h" #ifndef LOG_LEVEL @@ -30,13 +30,13 @@ extern "C" { #endif -int dpl_task_init(struct dpl_task *t, const char *name, dpl_task_func_t func, - void *arg, uint8_t prio, dpl_time_t sanity_itvl, - dpl_stack_t *stack_bottom, uint16_t stack_size) +int os_task_init(struct os_task *t, const char *name, os_task_func_t func, + void *arg, uint8_t prio, os_time_t sanity_itvl, + os_stack_t *stack_bottom, uint16_t stack_size) { (void) sanity_itvl; - LOG_INFO("dpl: starting thread %s\n", name); + LOG_INFO("[mynewt-core]: starting thread %s\n", name); kernel_pid_t pid = thread_create(stack_bottom, (int) stack_size, prio, THREAD_CREATE_STACKTEST, @@ -44,21 +44,21 @@ int dpl_task_init(struct dpl_task *t, const char *name, dpl_task_func_t func, t->pid = pid; - return (pid) ? DPL_ERROR : DPL_OK;; + return (pid) ? OS_ERROR : OS_OK;; } -int dpl_task_remove(struct dpl_task *t) +int os_task_remove(struct os_task *t) { thread_zombify(); return thread_kill_zombie(t->pid); } -uint8_t dpl_task_count(void) +uint8_t os_task_count(void) { return sched_num_threads; } -void dpl_task_yield(void) +void os_task_yield(void) { thread_yield(); } diff --git a/pkg/mynewt-core/doc.txt b/pkg/mynewt-core/doc.txt new file mode 100644 index 0000000000..f7c63bfd7b --- /dev/null +++ b/pkg/mynewt-core/doc.txt @@ -0,0 +1,12 @@ +/** + * @defgroup pkg_mynewt_core mynewt-core + * @ingroup pkg + * @brief Apache MyNewt package for MyNewt based packages: uwb-core, nimble + * @see https://github.com/apache/mynewt-core + */ + +# Apache MyNewt mynewt-core Package + +Packages like @ref pkg_uwb_core and @ref nimble where developed with MyNewt +as their default OS. Some of the features provided by that OS are not abstracted. +For those cases and to avoid header re-definitions mynewt-core is pulled in. diff --git a/pkg/uwb-dw1000/include/hal/hal_gpio.h b/pkg/mynewt-core/include/hal/hal_gpio.h similarity index 100% rename from pkg/uwb-dw1000/include/hal/hal_gpio.h rename to pkg/mynewt-core/include/hal/hal_gpio.h diff --git a/pkg/uwb-dw1000/include/hal/hal_spi.h b/pkg/mynewt-core/include/hal/hal_spi.h similarity index 100% rename from pkg/uwb-dw1000/include/hal/hal_spi.h rename to pkg/mynewt-core/include/hal/hal_spi.h diff --git a/pkg/uwb-core/include/log/dpl_log.h b/pkg/mynewt-core/include/log/log.h similarity index 82% rename from pkg/uwb-core/include/log/dpl_log.h rename to pkg/mynewt-core/include/log/log.h index 34ab483832..7ee5fe776e 100644 --- a/pkg/uwb-core/include/log/dpl_log.h +++ b/pkg/mynewt-core/include/log/log.h @@ -7,18 +7,18 @@ */ /** - * @ingroup pkg_uwb_core + * @ingroup pkg_mynewt_core * @{ * * @file - * @brief System logging header for uwb-core + * @brief System logging header for mynewt-core * * @author Francisco Molina * @} */ -#ifndef LOG_DPL_LOG_H -#define LOG_DPL_LOG_H +#ifndef LOG_LOG_H +#define LOG_LOG_H #ifdef __cplusplus extern "C" { @@ -45,4 +45,4 @@ struct log { } #endif -#endif /* LOG_DPL_LOG_H */ +#endif /* LOG_LOG_H */ diff --git a/pkg/mynewt-core/include/mcu/mcu.h b/pkg/mynewt-core/include/mcu/mcu.h new file mode 100644 index 0000000000..2c3185a5c1 --- /dev/null +++ b/pkg/mynewt-core/include/mcu/mcu.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2020 Inria + * + * 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 pkg_mynewt_core + * @{ + * + * @file + * @brief Abstraction layer for RIOT adaption + * + * @author Francisco Molina + * @} + */ + +#ifndef MCU_MCU_H +#define MCU_MCU_H + +#include "cpu.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Set nrf5x radio ISR callback + * + * @param[in] irqn IRQ number + * @param[in] addr the ISR callback + */ +void nrf5x_hw_set_isr(int irqn, void (*addr)(void)); + +/** + * @name Entering and exiting critical section defines + * @{ + */ +#define __HAL_DISABLE_INTERRUPTS(x) \ + do { \ + x = irq_disable(); \ + } while (0); + +#define __HAL_ENABLE_INTERRUPTS(x) \ + do { \ + if (x) { \ + irq_restore(x); \ + } \ + else { \ + irq_enable(); \ + } \ + } while (0); +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* MCU_MCU_H */ diff --git a/pkg/uwb-core/include/stats/stats.h b/pkg/mynewt-core/include/os/mynewt.h similarity index 62% rename from pkg/uwb-core/include/stats/stats.h rename to pkg/mynewt-core/include/os/mynewt.h index 1be9452c1c..97bf9c986d 100644 --- a/pkg/uwb-core/include/stats/stats.h +++ b/pkg/mynewt-core/include/os/mynewt.h @@ -7,27 +7,30 @@ */ /** - * @ingroup pkg_uwb_core + * @ingroup pkg_mynewt_core * @{ * * @file - * @brief Abstraction layer for RIOT adaption + * @brief mynewt-core header * * @author Francisco Molina * @} */ -#ifndef STATS_STATS_H -#define STATS_STATS_H +#ifndef OS_MYNEWT_H +#define OS_MYNEWT_H + +#include +#include "syscfg/syscfg.h" +#include "sysinit/sysinit.h" +#include "os/os.h" #ifdef __cplusplus extern "C" { #endif -/* empty header */ - #ifdef __cplusplus } #endif -#endif /* STATS_STATS_H */ +#endif /* OS_MYNEWT_H */ diff --git a/pkg/mynewt-core/include/os/os.h b/pkg/mynewt-core/include/os/os.h new file mode 100644 index 0000000000..e39c1e81ac --- /dev/null +++ b/pkg/mynewt-core/include/os/os.h @@ -0,0 +1,146 @@ +/** + * Apache Mynewt + * Copyright 2015-2021 The Apache Software Foundation + * + * This product includes software developed at + * The Apache Software Foundation (http://www.apache.org/). + * + * Portions of this software were developed at + * Runtime Inc, copyright 2015. + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * @ingroup pkg_mynewt_core + * @{ + * + * @file + * @brief mynewt-core error types + * + * @} + */ + +#ifndef OS_OS_H +#define OS_OS_H + +#include +#include + +#include "irq.h" +#include "os/os_types.h" +#include "os/os_error.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name MyNewt os/%.h required macros + * @{ + * + * PLEASE NOTE: Following macro definitions where copied directly from + * apache/mynewt-core and are under the copyright specified in + * the header. + * + */ +#ifndef min +#define min(a, b) ((a)<(b)?(a):(b)) +#endif + +#ifndef max +#define max(a, b) ((a)>(b)?(a):(b)) +#endif + +#define OS_ALIGN(__n, __a) ( \ + (((__n) & ((__a) - 1)) == 0) ? \ + (__n) : \ + ((__n) + ((__a) - ((__n) & ((__a) - 1)))) \ + ) +#define OS_ALIGNMENT (4) +/** @} */ + +/** + * @brief CPU status register + */ +typedef uint32_t os_sr_t; + +/** + * @name Entering and exiting critical section defines + * @{ + */ +#define OS_ENTER_CRITICAL(_sr) (_sr = os_hw_enter_critical()) +#define OS_EXIT_CRITICAL(_sr) (os_hw_exit_critical(_sr)) +#define OS_ASSERT_CRITICAL() assert(os_hw_is_in_critical()) +/** @} */ + +/** + * @brief Disable ISRs + * + * @return current isr context + */ +static inline uint32_t os_hw_enter_critical(void) +{ + uint32_t ctx = irq_disable(); + return ctx; +} + +/** + * @brief Restores ISR context + * + * @param[in] ctx ISR context to restore. + */ +static inline void os_hw_exit_critical(uint32_t ctx) +{ + irq_restore((unsigned)ctx); +} + +/** + * @brief Check if is in critical section + * + * @return true, if in critical section, false otherwise + */ +static inline bool os_hw_is_in_critical(void) +{ + return (irq_is_in() || __get_PRIMASK()); +} + +/* Mynewt components (not abstracted in NPL or DPL) */ +#include "os/endian.h" +#include "os/os_callout.h" +#include "os/os_cputime.h" +#include "os/os_dev.h" +#include "os/os_eventq.h" +#include "os/os_mbuf.h" +#include "os/os_mempool.h" +#include "os/os_mutex.h" +#include "os/os_sem.h" +#include "os/os_task.h" +#include "os/os_time.h" +#include "os/os_trace_api.h" +#include "os/queue.h" + +#if IS_USED(MODULE_NIMBLE) +#include "nimble/nimble_npl.h" +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* OS_OS_H */ diff --git a/pkg/uwb-core/include/os/os_dev.h b/pkg/mynewt-core/include/os/os_dev.h similarity index 76% rename from pkg/uwb-core/include/os/os_dev.h rename to pkg/mynewt-core/include/os/os_dev.h index f1068749fb..6998d0887c 100644 --- a/pkg/uwb-core/include/os/os_dev.h +++ b/pkg/mynewt-core/include/os/os_dev.h @@ -7,7 +7,7 @@ */ /** - * @ingroup pkg_uwb_core + * @ingroup pkg_mynewt_core * @{ * * @file @@ -19,13 +19,6 @@ #ifndef OS_OS_DEV_H #define OS_OS_DEV_H -#include "dpl/dpl.h" -#include "dpl/queue.h" - -#include "net/ieee802154.h" -#include "net/netdev.h" -#include "net/netdev/ieee802154.h" - #ifdef __cplusplus extern "C" { #endif @@ -34,7 +27,6 @@ extern "C" { * @brief Device structure. */ struct os_dev { - netdev_ieee802154_t netdev; /**< Netdev parent struct */ }; /** diff --git a/pkg/mynewt-core/include/os/os_eventq.h b/pkg/mynewt-core/include/os/os_eventq.h new file mode 100644 index 0000000000..6a49d058f4 --- /dev/null +++ b/pkg/mynewt-core/include/os/os_eventq.h @@ -0,0 +1,236 @@ +/* + * Copyright (C) 2020 Inria + * + * 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 pkg_mynewt_core + * @{ + * + * @file + * @brief mynewt-core event and event queue abstraction + * + * @author Francisco Molina + * @} + */ + +#ifndef OS_OS_EVENTQ_H +#define OS_OS_EVENTQ_H + +#include + +#include "event/callback.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Event wrapper + */ +struct os_event +{ + event_callback_t e; /**< the event callback */ + void *arg; /**< the event argument */ +}; + +/** + * @brief Event queue wrapper + */ +struct os_eventq +{ + event_queue_t q; /**< the event queue */ +}; + +/** + * @brief Event callback function + */ +typedef void os_event_fn(struct os_event *ev); + +/** + * @brief Init a event + * + * @param[in] ev pointer to event to set + * @param[in] fn event callback function + * @param[in] arg event argument + */ +static inline void os_event_init(struct os_event *ev, os_event_fn * fn, + void *arg) +{ + /* + * Need to clear list_node manually since init function below does not do + * this. + */ + ev->e.super.list_node.next = NULL; + event_callback_init(&ev->e, (void(*)(void *))fn, ev); + ev->arg = arg; +} + +/** + * @brief Check if event is in queue + * + * @param[in] ev event to check + * + * @return true if event is queues, false otherwise + */ +static inline bool os_event_is_queued(struct os_event *ev) +{ + return (ev->e.super.list_node.next != NULL); +} + +/** + * @brief Returns event argument + * + * @param[in] ev event + */ +static inline void *os_event_get_arg(struct os_event *ev) +{ + return ev->arg; +} + +/** + * @brief Set the event argument + * + * @param[in] ev event + * @param[in] arg arg to set event + */ +static inline void os_event_set_arg(struct os_event *ev, void *arg) +{ + ev->arg = arg; +} + +/** + * @brief Runs an event + * + * @param[in] ev event to run + */ +static inline void os_event_run(struct os_event *ev) +{ + ev->e.super.handler(&ev->e.super); +} + +/** + * @brief Initialize the event queue + * + * @param[in] evq The event queue to initialize + */ +static inline void os_eventq_init(struct os_eventq *evq) +{ + event_queue_init_detached(&evq->q); +} + +/** + * @brief Check whether the event queue is initialized. + * + * @param[in] evq the event queue to check + */ +static inline int os_eventq_inited(struct os_eventq *evq) +{ + return evq->q.waiter != NULL; +} + +/** + * @brief Deinitialize an event queue + * + * @note Not supported in RIOT + * + * @param[in] evq the event queue to deinit + */ +static inline void os_eventq_deinit(struct os_eventq *evq) +{ + (void) evq; + /* Can't deinit an eventq in RIOT */ +} + +/** +* @brief Get next event from event queue + * + * @param[in] evq the event queue to pull an event from + * @param[in] tmo timeout, OS_WAIT_FOREVER to block, 0 to return immediately + * + * @return the event from the queue + */ +static inline struct os_event * os_eventq_get(struct os_eventq *evq, os_time_t tmo) +{ + if (evq->q.waiter == NULL) { + event_queue_claim(&evq->q); + } + + if (tmo == 0) { + return (struct os_event *)event_get(&evq->q); + } else if (tmo == OS_WAIT_FOREVER) { + return (struct os_event *)event_wait(&evq->q); + } else { + return (struct os_event *)event_wait_timeout_ztimer(&evq->q, + ZTIMER_MSEC, + (uint32_t)tmo); + } +} + +/** + * @brief Get next event from event queue, non-blocking + * + * @return event from the queue, or NULL if none available. + */ +static inline struct os_event * os_eventq_get_no_wait(struct os_eventq *evq) +{ + if (evq->q.waiter == NULL) { + event_queue_claim(&evq->q); + } + + return (struct os_event *) event_get(&evq->q); +} + +/** + * @brief Put an event on the event queue. + * + * @param[in] evq event queue + * @param[in] ev event to put in queue + */ +static inline void os_eventq_put(struct os_eventq *evq, struct os_event *ev) +{ + event_post(&evq->q, &ev->e.super); +} + +/** + * @brief Remove an event from the queue. + * + * @param[in] evq event queue to remove the event from + * @param[in] ev event to remove from the queue + */ +static inline void os_eventq_remove(struct os_eventq *evq, struct os_event *ev) +{ + event_cancel(&evq->q, &ev->e.super); +} + +/** + * @brief Gets and runs an event from the queue callback. + * + * @param[in] evq The event queue to pull the item off. + */ +static inline void os_eventq_run(struct os_eventq *evq) +{ + struct os_event *ev = os_eventq_get(evq, OS_WAIT_FOREVER); + os_event_run(ev); +} + +/** + * @brief Check if queue is empty + * + * @param[in] evq the event queue to check + * + * @return true if empty, false otherwise + */ +static inline bool os_eventq_is_empty(struct os_eventq *evq) +{ + return clist_count(&(evq->q.event_list)) == 0; +} + +#ifdef __cplusplus +} +#endif + +#endif /* OS_OS_EVENTQ_H */ diff --git a/pkg/mynewt-core/include/os/os_time.h b/pkg/mynewt-core/include/os/os_time.h new file mode 100644 index 0000000000..1ca7f50a59 --- /dev/null +++ b/pkg/mynewt-core/include/os/os_time.h @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2020 Inria + * + * 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 pkg_mynewt_core + * @{ + * + * @file + * @brief mynewt-core time abstraction + * + * @author Francisco Molina + * @} + */ + +#ifndef OS_OS_TIME_H +#define OS_OS_TIME_H + +#include "os/os_error.h" +#include "ztimer.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Ticks per seconds, ztimer_msec is used as system timer + */ +#define OS_TICKS_PER_SEC (MS_PER_SEC) + +/** + * @brief Returns the low 32 bits of cputime. + * + * @return uint32_t The lower 32 bits of cputime + */ +static inline os_time_t os_time_get(void) +{ + return ztimer_now(ZTIMER_MSEC); +} + +/** + * @brief Converts the given number of milliseconds into cputime ticks. + * + * @param[in] ms The number of milliseconds to convert to ticks + * @param[out] out_ticks The number of ticks corresponding to 'ms' + * + * @return os_error_t OS_OK - no error + */ +static inline os_error_t os_time_ms_to_ticks(uint32_t ms, os_time_t *out_ticks) +{ + *out_ticks = ms; + return OS_OK; +} + +/** + * @brief Convert the given number of ticks into milliseconds. + * + * @param[in] ticks The number of ticks to convert to milliseconds. + * @param[out] out_ms The converted milliseconds from 'ticks' + * + * @return os_error_t OS_OK - no error + */ +static inline os_error_t os_time_ticks_to_ms(os_time_t ticks, uint32_t *out_ms) +{ + *out_ms = ticks; + return OS_OK; +} + +/** + * @brief Converts the given number of milliseconds into cputime ticks. + * + * @param[in] ms The number of milliseconds to convert to ticks + * + * @return uint32_t The number of ticks corresponding to 'ms' + */ +static inline os_time_t os_time_ms_to_ticks32(uint32_t ms) +{ + return ms; +} + +/** + * @brief Convert the given number of ticks into milliseconds. + * + * @param[in] ticks The number of ticks to convert to milliseconds. + * + * @return uint32_t The number of milliseconds corresponding to 'ticks' + */ +static inline os_time_t os_time_ticks_to_ms32(os_time_t ticks) +{ + return ticks; +} + +/** + * @brief Wait until the number of ticks has elapsed, BLOICKING. + * + * @param[in] ticks The number of ticks to wait. + */ +static inline void os_time_delay(os_time_t ticks) +{ + if (irq_is_in()) { + ztimer_spin(ZTIMER_MSEC, ticks); + } + else { + ztimer_sleep(ZTIMER_MSEC, ticks); + } +} + +#ifdef __cplusplus +} +#endif + +#endif /* OS_OS_TIME_H */ diff --git a/pkg/mynewt-core/include/os/os_types.h b/pkg/mynewt-core/include/os/os_types.h new file mode 100644 index 0000000000..819f093e83 --- /dev/null +++ b/pkg/mynewt-core/include/os/os_types.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2020 Inria + * + * 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 pkg_mynewt_core + * @{ + * + * @file + * @brief mynewt-core types + * + * @author Francisco Molina + * @} + */ + +#ifndef OS_OS_TYPES_H +#define OS_OS_TYPES_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name Error codes not abstracted in mynewt-core/kernel/os + * @{ + */ +#define SYS_EINVAL (-2) +#define SYS_ENOMEM (-1) +/** @} */ + +/** + * @name Macro to wait forever on events and mutexes + * @{ + */ +#define OS_TIMEOUT_NEVER (UINT32_MAX) +#define OS_WAIT_FOREVER (OS_TIMEOUT_NEVER) +/** @} */ + +/** + * @brief time type + */ +typedef uint32_t os_time_t; + +/** + * @brief stack buffer type + */ +typedef char os_stack_t; + +#ifdef __cplusplus +} +#endif + +#endif /* OS_OS_TYPES_H */ diff --git a/pkg/mynewt-core/include/syscfg/syscfg.h b/pkg/mynewt-core/include/syscfg/syscfg.h new file mode 100644 index 0000000000..b546f9c19f --- /dev/null +++ b/pkg/mynewt-core/include/syscfg/syscfg.h @@ -0,0 +1,122 @@ +/** + * Apache Mynewt + * Copyright 2015-2021 The Apache Software Foundation + * + * This product includes software developed at + * The Apache Software Foundation (http://www.apache.org/). + * + * Portions of this software were developed at + * Runtime Inc, copyright 2015. + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * @ingroup pkg_mynewt_core + * @{ + * + * @file + * @brief mynewt-core system configurations + * + * @} + */ + +#ifndef SYSCFG_SYSCFG_H +#define SYSCFG_SYSCFG_H + +#include "kernel_defines.h" + +/** + * @name MyNewt header inclusion macro definitions + * @{ + * + * PLEASE NOTE: Following macro definitions where copied directly from + * apache/mynewt-core and are under the copyright specified in + * the header. + * + * This macro exists to ensure code includes this header when needed. If code + * checks the existence of a setting directly via ifdef without including this + * header, the setting macro will silently evaluate to 0. In contrast, an + * attempt to use these macros without including this header will result in a + * compiler error. + */ +#define MYNEWT_VAL(_name) MYNEWT_VAL_ ## _name +#define MYNEWT_VAL_CHOICE(_name, _val) MYNEWT_VAL_ ## _name ## __ ## _val +/** @} */ + +/** + * @brief TIMER 5 (RTC_DEV0) will be mynewt-core OS_CPUTIME timer + */ +#ifndef MYNEWT_VAL_OS_CPUTIME_TIMER_NUM +#define MYNEWT_VAL_OS_CPUTIME_TIMER_NUM (5) +#endif + +/** + * @brief Enable TIMER 5 (RTC_DEV0) + */ +#ifndef MYNEWT_VAL_TIMER_5 +#define MYNEWT_VAL_TIMER_5 (1) +#endif + +#if IS_USED(MODULE_NIMBLE) +/*** @mynewt-nimble */ +#undef MYNEWT_VAL +#undef MYNEWT_VAL_CHOICE +#include "npl_sycfg.h" +#endif + +#if IS_USED(MODULE_UWB_CORE) +/*** @decawave-mynewt-core/hw/drivers/uwb */ +#include "dpl_syscfg/syscfg_uwb.h" + +/*** @decawave-mynewt-core/lib/twr_ds */ +#include "dpl_syscfg/syscfg_twr_ds.h" + +/*** @decawave-mynewt-core/lib/twr_ds_ext */ +#include "dpl_syscfg/syscfg_twr_ds_ext.h" + +/*** @decawave-mynewt-core/lib/twr_ss */ +#include "dpl_syscfg/syscfg_twr_ss.h" + +/*** @decawave-mynewt-core/lib/twr_ss_ack */ +#include "dpl_syscfg/syscfg_twr_ss_ack.h" + +/*** @decawave-mynewt-core/lib/twr_ss_ext */ +#include "dpl_syscfg/syscfg_twr_ss_ext.h" + +/*** @decawave-mynewt-core/lib/uwb_rng */ +#include "dpl_syscfg/syscfg_uwb_rng.h" + +/*** @decawave-mynewt-core/sys/uwbcfg */ +#include "dpl_syscfg/syscfg_uwbcfg.h" +#endif + +#if IS_USED(MODULE_UWB_DW1000) +/*** @decawave-uwb-dw1000/hw/drivers/uwb/uwb_dw1000 */ +#include "syscfg_uwb_dw1000.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* SYSCFG_SYSCFG_H */ diff --git a/pkg/uwb-core/include/sysinit/sysinit.h b/pkg/mynewt-core/include/sysinit/sysinit.h similarity index 83% rename from pkg/uwb-core/include/sysinit/sysinit.h rename to pkg/mynewt-core/include/sysinit/sysinit.h index c340c1c2fc..7c65fd56f6 100644 --- a/pkg/uwb-core/include/sysinit/sysinit.h +++ b/pkg/mynewt-core/include/sysinit/sysinit.h @@ -7,7 +7,7 @@ */ /** - * @ingroup pkg_uwb_core + * @ingroup pkg_mynewt_core * @{ * * @file @@ -27,10 +27,15 @@ extern "C" { #endif /** - * @brief DPL assert macro + * @brief assert macro */ #define SYSINIT_PANIC_ASSERT(rc) assert(rc); +/** + * @brief empty definition + */ +#define SYSINIT_ASSERT_ACTIVE() + #ifdef __cplusplus } #endif diff --git a/pkg/mynewt-core/mynewt-core_nrf5x_hal.mk b/pkg/mynewt-core/mynewt-core_nrf5x_hal.mk new file mode 100644 index 0000000000..b1f2145380 --- /dev/null +++ b/pkg/mynewt-core/mynewt-core_nrf5x_hal.mk @@ -0,0 +1,5 @@ +MODULE = mynewt-core_nrf5x_hal + +SRC := hal_timer.c + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/mynewt-core/mynewt-core_os.mk b/pkg/mynewt-core/mynewt-core_os.mk new file mode 100644 index 0000000000..8077bdeabe --- /dev/null +++ b/pkg/mynewt-core/mynewt-core_os.mk @@ -0,0 +1,15 @@ +MODULE = mynewt-core_os + +SRC := \ + endian.c \ + os_mbuf.c \ + os_mempool.c \ + os_msys.c \ + os_cputime_pwr2.c \ + # + +ifneq (,$(filter nrf%,$(CPU))) + SRC += os_cputime.c +endif + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/mynewt-core/mynewt-core_util.mk b/pkg/mynewt-core/mynewt-core_util.mk new file mode 100644 index 0000000000..eb4abdce05 --- /dev/null +++ b/pkg/mynewt-core/mynewt-core_util.mk @@ -0,0 +1,5 @@ +MODULE = mynewt-core_util + +SRC := mem.c + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/mynewt-core/patches/0001-hw-mcu-nrf5x-adapt-NVIC-init-to-RIOT.patch b/pkg/mynewt-core/patches/0001-hw-mcu-nrf5x-adapt-NVIC-init-to-RIOT.patch new file mode 100644 index 0000000000..de1c0ba6c3 --- /dev/null +++ b/pkg/mynewt-core/patches/0001-hw-mcu-nrf5x-adapt-NVIC-init-to-RIOT.patch @@ -0,0 +1,76 @@ +From 37f6d02ec7bedd03d36f261322043675a3a37180 Mon Sep 17 00:00:00 2001 +From: Francisco Molina +Date: Mon, 19 Apr 2021 15:50:06 +0200 +Subject: [PATCH 1/3] hw/mcu/nrf5x: adapt NVIC init to RIOT + +--- + hw/mcu/nordic/nrf51xxx/src/hal_timer.c | 10 +++++----- + hw/mcu/nordic/nrf52xxx/src/hal_timer.c | 11 +++++------ + 2 files changed, 10 insertions(+), 11 deletions(-) + +diff --git a/hw/mcu/nordic/nrf51xxx/src/hal_timer.c b/hw/mcu/nordic/nrf51xxx/src/hal_timer.c +index a99be65cb..3efc81fa0 100644 +--- a/hw/mcu/nordic/nrf51xxx/src/hal_timer.c ++++ b/hw/mcu/nordic/nrf51xxx/src/hal_timer.c +@@ -22,11 +22,9 @@ + #include + #include + #include "os/mynewt.h" +-#include "mcu/cmsis_nvic.h" ++#include "mcu/mcu.h" + #include "hal/hal_timer.h" +-#include "nrf51.h" +-#include "nrf51_bitfields.h" +-#include "mcu/nrf51_hal.h" ++#include "nrfx.h" + + /* IRQ prototype */ + typedef void (*hal_timer_irq_handler_t)(void); +@@ -575,8 +573,10 @@ hal_timer_init(int timer_num, void *cfg) + + /* Disable IRQ, set priority and set vector in table */ + NVIC_DisableIRQ(irq_num); ++#ifndef RIOT_VERSION + NVIC_SetPriority(irq_num, (1 << __NVIC_PRIO_BITS) - 1); +- NVIC_SetVector(irq_num, (uint32_t)irq_isr); ++#endif ++ nrf5x_hw_set_isr(irq_num, irq_isr); + + return 0; + +diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_timer.c b/hw/mcu/nordic/nrf52xxx/src/hal_timer.c +index fc6fe834d..c2ca88f65 100644 +--- a/hw/mcu/nordic/nrf52xxx/src/hal_timer.c ++++ b/hw/mcu/nordic/nrf52xxx/src/hal_timer.c +@@ -22,11 +22,9 @@ + #include + #include + #include "os/mynewt.h" +-#include "mcu/cmsis_nvic.h" ++#include "mcu/mcu.h" + #include "hal/hal_timer.h" +-#include "nrf.h" +-#include "mcu/nrf52_hal.h" +-#include "mcu/nrf52_clock.h" ++#include "nrfx.h" + + /* IRQ prototype */ + typedef void (*hal_timer_irq_handler_t)(void); +@@ -537,11 +535,12 @@ hal_timer_init(int timer_num, void *cfg) + + bsptimer->tmr_reg = hwtimer; + bsptimer->tmr_irq_num = irq_num; +- + /* Disable IRQ, set priority and set vector in table */ + NVIC_DisableIRQ(irq_num); ++#ifndef RIOT_VERSION + NVIC_SetPriority(irq_num, (1 << __NVIC_PRIO_BITS) - 1); +- NVIC_SetVector(irq_num, (uint32_t)irq_isr); ++#endif ++ nrf5x_hw_set_isr(irq_num, irq_isr); + + return 0; + +-- +2.28.0 + diff --git a/pkg/mynewt-core/patches/0002-kernel-os-src-riot-patches.patch b/pkg/mynewt-core/patches/0002-kernel-os-src-riot-patches.patch new file mode 100644 index 0000000000..68ad996c3e --- /dev/null +++ b/pkg/mynewt-core/patches/0002-kernel-os-src-riot-patches.patch @@ -0,0 +1,293 @@ +From e02018ca20f3a7192764973cf47ef27520dd50bf Mon Sep 17 00:00:00 2001 +From: Francisco Molina +Date: Thu, 27 May 2021 11:58:13 +0200 +Subject: [PATCH 2/3] kernel/os/src: riot patches + +--- + kernel/os/include/os/endian.h | 1 + + kernel/os/include/os/os_callout.h | 16 ++++---- + kernel/os/include/os/os_mutex.h | 16 +++----- + kernel/os/include/os/os_sem.h | 10 ++--- + kernel/os/include/os/os_task.h | 62 +++++-------------------------- + kernel/os/src/os_mbuf.c | 4 +- + kernel/os/src/os_msys.c | 1 - + 7 files changed, 30 insertions(+), 80 deletions(-) + +diff --git a/kernel/os/include/os/endian.h b/kernel/os/include/os/endian.h +index 021a73ed6..4affebec2 100644 +--- a/kernel/os/include/os/endian.h ++++ b/kernel/os/include/os/endian.h +@@ -20,6 +20,7 @@ + #ifndef H_ENDIAN_ + #define H_ENDIAN_ + ++#include "byteorder.h" + #include + + #ifdef __cplusplus +diff --git a/kernel/os/include/os/os_callout.h b/kernel/os/include/os/os_callout.h +index b407f3f44..749e41a10 100644 +--- a/kernel/os/include/os/os_callout.h ++++ b/kernel/os/include/os/os_callout.h +@@ -31,7 +31,9 @@ + extern "C" { + #endif + ++#include "os/queue.h" + #include "os/os_eventq.h" ++#include "ztimer.h" + #include + + /** +@@ -43,11 +45,7 @@ struct os_callout { + struct os_event c_ev; + /** Pointer to the event queue to post the event to */ + struct os_eventq *c_evq; +- /** Number of ticks in the future to expire the callout */ +- os_time_t c_ticks; +- +- +- TAILQ_ENTRY(os_callout) c_next; ++ ztimer_t timer; + }; + + /** +@@ -86,7 +84,7 @@ void os_callout_init(struct os_callout *cf, struct os_eventq *evq, + * + * @param c The callout to stop + */ +-void os_callout_stop(struct os_callout *); ++void os_callout_stop(struct os_callout *c); + + + /** +@@ -97,7 +95,7 @@ void os_callout_stop(struct os_callout *); + * + * @return 0 on success, non-zero on failure + */ +-int os_callout_reset(struct os_callout *, os_time_t); ++int os_callout_reset(struct os_callout *c, os_time_t ticks); + + /** + * Returns the number of ticks which remains to callout. +@@ -107,7 +105,7 @@ int os_callout_reset(struct os_callout *, os_time_t); + * + * @return Number of ticks to first pending callout + */ +-os_time_t os_callout_remaining_ticks(struct os_callout *, os_time_t); ++os_time_t os_callout_remaining_ticks(struct os_callout *c, os_time_t now); + + /** + * Returns whether the callout is pending or not. +@@ -119,7 +117,7 @@ os_time_t os_callout_remaining_ticks(struct os_callout *, os_time_t); + static inline int + os_callout_queued(struct os_callout *c) + { +- return c->c_next.tqe_prev != NULL; ++ return ztimer_is_set(ZTIMER_MSEC, &c->timer); + } + + /** +diff --git a/kernel/os/include/os/os_mutex.h b/kernel/os/include/os/os_mutex.h +index 7fb67fa49..3449c420c 100644 +--- a/kernel/os/include/os/os_mutex.h ++++ b/kernel/os/include/os/os_mutex.h +@@ -27,8 +27,10 @@ + #ifndef _OS_MUTEX_H_ + #define _OS_MUTEX_H_ + +-#include "os/os.h" + #include "os/queue.h" ++#include "os/os_types.h" ++#include "os/os_error.h" ++#include "mutex.h" + + #ifdef __cplusplus + extern "C" { +@@ -38,14 +40,7 @@ extern "C" { + * OS mutex structure + */ + struct os_mutex { +- SLIST_HEAD(, os_task) mu_head; +- uint8_t _pad; +- /** Mutex owner's default priority */ +- uint8_t mu_prio; +- /** Mutex call nesting level */ +- uint16_t mu_level; +- /** Task that owns the mutex */ +- struct os_task *mu_owner; ++ mutex_t mutex; + }; + + /* +@@ -119,7 +114,8 @@ os_error_t os_mutex_pend(struct os_mutex *mu, os_time_t timeout); + */ + static inline uint16_t os_mutex_get_level(struct os_mutex *mu) + { +- return mu->mu_level; ++ (void) mu; ++ return 0; + } + + #ifdef __cplusplus +diff --git a/kernel/os/include/os/os_sem.h b/kernel/os/include/os/os_sem.h +index aa5456d42..32c5a0d12 100644 +--- a/kernel/os/include/os/os_sem.h ++++ b/kernel/os/include/os/os_sem.h +@@ -27,7 +27,10 @@ + #ifndef _OS_SEM_H_ + #define _OS_SEM_H_ + ++#include "os/os_types.h" + #include "os/queue.h" ++#include "os/os_error.h" ++#include "sema.h" + + #ifdef __cplusplus + extern "C" { +@@ -37,10 +40,7 @@ extern "C" { + * Structure representing an OS semaphore. + */ + struct os_sem { +- SLIST_HEAD(, os_task) sem_head; +- uint16_t _pad; +- /** Number of tokens */ +- uint16_t sem_tokens; ++ sema_t sema; /**< the semaphore */ + }; + + /* +@@ -100,7 +100,7 @@ os_error_t os_sem_pend(struct os_sem *sem, os_time_t timeout); + */ + static inline uint16_t os_sem_get_count(struct os_sem *sem) + { +- return sem->sem_tokens; ++ return sem->sema.value; + } + + #ifdef __cplusplus +diff --git a/kernel/os/include/os/os_task.h b/kernel/os/include/os/os_task.h +index b42f51ca2..ce6418941 100644 +--- a/kernel/os/include/os/os_task.h ++++ b/kernel/os/include/os/os_task.h +@@ -28,10 +28,9 @@ + #ifndef _OS_TASK_H + #define _OS_TASK_H + +-#include "os/os.h" +-#include "os/os_sanity.h" +-#include "os/os_arch.h" ++#include "os/os_types.h" + #include "os/queue.h" ++#include "thread.h" + + #ifdef __cplusplus + extern "C" { +@@ -76,7 +75,7 @@ typedef enum os_task_state { + /** Task waiting on a event queue */ + #define OS_TASK_FLAG_EVQ_WAIT (0x08U) + +-typedef void (*os_task_func_t)(void *); ++typedef thread_task_func_t os_task_func_t; + + #define OS_TASK_MAX_NAME_LEN (32) + +@@ -84,54 +83,7 @@ typedef void (*os_task_func_t)(void *); + * Structure containing information about a running task + */ + struct os_task { +- /* +- * t_stackptr and t_stackbottom fields may be accessed directly from +- * assembly code and should never be moved in this structure. +- */ +- +- /** Current stack pointer for this task */ +- os_stack_t *t_stackptr; +- /** Pointer to bottom of this task's stack */ +- os_stack_t *t_stackbottom; +- /** Size of this task's stack */ +- uint16_t t_stacksize; +- /** Task ID */ +- uint8_t t_taskid; +- /** Task Priority */ +- uint8_t t_prio; +- /* Task state, either READY or SLEEP */ +- uint8_t t_state; +- /** Task flags, bitmask */ +- uint8_t t_flags; +- uint8_t t_lockcnt; +- uint8_t t_pad; +- +- /** Task name */ +- const char *t_name; +- /** Task function that executes */ +- os_task_func_t t_func; +- /** Argument to pass to task function when called */ +- void *t_arg; +- +- /** Current object task is waiting on, either a semaphore or mutex */ +- void *t_obj; +- +- /** Default sanity check for this task */ +- struct os_sanity_check t_sanity_check; +- +- /** Next scheduled wakeup if this task is sleeping */ +- os_time_t t_next_wakeup; +- /** Total task run time */ +- os_time_t t_run_time; +- /** +- * Total number of times this task has been context switched during +- * execution. +- */ +- uint32_t t_ctx_sw_cnt; +- +- STAILQ_ENTRY(os_task) t_os_task_list; +- TAILQ_ENTRY(os_task) t_os_list; +- SLIST_ENTRY(os_task) t_obj_list; ++ kernel_pid_t pid; + }; + + /** @cond INTERNAL_HIDDEN */ +@@ -263,6 +215,12 @@ struct os_task *os_task_info_get_next(const struct os_task *, + */ + void os_task_info_get(const struct os_task *task, struct os_task_info *oti); + ++/** ++ * * @brief Lets current thread yield. ++ * ++ */ ++void os_task_yield(void); ++ + #ifdef __cplusplus + } + #endif +diff --git a/kernel/os/src/os_mbuf.c b/kernel/os/src/os_mbuf.c +index 494dedc32..ed9f1c693 100644 +--- a/kernel/os/src/os_mbuf.c ++++ b/kernel/os/src/os_mbuf.c +@@ -50,9 +50,7 @@ os_mqueue_init(struct os_mqueue *mq, os_event_fn *ev_cb, void *arg) + STAILQ_INIT(&mq->mq_head); + + ev = &mq->mq_ev; +- memset(ev, 0, sizeof(*ev)); +- ev->ev_cb = ev_cb; +- ev->ev_arg = arg; ++ os_event_init(ev, ev_cb, arg); + + return (0); + } +diff --git a/kernel/os/src/os_msys.c b/kernel/os/src/os_msys.c +index 67c118473..9a06db6fd 100644 +--- a/kernel/os/src/os_msys.c ++++ b/kernel/os/src/os_msys.c +@@ -20,7 +20,6 @@ + #include + #include "os/mynewt.h" + #include "mem/mem.h" +-#include "os_priv.h" + + static STAILQ_HEAD(, os_mbuf_pool) g_msys_pool_list = + STAILQ_HEAD_INITIALIZER(g_msys_pool_list); +-- +2.28.0 + diff --git a/pkg/mynewt-core/patches/0003-hw-hal-patch-hal_timer.patch b/pkg/mynewt-core/patches/0003-hw-hal-patch-hal_timer.patch new file mode 100644 index 0000000000..0dfa71f5ee --- /dev/null +++ b/pkg/mynewt-core/patches/0003-hw-hal-patch-hal_timer.patch @@ -0,0 +1,48 @@ +From fe5793956395153af816d3336db99850335f20f5 Mon Sep 17 00:00:00 2001 +From: Francisco Molina +Date: Fri, 18 Jun 2021 12:24:27 +0200 +Subject: [PATCH 3/3] hw/hal: patch hal_timer + +NimBLE relies on mynewt-core specific timer initialization, this +only affects nordic BOARDs. For other BOARDs use ZTIMER_MSEC_BASE, +and therefore ztimer as the base timer. +--- + hw/hal/include/hal/hal_timer.h | 8 ++++++++ + 1 file changed, 8 insertions(+) + +diff --git a/hw/hal/include/hal/hal_timer.h b/hw/hal/include/hal/hal_timer.h +index be41c6095..7d8de9fb4 100644 +--- a/hw/hal/include/hal/hal_timer.h ++++ b/hw/hal/include/hal/hal_timer.h +@@ -31,6 +31,10 @@ + #include + #include "os/queue.h" + ++#if !defined(CPU_NRF52) && !defined(CPU_NRF51) ++#include "ztimer.h" ++#include "ztimer/config.h" ++#endif + #ifdef __cplusplus + extern "C" { + #endif +@@ -49,6 +53,9 @@ typedef void (*hal_timer_cb)(void *arg); + * structure; the hal timer API should be used. + */ + struct hal_timer { ++#if !defined(CPU_NRF52) && !defined(CPU_NRF51) ++ ztimer_t timer; ++#else + /** Internal platform specific pointer */ + void *bsp_timer; + /** Callback function */ +@@ -58,6 +65,7 @@ struct hal_timer { + /** Tick at which timer should expire */ + uint32_t expiry; + TAILQ_ENTRY(hal_timer) link; /* Queue linked list structure */ ++#endif + }; + + /** +-- +2.28.0 + diff --git a/pkg/nimble/Makefile b/pkg/nimble/Makefile index 28e4797fbc..11d7c071a7 100644 --- a/pkg/nimble/Makefile +++ b/pkg/nimble/Makefile @@ -30,12 +30,12 @@ SUBMODS := $(filter-out $(IGNORE),$(filter nimble_%,$(USEMODULE))) all: $(SUBMODS) -# blue code and RIOT port modules +# glue code and RIOT port modules nimble_riot_contrib: $(QQ)"$(MAKE)" -C $(TDIR)/contrib/ nimble_porting_nimble: - $(QQ)"$(MAKE)" -C $(PDIR)/porting/nimble/src/ -f $(RIOTBASE)/Makefile.base MODULE=$@ + $(QQ)"$(MAKE)" -C $(PDIR)/porting/nimble/src/ -f $(RIOTPKG)/$(PKG_NAME)/nimble.porting.mk MODULE=$@ nimble_npl_riot: $(QQ)"$(MAKE)" -C $(PDIR)/porting/npl/riot/src/ -f $(RIOTBASE)/Makefile.base MODULE=$@ diff --git a/pkg/nimble/Makefile.dep b/pkg/nimble/Makefile.dep index 7a34d5942a..73f305fe65 100644 --- a/pkg/nimble/Makefile.dep +++ b/pkg/nimble/Makefile.dep @@ -11,7 +11,20 @@ USEMODULE += nimble_riot_contrib # RIOT port USEMODULE += nimble_porting_nimble -USEMODULE += nimble_npl_riot + +# NOTE: this dependency depends on inclusion order, for it to work properly +# mynewt-core should be selected as nimble backend as early as possible, +# i.e. at the application level. +ifneq (,$(filter mynewt-core,$(USEPKG))) + USEMODULE += mynewt-core_os + USEMODULE += mynewt-core_util + USEMODULE += mynewt-core_nrf5x_hal +else + # uwb-% requires mynewt-core so is incompatible with nimble_npl_riot + ifeq (,$(filter uwb%,$(USEPKG))) + USEMODULE += nimble_npl_riot + endif +endif # if nothing else is specified, we build the host and controller ifeq (,$(filter nimble_host nimble_controller,$(USEMODULE))) diff --git a/pkg/nimble/Makefile.include b/pkg/nimble/Makefile.include index b28dad166e..21e4649de3 100644 --- a/pkg/nimble/Makefile.include +++ b/pkg/nimble/Makefile.include @@ -7,7 +7,12 @@ INCLUDES += -I$(RIOTPKG)/nimble/contrib/include INCLUDES += $(NIMIBASE)/nimble/include # include the RIOT NPL headers -INCLUDES += $(NIMIBASE)/porting/npl/riot/include +ifneq (,$(filter nimble_npl_riot,$(USEMODULE))) + INCLUDES += $(NIMIBASE)/porting/npl/riot/include +else + INCLUDES += $(NIMIBASE)/porting/npl/riot/include/npl_syscfg + INCLUDES += -I$(RIOTPKG)/nimble/npl/include +endif INCLUDES += $(NIMIBASE)/porting/nimble/include # include nimble controller headers @@ -15,8 +20,9 @@ ifneq (,$(filter nimble_controller,$(USEMODULE))) INCLUDES += $(NIMIBASE)/nimble/controller/include # set environment CFLAGS += -DNIMBLE_CFG_CONTROLLER=1 - CFLAGS += -DMYNEWT_VAL_OS_CPUTIME_FREQ=32768 - + ifneq (,$(filter nimble_npl_riot,$(USEMODULE))) + CFLAGS += -DMYNEWT_VAL_OS_CPUTIME_FREQ=32768 + endif ifneq (,$(filter nimble_drivers_nrf5x,$(USEMODULE))) INCLUDES += $(NIMIBASE)/nimble/drivers/$(CPU_FAM)/include endif diff --git a/pkg/nimble/nimble.porting.mk b/pkg/nimble/nimble.porting.mk new file mode 100644 index 0000000000..84cb2c3609 --- /dev/null +++ b/pkg/nimble/nimble.porting.mk @@ -0,0 +1,5 @@ +ifneq (,$(filter mynewt-core,$(USEMODULE))) + SRC = nimble_port.c +endif + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/nimble/npl/include/nimble/nimble_npl_os.h b/pkg/nimble/npl/include/nimble/nimble_npl_os.h new file mode 100644 index 0000000000..b223388f2c --- /dev/null +++ b/pkg/nimble/npl/include/nimble/nimble_npl_os.h @@ -0,0 +1,571 @@ +/* + * Copyright (C) 2020 Inria + * + * 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 pkg_nimble + * @{ + * + * @file + * @brief Mynewt-Nimble Porting layer wrappers + * + * @author Hauke Petersen + * @} + */ + +#ifndef NIMBLE_NIMBLE_NPL_OS_H +#define NIMBLE_NIMBLE_NPL_OS_H + +#include +#include +#include "os/os.h" +#include "mcu/mcu.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name BLE NPL layer macros + * @{ + */ +#define BLE_NPL_OS_ALIGNMENT (OS_ALIGNMENT) +#define BLE_NPL_TIME_FOREVER (OS_WAIT_FOREVER) +/** @} */ + +/** + * @brief time type + */ +typedef uint32_t ble_npl_time_t; +/** + * @brief time type + */ +typedef int32_t ble_npl_stime_t; + +/** + * @brief ble_npl event wrapper + */ +struct ble_npl_event { + struct os_event ev; /**< the event */ +}; + +/** + * @brief ble_npl event queue wrapper + */ +struct ble_npl_eventq { + struct os_eventq evq; /**< the event queue */ +}; + +/** + * @brief ble_npl callout wrapper + */ +struct ble_npl_callout { + uint32_t ticks; /**< the callout set timeout */ + struct os_callout co; /**< the callout */ +}; + +/** + * @brief ble_npl mutex wrapper + */ +struct ble_npl_mutex { + struct os_mutex mu; /**< mutex */ +}; + +/** + * @brief ble_npl semaphore wrapper + */ +struct ble_npl_sem { + struct os_sem sem; /**< semaphore */ +}; + +/** + * @brief Not used in RIOT + * + * @return Always true + */ +static inline bool ble_npl_os_started(void) +{ + return true; +} + +/** + * @brief Init a event + * + * @param[in] ev pointer to event to set + * @param[in] fn event callback function + * @param[in] arg event argument + */ +static inline void ble_npl_event_init(struct ble_npl_event *ev, ble_npl_event_fn *fn, + void *arg) +{ + os_event_init(&ev->ev, (os_event_fn *)fn, arg); +} + +/** + * @brief Check if event is in queue + * + * @param[in] ev event to check + * + * @return true if event is queues, false otherwise + */ +static inline bool ble_npl_event_is_queued(struct ble_npl_event *ev) +{ + return os_event_is_queued(&ev->ev); +} + +/** + * @brief Runs an event + * + * @param[in] ev event to run + */ +static inline void *ble_npl_event_get_arg(struct ble_npl_event *ev) +{ + return os_event_get_arg(&ev->ev); +} + +/** + * @brief Set the vent arg + * + * @param[in] ev event + * @param[in] arg arg to set event + */ +static inline void ble_npl_event_set_arg(struct ble_npl_event *ev, void *arg) +{ + os_event_set_arg(&ev->ev, arg); +} + +/** + * @brief Runs an event + * + * @param[in] ev event to run + */ +static inline void ble_npl_event_run(struct ble_npl_event *ev) +{ + os_event_run(&ev->ev); +} + +/** + * @brief Initialize the event queue + * + * @param[in] evq The event queue to initialize + */ +static inline void ble_npl_eventq_init(struct ble_npl_eventq *evq) +{ + os_eventq_init(&evq->evq); +} + +/** + * @brief Check whether the event queue is initialized. + * + * @param[in] evq the event queue to check + */ +static inline int ble_npl_eventq_inited(struct ble_npl_eventq *evq) +{ + return os_eventq_inited(&evq->evq); +} + +/** + * @brief Deinitialize an event queue + * + * @note Not supported in RIOT + * + * @param[in] evq the event queue to deinit + */ +static inline void ble_npl_eventq_deinit(struct ble_npl_eventq *evq) +{ + (void)evq; + /* Can't deinit an eventq in RIOT */ +} + +/** + * @brief Get next event from event queue, blocking. + * + * @param[in] evq the event queue to pull an event from + * @param[in] tmo timeout, NPL_TIME_FOREVER to block, 0 to return immediately + * + * @return the event from the queue + */ +static inline struct ble_npl_event *ble_npl_eventq_get(struct ble_npl_eventq *evq, + ble_npl_time_t tmo) +{ + return (struct ble_npl_event *)os_eventq_get(&evq->evq, tmo); +} + +/** + * @brief Get next event from event queue, non-blocking + * + * @param[in] evq the event queue to pull an event from + * + * @return event from the queue, or NULL if none available. + */ +static inline struct ble_npl_event *ble_npl_eventq_get_no_wait(struct ble_npl_eventq *evq) +{ + return (struct ble_npl_event *)os_eventq_get_no_wait(&evq->evq); +} + +/** + * @brief Put an event on the event queue. + * + * @param[in] evq event queue + * @param[in] ev event to put in queue + */ +static inline void ble_npl_eventq_put(struct ble_npl_eventq *evq, struct ble_npl_event *ev) +{ + os_eventq_put(&evq->evq, &ev->ev); +} + +/** + * @brief Remove an event from the queue. + * + * @param[in] evq event queue to remove the event from + * @param[in] ev event to remove from the queue + */ +static inline void ble_npl_eventq_remove(struct ble_npl_eventq *evq, struct ble_npl_event *ev) +{ + os_eventq_remove(&evq->evq, &ev->ev); +} + +/** + * @brief Gets and runs an event from the queue callback. + * + * @param[in] evq The event queue to pull the item off. + */ +static inline void ble_npl_eventq_run(struct ble_npl_eventq *evq) +{ + os_eventq_run(&evq->evq); +} + +/** + * @brief Check if queue is empty + * + * @param[in] evq the event queue to check + * + * @return true if empty, false otherwise + */ +static inline bool ble_npl_eventq_is_empty(struct ble_npl_eventq *evq) +{ + return os_eventq_is_empty(&evq->evq); +} + +/** + * @brief Initializes a mutex object. + * + * @param[out] mu pre-allocated mutex structure, must not be NULL. + */ +static inline ble_npl_error_t ble_npl_mutex_init(struct ble_npl_mutex *mu) +{ + return (ble_npl_error_t)os_mutex_init(&mu->mu); +} + +/** + * @brief Pend (wait) for a mutex. + * + * @param[in] mu Pointer to mutex. + * @param[in] timeout Timeout, in os ticks. + * A timeout of 0 means do not wait if not available. + * A timeout of OS_TIMEOUT_NEVER means wait forever. + * + * @return ble_npl_error_t + * BLE_NPL_INVALID_PARM mutex passed in was NULL + * BLE_NPL_OK no error + */ +static inline ble_npl_error_t ble_npl_mutex_pend(struct ble_npl_mutex *mu, ble_npl_time_t timeout) +{ + return (ble_npl_error_t)os_mutex_pend(&mu->mu, timeout); +} + +/** + * + * @brief Release a mutex. + * + * @return ble_npl_error_t + * BLE_NPL_INVALID_PARM mutex was NULL + * BLE_NPL_OK no error + */ +static inline ble_npl_error_t ble_npl_mutex_release(struct ble_npl_mutex *mu) +{ + return (ble_npl_error_t)os_mutex_release(&mu->mu); +} + +/** + * @brief Initialize a semaphore + * + * @param[in] sem pointer to semaphore + * @param[in] tokens # of tokens the semaphore should contain initially. + * + * @return ble_npl_error_t + * BLE_NPL_INVALID_PARM Semaphore passed in was NULL. + * BLE_NPL_OK no error. + */ +static inline ble_npl_error_t ble_npl_sem_init(struct ble_npl_sem *sem, uint16_t tokens) +{ + return (ble_npl_error_t)os_sem_init(&sem->sem, tokens); +} + +/** + * @brief Pend (wait) for a semaphore. + * + * @param[in] sem pointer to semaphore. + * @param[in] timeout timeout, in os ticks. + * A timeout of 0 means do not wait if not available. + * A timeout of BLE_NPL_TIMEOUT_NEVER means wait forever. + * + * + * @return ble_npl_error_t + * BLE_NPL_INVALID_PARM semaphore passed in was NULL. + * BLE_NPL_TIMEOUT semaphore was owned by another task and timeout=0 + * BLE_NPL_OK no error + */ +static inline ble_npl_error_t ble_npl_sem_pend(struct ble_npl_sem *sem, ble_npl_time_t timeout) +{ + return (ble_npl_error_t)os_sem_pend(&sem->sem, timeout); +} + +/** + * @brief Release a semaphore. + * + * @param[in] sem pointer to the semaphore to be released + * + * @return ble_npl_error_t + * BLE_NPL_INVALID_PARM semaphore passed in was NULL. + * BLE_NPL_OK no error + */ +static inline ble_npl_error_t ble_npl_sem_release(struct ble_npl_sem *sem) +{ + return (ble_npl_error_t)os_sem_release(&sem->sem); +} + +/** + * @brief Get current semaphore's count + */ +static inline uint16_t ble_npl_sem_get_count(struct ble_npl_sem *sem) +{ + return os_sem_get_count(&sem->sem); +} + +/** + * @brief Initialize a callout. + * + * Callouts are used to schedule events in the future onto an event + * queue. Callout timers are scheduled using the ble_npl_callout_reset() + * function. When the timer expires, an event is posted to the event + * queue specified in ble_npl_callout_init(). The event argument given here + * is posted in the ev_arg field of that event. + * + * @param[out] c callout to initialize + * @param[in] q event queue to queue event in + * @param[in] e_cb callback function + * @param[in] e_arg callback function argument + */ +static inline void ble_npl_callout_init(struct ble_npl_callout *c, struct ble_npl_eventq *q, + ble_npl_event_fn *e_cb, void *e_arg) +{ + os_callout_init(&c->co, &q->evq, (os_event_fn *)e_cb, e_arg); +} + +/** + * @brief Reset the callout to fire off in 'ticks' ticks. + * + * @param[in] c callout to reset + * @param[in] ticks number of ticks to wait before posting an event + * + * @return 0 on success, non-zero on failure + */ +static inline ble_npl_error_t ble_npl_callout_reset(struct ble_npl_callout *c, ble_npl_time_t ticks) +{ + uint32_t state = os_hw_enter_critical(); + + c->ticks = ztimer_now(ZTIMER_MSEC) + ticks; + os_callout_reset(&c->co, ticks); + os_hw_exit_critical(state); + return BLE_NPL_OK; +} + +/** + * @brief Stops the callout from firing. + * + * @param[in] c the callout to stop + */ +static inline void ble_npl_callout_stop(struct ble_npl_callout *c) +{ + os_callout_stop(&c->co); +} + +/** + * @brief Check if callout is active + * + * @param[in] c the callout to check + * + * @return true if active, false otherwise + */ +static inline bool ble_npl_callout_is_active(struct ble_npl_callout *c) +{ + return ztimer_is_set(ZTIMER_MSEC, &c->co.timer); +} + +/** + * @brief Get the callout set ticks + * + * @param[in] co the callout to check + */ +static inline ble_npl_time_t ble_npl_callout_get_ticks(struct ble_npl_callout *co) +{ + return co->ticks; +} + +/** + * @brief Get the remaining ticks for callout expire + * + * @param[in] co the callout to check + * @param[in] time ignored + * + * @return remaining ticks + */ +static inline ble_npl_time_t ble_npl_callout_remaining_ticks(struct ble_npl_callout *co, + ble_npl_time_t time) +{ + (void)time; + ztimer_now_t now = ztimer_now(ZTIMER_MSEC); + return (ble_npl_time_t)(co->ticks - now); +} + +/** + * @brief Set the callout event argument + * + * @param[in] co the callout + * @param[in] arg callback function argument + */ +static inline void ble_npl_callout_set_arg(struct ble_npl_callout *co, void *arg) +{ + co->co.c_ev.arg = arg; +} + +/** + * @brief Returns the low 32 bits of cputime. + * + * @return uint32_t The lower 32 bits of cputime + */ +static inline ble_npl_time_t ble_npl_time_get(void) +{ + return os_time_get(); +} + +/** + * @brief Converts the given number of milliseconds into cputime ticks. + * + * @param[in] ms The number of milliseconds to convert to ticks + * @param[out] out_ticks The number of ticks corresponding to 'ms' + * + * @return ble_npl_error_t BLE_NPL_OK - no error + */ +static inline ble_npl_error_t ble_npl_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks) +{ + return (ble_npl_error_t)os_time_ms_to_ticks(ms, out_ticks); +} + +/** + * @brief Convert the given number of ticks into milliseconds. + * + * @param[in] ticks The number of ticks to convert to milliseconds. + * @param[out] out_ms The converted milliseconds from 'ticks' + * + * @return ble_npl_error_t BLE_NPL_OK - no error + */ +static inline ble_npl_error_t ble_npl_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms) +{ + return (ble_npl_error_t)os_time_ticks_to_ms(ticks, out_ms); +} + +/** + * @brief Converts the given number of milliseconds into cputime ticks. + * + * @param[in] ms The number of milliseconds to convert to ticks + * + * @return uint32_t The number of ticks corresponding to 'ms' + */ +static inline ble_npl_time_t ble_npl_time_ms_to_ticks32(uint32_t ms) +{ + return os_time_ms_to_ticks32(ms); +} + +/** + * @brief Convert the given number of ticks into milliseconds. + * + * @param[in] ticks The number of ticks to convert to milliseconds. + * + * @return uint32_t The number of milliseconds corresponding to 'ticks' + */ +static inline ble_npl_time_t ble_npl_time_ticks_to_ms32(ble_npl_time_t ticks) +{ + return os_time_ticks_to_ms32(ticks); +} +/** + * @brief Wait until the number of ticks has elapsed, BLOICKING. + * + * @param[in] ticks The number of ticks to wait. + */ +static inline void ble_npl_time_delay(ble_npl_time_t ticks) +{ + return os_time_delay(ticks); +} + +/** + * @brief Disable ISRs + * + * @return current isr context + */ +static inline uint32_t ble_npl_hw_enter_critical(void) +{ + return os_hw_enter_critical(); +} + +/** + * @brief Restores ISR context + * + * @param[in] ctx ISR context to restore. + */ +static inline void ble_npl_hw_exit_critical(uint32_t ctx) +{ + os_hw_exit_critical(ctx); +} + +/** + * @brief Check if is in critical section + * + * @return true, if in critical section, false otherwise + */ +static inline bool ble_npl_hw_is_in_critical(void) +{ + return os_hw_is_in_critical(); +} + +/** + * @brief Return current thread PID + * + * @return PID + */ +static inline void *ble_npl_get_current_task_id(void) +{ + return (void *)(uint32_t)thread_getpid(); +} + +/** + * @brief Set nrf5x radio ISR callback + * + * @param[in] irqn IRQ number + * @param[in] addr the ISR callback + */ +static inline void ble_npl_hw_set_isr(int irqn, void (*addr)(void)) +{ + nrf5x_hw_set_isr(irqn, addr); +} + +#ifdef __cplusplus +} +#endif + +#endif /* NIMBLE_NIMBLE_NPL_OS_H */ diff --git a/pkg/nimble/patches/0001-porting-nimble-src-nimble_port-riot-initializes-time.patch b/pkg/nimble/patches/0001-porting-nimble-src-nimble_port-riot-initializes-time.patch new file mode 100644 index 0000000000..2649714097 --- /dev/null +++ b/pkg/nimble/patches/0001-porting-nimble-src-nimble_port-riot-initializes-time.patch @@ -0,0 +1,27 @@ +From 395209627ba495309098459173d40d490f680b8b Mon Sep 17 00:00:00 2001 +From: Francisco Molina +Date: Mon, 19 Apr 2021 15:47:49 +0200 +Subject: [PATCH] porting/nimble/src/nimble_port: riot initializes timers + +--- + porting/nimble/src/nimble_port.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/porting/nimble/src/nimble_port.c b/porting/nimble/src/nimble_port.c +index 484e3799..139179e1 100644 +--- a/porting/nimble/src/nimble_port.c ++++ b/porting/nimble/src/nimble_port.c +@@ -45,8 +45,10 @@ nimble_port_init(void) + + #if NIMBLE_CFG_CONTROLLER + ble_hci_ram_init(); ++#ifndef MODULE_MYNEWT_CORE + hal_timer_init(5, NULL); + os_cputime_init(32768); ++#endif + ble_ll_init(); + #endif + } +-- +2.28.0 + diff --git a/pkg/nimble/patches/0002-porting-npl-riot-add-namespaced-syscfg-symlink.patch b/pkg/nimble/patches/0002-porting-npl-riot-add-namespaced-syscfg-symlink.patch new file mode 100644 index 0000000000..f18026b948 --- /dev/null +++ b/pkg/nimble/patches/0002-porting-npl-riot-add-namespaced-syscfg-symlink.patch @@ -0,0 +1,21 @@ +From 40012b6fad9772cb38547abff42149b7ce1ca8d1 Mon Sep 17 00:00:00 2001 +From: Francisco Molina +Date: Mon, 5 Jul 2021 14:38:12 +0200 +Subject: [PATCH 2/2] porting/npl/riot: add namespaced syscfg symlink + +--- + porting/npl/riot/include/npl_syscfg/npl_sycfg.h | 1 + + 1 file changed, 1 insertion(+) + create mode 120000 porting/npl/riot/include/npl_syscfg/npl_sycfg.h + +diff --git a/porting/npl/riot/include/npl_syscfg/npl_sycfg.h b/porting/npl/riot/include/npl_syscfg/npl_sycfg.h +new file mode 120000 +index 00000000..53c55a90 +--- /dev/null ++++ b/porting/npl/riot/include/npl_syscfg/npl_sycfg.h +@@ -0,0 +1 @@ ++../syscfg/syscfg.h +\ No newline at end of file +-- +2.28.0 + diff --git a/pkg/uwb-core/Makefile b/pkg/uwb-core/Makefile index 0e03c05e7a..70b987aeeb 100644 --- a/pkg/uwb-core/Makefile +++ b/pkg/uwb-core/Makefile @@ -1,10 +1,11 @@ PKG_NAME=uwb-core PKG_URL=https://github.com/Decawave/uwb-core -PKG_VERSION=8ffba63755a932a89d841872ce5bdf35b9c78777 +PKG_VERSION=66f468659ec3353cf7fd6f2bd14f3a6cef397f4e PKG_LICENSE=Apache-2.0 include $(RIOTBASE)/pkg/pkg.mk +CFLAGS += -Wno-enum-compare CFLAGS += -Wno-implicit-int CFLAGS += -Wno-int-conversion CFLAGS += -Wno-strict-prototypes diff --git a/pkg/uwb-core/Makefile.dep b/pkg/uwb-core/Makefile.dep index d23cc1dcab..b4f0c0355a 100644 --- a/pkg/uwb-core/Makefile.dep +++ b/pkg/uwb-core/Makefile.dep @@ -3,9 +3,6 @@ USEMODULE += uwb-core_contrib DEFAULT_MODULE += auto_init_uwb-core -USEMODULE += sema -USEMODULE += event_callback -USEMODULE += xtimer USEMODULE += fmt FEATURES_REQUIRED += periph_gpio_irq @@ -25,12 +22,17 @@ ifneq (,$(filter uwb-core_uwbcfg,$(USEMODULE))) USEMODULE += uwb-core_config endif +ifneq (,$(filter uwb-core_dpl,$(USEMODULE))) + USEPKG += mynewt-core + USEMODULE += mynewt-core_os + ifneq (,$(filter nrf%,$(CPU))) + USEMODULE += mynewt-core_nrf5x_hal + endif +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 # libraries these introduce additional compilation issues that have not # been addressed in this port FEATURES_BLACKLIST += arch_native - -# LLVM ARM shows issues with missing definitions for stdatomic -TOOLCHAINS_BLACKLIST += llvm diff --git a/pkg/uwb-core/Makefile.include b/pkg/uwb-core/Makefile.include index 6eb2f5f9ca..95a7b949c0 100644 --- a/pkg/uwb-core/Makefile.include +++ b/pkg/uwb-core/Makefile.include @@ -14,9 +14,7 @@ INCLUDES += -I$(PKGDIRBASE)/uwb-core/hw/drivers/uwb/include/ \ -I$(RIOTPKG)/uwb-core/include \ # -DIRS += $(RIOTPKG)/uwb-core/dpl \ - $(RIOTPKG)/uwb-core/contrib \ - # +PSEUDOMODULES += uwb-core_dpl -# A cflag to indicate in pkg code that we are building for RIOT -CFLAGS += -DRIOT +DIRS += $(RIOTPKG)/uwb-core/contrib \ + # diff --git a/pkg/uwb-core/contrib/uwb_core.c b/pkg/uwb-core/contrib/uwb_core.c index bc275d325c..dfde98d1dc 100644 --- a/pkg/uwb-core/contrib/uwb_core.c +++ b/pkg/uwb-core/contrib/uwb_core.c @@ -17,13 +17,14 @@ * @} */ -#include - #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 @@ -35,11 +36,10 @@ static char _stack_uwb_core[UWB_CORE_STACKSIZE]; static event_queue_t _queue; -atomic_uint dpl_in_critical = 0; - static void *_uwb_core_thread(void *arg) { (void)arg; + event_queue_init(&_queue); event_loop(&_queue); /* never reached */ diff --git a/pkg/uwb-core/contrib/uwb_core_init.c b/pkg/uwb-core/contrib/uwb_core_init.c index 62a84093de..d6b8ad0815 100644 --- a/pkg/uwb-core/contrib/uwb_core_init.c +++ b/pkg/uwb-core/contrib/uwb_core_init.c @@ -45,35 +45,35 @@ void uwb_core_init(void) uwb_dw1000_set_buffs(&dev, _dw1000_tx_buffer, _dw1000_rx_buffer); /* setup dw1000 device */ uwb_dw1000_setup(&dev, (void *) &dw1000_params[0]); - /* this will start a thread handling dw1000 device*/ + /* this will start a thread handling dw1000 device */ uwb_dw1000_config_and_start(&dev); /* init uwb pkg's */ - if (IS_USED(MODULE_UWB_CORE_RNG)) { - extern void uwb_rng_pkg_init(void); - uwb_rng_pkg_init(); - } +#if IS_USED(MODULE_UWB_CORE_RNG) + 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(); - } +#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_RNG)) { - twr_ss_pkg_init(); - } - if (IS_USED(MODULE_UWB_CORE_RNG)) { - twr_ss_ack_pkg_init(); - } - if (IS_USED(MODULE_UWB_CORE_RNG)) { - twr_ss_ext_pkg_init(); - } - if (IS_USED(MODULE_UWB_CORE_RNG)) { - twr_ds_pkg_init(); - } - if (IS_USED(MODULE_UWB_CORE_RNG)) { - twr_ds_ext_pkg_init(); - } +#if IS_USED(MODULE_UWB_CORE_TWR_SS) + twr_ss_pkg_init(); +#endif +#if IS_USED(MODULE_UWB_CORE_TWR_SS_ACK) + twr_ss_ack_pkg_init(); +#endif +#if IS_USED(MODULE_UWB_CORE_TWR_SS_EXT) + twr_ss_ext_pkg_init(); +#endif +#if IS_USED(MODULE_UWB_CORE_TWR_DS) + twr_ds_pkg_init(); +#endif +#if IS_USED(MODULE_UWB_CORE_TWR_DS_EXT) + twr_ds_ext_pkg_init(); +#endif } diff --git a/pkg/uwb-core/dpl/Makefile b/pkg/uwb-core/dpl/Makefile deleted file mode 100644 index 6f5935a4a6..0000000000 --- a/pkg/uwb-core/dpl/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -MODULE = uwb-core_dpl - -include $(RIOTBASE)/Makefile.base diff --git a/pkg/uwb-core/dpl/dpl_callout.c b/pkg/uwb-core/dpl/dpl_callout.c deleted file mode 100644 index 232eaead62..0000000000 --- a/pkg/uwb-core/dpl/dpl_callout.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2020 Inria - * - * 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 pkg_uwb_core - * @{ - * - * @file - * @brief uwb-core DPL (Decawave Porting Layer) callout - * - * @author Francisco Molina - * @} - */ - -#include - -#include "xtimer.h" -#include "dpl/dpl_callout.h" - -static void _dpl_callout_timer_cb(void* arg) -{ - struct dpl_callout *c = (struct dpl_callout *) arg; - assert(c); - - /* post the event if there is a queue, otherwise call the callback - here */ - if (c->c_q) { - dpl_eventq_put(c->c_q, &c->c_e); - } else { - c->c_e.e.callback(&c->c_e); - } -} - -void dpl_callout_init(struct dpl_callout *c, struct dpl_eventq *q, - dpl_event_fn *e_cb, void *e_arg) -{ - dpl_event_init(&c->c_e, e_cb, e_arg); - c->c_q = q; - c->timer.callback = _dpl_callout_timer_cb; - c->timer.arg = (void*) c; -} - -dpl_error_t dpl_callout_reset(struct dpl_callout *c, dpl_time_t ticks) -{ - xtimer_ticks32_t val = {.ticks32 = ticks}; - xtimer_set(&(c->timer), xtimer_usec_from_ticks(val)); - return DPL_OK; -} - -void dpl_callout_stop(struct dpl_callout *c) -{ - xtimer_remove(&(c->timer)); -} diff --git a/pkg/uwb-core/dpl/dpl_sem.c b/pkg/uwb-core/dpl/dpl_sem.c deleted file mode 100644 index a6e2c39437..0000000000 --- a/pkg/uwb-core/dpl/dpl_sem.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2020 Inria - * - * 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 pkg_uwb_core - * @{ - * - * @file - * @brief Decawave Porting Layer semaphore RIOT wrapper - * - * @author Francisco Molina - * @} - */ - -#include - -#include "irq.h" -#include "dpl/dpl_sem.h" - -dpl_error_t dpl_sem_init(struct dpl_sem *sem, uint16_t tokens) -{ - if (!sem) { - return DPL_INVALID_PARAM; - } - - sema_create(&sem->sema, tokens); - return DPL_OK; -} - -dpl_error_t dpl_sem_release(struct dpl_sem *sem) -{ - int ret; - - if (!sem) { - return DPL_INVALID_PARAM; - } - - ret = sema_post(&sem->sema); - - return (ret) ? DPL_ERROR : DPL_OK; -} - -uint16_t dpl_sem_get_count(struct dpl_sem *sem) -{ - unsigned state = irq_disable(); - unsigned int value = sem->sema.value; - irq_restore(state); - return value; -} - -dpl_error_t dpl_sem_pend(struct dpl_sem *sem, dpl_time_t timeout) -{ - int ret = sema_wait_timed(&sem->sema, timeout); - return (ret) ? DPL_ERROR : DPL_OK; -} diff --git a/pkg/uwb-core/include/dpl/dpl.h b/pkg/uwb-core/include/dpl/dpl.h index 79612a6140..309ea1343b 100644 --- a/pkg/uwb-core/include/dpl/dpl.h +++ b/pkg/uwb-core/include/dpl/dpl.h @@ -32,7 +32,6 @@ #include "dpl/dpl_tasks.h" #include "dpl/dpl_time.h" #include "kernel_defines.h" - #ifdef __cplusplus extern "C" { #endif diff --git a/pkg/uwb-core/include/dpl/dpl_callout.h b/pkg/uwb-core/include/dpl/dpl_callout.h index 5759522fc7..b524238347 100644 --- a/pkg/uwb-core/include/dpl/dpl_callout.h +++ b/pkg/uwb-core/include/dpl/dpl_callout.h @@ -23,23 +23,17 @@ #ifndef DPL_DPL_CALLOUT_H #define DPL_DPL_CALLOUT_H -#include "xtimer.h" - -#include "dpl/dpl_types.h" -#include "dpl/dpl_eventq.h" -#include "dpl/dpl_error.h" +#include "os/os_callout.h" #ifdef __cplusplus extern "C" { #endif /** - * @brief callout structure + * @brief dpl callout wrapper */ struct dpl_callout { - xtimer_t timer; /**< timer */ - struct dpl_event c_e; /**< callout event */ - struct dpl_eventq *c_q; /**< callout event queue */ + struct os_callout co; /**< the callout */ }; /** @@ -56,8 +50,11 @@ struct dpl_callout { * @param[in] e_cb callback function * @param[in] e_arg callback function argument */ -void dpl_callout_init(struct dpl_callout *c, struct dpl_eventq *q, - dpl_event_fn *e_cb, void *e_arg); +static inline void dpl_callout_init(struct dpl_callout *c, struct dpl_eventq *q, + dpl_event_fn *e_cb, void *e_arg) +{ + os_callout_init(&c->co, &q->evq, (os_event_fn *) e_cb, e_arg); +} /** * @brief Reset the callout to fire off in 'ticks' ticks. @@ -67,14 +64,20 @@ void dpl_callout_init(struct dpl_callout *c, struct dpl_eventq *q, * * @return 0 on success, non-zero on failure */ -dpl_error_t dpl_callout_reset(struct dpl_callout *c, dpl_time_t ticks); +static inline dpl_error_t dpl_callout_reset(struct dpl_callout *c, dpl_time_t ticks) +{ + return (dpl_error_t) os_callout_reset(&c->co, ticks); +} /** * @brief Stops the callout from firing. * * @param[in] c the callout to stop */ -void dpl_callout_stop(struct dpl_callout *c); +static inline void dpl_callout_stop(struct dpl_callout *c) +{ + os_callout_stop(&c->co); +} #ifdef __cplusplus } diff --git a/pkg/uwb-core/include/dpl/dpl_cputime.h b/pkg/uwb-core/include/dpl/dpl_cputime.h index e5ee6b27f1..e299fbd429 100644 --- a/pkg/uwb-core/include/dpl/dpl_cputime.h +++ b/pkg/uwb-core/include/dpl/dpl_cputime.h @@ -24,10 +24,7 @@ extern "C" { #endif -#include - -#include "xtimer.h" -#include "hal/hal_timer.h" +#include "os/os_cputime.h" /** * Returns the low 32 bits of cputime. @@ -36,7 +33,7 @@ extern "C" { */ static inline uint32_t dpl_cputime_get32(void) { - return xtimer_now().ticks32; + return os_cputime_get32(); } /** @@ -48,7 +45,7 @@ static inline uint32_t dpl_cputime_get32(void) */ static inline uint32_t dpl_cputime_usecs_to_ticks(uint32_t usecs) { - return xtimer_ticks_from_usec(usecs).ticks32; + return os_cputime_usecs_to_ticks(usecs); } /** @@ -60,8 +57,7 @@ static inline uint32_t dpl_cputime_usecs_to_ticks(uint32_t usecs) */ static inline uint32_t dpl_cputime_ticks_to_usecs(uint32_t ticks) { - xtimer_ticks32_t val = {.ticks32 = ticks}; - return xtimer_usec_from_ticks(val); + return os_cputime_ticks_to_usecs(ticks); } /** @@ -71,8 +67,7 @@ static inline uint32_t dpl_cputime_ticks_to_usecs(uint32_t ticks) */ static inline void dpl_cputime_delay_ticks(uint32_t ticks) { - xtimer_ticks32_t val = {.ticks32 = ticks}; - xtimer_tsleep32((xtimer_ticks32_t) val); + os_cputime_delay_ticks(ticks); } /** @@ -82,7 +77,7 @@ static inline void dpl_cputime_delay_ticks(uint32_t ticks) */ static inline void dpl_cputime_delay_usecs(uint32_t usecs) { - xtimer_usleep(usecs); + os_cputime_delay_usecs(usecs); } /** @@ -95,8 +90,7 @@ static inline void dpl_cputime_delay_usecs(uint32_t usecs) static inline void dpl_cputime_timer_init(struct hal_timer *timer, hal_timer_cb fp, void *arg) { - timer->timer.callback = fp; - timer->timer.arg = arg; + os_cputime_timer_init(timer, fp, arg); } /** @@ -107,15 +101,14 @@ static inline void dpl_cputime_timer_init(struct hal_timer *timer, hal_timer_cb * * @param timer Pointer to timer to start. Cannot be NULL. * @param cputime The cputime at which the timer should expire. - * + *time * @return int 0 on success; EINVAL if timer already started or timer struct * invalid * */ static inline int dpl_cputime_timer_start(struct hal_timer *timer, uint32_t cputime) { - xtimer_set(&timer->timer, xtimer_now_usec() + cputime); - return 0; + return os_cputime_timer_start(timer, cputime); } /** @@ -132,13 +125,7 @@ static inline int dpl_cputime_timer_start(struct hal_timer *timer, uint32_t cput */ static inline int dpl_cputime_timer_relative(struct hal_timer *timer, uint32_t usecs) { - uint32_t now = xtimer_now_usec(); - if (now > usecs) { - xtimer_set(&timer->timer, now); - } else { - xtimer_set(&timer->timer, 0); - } - return 0; + return os_cputime_timer_relative(timer, usecs); } /** @@ -152,7 +139,7 @@ static inline int dpl_cputime_timer_relative(struct hal_timer *timer, uint32_t u */ static inline void dpl_cputime_timer_stop(struct hal_timer *timer) { - xtimer_remove(&timer->timer); + os_cputime_timer_stop(timer); } #ifdef __cplusplus diff --git a/pkg/uwb-core/include/dpl/dpl_error.h b/pkg/uwb-core/include/dpl/dpl_error.h index 212a32efed..24c46e60ea 100644 --- a/pkg/uwb-core/include/dpl/dpl_error.h +++ b/pkg/uwb-core/include/dpl/dpl_error.h @@ -24,29 +24,31 @@ extern "C" { #endif +#include "os/os_error.h" + /** * @brief DPL error types */ enum dpl_error { - DPL_OK = 0, - DPL_ENOMEM = 1, - DPL_EINVAL = 2, - DPL_INVALID_PARAM = 3, - DPL_MEM_NOT_ALIGNED = 4, - DPL_BAD_MUTEX = 5, - DPL_TIMEOUT = 6, - DPL_ERR_IN_ISR = 7, - DPL_ERR_PRIV = 8, - DPL_OS_NOT_STARTED = 9, - DPL_ENOENT = 10, - DPL_EBUSY = 11, - DPL_ERROR = 12, + DPL_OK = OS_OK, + DPL_ENOMEM = OS_ENOMEM, + DPL_EINVAL = OS_EINVAL, + DPL_INVALID_PARAM = OS_INVALID_PARM, + DPL_MEM_NOT_ALIGNED = OS_MEM_NOT_ALIGNED, + DPL_BAD_MUTEX = OS_BAD_MUTEX, + DPL_TIMEOUT = OS_TIMEOUT, + DPL_ERR_IN_ISR = OS_ERR_IN_ISR, + DPL_ERR_PRIV = OS_ERR_PRIV, + DPL_OS_NOT_STARTED = OS_NOT_STARTED, + DPL_ENOENT = OS_ENOENT, + DPL_EBUSY = OS_EBUSY, + DPL_ERROR = OS_ERROR , }; /** - * @brief dep error type + * @brief dpl error type */ -typedef enum dpl_error dpl_error_t; +typedef os_error_t dpl_error_t; #ifdef __cplusplus } diff --git a/pkg/uwb-core/include/dpl/dpl_eventq.h b/pkg/uwb-core/include/dpl/dpl_eventq.h index 5244879339..3108acde82 100644 --- a/pkg/uwb-core/include/dpl/dpl_eventq.h +++ b/pkg/uwb-core/include/dpl/dpl_eventq.h @@ -22,8 +22,8 @@ #include +#include "os/os_eventq.h" #include "uwb_core.h" -#include "event/callback.h" #ifdef __cplusplus extern "C" { @@ -32,18 +32,15 @@ extern "C" { /** * @brief dpl event wrapper */ -struct dpl_event -{ - event_callback_t e; /**< the event callback */ - void *arg; /**< the event argument */ +struct dpl_event { + struct os_event ev; /**< the envent */ }; /** * @brief dpl event queue wrapper */ -struct dpl_eventq -{ - event_queue_t q; /**< the event queue */ +struct dpl_eventq { + struct os_eventq evq; /**< the event queue */ }; /** @@ -61,13 +58,7 @@ typedef void dpl_event_fn(struct dpl_event *ev); static inline void dpl_event_init(struct dpl_event *ev, dpl_event_fn * fn, void *arg) { - /* - * Need to clear list_node manually since init function below does not do - * this. - */ - ev->e.super.list_node.next = NULL; - event_callback_init(&ev->e, (void(*)(void *))fn, ev); - ev->arg = arg; + os_event_init(&ev->ev, (os_event_fn*) fn, arg); } /** @@ -79,7 +70,7 @@ static inline void dpl_event_init(struct dpl_event *ev, dpl_event_fn * fn, */ static inline bool dpl_event_is_queued(struct dpl_event *ev) { - return (ev->e.super.list_node.next != NULL); + return os_event_is_queued(&ev->ev); } /** @@ -89,7 +80,7 @@ static inline bool dpl_event_is_queued(struct dpl_event *ev) */ static inline void *dpl_event_get_arg(struct dpl_event *ev) { - return ev->arg; + return os_event_get_arg(&ev->ev); } /** @@ -100,7 +91,7 @@ static inline void *dpl_event_get_arg(struct dpl_event *ev) */ static inline void dpl_event_set_arg(struct dpl_event *ev, void *arg) { - ev->arg = arg; + os_event_set_arg(&ev->ev, arg); } /** @@ -110,7 +101,7 @@ static inline void dpl_event_set_arg(struct dpl_event *ev, void *arg) */ static inline void dpl_event_run(struct dpl_event *ev) { - ev->e.super.handler(&ev->e.super); + os_event_run(&ev->ev); } /** @@ -120,7 +111,7 @@ static inline void dpl_event_run(struct dpl_event *ev) */ static inline void dpl_eventq_init(struct dpl_eventq *evq) { - event_queue_init_detached(&evq->q); + os_eventq_init(&evq->evq); } /** @@ -130,7 +121,7 @@ static inline void dpl_eventq_init(struct dpl_eventq *evq) */ static inline int dpl_eventq_inited(struct dpl_eventq *evq) { - return evq->q.waiter != NULL; + return os_eventq_inited(&evq->evq); } /** @@ -155,11 +146,7 @@ static inline void dpl_eventq_deinit(struct dpl_eventq *evq) */ static inline struct dpl_event * dpl_eventq_get(struct dpl_eventq *evq) { - if (evq->q.waiter == NULL) { - event_queue_claim(&evq->q); - } - - return (struct dpl_event *) event_wait(&evq->q); + return (struct dpl_event *) os_eventq_get(&evq->evq, DPL_WAIT_FOREVER); } /** @@ -169,11 +156,7 @@ static inline struct dpl_event * dpl_eventq_get(struct dpl_eventq *evq) */ static inline struct dpl_event * dpl_eventq_get_no_wait(struct dpl_eventq *evq) { - if (evq->q.waiter == NULL) { - event_queue_claim(&evq->q); - } - - return (struct dpl_event *) event_get(&evq->q); + return (struct dpl_event *) os_eventq_get_no_wait(&evq->evq); } /** @@ -184,7 +167,7 @@ static inline struct dpl_event * dpl_eventq_get_no_wait(struct dpl_eventq *evq) */ static inline void dpl_eventq_put(struct dpl_eventq *evq, struct dpl_event *ev) { - event_post(&evq->q, &ev->e.super); + os_eventq_put(&evq->evq, &ev->ev); } /** @@ -195,7 +178,7 @@ static inline void dpl_eventq_put(struct dpl_eventq *evq, struct dpl_event *ev) */ static inline void dpl_eventq_remove(struct dpl_eventq *evq, struct dpl_event *ev) { - event_cancel(&evq->q, &ev->e.super); + os_eventq_remove(&evq->evq, &ev->ev); } /** @@ -205,8 +188,7 @@ static inline void dpl_eventq_remove(struct dpl_eventq *evq, struct dpl_event *e */ static inline void dpl_eventq_run(struct dpl_eventq *evq) { - struct dpl_event *ev = dpl_eventq_get(evq); - dpl_event_run(ev); + os_eventq_run(&evq->evq); } /** @@ -218,7 +200,7 @@ static inline void dpl_eventq_run(struct dpl_eventq *evq) */ static inline bool dpl_eventq_is_empty(struct dpl_eventq *evq) { - return clist_count(&(evq->q.event_list)) == 0; + return os_eventq_is_empty(&evq->evq); } /** @@ -231,7 +213,7 @@ static inline bool dpl_eventq_is_empty(struct dpl_eventq *evq) */ static inline struct dpl_eventq * dpl_eventq_dflt_get(void) { - return (struct dpl_eventq*) uwb_core_get_eventq(); + return (struct dpl_eventq *) uwb_core_get_eventq(); } #ifdef __cplusplus diff --git a/pkg/uwb-core/include/dpl/dpl_mutex.h b/pkg/uwb-core/include/dpl/dpl_mutex.h index 667a5201d7..cb38b4f7db 100644 --- a/pkg/uwb-core/include/dpl/dpl_mutex.h +++ b/pkg/uwb-core/include/dpl/dpl_mutex.h @@ -20,10 +20,7 @@ #ifndef DPL_DPL_MUTEX_H #define DPL_DPL_MUTEX_H -#include "dpl_types.h" -#include "dpl_error.h" - -#include "mutex.h" +#include "os/os_mutex.h" #ifdef __cplusplus extern "C" { @@ -33,7 +30,7 @@ extern "C" { * @brief dpl mutex wrapper */ struct dpl_mutex { - mutex_t mutex; /**< the mutex */ + struct os_mutex mu; /**< the mutex */ }; /** @@ -41,7 +38,10 @@ struct dpl_mutex { * * @param[out] mu pre-allocated mutex structure, must not be NULL. */ -dpl_error_t dpl_mutex_init(struct dpl_mutex *mu); +static inline dpl_error_t dpl_mutex_init(struct dpl_mutex *mu) +{ + return (dpl_error_t) os_mutex_init(&mu->mu); +} /** * @brief Pend (wait) for a mutex. @@ -55,7 +55,10 @@ dpl_error_t dpl_mutex_init(struct dpl_mutex *mu); * DPL_INVALID_PARM mutex passed in was NULL * DPL_OK no error */ -dpl_error_t dpl_mutex_pend(struct dpl_mutex *mu, dpl_time_t timeout); +static inline dpl_error_t dpl_mutex_pend(struct dpl_mutex *mu, dpl_time_t timeout) +{ + return (dpl_error_t) os_mutex_pend(&mu->mu, timeout); +} /** * @@ -65,7 +68,10 @@ dpl_error_t dpl_mutex_pend(struct dpl_mutex *mu, dpl_time_t timeout); * DPL_INVALID_PARM mutex was NULL * DPL_OK no error */ -dpl_error_t dpl_mutex_release(struct dpl_mutex *mu); +static inline dpl_error_t dpl_mutex_release(struct dpl_mutex *mu) +{ + return (dpl_error_t) os_mutex_release(&mu->mu); +} #ifdef __cplusplus } diff --git a/pkg/uwb-core/include/dpl/dpl_os.h b/pkg/uwb-core/include/dpl/dpl_os.h index 62d703a18a..adfdcd5b99 100644 --- a/pkg/uwb-core/include/dpl/dpl_os.h +++ b/pkg/uwb-core/include/dpl/dpl_os.h @@ -11,7 +11,7 @@ * @{ * * @file - * @brief uwb-core DPL (Decawave Porting Layer) error types + * @brief uwb-core DPL (Decawave Porting Layer) os abstraction layer * * @author Francisco Molina * @} @@ -20,12 +20,7 @@ #ifndef DPL_DPL_OS_H #define DPL_DPL_OS_H -#include -#include -#include - -#include "irq.h" -#include "dpl/dpl_types.h" +#include "os/os.h" #ifdef __cplusplus extern "C" { @@ -35,20 +30,15 @@ extern "C" { * @name Entering and exiting critical section defines * @{ */ -#define DPL_ENTER_CRITICAL(_sr) (_sr = dpl_hw_enter_critical()) -#define DPL_EXIT_CRITICAL(_sr) (dpl_hw_exit_critical(_sr)) -#define DPL_ASSERT_CRITICAL() assert(dpl_hw_is_in_critical()) +#define DPL_ENTER_CRITICAL(_sr) (_sr = os_hw_enter_critical()) +#define DPL_EXIT_CRITICAL(_sr) (os_hw_exit_critical(_sr)) +#define DPL_ASSERT_CRITICAL() assert(os_hw_is_in_critical()) /** @} */ -/** - * @brief variable to check if ISR are disabled - */ -extern atomic_uint dpl_in_critical; - /** * @brief CPU status register */ -typedef uint32_t dpl_sr_t; +typedef os_sr_t dpl_sr_t; /** * @brief Disable ISRs @@ -57,10 +47,7 @@ typedef uint32_t dpl_sr_t; */ static inline uint32_t dpl_hw_enter_critical(void) { - uint32_t ctx = irq_disable(); - unsigned int count = atomic_load(&dpl_in_critical); - atomic_store(&dpl_in_critical, count + 1); - return ctx; + return os_hw_enter_critical(); } /** @@ -70,9 +57,7 @@ static inline uint32_t dpl_hw_enter_critical(void) */ static inline void dpl_hw_exit_critical(uint32_t ctx) { - unsigned int count = atomic_load(&dpl_in_critical); - atomic_store(&dpl_in_critical, count - 1); - irq_restore((unsigned)ctx); + os_hw_exit_critical(ctx); } /** @@ -82,12 +67,7 @@ static inline void dpl_hw_exit_critical(uint32_t ctx) */ static inline bool dpl_hw_is_in_critical(void) { - /* - * XXX Currently RIOT does not support an API for finding out if interrupts - * are currently disabled, hence in a critical section in this context. - * So for now, we use this global variable to keep this state for us. - */ - return (atomic_load(&dpl_in_critical) > 0); + return os_hw_is_in_critical(); } #ifdef __cplusplus diff --git a/pkg/uwb-core/include/dpl/dpl_sem.h b/pkg/uwb-core/include/dpl/dpl_sem.h index 4184199556..56d6713021 100644 --- a/pkg/uwb-core/include/dpl/dpl_sem.h +++ b/pkg/uwb-core/include/dpl/dpl_sem.h @@ -22,10 +22,7 @@ #include -#include "dpl_types.h" -#include "dpl_error.h" - -#include "sema.h" +#include "os/os_sem.h" #ifdef __cplusplus extern "C" { @@ -35,7 +32,7 @@ extern "C" { * @brief dpl semaphore wrapper */ struct dpl_sem { - sema_t sema; /**< the semaphore */ + struct os_sem sem; /**< the semaphore */ }; /** @@ -48,7 +45,10 @@ struct dpl_sem { * DPL_INVALID_PARM Semaphore passed in was NULL. * DPL_OK no error. */ -dpl_error_t dpl_sem_init(struct dpl_sem *sem, uint16_t tokens); +static inline dpl_error_t dpl_sem_init(struct dpl_sem *sem, uint16_t tokens) +{ + return (dpl_error_t) os_sem_init(&sem->sem, tokens); +} /** * @brief Pend (wait) for a semaphore. @@ -64,7 +64,10 @@ dpl_error_t dpl_sem_init(struct dpl_sem *sem, uint16_t tokens); * DPL_TIMEOUT semaphore was owned by another task and timeout=0 * DPL_OK no error */ -dpl_error_t dpl_sem_pend(struct dpl_sem *sem, dpl_time_t timeout); +static inline dpl_error_t dpl_sem_pend(struct dpl_sem *sem, dpl_time_t timeout) +{ + return (dpl_error_t) os_sem_pend(&sem->sem, timeout); +} /** * @brief Release a semaphore. @@ -75,12 +78,18 @@ dpl_error_t dpl_sem_pend(struct dpl_sem *sem, dpl_time_t timeout); * DPL_INVALID_PARM semaphore passed in was NULL. * DPL_OK no error */ -dpl_error_t dpl_sem_release(struct dpl_sem *sem); +static inline dpl_error_t dpl_sem_release(struct dpl_sem *sem) +{ + return (dpl_error_t) os_sem_release(&sem->sem); +} /** * @brief Get current semaphore's count */ -uint16_t dpl_sem_get_count(struct dpl_sem *sem); +static inline int16_t dpl_sem_get_count(struct dpl_sem *sem) +{ + return os_sem_get_count(&sem->sem); +} #ifdef __cplusplus } diff --git a/pkg/uwb-core/include/dpl/dpl_tasks.h b/pkg/uwb-core/include/dpl/dpl_tasks.h index 62b2139aaf..e92b7442e8 100644 --- a/pkg/uwb-core/include/dpl/dpl_tasks.h +++ b/pkg/uwb-core/include/dpl/dpl_tasks.h @@ -20,10 +20,7 @@ #ifndef DPL_DPL_TASKS_H #define DPL_DPL_TASKS_H -#include "dpl_types.h" - -#include "sched.h" -#include "thread.h" +#include "os/os_task.h" #ifdef __cplusplus extern "C" { @@ -33,13 +30,13 @@ extern "C" { * @brief dpl task wrapper */ struct dpl_task { - kernel_pid_t pid; /**< the process id */ + struct os_task t; /**< os task */ }; /** * @brief dpl task function */ -typedef thread_task_func_t dpl_task_func_t; +typedef os_task_func_t dpl_task_func_t; /** * @brief Initialize a task. @@ -60,28 +57,39 @@ typedef thread_task_func_t dpl_task_func_t; * * @return 0 on success, non-zero on failure. */ -int dpl_task_init(struct dpl_task *t, const char *name, dpl_task_func_t func, +static inline int dpl_task_init(struct dpl_task *t, const char *name, dpl_task_func_t func, void *arg, uint8_t prio, dpl_time_t sanity_itvl, - dpl_stack_t *stack_bottom, uint16_t stack_size); - + dpl_stack_t *stack_bottom, uint16_t stack_size) +{ + return os_task_init(&t->t, name, func, arg, prio, sanity_itvl, stack_bottom, stack_size); +} /** * @brief removes specified task * * NOTE: This interface is currently experimental and not ready for common use */ -int dpl_task_remove(struct dpl_task *t); +static inline int dpl_task_remove(struct dpl_task *t) +{ + return os_task_remove(&t->t); +} /** * @brief Return the number of tasks initialized. * * @return number of tasks initialized */ -uint8_t dpl_task_count(void); +static inline uint8_t dpl_task_count(void) +{ + return os_task_count(); +} /** * @brief Lets current thread yield. */ -void dpl_task_yield(void); +static inline void dpl_task_yield(void) +{ + return os_task_yield(); +} #ifdef __cplusplus } diff --git a/pkg/uwb-core/include/dpl/dpl_time.h b/pkg/uwb-core/include/dpl/dpl_time.h index 192ccc5dd9..4432bf1ea9 100644 --- a/pkg/uwb-core/include/dpl/dpl_time.h +++ b/pkg/uwb-core/include/dpl/dpl_time.h @@ -20,17 +20,12 @@ #ifndef DPL_DPL_TIME_H #define DPL_DPL_TIME_H -#include "xtimer.h" +#include "os/os_time.h" #ifdef __cplusplus extern "C" { #endif -/** - * @brief DPL ticks per seconds - */ -#define DPL_TICKS_PER_SEC (XTIMER_HZ) - /** * @brief Returns the low 32 bits of cputime. * @@ -38,7 +33,7 @@ extern "C" { */ static inline dpl_time_t dpl_time_get(void) { - return xtimer_now().ticks32; + return os_time_get(); } /** @@ -51,8 +46,7 @@ static inline dpl_time_t dpl_time_get(void) */ static inline dpl_error_t dpl_time_ms_to_ticks(uint32_t ms, dpl_time_t *out_ticks) { - *out_ticks = xtimer_ticks_from_usec(ms * US_PER_MS).ticks32; - return DPL_OK; + return (dpl_error_t) os_time_ms_to_ticks(ms, out_ticks); } /** @@ -65,9 +59,7 @@ static inline dpl_error_t dpl_time_ms_to_ticks(uint32_t ms, dpl_time_t *out_tick */ static inline dpl_error_t dpl_time_ticks_to_ms(dpl_time_t ticks, uint32_t *out_ms) { - xtimer_ticks32_t val = {.ticks32 = ticks}; - *out_ms = xtimer_usec_from_ticks(val) * US_PER_MS; - return DPL_OK; + return (dpl_error_t) os_time_ticks_to_ms(ticks, out_ms); } /** @@ -79,7 +71,7 @@ static inline dpl_error_t dpl_time_ticks_to_ms(dpl_time_t ticks, uint32_t *out_ */ static inline dpl_time_t dpl_time_ms_to_ticks32(uint32_t ms) { - return xtimer_ticks_from_usec(ms * US_PER_MS).ticks32; + return os_time_ms_to_ticks32(ms); } /** @@ -91,8 +83,7 @@ static inline dpl_time_t dpl_time_ms_to_ticks32(uint32_t ms) */ static inline dpl_time_t dpl_time_ticks_to_ms32(dpl_time_t ticks) { - xtimer_ticks32_t val = {.ticks32 = ticks}; - return xtimer_usec_from_ticks(val) * US_PER_MS; + return os_time_ticks_to_ms32(ticks); } /** @@ -102,8 +93,7 @@ static inline dpl_time_t dpl_time_ticks_to_ms32(dpl_time_t ticks) */ static inline void dpl_time_delay(dpl_time_t ticks) { - xtimer_ticks32_t val = {.ticks32 = ticks}; - xtimer_tsleep32((xtimer_ticks32_t) val); + return os_time_delay(ticks); } #ifdef __cplusplus diff --git a/pkg/uwb-core/include/dpl/dpl_types.h b/pkg/uwb-core/include/dpl/dpl_types.h index a8d9eeb767..4009bf0c89 100644 --- a/pkg/uwb-core/include/dpl/dpl_types.h +++ b/pkg/uwb-core/include/dpl/dpl_types.h @@ -23,6 +23,8 @@ #include #include +#include "os/os_types.h" + #ifdef __cplusplus extern "C" { #endif @@ -38,26 +40,26 @@ extern "C" { * @name Macro to wait forever on events and mutexes * @{ */ -#define DPL_TIMEOUT_NEVER (UINT32_MAX) -#define DPL_WAIT_FOREVER (DPL_TIMEOUT_NEVER) +#define DPL_TIMEOUT_NEVER (OS_TIMEOUT_NEVER) +#define DPL_WAIT_FOREVER (OS_WAIT_FOREVER) /** @} */ /** * @name Decawave porting layer (DPL) stack alignment requirement * @{ */ -#define DPL_STACK_ALIGNMENT (4) +#define DPL_STACK_ALIGNMENT (OS_ALIGNMENT) /** @} */ /** * @brief dpl time type */ -typedef uint32_t dpl_time_t; +typedef os_time_t dpl_time_t; /** * @brief dpl stack buffer type */ -typedef char dpl_stack_t; +typedef os_stack_t dpl_stack_t; /** * @brief dpl float 32 type diff --git a/pkg/uwb-core/include/mcu/mcu.h b/pkg/uwb-core/include/dpl/queue.h similarity index 83% rename from pkg/uwb-core/include/mcu/mcu.h rename to pkg/uwb-core/include/dpl/queue.h index e58aa6c3ed..84e9da9ae1 100644 --- a/pkg/uwb-core/include/mcu/mcu.h +++ b/pkg/uwb-core/include/dpl/queue.h @@ -17,17 +17,17 @@ * @} */ -#ifndef MCU_MCU_H -#define MCU_MCU_H +#ifndef DPL_QUEUE_H +#define DPL_QUEUE_H + +#include "os/os_queue.h" #ifdef __cplusplus extern "C" { #endif -/* empty header */ - #ifdef __cplusplus } #endif -#endif /* MCU_MCU_H */ +#endif /* DPL_QUEUE_H */ diff --git a/pkg/uwb-core/include/syscfg/syscfg_twr_ds.h b/pkg/uwb-core/include/dpl_syscfg/syscfg_twr_ds.h similarity index 90% rename from pkg/uwb-core/include/syscfg/syscfg_twr_ds.h rename to pkg/uwb-core/include/dpl_syscfg/syscfg_twr_ds.h index 54345c88ac..350b64c6c6 100644 --- a/pkg/uwb-core/include/syscfg/syscfg_twr_ds.h +++ b/pkg/uwb-core/include/dpl_syscfg/syscfg_twr_ds.h @@ -18,8 +18,8 @@ * @} */ -#ifndef SYSCFG_SYSCFG_TWR_DS_H -#define SYSCFG_SYSCFG_TWR_DS_H +#ifndef DPL_SYSCFG_SYSCFG_TWR_DS_H +#define DPL_SYSCFG_SYSCFG_TWR_DS_H #ifdef __cplusplus extern "C" { @@ -50,4 +50,4 @@ extern "C" { } #endif -#endif /* SYSCFG_SYSCFG_TWR_DS_H */ +#endif /* DPL_SYSCFG_SYSCFG_TWR_DS_H */ diff --git a/pkg/uwb-core/include/syscfg/syscfg_twr_ds_ext.h b/pkg/uwb-core/include/dpl_syscfg/syscfg_twr_ds_ext.h similarity index 90% rename from pkg/uwb-core/include/syscfg/syscfg_twr_ds_ext.h rename to pkg/uwb-core/include/dpl_syscfg/syscfg_twr_ds_ext.h index 9163686515..36a3fc7fcb 100644 --- a/pkg/uwb-core/include/syscfg/syscfg_twr_ds_ext.h +++ b/pkg/uwb-core/include/dpl_syscfg/syscfg_twr_ds_ext.h @@ -18,8 +18,8 @@ * @} */ -#ifndef SYSCFG_SYSCFG_TWR_DS_EXT_H -#define SYSCFG_SYSCFG_TWR_DS_EXT_H +#ifndef DPL_SYSCFG_SYSCFG_TWR_DS_EXT_H +#define DPL_SYSCFG_SYSCFG_TWR_DS_EXT_H #ifdef __cplusplus extern "C" { @@ -50,4 +50,4 @@ extern "C" { } #endif -#endif /* SYSCFG_SYSCFG_TWR_DS_EXT_H */ +#endif /* DPL_SYSCFG_SYSCFG_TWR_DS_EXT_H */ diff --git a/pkg/uwb-core/include/syscfg/syscfg_twr_ss.h b/pkg/uwb-core/include/dpl_syscfg/syscfg_twr_ss.h similarity index 90% rename from pkg/uwb-core/include/syscfg/syscfg_twr_ss.h rename to pkg/uwb-core/include/dpl_syscfg/syscfg_twr_ss.h index e730ecba8d..55c8a41126 100644 --- a/pkg/uwb-core/include/syscfg/syscfg_twr_ss.h +++ b/pkg/uwb-core/include/dpl_syscfg/syscfg_twr_ss.h @@ -18,8 +18,8 @@ * @} */ -#ifndef SYSCFG_SYSCFG_TWR_SS_H -#define SYSCFG_SYSCFG_TWR_SS_H +#ifndef DPL_SYSCFG_SYSCFG_TWR_SS_H +#define DPL_SYSCFG_SYSCFG_TWR_SS_H #ifdef __cplusplus extern "C" { @@ -50,4 +50,4 @@ extern "C" { } #endif -#endif /* SYSCFG_SYSCFG_TWR_SS_H */ +#endif /* DPL_SYSCFG_SYSCFG_TWR_SS_H */ diff --git a/pkg/uwb-core/include/syscfg/syscfg_twr_ss_ack.h b/pkg/uwb-core/include/dpl_syscfg/syscfg_twr_ss_ack.h similarity index 90% rename from pkg/uwb-core/include/syscfg/syscfg_twr_ss_ack.h rename to pkg/uwb-core/include/dpl_syscfg/syscfg_twr_ss_ack.h index 5371159033..e1af338fad 100644 --- a/pkg/uwb-core/include/syscfg/syscfg_twr_ss_ack.h +++ b/pkg/uwb-core/include/dpl_syscfg/syscfg_twr_ss_ack.h @@ -18,8 +18,8 @@ * @} */ -#ifndef SYSCFG_SYSCFG_TWR_SS_ACK_H -#define SYSCFG_SYSCFG_TWR_SS_ACK_H +#ifndef DPL_SYSCFG_SYSCFG_TWR_SS_ACK_H +#define DPL_SYSCFG_SYSCFG_TWR_SS_ACK_H #ifdef __cplusplus extern "C" { @@ -50,4 +50,4 @@ extern "C" { } #endif -#endif /* SYSCFG_SYSCFG_TWR_SS_ACK_H */ +#endif /* DPL_SYSCFG_SYSCFG_TWR_SS_ACK_H */ diff --git a/pkg/uwb-core/include/syscfg/syscfg_twr_ss_ext.h b/pkg/uwb-core/include/dpl_syscfg/syscfg_twr_ss_ext.h similarity index 89% rename from pkg/uwb-core/include/syscfg/syscfg_twr_ss_ext.h rename to pkg/uwb-core/include/dpl_syscfg/syscfg_twr_ss_ext.h index 3fe15820e8..4d3b335d3f 100644 --- a/pkg/uwb-core/include/syscfg/syscfg_twr_ss_ext.h +++ b/pkg/uwb-core/include/dpl_syscfg/syscfg_twr_ss_ext.h @@ -18,8 +18,8 @@ * @} */ -#ifndef SYSCFG_SYSCFG_TWR_SS_EXT_H -#define SYSCFG_SYSCFG_TWR_SS_EXT_H +#ifndef DPL_SYSCFG_SYSCFG_TWR_SS_EXT_H +#define DPL_SYSCFG_SYSCFG_TWR_SS_EXT_H #ifdef __cplusplus extern "C" { @@ -50,4 +50,4 @@ extern "C" { } #endif -#endif /* SYSCFG_SYSCFG_TWR_SS_EXT_H */ +#endif /* DPL_SYSCFG_SYSCFG_TWR_SS_EXT_H */ diff --git a/pkg/uwb-core/include/syscfg/syscfg_uwb.h b/pkg/uwb-core/include/dpl_syscfg/syscfg_uwb.h similarity index 95% rename from pkg/uwb-core/include/syscfg/syscfg_uwb.h rename to pkg/uwb-core/include/dpl_syscfg/syscfg_uwb.h index 48ac7b849d..3ebe026879 100644 --- a/pkg/uwb-core/include/syscfg/syscfg_uwb.h +++ b/pkg/uwb-core/include/dpl_syscfg/syscfg_uwb.h @@ -18,8 +18,8 @@ * @} */ -#ifndef SYSCFG_SYSCFG_UWB_H -#define SYSCFG_SYSCFG_UWB_H +#ifndef DPL_SYSCFG_SYSCFG_UWB_H +#define DPL_SYSCFG_SYSCFG_UWB_H #ifdef __cplusplus extern "C" { @@ -50,7 +50,7 @@ extern "C" { * @brief Enable init messages showing each package has been initialised */ #ifndef MYNEWT_VAL_UWB_PKG_INIT_LOG -#define MYNEWT_VAL_UWB_PKG_INIT_LOG (1) +#define MYNEWT_VAL_UWB_PKG_INIT_LOG (0) #endif /** @@ -141,4 +141,4 @@ extern "C" { } #endif -#endif /* SYSCFG_SYSCFG_UWB_H */ +#endif /* DPL_SYSCFG_SYSCFG_UWB_H */ diff --git a/pkg/uwb-core/include/syscfg/syscfg_uwb_rng.h b/pkg/uwb-core/include/dpl_syscfg/syscfg_uwb_rng.h similarity index 91% rename from pkg/uwb-core/include/syscfg/syscfg_uwb_rng.h rename to pkg/uwb-core/include/dpl_syscfg/syscfg_uwb_rng.h index 572ceccad6..d56f75c93d 100644 --- a/pkg/uwb-core/include/syscfg/syscfg_uwb_rng.h +++ b/pkg/uwb-core/include/dpl_syscfg/syscfg_uwb_rng.h @@ -18,8 +18,8 @@ * @} */ -#ifndef SYSCFG_SYSCFG_UWB_RNG_H -#define SYSCFG_SYSCFG_UWB_RNG_H +#ifndef DPL_SYSCFG_SYSCFG_UWB_RNG_H +#define DPL_SYSCFG_SYSCFG_UWB_RNG_H #ifdef __cplusplus extern "C" { @@ -64,4 +64,4 @@ extern "C" { } #endif -#endif /* SYSCFG_SYSCFG_UWB_RNG_H */ +#endif /* DPL_SYSCFG_SYSCFG_UWB_RNG_H */ diff --git a/pkg/uwb-core/include/syscfg/syscfg_uwbcfg.h b/pkg/uwb-core/include/dpl_syscfg/syscfg_uwbcfg.h similarity index 97% rename from pkg/uwb-core/include/syscfg/syscfg_uwbcfg.h rename to pkg/uwb-core/include/dpl_syscfg/syscfg_uwbcfg.h index 543a746784..45e27a7e9c 100644 --- a/pkg/uwb-core/include/syscfg/syscfg_uwbcfg.h +++ b/pkg/uwb-core/include/dpl_syscfg/syscfg_uwbcfg.h @@ -18,8 +18,8 @@ * @} */ -#ifndef SYSCFG_SYSCFG_UWBCFG_H -#define SYSCFG_SYSCFG_UWBCFG_H +#ifndef DPL_SYSCFG_SYSCFG_UWBCFG_H +#define DPL_SYSCFG_SYSCFG_UWBCFG_H #ifdef __cplusplus extern "C" { @@ -238,4 +238,4 @@ extern "C" { } #endif -#endif /* SYSCFG_SYSCFG_UWBCFG_H */ +#endif /* DPL_SYSCFG_SYSCFG_UWBCFG_H */ diff --git a/pkg/uwb-core/include/os/os.h b/pkg/uwb-core/include/os/os.h deleted file mode 100644 index c9cff4a40e..0000000000 --- a/pkg/uwb-core/include/os/os.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2020 Inria - * - * 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 pkg_uwb_core - * @{ - * - * @file - * @brief Abstraction layer for RIOT adaption - * - * @author Francisco Molina - * @} - */ -#ifndef OS_OS_H -#define OS_OS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* OS_OS_H */ diff --git a/pkg/uwb-core/include/syscfg/syscfg.h b/pkg/uwb-core/include/syscfg/syscfg.h deleted file mode 100644 index 7d412928b7..0000000000 --- a/pkg/uwb-core/include/syscfg/syscfg.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2020 Inria - * - * 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 pkg_uwb_core - * @{ - * - * @file - * @brief uwb-core system configurations - * - * @author Francisco Molina - * @} - */ - -#ifndef SYSCFG_SYSCFG_H -#define SYSCFG_SYSCFG_H - -#include "kernel_defines.h" - -/** - * @name MyNewt header inclusion macro definitions - * @{ - * - * This macro exists to ensure code includes this header when needed. If code - * checks the existence of a setting directly via ifdef without including this - * header, the setting macro will silently evaluate to 0. In contrast, an - * attempt to use these macros without including this header will result in a - * compiler error. - */ -#define MYNEWT_VAL(_name) MYNEWT_VAL_ ## _name -#define MYNEWT_VAL_CHOICE(_name, _val) MYNEWT_VAL_ ## _name ## __ ## _val -/** @} */ - - -/*** @decawave-uwb-core/hw/drivers/uwb */ -#include "syscfg_uwb.h" - -/*** @decawave-uwb-core/lib/twr_ds */ -#include "syscfg_twr_ds.h" - -/*** @decawave-uwb-core/lib/twr_ds_ext */ -#include "syscfg_twr_ds_ext.h" - -/*** @decawave-uwb-core/lib/twr_ss */ -#include "syscfg_twr_ss.h" - -/*** @decawave-uwb-core/lib/twr_ss_ack */ -#include "syscfg_twr_ss_ack.h" - -/*** @decawave-uwb-core/lib/twr_ss_ext */ -#include "syscfg_twr_ss_ext.h" - -/*** @decawave-uwb-core/lib/uwb_rng */ -#include "syscfg_uwb_rng.h" - -/*** @decawave-uwb-core/sys/uwbcfg */ -#include "syscfg_uwbcfg.h" - -/*** @decawave-uwb-dw1000/hw/drivers/uwb/uwb_dw1000 */ -#include "syscfg_uwb_dw1000.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* SYSCFG_SYSCFG_H */ diff --git a/pkg/uwb-core/patches/0001-uwb-uwb.c-use-RIOT-specific-uwb_dev_idx_lookup.patch b/pkg/uwb-core/patches/0001-uwb-uwb.c-use-RIOT-specific-uwb_dev_idx_lookup.patch index 0af7be3d93..8b46dc0c65 100644 --- a/pkg/uwb-core/patches/0001-uwb-uwb.c-use-RIOT-specific-uwb_dev_idx_lookup.patch +++ b/pkg/uwb-core/patches/0001-uwb-uwb.c-use-RIOT-specific-uwb_dev_idx_lookup.patch @@ -1,14 +1,14 @@ -From 0a9b2ebbe97dbe10a7bc9afdf3914b099c0264da Mon Sep 17 00:00:00 2001 +From 2bda36deef20463ae499298751d1e575fca09480 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Fri, 14 Aug 2020 14:14:23 +0200 -Subject: [PATCH 1/7] uwb/uwb.c: use RIOT specific uwb_dev_idx_lookup() +Subject: [PATCH 1/5] uwb/uwb.c: use RIOT specific uwb_dev_idx_lookup() --- hw/drivers/uwb/src/uwb.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/drivers/uwb/src/uwb.c b/hw/drivers/uwb/src/uwb.c -index 70c1b71..69e6714 100644 +index 70c1b71..8a4105f 100644 --- a/hw/drivers/uwb/src/uwb.c +++ b/hw/drivers/uwb/src/uwb.c @@ -31,6 +31,8 @@ @@ -16,7 +16,7 @@ index 70c1b71..69e6714 100644 #include #endif + -+#if !defined(RIOT) ++#if !defined(RIOT_VERSION) struct uwb_dev* uwb_dev_idx_lookup(int idx) { diff --git a/pkg/uwb-core/patches/0006-lib-json-src-use-fmt-to-avoid-newlib-issue.patch b/pkg/uwb-core/patches/0002-lib-json-src-use-fmt-to-avoid-newlib-issue.patch similarity index 91% rename from pkg/uwb-core/patches/0006-lib-json-src-use-fmt-to-avoid-newlib-issue.patch rename to pkg/uwb-core/patches/0002-lib-json-src-use-fmt-to-avoid-newlib-issue.patch index a6c242b808..2a916f1ed9 100644 --- a/pkg/uwb-core/patches/0006-lib-json-src-use-fmt-to-avoid-newlib-issue.patch +++ b/pkg/uwb-core/patches/0002-lib-json-src-use-fmt-to-avoid-newlib-issue.patch @@ -1,7 +1,7 @@ -From b7dd28c1fa7610baa00950e8798392102dfd69f9 Mon Sep 17 00:00:00 2001 +From f4c345b41b6c40c2d57c700fbbff31a92647a2dc Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Thu, 17 Sep 2020 17:00:09 +0200 -Subject: [PATCH 6/7] lib/json/src: use fmt to avoid newlib issue +Subject: [PATCH 2/5] lib/json/src: use fmt to avoid newlib issue --- lib/json/src/json_encode.c | 8 ++++---- diff --git a/pkg/uwb-core/patches/0002-lib-twr_-enable-stats-optionally.patch b/pkg/uwb-core/patches/0002-lib-twr_-enable-stats-optionally.patch deleted file mode 100644 index 9877337b9f..0000000000 --- a/pkg/uwb-core/patches/0002-lib-twr_-enable-stats-optionally.patch +++ /dev/null @@ -1,758 +0,0 @@ -From cac1c7aeb1db0732519fa6ae27f3f34234c83615 Mon Sep 17 00:00:00 2001 -From: Francisco Molina -Date: Fri, 14 Aug 2020 14:22:29 +0200 -Subject: [PATCH 2/7] lib/twr_*: enable stats optionally - ---- - lib/twr_ds/src/twr_ds.c | 41 +++++++++++++---------- - lib/twr_ds/syscfg.yml | 3 ++ - lib/twr_ds_ext/src/twr_ds_ext.c | 17 +++++++--- - lib/twr_ds_ext/syscfg.yml | 3 ++ - lib/twr_ds_ext_nrng/src/twr_ds_ext_nrng.c | 16 ++++++--- - lib/twr_ds_ext_nrng/syscfg.yml | 3 ++ - lib/twr_ds_nrng/src/twr_ds_nrng.c | 16 ++++++--- - lib/twr_ds_nrng/syscfg.yml | 3 ++ - lib/twr_ss/src/twr_ss.c | 6 ++++ - lib/twr_ss/syscfg.yml | 3 ++ - lib/twr_ss_ack/src/twr_ss_ack.c | 8 +++-- - lib/twr_ss_ack/syscfg.yml | 3 ++ - lib/twr_ss_ext/src/twr_ss_ext.c | 15 ++++++--- - lib/twr_ss_ext/syscfg.yml | 3 ++ - lib/twr_ss_ext_nrng/src/twr_ss_ext_nrng.c | 9 ++++- - lib/twr_ss_ext_nrng/syscfg.yml | 3 ++ - lib/twr_ss_nrng/src/twr_ss_nrng.c | 39 ++++++++++++++++++--- - lib/twr_ss_nrng/syscfg.yml | 3 ++ - 18 files changed, 151 insertions(+), 43 deletions(-) - -diff --git a/lib/twr_ds/src/twr_ds.c b/lib/twr_ds/src/twr_ds.c -index c73c412..cb5de6a 100644 ---- a/lib/twr_ds/src/twr_ds.c -+++ b/lib/twr_ds/src/twr_ds.c -@@ -51,6 +51,23 @@ - #endif - #endif - -+#if MYNEWT_VAL(TWR_DS_STATS) -+STATS_SECT_START(twr_ds_stat_section) -+ STATS_SECT_ENTRY(complete) -+ STATS_SECT_ENTRY(start_tx_error) -+STATS_SECT_END -+ -+STATS_NAME_START(twr_ds_stat_section) -+ STATS_NAME(twr_ds_stat_section, complete) -+ STATS_NAME(twr_ds_stat_section, start_tx_error) -+STATS_NAME_END(twr_ds_stat_section) -+ -+STATS_SECT_DECL(twr_ds_stat_section) g_twr_ds_stat; -+#define DS_STATS_INC(__X) STATS_INC(g_twr_ds_stat, __X) -+#else -+#define DS_STATS_INC(__X) {} -+#endif -+ - static bool rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs); - - static struct uwb_mac_interface g_cbs[] = { -@@ -72,18 +89,6 @@ static struct uwb_mac_interface g_cbs[] = { - #endif - }; - --STATS_SECT_START(twr_ds_stat_section) -- STATS_SECT_ENTRY(complete) -- STATS_SECT_ENTRY(start_tx_error) --STATS_SECT_END -- --STATS_NAME_START(twr_ds_stat_section) -- STATS_NAME(twr_ds_stat_section, complete) -- STATS_NAME(twr_ds_stat_section, start_tx_error) --STATS_NAME_END(twr_ds_stat_section) -- --STATS_SECT_DECL(twr_ds_stat_section) g_twr_ds_stat; -- - static struct uwb_rng_config g_config = { - .tx_holdoff_delay = MYNEWT_VAL(TWR_DS_TX_HOLDOFF), // Send Time delay in usec. - .rx_timeout_delay = MYNEWT_VAL(TWR_DS_RX_TIMEOUT) // Receive response timeout in usec -@@ -137,6 +142,7 @@ void twr_ds_pkg_init(void) - uwb_rng_append_config(g_cbs[i].inst_ptr, &g_rng_cfgs[i]); - } - -+#if MYNEWT_VAL(TWR_DS_STATS) - rc = stats_init( - STATS_HDR(g_twr_ds_stat), - STATS_SIZE_INIT_PARMS(g_twr_ds_stat, STATS_SIZE_32), -@@ -145,6 +151,7 @@ void twr_ds_pkg_init(void) - - rc = stats_register("twr_ds", STATS_HDR(g_twr_ds_stat)); - assert(rc == 0); -+#endif - - } - -@@ -231,7 +238,7 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) - - /* Start tx now, the remaining settings can be done whilst sending anyway */ - if (uwb_start_tx(inst).start_tx_error){ -- STATS_INC(g_twr_ds_stat, start_tx_error); -+ DS_STATS_INC(start_tx_error); - dpl_sem_release(&rng->sem); - } - -@@ -291,7 +298,7 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) - uwb_set_rxauto_disable(inst, true); - - if (uwb_start_tx(inst).start_tx_error){ -- STATS_INC(g_twr_ds_stat, start_tx_error); -+ DS_STATS_INC(start_tx_error); - dpl_sem_release(&rng->sem); - } - /* Setup when to listen for response, relative the end of our transmitted frame */ -@@ -337,11 +344,11 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) - uwb_set_delay_start(inst, txd.response_tx_delay); - - if (uwb_start_tx(inst).start_tx_error) { -- STATS_INC(g_twr_ds_stat, start_tx_error); -+ DS_STATS_INC(start_tx_error); - dpl_sem_release(&rng->sem); - rng_issue_complete(inst); - } else { -- STATS_INC(g_twr_ds_stat, complete); -+ DS_STATS_INC(complete); - rng->control.complete_after_tx = 1; - } - -@@ -352,7 +359,7 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) - // This code executes on the device that initialed the original request, and has now receive the final response timestamp. - // This marks the completion of the double-single-two-way request. - -- STATS_INC(g_twr_ds_stat, complete); -+ DS_STATS_INC(complete); - dpl_sem_release(&rng->sem); - rng_issue_complete(inst); - break; -diff --git a/lib/twr_ds/syscfg.yml b/lib/twr_ds/syscfg.yml -index cb12594..288b8fd 100644 ---- a/lib/twr_ds/syscfg.yml -+++ b/lib/twr_ds/syscfg.yml -@@ -10,3 +10,6 @@ syscfg.defs: - TWR_DS_RX_TIMEOUT: - description: 'TOA timeout delay for DS TWR (usec)' - value: ((uint16_t)0x30) -+ TWR_DS_STATS: -+ description: 'Enable statistics for the twr_ds module' -+ value: 1 -diff --git a/lib/twr_ds_ext/src/twr_ds_ext.c b/lib/twr_ds_ext/src/twr_ds_ext.c -index 95f38fe..07cc28c 100644 ---- a/lib/twr_ds_ext/src/twr_ds_ext.c -+++ b/lib/twr_ds_ext/src/twr_ds_ext.c -@@ -67,6 +67,7 @@ static struct uwb_mac_interface g_cbs[] = { - #endif - }; - -+#if MYNEWT_VAL(TWR_DS_EXT_STATS) - STATS_SECT_START(twr_ds_ext_stat_section) - STATS_SECT_ENTRY(complete) - STATS_SECT_ENTRY(tx_error) -@@ -78,6 +79,10 @@ STATS_NAME_START(twr_ds_ext_stat_section) - STATS_NAME_END(twr_ds_ext_stat_section) - - static STATS_SECT_DECL(twr_ds_ext_stat_section) g_twr_ds_ext_stat; -+#define DS_STATS_INC(__X) STATS_INC(g_twr_ds_ext_stat, __X) -+#else -+#define DS_STATS_INC(__X) {} -+#endif - - static struct uwb_rng_config g_config = { - .tx_holdoff_delay = MYNEWT_VAL(TWR_DS_EXT_TX_HOLDOFF), // Send Time delay in usec. -@@ -132,6 +137,7 @@ void twr_ds_ext_pkg_init(void) - uwb_rng_append_config(g_cbs[i].inst_ptr, &g_rng_cfgs[i]); - } - -+#if MYNEWT_VAL(TWR_DS_EXT_STATS) - rc = stats_init( - STATS_HDR(g_twr_ds_ext_stat), - STATS_SIZE_INIT_PARMS(g_twr_ds_ext_stat, STATS_SIZE_32), -@@ -140,6 +146,7 @@ void twr_ds_ext_pkg_init(void) - - rc = stats_register("twr_ds_ext", STATS_HDR(g_twr_ds_ext_stat)); - assert(rc == 0); -+#endif - } - - -@@ -224,7 +231,7 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) - uwb_set_rxauto_disable(inst, true); - - if (uwb_start_tx(inst).start_tx_error){ -- STATS_INC(g_twr_ds_ext_stat, tx_error); -+ DS_STATS_INC(tx_error); - dpl_sem_release(&rng->sem); - } - -@@ -293,7 +300,7 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) - uwb_set_rxauto_disable(inst, true); - - if (uwb_start_tx(inst).start_tx_error){ -- STATS_INC(g_twr_ds_ext_stat, tx_error); -+ DS_STATS_INC(tx_error); - dpl_sem_release(&rng->sem); - } - /* Setup when to listen for response, relative the end of our transmitted frame */ -@@ -348,11 +355,11 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) - uwb_rng_clear_twr_data(&frame->remote); - - if (uwb_start_tx(inst).start_tx_error) { -- STATS_INC(g_twr_ds_ext_stat, tx_error); -+ DS_STATS_INC(tx_error); - dpl_sem_release(&rng->sem); - rng_issue_complete(inst); - }else{ -- STATS_INC(g_twr_ds_ext_stat, complete); -+ DS_STATS_INC(complete); - rng->control.complete_after_tx = 1; - } - break; -@@ -362,7 +369,7 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) - // This code executes on the device that initialed the original request, and has now receive the final response timestamp. - // This marks the completion of the double-single-two-way request. - -- STATS_INC(g_twr_ds_ext_stat, complete); -+ DS_STATS_INC(complete); - dpl_sem_release(&rng->sem); - rng_issue_complete(inst); - break; -diff --git a/lib/twr_ds_ext/syscfg.yml b/lib/twr_ds_ext/syscfg.yml -index 199a671..fe80282 100644 ---- a/lib/twr_ds_ext/syscfg.yml -+++ b/lib/twr_ds_ext/syscfg.yml -@@ -10,3 +10,6 @@ syscfg.defs: - TWR_DS_EXT_RX_TIMEOUT: - description: 'TOA timeout delay for DS TWR extended frame (usec)' - value: ((uint16_t)0x40) -+ TWR_DS_EXT_STATS: -+ description: 'Enable statistics for the twr_ds_ext module' -+ value: 1 -diff --git a/lib/twr_ds_ext_nrng/src/twr_ds_ext_nrng.c b/lib/twr_ds_ext_nrng/src/twr_ds_ext_nrng.c -index b2a821e..2b15ae1 100644 ---- a/lib/twr_ds_ext_nrng/src/twr_ds_ext_nrng.c -+++ b/lib/twr_ds_ext_nrng/src/twr_ds_ext_nrng.c -@@ -65,6 +65,7 @@ static struct uwb_mac_interface g_cbs = { - .final_cb = tx_final_cb, - }; - -+#if MYNEWT_VAL(TWR_DS_EXT_NRNG_STATS) - STATS_SECT_START(twr_ds_ext_nrng_stat_section) - STATS_SECT_ENTRY(complete) - STATS_SECT_ENTRY(rx_error) -@@ -78,6 +79,11 @@ STATS_NAME_START(twr_ds_ext_nrng_stat_section) - STATS_NAME_END(twr_ds_ext_nrng_stat_section) - - static STATS_SECT_DECL(twr_ds_ext_nrng_stat_section) g_stat; -+#define DS_STATS_INC(__X) STATS_INC(g_stat, __X) -+#else -+#define DS_STATS_INC(__X) {} -+#endif -+ - - static struct uwb_rng_config g_config = { - .tx_holdoff_delay = MYNEWT_VAL(TWR_DS_EXT_NRNG_TX_HOLDOFF), // Send Time delay in usec. -@@ -96,6 +102,7 @@ void twr_ds_ext_nrng_pkg_init(void){ - printf("{\"utime\": %lu,\"msg\": \"twr_ds_ext_nrng_pkg_init\"}\n",os_cputime_ticks_to_usecs(os_cputime_get32())); - uwb_mac_append_interface(hal_dw1000_inst(0), &g_cbs); - -+#if MYNEWT_VAL(TWR_DS_EXT_NRNG_STATS) - int rc = stats_init( - STATS_HDR(g_stat), - STATS_SIZE_INIT_PARMS(g_stat, STATS_SIZE_32), -@@ -104,6 +111,7 @@ void twr_ds_ext_nrng_pkg_init(void){ - - rc = stats_register("twr_ds_ext_nrng", STATS_HDR(g_stat)); - assert(rc == 0); -+#endif - } - - -@@ -145,7 +153,7 @@ rx_timeout_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs){ - if(inst->fctrl != FCNTL_IEEE_N_RANGES_16){ - return false; - } -- STATS_INC(g_stat, rx_timeout); -+ DS_STATS_INC(rx_timeout); - assert(inst->nrng); - switch(inst->nrng->code){ - case UWB_DATA_CODE_DS_TWR_NRNG_EXT ... UWB_DATA_CODE_DS_TWR_NRNG_EXT_FINAL: -@@ -191,7 +199,7 @@ rx_error_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs){ - if(inst->fctrl != FCNTL_IEEE_N_RANGES_16){ - return false; - } -- STATS_INC(g_stat, rx_error); -+ DS_STATS_INC(rx_error); - assert(inst->nrng); - struct nrng_instance * nrng = inst->nrng; - os_error_t err = os_sem_release(&nrng->sem); -@@ -371,7 +379,7 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) - if (cbs!=NULL && cbs->start_tx_error_cb) - cbs->start_tx_error_cb(inst, cbs); - }else{ -- STATS_INC(g_stat, complete); -+ DS_STATS_INC(complete); - os_sem_release(&nrng->sem); - struct uwb_mac_interface * cbs = NULL; - if(!(SLIST_EMPTY(&inst->interface_cbs))){ -@@ -416,7 +424,7 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) - if(idx == nnodes -1){ - os_sem_release(&nrng->sem); - nrng->resp_count = 0; -- STATS_INC(g_stat, complete); -+ DS_STATS_INC(complete); - struct uwb_mac_interface * cbs = NULL; - if(!(SLIST_EMPTY(&inst->interface_cbs))){ - SLIST_FOREACH(cbs, &inst->interface_cbs, next){ -diff --git a/lib/twr_ds_ext_nrng/syscfg.yml b/lib/twr_ds_ext_nrng/syscfg.yml -index 5fd3404..92a952b 100644 ---- a/lib/twr_ds_ext_nrng/syscfg.yml -+++ b/lib/twr_ds_ext_nrng/syscfg.yml -@@ -12,3 +12,6 @@ syscfg.defs: - value: ((uint16_t)0x10) - TWR_DS_EXT_NRNG_TX_GUARD_DELAY: - value: ((uint16_t)0x150) -+ TWR_DS_EXT_NRNG_STATS: -+ description: 'Enable statistics for the twr_ds_ext_nrng module' -+ value: 1 -diff --git a/lib/twr_ds_nrng/src/twr_ds_nrng.c b/lib/twr_ds_nrng/src/twr_ds_nrng.c -index b32b2f8..3aea94a 100644 ---- a/lib/twr_ds_nrng/src/twr_ds_nrng.c -+++ b/lib/twr_ds_nrng/src/twr_ds_nrng.c -@@ -61,6 +61,7 @@ static struct uwb_mac_interface g_cbs = { - .rx_error_cb = rx_error_cb, - }; - -+#if MYNEWT_VAL(TWR_DS_NRNG_STATS) - STATS_SECT_START(twr_ds_nrng_stat_section) - STATS_SECT_ENTRY(complete) - STATS_SECT_ENTRY(rx_timeout) -@@ -74,6 +75,10 @@ STATS_NAME_START(twr_ds_nrng_stat_section) - STATS_NAME_END(twr_ds_nrng_stat_section) - - static STATS_SECT_DECL(twr_ds_nrng_stat_section) g_stat; -+#define DS_STATS_INC(__X) STATS_INC(g_stat, __X) -+#else -+#define DS_STATS_INC(__X) {} -+#endif - - static struct uwb_rng_config g_config = { - .tx_holdoff_delay = MYNEWT_VAL(TWR_DS_NRNG_TX_HOLDOFF), // Send Time delay in usec. -@@ -101,6 +106,7 @@ void twr_ds_nrng_pkg_init(void){ - uwb_mac_append_interface(uwb_dev_idx_lookup(0), &g_cbs); - nrng_append_config(nrng, &g_rng_cfgs); - -+#if MYNEWT_VAL(TWR_DS_NRNG_STATS) - int rc = stats_init( - STATS_HDR(g_stat), - STATS_SIZE_INIT_PARMS(g_stat, STATS_SIZE_32), -@@ -109,7 +115,7 @@ void twr_ds_nrng_pkg_init(void){ - - rc = stats_register("twr_ds_nrng", STATS_HDR(g_stat)); - assert(rc == 0); -- -+#endif - } - - -@@ -139,7 +145,7 @@ rx_timeout_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs){ - if(inst->fctrl != FCNTL_IEEE_N_RANGES_16){ - return false; - } -- STATS_INC(g_stat, rx_timeout); -+ DS_STATS_INC(rx_timeout); - switch(inst->nrng->code){ - case UWB_DATA_CODE_DS_TWR_NRNG ... UWB_DATA_CODE_DS_TWR_NRNG_FINAL: - { -@@ -183,7 +189,7 @@ rx_error_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs){ - if(inst->fctrl != FCNTL_IEEE_N_RANGES_16){ - return false; - } -- STATS_INC(g_stat, rx_error); -+ DS_STATS_INC(rx_error); - assert(inst->nrng); - struct nrng_instance * nrng = inst->nrng; - if(os_sem_get_count(&nrng->sem) == 0){ -@@ -381,7 +387,7 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) - if (cbs!=NULL && cbs->start_tx_error_cb) - cbs->start_tx_error_cb(inst, cbs); - }else{ -- STATS_INC(g_stat, complete); -+ DS_STATS_INC(complete); - os_sem_release(&nrng->sem); - struct uwb_mac_interface * cbs = NULL; - if(!(SLIST_EMPTY(&inst->interface_cbs))){ -@@ -430,7 +436,7 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) - frame->transmission_timestamp = dw1000_read_txtime_lo(inst); - if(idx == nnodes -1) - { -- STATS_INC(g_stat, complete); -+ DS_STATS_INC(complete); - os_sem_release(&nrng->sem); - struct uwb_mac_interface * cbs = NULL; - if(!(SLIST_EMPTY(&inst->interface_cbs))){ -diff --git a/lib/twr_ds_nrng/syscfg.yml b/lib/twr_ds_nrng/syscfg.yml -index 804234a..28777c1 100644 ---- a/lib/twr_ds_nrng/syscfg.yml -+++ b/lib/twr_ds_nrng/syscfg.yml -@@ -12,3 +12,6 @@ syscfg.defs: - value: ((uint16_t)0x10) - TWR_DS_NRNG_TX_GUARD_DELAY: - value: ((uint16_t)0x100) -+ TWR_DS_NRNG_STATS: -+ description: 'Enable statistics for the twr_ds_nrng module' -+ value: 1 -diff --git a/lib/twr_ss/src/twr_ss.c b/lib/twr_ss/src/twr_ss.c -index 84c5084..7394ef4 100644 ---- a/lib/twr_ss/src/twr_ss.c -+++ b/lib/twr_ss/src/twr_ss.c -@@ -76,6 +76,7 @@ static struct uwb_mac_interface g_cbs[] = { - #endif - }; - -+#if MYNEWT_VAL(TWR_SS_STATS) - STATS_SECT_START(twr_ss_stat_section) - STATS_SECT_ENTRY(complete) - STATS_SECT_ENTRY(tx_error) -@@ -88,6 +89,9 @@ STATS_NAME_END(twr_ss_stat_section) - - STATS_SECT_DECL(twr_ss_stat_section) g_twr_ss_stat; - #define SS_STATS_INC(__X) STATS_INC(g_twr_ss_stat, __X) -+#else -+#define SS_STATS_INC(__X) {} -+#endif - - static struct uwb_rng_config g_config = { - .tx_holdoff_delay = MYNEWT_VAL(TWR_SS_TX_HOLDOFF), // Send Time delay in usec. -@@ -143,6 +147,7 @@ twr_ss_pkg_init(void) - uwb_rng_append_config(g_cbs[i].inst_ptr, &g_rng_cfgs[i]); - } - -+#if MYNEWT_VAL(TWR_SS_STATS) - rc = stats_init( - STATS_HDR(g_twr_ss_stat), - STATS_SIZE_INIT_PARMS(g_twr_ss_stat, STATS_SIZE_32), -@@ -151,6 +156,7 @@ twr_ss_pkg_init(void) - - rc |= stats_register("twr_ss", STATS_HDR(g_twr_ss_stat)); - assert(rc == 0); -+#endif - } - - /** -diff --git a/lib/twr_ss/syscfg.yml b/lib/twr_ss/syscfg.yml -index e2ab7a5..05dc497 100644 ---- a/lib/twr_ss/syscfg.yml -+++ b/lib/twr_ss/syscfg.yml -@@ -10,3 +10,6 @@ syscfg.defs: - TWR_SS_RX_TIMEOUT: - description: 'TOA timeout delay for SS TWR (usec)' - value: ((uint16_t)0x30) -+ TWR_SS_STATS: -+ description: 'Enable statistics for the twr_ss module' -+ value: 1 -diff --git a/lib/twr_ss_ack/src/twr_ss_ack.c b/lib/twr_ss_ack/src/twr_ss_ack.c -index f0e0884..a64ce37 100644 ---- a/lib/twr_ss_ack/src/twr_ss_ack.c -+++ b/lib/twr_ss_ack/src/twr_ss_ack.c -@@ -78,7 +78,7 @@ static struct uwb_mac_interface g_cbs[] = { - #endif - }; - -- -+#if MYNEWT_VAL(TWR_SS_ACK_STATS) - STATS_SECT_START(twr_ss_ack_stat_section) - STATS_SECT_ENTRY(complete) - STATS_SECT_ENTRY(tx_error) -@@ -97,7 +97,9 @@ STATS_NAME_END(twr_ss_ack_stat_section) - - STATS_SECT_DECL(twr_ss_ack_stat_section) g_twr_ss_ack_stat; - #define SS_STATS_INC(__X) STATS_INC(g_twr_ss_ack_stat, __X) -- -+#else -+#define SS_STATS_INC(__X) {} -+#endif - - static struct uwb_rng_config g_config = { - .tx_holdoff_delay = MYNEWT_VAL(TWR_SS_ACK_TX_HOLDOFF), // Send Time delay in usec. -@@ -154,6 +156,7 @@ twr_ss_ack_pkg_init(void) - uwb_rng_append_config(g_cbs[i].inst_ptr, &g_rng_cfgs[i]); - } - -+#if MYNEWT_VAL(TWR_SS_ACK_STATS) - rc = stats_init( - STATS_HDR(g_twr_ss_ack_stat), - STATS_SIZE_INIT_PARMS(g_twr_ss_ack_stat, STATS_SIZE_32), -@@ -162,6 +165,7 @@ twr_ss_ack_pkg_init(void) - - rc |= stats_register("twr_ss_ack", STATS_HDR(g_twr_ss_ack_stat)); - assert(rc == 0); -+#endif - } - - /** -diff --git a/lib/twr_ss_ack/syscfg.yml b/lib/twr_ss_ack/syscfg.yml -index 4a27a9c..52177a2 100644 ---- a/lib/twr_ss_ack/syscfg.yml -+++ b/lib/twr_ss_ack/syscfg.yml -@@ -10,3 +10,6 @@ syscfg.defs: - TWR_SS_ACK_RX_TIMEOUT: - description: 'TOA timeout delay for SS TWR (usec)' - value: ((uint16_t)0x100) -+ TWR_SS_ACK_STATS: -+ description: 'Enable statistics for the twr_ss_ack module' -+ value: 1 -diff --git a/lib/twr_ss_ext/src/twr_ss_ext.c b/lib/twr_ss_ext/src/twr_ss_ext.c -index 6e55a13..2ea3384 100644 ---- a/lib/twr_ss_ext/src/twr_ss_ext.c -+++ b/lib/twr_ss_ext/src/twr_ss_ext.c -@@ -74,6 +74,7 @@ static struct uwb_mac_interface g_cbs[] = { - #endif - }; - -+#if MYNEWT_VAL(TWR_SS_EXT_STATS) - STATS_SECT_START(twr_ss_ext_stat_section) - STATS_SECT_ENTRY(complete) - STATS_SECT_ENTRY(tx_error) -@@ -85,6 +86,10 @@ STATS_NAME_START(twr_ss_ext_stat_section) - STATS_NAME_END(twr_ss_ext_stat_section) - - static STATS_SECT_DECL(twr_ss_ext_stat_section) g_twr_ss_ext_stat; -+#define SS_STATS_INC(__X) STATS_INC(g_twr_ss_ext_stat __X) -+#else -+#define SS_STATS_INC(__X) {} -+#endif - - static struct uwb_rng_config g_config = { - .tx_holdoff_delay = MYNEWT_VAL(TWR_SS_EXT_TX_HOLDOFF), // Send Time delay in usec. -@@ -140,12 +145,14 @@ twr_ss_ext_pkg_init(void) - uwb_rng_append_config(g_cbs[i].inst_ptr, &g_rng_cfgs[i]); - } - -+#if MYNEWT_VAL(TWR_SS_EXT_STATS) - rc = stats_init( - STATS_HDR(g_twr_ss_ext_stat), - STATS_SIZE_INIT_PARMS(g_twr_ss_ext_stat, STATS_SIZE_32), - STATS_NAME_INIT_PARMS(twr_ss_ext_stat_section)); - rc |= stats_register("twr_ss_ext", STATS_HDR(g_twr_ss_ext_stat)); - assert(rc == 0); -+#endif - } - - /** -@@ -241,7 +248,7 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) - uwb_set_delay_start(inst, txd.response_tx_delay); - - if (uwb_start_tx(inst).start_tx_error){ -- STATS_INC(g_twr_ss_ext_stat, tx_error); -+ SS_STATS_INC(tx_error); - dpl_sem_release(&rng->sem); - } - /* Setup when to listen for response, relative the end of our transmitted frame */ -@@ -284,12 +291,12 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) - uwb_set_delay_start(inst, txd.response_tx_delay); - - if (uwb_start_tx(inst).start_tx_error){ -- STATS_INC(g_twr_ss_ext_stat, tx_error); -+ SS_STATS_INC(tx_error); - dpl_sem_release(&rng->sem); - rng_issue_complete(inst); - } - else{ -- STATS_INC(g_twr_ss_ext_stat, complete); -+ SS_STATS_INC(complete); - rng->control.complete_after_tx = 1; - } - break; -@@ -301,7 +308,7 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) - if (inst->frame_len != sizeof(twr_frame_final_t)) - break; - -- STATS_INC(g_twr_ss_ext_stat, complete); -+ SS_STATS_INC(complete); - dpl_sem_release(&rng->sem); - rng_issue_complete(inst); - break; -diff --git a/lib/twr_ss_ext/syscfg.yml b/lib/twr_ss_ext/syscfg.yml -index fcca45a..a71963f 100644 ---- a/lib/twr_ss_ext/syscfg.yml -+++ b/lib/twr_ss_ext/syscfg.yml -@@ -10,3 +10,6 @@ syscfg.defs: - TWR_SS_EXT_RX_TIMEOUT: - description: 'TOA timeout delay for SS EXT TWR (usec)' - value: ((uint16_t)0x40) -+ TWR_SS_EXT_STATS: -+ description: 'Enable statistics for the twr_ss_ext module' -+ value: 1 -diff --git a/lib/twr_ss_ext_nrng/src/twr_ss_ext_nrng.c b/lib/twr_ss_ext_nrng/src/twr_ss_ext_nrng.c -index 3808785..759f928 100644 ---- a/lib/twr_ss_ext_nrng/src/twr_ss_ext_nrng.c -+++ b/lib/twr_ss_ext_nrng/src/twr_ss_ext_nrng.c -@@ -67,6 +67,7 @@ static struct uwb_mac_interface g_cbs = { - .final_cb = tx_final_cb, - }; - -+#if MYNEWT_VAL(TWR_SS_EXT_NRNG_STATS) - STATS_SECT_START(twr_ss_ext_nrng_stat_section) - STATS_SECT_ENTRY(complete) - STATS_SECT_ENTRY(rx_error) -@@ -80,6 +81,10 @@ STATS_NAME_START(twr_ss_ext_nrng_stat_section) - STATS_NAME_END(twr_ss_ext_nrng_stat_section) - - static STATS_SECT_DECL(twr_ss_ext_nrng_stat_section) g_stat; -+#define SS_STATS_INC(__X) STATS_INC(g_stat, __X) -+#else -+#define SS_STATS_INC(__X) {} -+#endif - - static struct uwb_rng_config g_config = { - .tx_holdoff_delay = MYNEWT_VAL(TWR_SS_EXT_NRNG_TX_HOLDOFF), // Send Time delay in usec. -@@ -107,12 +112,14 @@ void twr_ss_ext_nrng_pkg_init(void) - uwb_mac_append_interface(uwb_dev_idx_lookup(0), &g_cbs); - nrng_append_config(nrng, &g_rng_cfgs); - -+#if MYNEWT_VAL(TWR_SS_EXT_NRNG_STATS) - int rc = stats_init( - STATS_HDR(g_stat), - STATS_SIZE_INIT_PARMS(g_stat, STATS_SIZE_32), - STATS_NAME_INIT_PARMS(twr_ss_ext_nrng_stat_section)); - rc |= stats_register("ss_ext_nrng", STATS_HDR(g_stat)); - assert(rc == 0); -+#endif - } - - /** -@@ -144,7 +151,7 @@ rx_error_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs){ - } - struct uwb_rng_instance * rng = inst->rng; - if(os_sem_get_count(&rng->sem) == 0){ -- STATS_INC(g_stat, rx_error); -+ SS_STATS_INC(rx_error); - os_error_t err = os_sem_release(&rng->sem); - assert(err == OS_OK); - return true; -diff --git a/lib/twr_ss_ext_nrng/syscfg.yml b/lib/twr_ss_ext_nrng/syscfg.yml -index 997def3..ff8c789 100644 ---- a/lib/twr_ss_ext_nrng/syscfg.yml -+++ b/lib/twr_ss_ext_nrng/syscfg.yml -@@ -12,6 +12,9 @@ syscfg.defs: - value: ((uint16_t)0x10) - TWR_SS_EXT_NRNG_TX_GUARD_DELAY: - value: ((uint32_t)0x90) -+ TWR_SS_EXT_NRNG_STATS: -+ description: 'Enable statistics for the twr_ss_ext_nrng module' -+ value: 1 - CELL_ENABLED: - description: 'Cell network model on slot decoding' - value: 0 -diff --git a/lib/twr_ss_nrng/src/twr_ss_nrng.c b/lib/twr_ss_nrng/src/twr_ss_nrng.c -index b6550f6..f5a60fc 100644 ---- a/lib/twr_ss_nrng/src/twr_ss_nrng.c -+++ b/lib/twr_ss_nrng/src/twr_ss_nrng.c -@@ -52,6 +52,24 @@ - #define DIAGMSG(s,u) - #endif - -+#if MYNEWT_VAL(TWR_SS_NRNG_STATS) -+STATS_SECT_START(twr_ss_nrng_stat_section) -+ STATS_SECT_ENTRY(complete) -+ STATS_SECT_ENTRY(start_tx_error) -+STATS_SECT_END -+ -+STATS_NAME_START(twr_ss_nrng_stat_section) -+ STATS_NAME(twr_ss_nrng_stat_section, complete) -+ STATS_NAME(twr_ss_nrng_stat_section, start_tx_error) -+STATS_NAME_END(twr_ss_nrng_stat_section) -+ -+STATS_SECT_DECL(twr_ss_nrng_stat_section) g_twr_ss_nrng_stat; -+#define SS_STATS_INC(__X) STATS_INC(g_twr_ss_nrng_stat, __X) -+#else -+#define SS_STATS_INC(__X) {} -+#endif -+ -+ - static bool rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs); - static bool rx_timeout_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs); - static bool rx_error_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs); -@@ -93,6 +111,17 @@ void twr_ss_nrng_pkg_init(void) - g_cbs.inst_ptr = nrng; - uwb_mac_append_interface(udev, &g_cbs); - nrng_append_config(nrng, &g_rng_cfgs); -+ -+#if MYNEWT_VAL(TWR_SS_NRNG_STATS) -+ int rc = stats_init( -+ STATS_HDR(g_twr_ss_nrng_stat), -+ STATS_SIZE_INIT_PARMS(g_twr_ss_nrng_stat, STATS_SIZE_32), -+ STATS_NAME_INIT_PARMS(twr_ss_nrng_stat_section)); -+ assert(rc == 0); -+ -+ rc = stats_register("twr_ss_nrng", STATS_HDR(g_twr_ss_nrng_stat)); -+ assert(rc == 0); -+#endif - } - - -@@ -126,7 +155,7 @@ rx_error_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) - return false; - - if(dpl_sem_get_count(&nrng->sem) == 0){ -- NRNG_STATS_INC(rx_error); -+ SS_STATS_INC(rx_error); - dpl_error_t err = dpl_sem_release(&nrng->sem); - assert(err == DPL_OK); - return true; -@@ -150,7 +179,7 @@ rx_timeout_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) - return false; - - if(dpl_sem_get_count(&nrng->sem) == 0){ -- NRNG_STATS_INC(rx_timeout); -+ SS_STATS_INC(rx_timeout); - // In the case of a NRNG timeout is used to mark the end of the request - // and is used to call the completion callback - if(!(SLIST_EMPTY(&inst->interface_cbs))){ -@@ -179,7 +208,7 @@ reset_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) - if(dpl_sem_get_count(&nrng->sem) == 0){ - dpl_error_t err = dpl_sem_release(&nrng->sem); - assert(err == DPL_OK); -- NRNG_STATS_INC(reset); -+ SS_STATS_INC(reset); - return true; - } - else -@@ -203,7 +232,7 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) - - if(dpl_sem_get_count(&nrng->sem) == 1){ - // unsolicited inbound -- NRNG_STATS_INC(rx_unsolicited); -+ SS_STATS_INC(rx_unsolicited); - return false; - } - -@@ -213,7 +242,7 @@ rx_complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) - if (_frame->dst_address != inst->my_short_address && _frame->dst_address != UWB_BROADCAST_ADDRESS) - return true; - -- NRNG_STATS_INC(rx_complete); -+ SS_STATS_INC(rx_complete); - - switch(_frame->code){ - case UWB_DATA_CODE_SS_TWR_NRNG: -diff --git a/lib/twr_ss_nrng/syscfg.yml b/lib/twr_ss_nrng/syscfg.yml -index 7ef5969..a296efd 100644 ---- a/lib/twr_ss_nrng/syscfg.yml -+++ b/lib/twr_ss_nrng/syscfg.yml -@@ -12,6 +12,9 @@ syscfg.defs: - value: ((uint16_t)0x10) - TWR_SS_NRNG_TX_GUARD_DELAY: - value: ((uint32_t)0x120) -+ TWR_SS_NRNG_STATS: -+ description: 'Enable statistics for the twr_ss_nrng module' -+ value: 1 - CELL_ENABLED: - description: 'Cell network model on slot decoding' - value: 1 --- -2.28.0 - diff --git a/pkg/uwb-core/patches/0003-lib-tofdb-use-DPL_ENOENT-instead-of-OS_ENOENT.patch b/pkg/uwb-core/patches/0003-lib-tofdb-use-DPL_ENOENT-instead-of-OS_ENOENT.patch deleted file mode 100644 index 774f3d5191..0000000000 --- a/pkg/uwb-core/patches/0003-lib-tofdb-use-DPL_ENOENT-instead-of-OS_ENOENT.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 478d952b17c33ed5644172c9b4aebf4cdf7bec62 Mon Sep 17 00:00:00 2001 -From: Francisco Molina -Date: Fri, 14 Aug 2020 15:04:20 +0200 -Subject: [PATCH 3/7] lib/tofdb/: use DPL_ENOENT instead of OS_ENOENT - ---- - lib/tofdb/src/tofdb.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/lib/tofdb/src/tofdb.c b/lib/tofdb/src/tofdb.c -index e6c8015..7d75942 100644 ---- a/lib/tofdb/src/tofdb.c -+++ b/lib/tofdb/src/tofdb.c -@@ -28,7 +28,7 @@ int tofdb_get_tof(uint16_t addr, uint32_t *tof) - goto ret; - } - } -- return OS_ENOENT; -+ return DPL_ENOENT; - ret: - return OS_OK; - } --- -2.28.0 - diff --git a/pkg/uwb-core/patches/0007-lib-uwb_rng-always-set-rssi-to-vrssi-0.patch b/pkg/uwb-core/patches/0003-lib-uwb_rng-always-set-rssi-to-vrssi-0.patch similarity index 90% rename from pkg/uwb-core/patches/0007-lib-uwb_rng-always-set-rssi-to-vrssi-0.patch rename to pkg/uwb-core/patches/0003-lib-uwb_rng-always-set-rssi-to-vrssi-0.patch index 9277b171f4..ae7f326365 100644 --- a/pkg/uwb-core/patches/0007-lib-uwb_rng-always-set-rssi-to-vrssi-0.patch +++ b/pkg/uwb-core/patches/0003-lib-uwb_rng-always-set-rssi-to-vrssi-0.patch @@ -1,7 +1,7 @@ -From f51123d3cfcd811090367a65d5bf029897aceb98 Mon Sep 17 00:00:00 2001 +From 46dfbfe2551d5fd10de7dd8956a3b210e6030c44 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Mon, 21 Sep 2020 13:42:56 +0200 -Subject: [PATCH 7/7] lib/uwb_rng: always set rssi to vrssi[0] +Subject: [PATCH 3/5] lib/uwb_rng: always set rssi to vrssi[0] --- lib/uwb_rng/src/uwb_rng.c | 5 +++++ diff --git a/pkg/uwb-core/patches/0004-porting-dpl-add-riot-files.patch b/pkg/uwb-core/patches/0004-porting-dpl-add-riot-files.patch new file mode 100644 index 0000000000..7666b20b2e --- /dev/null +++ b/pkg/uwb-core/patches/0004-porting-dpl-add-riot-files.patch @@ -0,0 +1,479 @@ +From 15d99a7e8e518f306bb0cebfc729e830eab81633 Mon Sep 17 00:00:00 2001 +From: Francisco Molina +Date: Tue, 3 Nov 2020 14:12:01 +0100 +Subject: [PATCH 4/5] porting/dpl: add riot files + +--- + porting/dpl/riot/include/config/config.h | 369 +++++++++++++++++++++++ + porting/dpl/riot/src/config.c | 83 +++++ + 2 files changed, 452 insertions(+) + create mode 100644 porting/dpl/riot/include/config/config.h + create mode 100644 porting/dpl/riot/src/config.c + +diff --git a/porting/dpl/riot/include/config/config.h b/porting/dpl/riot/include/config/config.h +new file mode 100644 +index 0000000..4dc4b69 +--- /dev/null ++++ b/porting/dpl/riot/include/config/config.h +@@ -0,0 +1,369 @@ ++/* ++ * Licensed to the Apache Software Foundation (ASF) under one ++ * or more contributor license agreements. See the NOTICE file ++ * distributed with this work for additional information ++ * regarding copyright ownership. The ASF licenses this file ++ * to you under the Apache License, Version 2.0 (the ++ * "License"); you may not use this file except in compliance ++ * with the License. You may obtain a copy of the License at ++ * ++ * http://www.apache.org/licenses/LICENSE-2.0 ++ * ++ * Unless required by applicable law or agreed to in writing, ++ * software distributed under the License is distributed on an ++ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ++ * KIND, either express or implied. See the License for the ++ * specific language governing permissions and limitations ++ * under the License. ++ */ ++#ifndef __SYS_CONFIG_H_ ++#define __SYS_CONFIG_H_ ++ ++/** ++ * @addtogroup SysConfig Configuration of Apache Mynewt System ++ * @{ ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#ifdef __cplusplus ++extern "C" { ++#endif ++ ++/** @cond INTERNAL_HIDDEN */ ++ ++#define CONF_MAX_DIR_DEPTH 8 /* max depth of config tree */ ++#define CONF_MAX_NAME_LEN (8 * CONF_MAX_DIR_DEPTH) ++#define CONF_MAX_VAL_LEN 256 ++#define CONF_NAME_SEPARATOR "/" ++ ++#define CONF_NMGR_OP 0 ++ ++/** @endcond */ ++ ++/** ++ * Type of configuration value. ++ */ ++typedef enum conf_type { ++ CONF_NONE = 0, ++ CONF_DIR, ++ /** 8-bit signed integer */ ++ CONF_INT8, ++ /** 16-bit signed integer */ ++ CONF_INT16, ++ /** 32-bit signed integer */ ++ CONF_INT32, ++ /** 64-bit signed integer */ ++ CONF_INT64, ++ /** String */ ++ CONF_STRING, ++ /** Bytes */ ++ CONF_BYTES, ++ /** Floating point */ ++ CONF_FLOAT, ++ /** Double precision */ ++ CONF_DOUBLE, ++ /** Boolean */ ++ CONF_BOOL, ++} __attribute__((__packed__)) conf_type_t; ++ ++/** ++ * Parameter to commit handler describing where data is going to. ++ */ ++enum conf_export_tgt { ++ /** Value is to be persisted */ ++ CONF_EXPORT_PERSIST, ++ /** Value is to be display */ ++ CONF_EXPORT_SHOW ++}; ++ ++typedef enum conf_export_tgt conf_export_tgt_t; ++ ++/** ++ * Handler for getting configuration items, this handler is called ++ * per-configuration section. Configuration sections are delimited ++ * by '/', for example: ++ * ++ * - section/name/value ++ * ++ * Would be passed as: ++ * ++ * - argc = 3 ++ * - argv[0] = section ++ * - argv[1] = name ++ * - argv[2] = value ++ * ++ * The handler returns the value into val, null terminated, up to ++ * val_len_max. ++ * ++ * @param argc The number of sections in the configuration variable ++ * @param argv The array of configuration sections ++ * @param val A pointer to the buffer to return the configuration ++ * value into. ++ * @param val_len_max The maximum length of the val buffer to copy into. ++ * ++ * @return A pointer to val or NULL if error. ++ */ ++typedef char *(*conf_get_handler_t)(int argc, char **argv, char *val, int val_len_max); ++ ++/** ++ * Set the configuration variable pointed to by argc and argv. See ++ * description of ch_get_handler_t for format of these variables. This sets the ++ * configuration variable to the shadow value, but does not apply the configuration ++ * change. In order to apply the change, call the ch_commit() handler. ++ * ++ * @param argc The number of sections in the configuration variable. ++ * @param argv The array of configuration sections ++ * @param val The value to configure that variable to ++ * ++ * @return 0 on success, non-zero error code on failure. ++ */ ++typedef int (*conf_set_handler_t)(int argc, char **argv, char *val); ++ ++/** ++ * Commit shadow configuration state to the active configuration. ++ * ++ * @return 0 on success, non-zero error code on failure. ++ */ ++typedef int (*conf_commit_handler_t)(void); ++ ++/** ++ * Called per-configuration variable being exported. ++ * ++ * @param name The name of the variable to export ++ * @param val The value of the variable to export ++ */ ++typedef void (*conf_export_func_t)(char *name, char *val); ++ ++/** ++ * Export all of the configuration variables, calling the export_func ++ * per variable being exported. ++ * ++ * @param export_func The export function to call. ++ * @param tgt The target of the export, either for persistence or display. ++ * ++ * @return 0 on success, non-zero error code on failure. ++ */ ++typedef int (*conf_export_handler_t)(conf_export_func_t export_func, ++ conf_export_tgt_t tgt); ++ ++/** ++ * Configuration handler, used to register a config item/subtree. ++ */ ++struct conf_handler { ++ SLIST_ENTRY(conf_handler) ch_list; ++ /** ++ * The name of the conifguration item/subtree ++ */ ++ char *ch_name; ++ /** Get configuration value */ ++ conf_get_handler_t ch_get; ++ /** Set configuration value */ ++ conf_set_handler_t ch_set; ++ /** Commit configuration value */ ++ conf_commit_handler_t ch_commit; ++ /** Export configuration value */ ++ conf_export_handler_t ch_export; ++}; ++ ++void conf_init(void); ++void conf_store_init(void); ++ ++/** ++ * Register a handler for configurations items. ++ * ++ * @param cf Structure containing registration info. ++ * ++ * @return 0 on success, non-zero on failure. ++ */ ++//int conf_register(struct conf_handler *cf); ++#define conf_register(__A) printf("%s:%d not implemented", __func__, __LINE__) ++ ++/** ++ * Load configuration from registered persistence sources. Handlers for ++ * configuration subtrees registered earlier will be called for encountered ++ * values. ++ * ++ * @return 0 on success, non-zero on failure. ++ */ ++int conf_load(void); ++ ++/** ++ * Load configuration from a specific registered persistence source. ++ * Handlers will be called for configuration subtree for ++ * encountered values. ++ * ++ * @param name of the configuration subtree. ++ * @return 0 on success, non-zero on failure. ++ */ ++int conf_load_one(char *name); ++ ++/** ++ * @brief Loads the configuration if it hasn't been loaded since reboot. ++ * ++ * @return 0 on success, non-zero on failure. ++ */ ++int conf_ensure_loaded(void); ++ ++/** ++ * Config setting comes as a result of conf_load(). ++ * ++ * @return 1 if yes, 0 if not. ++ */ ++int conf_set_from_storage(void); ++ ++/** ++ * Save currently running configuration. All configuration which is different ++ * from currently persisted values will be saved. ++ * ++ * @return 0 on success, non-zero on failure. ++ */ ++int conf_save(void); ++ ++/** ++ * Save currently running configuration for configuration subtree. ++ * ++ * @param name Name of the configuration subtree. ++ * ++ * @return 0 on success, non-zero on failure. ++ */ ++int conf_save_tree(char *name); ++ ++/** ++ * Write a single configuration value to persisted storage (if it has ++ * changed value). ++ * ++ * @param name Name/key of the configuration item. ++ * @param var Value of the configuration item. ++ * ++ * @return 0 on success, non-zero on failure. ++ */ ++int conf_save_one(const char *name, char *var); ++ ++/** ++ * Set configuration item identified by @p name to be value @p val_str. ++ * This finds the configuration handler for this subtree and calls it's ++ * set handler. ++ * ++ * @param name Name/key of the configuration item. ++ * @param val_str Value of the configuration item. ++ * ++ * @return 0 on success, non-zero on failure. ++ */ ++int conf_set_value(char *name, char *val_str); ++ ++/** ++ * Get value of configuration item identified by @p name. ++ * This calls the configuration handler ch_get for the subtree. ++ * ++ * Configuration handler can copy the string to @p buf, the maximum ++ * number of bytes it will copy is limited by @p buf_len. ++ * ++ * Return value will be pointer to beginning of the value. Note that ++ * this might, or might not be the same as buf. ++ * ++ * @param name Name/key of the configuration item. ++ * @param val_str Value of the configuration item. ++ * ++ * @return pointer to value on success, NULL on failure. ++ */ ++char *conf_get_value(char *name, char *buf, int buf_len); ++ ++/** ++ * Get stored value of configuration item identified by @p name. ++ * This traverses the configuration area(s), and copies the value ++ * of the latest value. ++ * ++ * Value is copied to @p buf, the maximum number of bytes it will copy is ++ * limited by @p buf_len. ++ * ++ * @param name Name/key of the configuration item. ++ * @param val_str Value of the configuration item. ++ * ++ * @return 0 on success, non-zero on failure. ++ */ ++int conf_get_stored_value(char *name, char *buf, int buf_len); ++ ++/** ++ * Call commit for all configuration handler. This should apply all ++ * configuration which has been set, but not applied yet. ++ * ++ * @param name Name of the configuration subtree, or NULL to commit everything. ++ * ++ * @return 0 on success, non-zero on failure. ++ */ ++int conf_commit(char *name); ++ ++/** ++ * Convenience routine for converting value passed as a string to native ++ * data type. ++ * ++ * @param val_str Value of the configuration item as string. ++ * @param type Type of the value to convert to. ++ * @param vp Pointer to variable to fill with the decoded value. ++ * @param vp Size of that variable. ++ * ++ * @return 0 on success, non-zero on failure. ++ */ ++int conf_value_from_str(char *val_str, enum conf_type type, void *vp, ++ int maxlen); ++ ++/** ++ * Convenience routine for converting byte array passed as a base64 ++ * encoded string. ++ * ++ * @param val_str Value of the configuration item as string. ++ * @param vp Pointer to variable to fill with the decoded value. ++ * @param len Size of that variable. On return the number of bytes in the array. ++ * ++ * @return 0 on success, non-zero on failure. ++ */ ++int conf_bytes_from_str(char *val_str, void *vp, int *len); ++ ++/** ++ * Convenience routine for converting native data type to a string. ++ * ++ * @param type Type of the value to convert from. ++ * @param vp Pointer to variable to convert. ++ * @param buf Buffer where string value will be stored. ++ * @param buf_len Size of the buffer. ++ * ++ * @return 0 on success, non-zero on failure. ++ */ ++char *conf_str_from_value(enum conf_type type, void *vp, char *buf, ++ int buf_len); ++ ++/** Return the length of a configuration string from buffer length. */ ++#define CONF_STR_FROM_BYTES_LEN(len) (((len) * 4 / 3) + 4) ++ ++/** ++ * Convenience routine for converting byte array into a base64 ++ * encoded string. ++ * ++ * @param vp Pointer to variable to convert. ++ * @param vp_len Number of bytes to convert. ++ * @param buf Buffer where string value will be stored. ++ * @param buf_len Size of the buffer. ++ * ++ * @return 0 on success, non-zero on failure. ++ */ ++char *conf_str_from_bytes(void *vp, int vp_len, char *buf, int buf_len); ++ ++/** ++ * Convert a string into a value of type ++ */ ++#define CONF_VALUE_SET(str, type, val) \ ++ conf_value_from_str((str), (type), &(val), sizeof(val)) ++ ++#ifdef __cplusplus ++} ++#endif ++ ++/** ++ * @} SysConfig ++ */ ++ ++#endif /* __SYS_CONFIG_H_ */ +diff --git a/porting/dpl/riot/src/config.c b/porting/dpl/riot/src/config.c +new file mode 100644 +index 0000000..9e4bde1 +--- /dev/null ++++ b/porting/dpl/riot/src/config.c +@@ -0,0 +1,83 @@ ++/* ++ * Licensed to the Apache Software Foundation (ASF) under one ++ * or more contributor license agreements. See the NOTICE file ++ * distributed with this work for additional information ++ * regarding copyright ownership. The ASF licenses this file ++ * to you under the Apache License, Version 2.0 (the ++ * "License"); you may not use this file except in compliance ++ * with the License. You may obtain a copy of the License at ++ * ++ * http://www.apache.org/licenses/LICENSE-2.0 ++ * ++ * Unless required by applicable law or agreed to in writing, ++ * software distributed under the License is distributed on an ++ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ++ * KIND, either express or implied. See the License for the ++ * specific language governing permissions and limitations ++ * under the License. ++ */ ++ ++#include "config/config.h" ++#include ++#include ++#include ++#include ++ ++int conf_value_from_str(char *val_str, enum conf_type type, void *vp, int maxlen) ++{ ++ int32_t val; ++ int64_t val64; ++ char *eptr; ++ ++ if (!val_str) { ++ goto err; ++ } ++ switch (type) { ++ case CONF_INT8: ++ case CONF_INT16: ++ case CONF_INT32: ++ case CONF_BOOL: ++ val = strtol(val_str, &eptr, 0); ++ if (*eptr != '\0') { ++ goto err; ++ } ++ if (type == CONF_BOOL) { ++ if (val < 0 || val > 1) { ++ goto err; ++ } ++ *(bool *)vp = val; ++ } else if (type == CONF_INT8) { ++ if (val < INT8_MIN || val > UINT8_MAX) { ++ goto err; ++ } ++ *(int8_t *)vp = val; ++ } else if (type == CONF_INT16) { ++ if (val < INT16_MIN || val > UINT16_MAX) { ++ goto err; ++ } ++ *(int16_t *)vp = val; ++ } else if (type == CONF_INT32) { ++ *(int32_t *)vp = val; ++ } ++ break; ++ case CONF_INT64: ++ val64 = strtoll(val_str, &eptr, 0); ++ if (*eptr != '\0') { ++ goto err; ++ } ++ *(int64_t *)vp = val64; ++ break; ++ case CONF_STRING: ++ val = strlen(val_str); ++ if (val + 1 > maxlen) { ++ goto err; ++ } ++ strcpy(vp, val_str); ++ break; ++ default: ++ goto err; ++ } ++ return 0; ++err: ++ return EINVAL; ++} +-- +2.28.0 + diff --git a/pkg/uwb-core/patches/0004-sys-uwbcfg-use-DPL_ENOENT-instead-of-OS_ENOENT.patch b/pkg/uwb-core/patches/0004-sys-uwbcfg-use-DPL_ENOENT-instead-of-OS_ENOENT.patch deleted file mode 100644 index a2d71e5d61..0000000000 --- a/pkg/uwb-core/patches/0004-sys-uwbcfg-use-DPL_ENOENT-instead-of-OS_ENOENT.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 2304bef6c63b15411fae3050554edc0538ae93d9 Mon Sep 17 00:00:00 2001 -From: Francisco Molina -Date: Fri, 14 Aug 2020 15:08:22 +0200 -Subject: [PATCH 4/7] sys/uwbcfg: use DPL_ENOENT instead of OS_ENOENT - ---- - sys/uwbcfg/src/uwbcfg.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/sys/uwbcfg/src/uwbcfg.c b/sys/uwbcfg/src/uwbcfg.c -index 595c19b..4c4678e 100644 ---- a/sys/uwbcfg/src/uwbcfg.c -+++ b/sys/uwbcfg/src/uwbcfg.c -@@ -149,7 +149,7 @@ uwbcfg_set(int argc, char **argv, char *val) - return CONF_VALUE_SET(val, CONF_STRING, g_uwb_config[i]); - } - } -- return OS_ENOENT; -+ return DPL_ENOENT; - } - - char* --- -2.28.0 - diff --git a/pkg/uwb-core/patches/0005-hw-drivers-uwb-include-uwb-add-UWB_ROLE_TAG-role.patch b/pkg/uwb-core/patches/0005-hw-drivers-uwb-include-uwb-add-UWB_ROLE_TAG-role.patch new file mode 100644 index 0000000000..196b545a5a --- /dev/null +++ b/pkg/uwb-core/patches/0005-hw-drivers-uwb-include-uwb-add-UWB_ROLE_TAG-role.patch @@ -0,0 +1,24 @@ +From f87d1a3ca89118b654a32cea58f4b03774042c17 Mon Sep 17 00:00:00 2001 +From: Francisco Molina +Date: Fri, 13 Nov 2020 15:20:42 +0100 +Subject: [PATCH 5/5] hw/drivers/uwb/include/uwb: add UWB_ROLE_TAG role + +--- + hw/drivers/uwb/include/uwb/uwb.h | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/hw/drivers/uwb/include/uwb/uwb.h b/hw/drivers/uwb/include/uwb/uwb.h +index 2872e46..00017be 100644 +--- a/hw/drivers/uwb/include/uwb/uwb.h ++++ b/hw/drivers/uwb/include/uwb/uwb.h +@@ -68,6 +68,7 @@ typedef enum uwb_extension_id { + } uwb_extension_id_t; + + //! Device Roles ++#define UWB_ROLE_TAG (0x0000) //!< Act as a TAG + #define UWB_ROLE_CCP_MASTER (0x0001) //!< Act as Clock Master for the network + #define UWB_ROLE_PAN_MASTER (0x0002) //!< Act as Pan Master handing out slots and addresses + #define UWB_ROLE_ANCHOR (0x0004) //!< Act as an Anchor, a non-mobile unit +-- +2.28.0 + diff --git a/pkg/uwb-core/patches/0005-treewide-use-dpl_log.h-instaed-of-log.h-to-avoid-con.patch b/pkg/uwb-core/patches/0005-treewide-use-dpl_log.h-instaed-of-log.h-to-avoid-con.patch deleted file mode 100644 index a9388932ad..0000000000 --- a/pkg/uwb-core/patches/0005-treewide-use-dpl_log.h-instaed-of-log.h-to-avoid-con.patch +++ /dev/null @@ -1,78 +0,0 @@ -From 86db74c73938d86a3bcf581af2174991cef632fe Mon Sep 17 00:00:00 2001 -From: Francisco Molina -Date: Fri, 14 Aug 2020 15:11:06 +0200 -Subject: [PATCH 5/7] treewide: use dpl_log.h instaed of log.h to avoid - conflict - ---- - lib/panmaster/src/panmaster.c | 10 +++++----- - sys/uwbcfg/src/uwbcfg.c | 2 +- - sys/uwbcfg/src/uwbcfg_priv.h | 10 +++++----- - 3 files changed, 11 insertions(+), 11 deletions(-) - -diff --git a/lib/panmaster/src/panmaster.c b/lib/panmaster/src/panmaster.c -index a1234b6..f2d9fef 100644 ---- a/lib/panmaster/src/panmaster.c -+++ b/lib/panmaster/src/panmaster.c -@@ -2,7 +2,7 @@ - #include - #include - #include --#include -+#include - #include - - #include "panmaster/panmaster.h" -@@ -23,10 +23,10 @@ static uint16_t pan_id = 0x0000; - static volatile int nodes_loaded = 0; - - #define LOG_MODULE_PAN_MASTER (91) --#define PM_INFO(...) LOG_INFO(&_log, LOG_MODULE_PAN_MASTER, __VA_ARGS__) --#define PM_DEBUG(...) LOG_DEBUG(&_log, LOG_MODULE_PAN_MASTER, __VA_ARGS__) --#define PM_WARN(...) LOG_WARN(&_log, LOG_MODULE_PAN_MASTER, __VA_ARGS__) --#define PM_ERR(...) LOG_ERROR(&_log, LOG_MODULE_PAN_MASTER, __VA_ARGS__) -+#define PM_INFO(...) LOG_INFO(__VA_ARGS__) -+#define PM_DEBUG(...) LOG_DEBUG(__VA_ARGS__) -+#define PM_WARN(...) LOG_WARN(__VA_ARGS__) -+#define PM_ERR(...) LOG_ERROR(__VA_ARGS__) - static struct log _log; - - /* -diff --git a/sys/uwbcfg/src/uwbcfg.c b/sys/uwbcfg/src/uwbcfg.c -index 4c4678e..c7c97ea 100644 ---- a/sys/uwbcfg/src/uwbcfg.c -+++ b/sys/uwbcfg/src/uwbcfg.c -@@ -21,7 +21,7 @@ - #include - - #include --#include -+#include - #include - #include - #include -diff --git a/sys/uwbcfg/src/uwbcfg_priv.h b/sys/uwbcfg/src/uwbcfg_priv.h -index 8f7f05b..4158b34 100644 ---- a/sys/uwbcfg/src/uwbcfg_priv.h -+++ b/sys/uwbcfg/src/uwbcfg_priv.h -@@ -20,12 +20,12 @@ - #ifndef __UWBCFG_PRIV_H_ - #define __UWBCFG_PRIV_H_ - --#include -+#include - #define LOG_MODULE_UWBCFG (92) --#define UC_INFO(...) LOG_INFO(&_uwbcfg_log, LOG_MODULE_UWBCFG, __VA_ARGS__) --#define UC_DEBUG(...) LOG_DEBUG(&_uwbcfg_log, LOG_MODULE_UWBCFG, __VA_ARGS__) --#define UC_WARN(...) LOG_WARN(&_uwbcfg_log, LOG_MODULE_UWBCFG, __VA_ARGS__) --#define UC_ERR(...) LOG_ERROR(&_uwbcfg_log, LOG_MODULE_UWBCFG, __VA_ARGS__) -+#define UC_INFO(...) LOG_INFO(__VA_ARGS__) -+#define UC_DEBUG(...) LOG_DEBUG(__VA_ARGS__) -+#define UC_WARN(...) LOG_WARN(__VA_ARGS__) -+#define UC_ERR(...) LOG_ERROR(__VA_ARGS__) - - enum { - CFGSTR_CH=0, --- -2.28.0 - diff --git a/pkg/uwb-core/patches/0008-porting-dpl-add-riot-files.patch b/pkg/uwb-core/patches/0008-porting-dpl-add-riot-files.patch deleted file mode 100644 index 300f04078b..0000000000 --- a/pkg/uwb-core/patches/0008-porting-dpl-add-riot-files.patch +++ /dev/null @@ -1,1012 +0,0 @@ -From 5662eb0df6c47d0e391de43887c7433912863514 Mon Sep 17 00:00:00 2001 -From: Francisco Molina -Date: Tue, 3 Nov 2020 14:12:01 +0100 -Subject: [PATCH 8/8] porting/dpl: add riot files - ---- - porting/dpl/riot/include/config/config.h | 369 ++++++++++++++++ - porting/dpl/riot/include/dpl/queue.h | 525 +++++++++++++++++++++++ - porting/dpl/riot/src/config.c | 83 ++++ - 3 files changed, 977 insertions(+) - create mode 100644 porting/dpl/riot/include/config/config.h - create mode 100644 porting/dpl/riot/include/dpl/queue.h - create mode 100644 porting/dpl/riot/src/config.c - -diff --git a/porting/dpl/riot/include/config/config.h b/porting/dpl/riot/include/config/config.h -new file mode 100644 -index 0000000..4dc4b69 ---- /dev/null -+++ b/porting/dpl/riot/include/config/config.h -@@ -0,0 +1,369 @@ -+/* -+ * Licensed to the Apache Software Foundation (ASF) under one -+ * or more contributor license agreements. See the NOTICE file -+ * distributed with this work for additional information -+ * regarding copyright ownership. The ASF licenses this file -+ * to you under the Apache License, Version 2.0 (the -+ * "License"); you may not use this file except in compliance -+ * with the License. You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, -+ * software distributed under the License is distributed on an -+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -+ * KIND, either express or implied. See the License for the -+ * specific language governing permissions and limitations -+ * under the License. -+ */ -+#ifndef __SYS_CONFIG_H_ -+#define __SYS_CONFIG_H_ -+ -+/** -+ * @addtogroup SysConfig Configuration of Apache Mynewt System -+ * @{ -+ */ -+ -+#include -+#include -+#include -+#include -+ -+#ifdef __cplusplus -+extern "C" { -+#endif -+ -+/** @cond INTERNAL_HIDDEN */ -+ -+#define CONF_MAX_DIR_DEPTH 8 /* max depth of config tree */ -+#define CONF_MAX_NAME_LEN (8 * CONF_MAX_DIR_DEPTH) -+#define CONF_MAX_VAL_LEN 256 -+#define CONF_NAME_SEPARATOR "/" -+ -+#define CONF_NMGR_OP 0 -+ -+/** @endcond */ -+ -+/** -+ * Type of configuration value. -+ */ -+typedef enum conf_type { -+ CONF_NONE = 0, -+ CONF_DIR, -+ /** 8-bit signed integer */ -+ CONF_INT8, -+ /** 16-bit signed integer */ -+ CONF_INT16, -+ /** 32-bit signed integer */ -+ CONF_INT32, -+ /** 64-bit signed integer */ -+ CONF_INT64, -+ /** String */ -+ CONF_STRING, -+ /** Bytes */ -+ CONF_BYTES, -+ /** Floating point */ -+ CONF_FLOAT, -+ /** Double precision */ -+ CONF_DOUBLE, -+ /** Boolean */ -+ CONF_BOOL, -+} __attribute__((__packed__)) conf_type_t; -+ -+/** -+ * Parameter to commit handler describing where data is going to. -+ */ -+enum conf_export_tgt { -+ /** Value is to be persisted */ -+ CONF_EXPORT_PERSIST, -+ /** Value is to be display */ -+ CONF_EXPORT_SHOW -+}; -+ -+typedef enum conf_export_tgt conf_export_tgt_t; -+ -+/** -+ * Handler for getting configuration items, this handler is called -+ * per-configuration section. Configuration sections are delimited -+ * by '/', for example: -+ * -+ * - section/name/value -+ * -+ * Would be passed as: -+ * -+ * - argc = 3 -+ * - argv[0] = section -+ * - argv[1] = name -+ * - argv[2] = value -+ * -+ * The handler returns the value into val, null terminated, up to -+ * val_len_max. -+ * -+ * @param argc The number of sections in the configuration variable -+ * @param argv The array of configuration sections -+ * @param val A pointer to the buffer to return the configuration -+ * value into. -+ * @param val_len_max The maximum length of the val buffer to copy into. -+ * -+ * @return A pointer to val or NULL if error. -+ */ -+typedef char *(*conf_get_handler_t)(int argc, char **argv, char *val, int val_len_max); -+ -+/** -+ * Set the configuration variable pointed to by argc and argv. See -+ * description of ch_get_handler_t for format of these variables. This sets the -+ * configuration variable to the shadow value, but does not apply the configuration -+ * change. In order to apply the change, call the ch_commit() handler. -+ * -+ * @param argc The number of sections in the configuration variable. -+ * @param argv The array of configuration sections -+ * @param val The value to configure that variable to -+ * -+ * @return 0 on success, non-zero error code on failure. -+ */ -+typedef int (*conf_set_handler_t)(int argc, char **argv, char *val); -+ -+/** -+ * Commit shadow configuration state to the active configuration. -+ * -+ * @return 0 on success, non-zero error code on failure. -+ */ -+typedef int (*conf_commit_handler_t)(void); -+ -+/** -+ * Called per-configuration variable being exported. -+ * -+ * @param name The name of the variable to export -+ * @param val The value of the variable to export -+ */ -+typedef void (*conf_export_func_t)(char *name, char *val); -+ -+/** -+ * Export all of the configuration variables, calling the export_func -+ * per variable being exported. -+ * -+ * @param export_func The export function to call. -+ * @param tgt The target of the export, either for persistence or display. -+ * -+ * @return 0 on success, non-zero error code on failure. -+ */ -+typedef int (*conf_export_handler_t)(conf_export_func_t export_func, -+ conf_export_tgt_t tgt); -+ -+/** -+ * Configuration handler, used to register a config item/subtree. -+ */ -+struct conf_handler { -+ SLIST_ENTRY(conf_handler) ch_list; -+ /** -+ * The name of the conifguration item/subtree -+ */ -+ char *ch_name; -+ /** Get configuration value */ -+ conf_get_handler_t ch_get; -+ /** Set configuration value */ -+ conf_set_handler_t ch_set; -+ /** Commit configuration value */ -+ conf_commit_handler_t ch_commit; -+ /** Export configuration value */ -+ conf_export_handler_t ch_export; -+}; -+ -+void conf_init(void); -+void conf_store_init(void); -+ -+/** -+ * Register a handler for configurations items. -+ * -+ * @param cf Structure containing registration info. -+ * -+ * @return 0 on success, non-zero on failure. -+ */ -+//int conf_register(struct conf_handler *cf); -+#define conf_register(__A) printf("%s:%d not implemented", __func__, __LINE__) -+ -+/** -+ * Load configuration from registered persistence sources. Handlers for -+ * configuration subtrees registered earlier will be called for encountered -+ * values. -+ * -+ * @return 0 on success, non-zero on failure. -+ */ -+int conf_load(void); -+ -+/** -+ * Load configuration from a specific registered persistence source. -+ * Handlers will be called for configuration subtree for -+ * encountered values. -+ * -+ * @param name of the configuration subtree. -+ * @return 0 on success, non-zero on failure. -+ */ -+int conf_load_one(char *name); -+ -+/** -+ * @brief Loads the configuration if it hasn't been loaded since reboot. -+ * -+ * @return 0 on success, non-zero on failure. -+ */ -+int conf_ensure_loaded(void); -+ -+/** -+ * Config setting comes as a result of conf_load(). -+ * -+ * @return 1 if yes, 0 if not. -+ */ -+int conf_set_from_storage(void); -+ -+/** -+ * Save currently running configuration. All configuration which is different -+ * from currently persisted values will be saved. -+ * -+ * @return 0 on success, non-zero on failure. -+ */ -+int conf_save(void); -+ -+/** -+ * Save currently running configuration for configuration subtree. -+ * -+ * @param name Name of the configuration subtree. -+ * -+ * @return 0 on success, non-zero on failure. -+ */ -+int conf_save_tree(char *name); -+ -+/** -+ * Write a single configuration value to persisted storage (if it has -+ * changed value). -+ * -+ * @param name Name/key of the configuration item. -+ * @param var Value of the configuration item. -+ * -+ * @return 0 on success, non-zero on failure. -+ */ -+int conf_save_one(const char *name, char *var); -+ -+/** -+ * Set configuration item identified by @p name to be value @p val_str. -+ * This finds the configuration handler for this subtree and calls it's -+ * set handler. -+ * -+ * @param name Name/key of the configuration item. -+ * @param val_str Value of the configuration item. -+ * -+ * @return 0 on success, non-zero on failure. -+ */ -+int conf_set_value(char *name, char *val_str); -+ -+/** -+ * Get value of configuration item identified by @p name. -+ * This calls the configuration handler ch_get for the subtree. -+ * -+ * Configuration handler can copy the string to @p buf, the maximum -+ * number of bytes it will copy is limited by @p buf_len. -+ * -+ * Return value will be pointer to beginning of the value. Note that -+ * this might, or might not be the same as buf. -+ * -+ * @param name Name/key of the configuration item. -+ * @param val_str Value of the configuration item. -+ * -+ * @return pointer to value on success, NULL on failure. -+ */ -+char *conf_get_value(char *name, char *buf, int buf_len); -+ -+/** -+ * Get stored value of configuration item identified by @p name. -+ * This traverses the configuration area(s), and copies the value -+ * of the latest value. -+ * -+ * Value is copied to @p buf, the maximum number of bytes it will copy is -+ * limited by @p buf_len. -+ * -+ * @param name Name/key of the configuration item. -+ * @param val_str Value of the configuration item. -+ * -+ * @return 0 on success, non-zero on failure. -+ */ -+int conf_get_stored_value(char *name, char *buf, int buf_len); -+ -+/** -+ * Call commit for all configuration handler. This should apply all -+ * configuration which has been set, but not applied yet. -+ * -+ * @param name Name of the configuration subtree, or NULL to commit everything. -+ * -+ * @return 0 on success, non-zero on failure. -+ */ -+int conf_commit(char *name); -+ -+/** -+ * Convenience routine for converting value passed as a string to native -+ * data type. -+ * -+ * @param val_str Value of the configuration item as string. -+ * @param type Type of the value to convert to. -+ * @param vp Pointer to variable to fill with the decoded value. -+ * @param vp Size of that variable. -+ * -+ * @return 0 on success, non-zero on failure. -+ */ -+int conf_value_from_str(char *val_str, enum conf_type type, void *vp, -+ int maxlen); -+ -+/** -+ * Convenience routine for converting byte array passed as a base64 -+ * encoded string. -+ * -+ * @param val_str Value of the configuration item as string. -+ * @param vp Pointer to variable to fill with the decoded value. -+ * @param len Size of that variable. On return the number of bytes in the array. -+ * -+ * @return 0 on success, non-zero on failure. -+ */ -+int conf_bytes_from_str(char *val_str, void *vp, int *len); -+ -+/** -+ * Convenience routine for converting native data type to a string. -+ * -+ * @param type Type of the value to convert from. -+ * @param vp Pointer to variable to convert. -+ * @param buf Buffer where string value will be stored. -+ * @param buf_len Size of the buffer. -+ * -+ * @return 0 on success, non-zero on failure. -+ */ -+char *conf_str_from_value(enum conf_type type, void *vp, char *buf, -+ int buf_len); -+ -+/** Return the length of a configuration string from buffer length. */ -+#define CONF_STR_FROM_BYTES_LEN(len) (((len) * 4 / 3) + 4) -+ -+/** -+ * Convenience routine for converting byte array into a base64 -+ * encoded string. -+ * -+ * @param vp Pointer to variable to convert. -+ * @param vp_len Number of bytes to convert. -+ * @param buf Buffer where string value will be stored. -+ * @param buf_len Size of the buffer. -+ * -+ * @return 0 on success, non-zero on failure. -+ */ -+char *conf_str_from_bytes(void *vp, int vp_len, char *buf, int buf_len); -+ -+/** -+ * Convert a string into a value of type -+ */ -+#define CONF_VALUE_SET(str, type, val) \ -+ conf_value_from_str((str), (type), &(val), sizeof(val)) -+ -+#ifdef __cplusplus -+} -+#endif -+ -+/** -+ * @} SysConfig -+ */ -+ -+#endif /* __SYS_CONFIG_H_ */ -diff --git a/porting/dpl/riot/include/dpl/queue.h b/porting/dpl/riot/include/dpl/queue.h -new file mode 100644 -index 0000000..4e74970 ---- /dev/null -+++ b/porting/dpl/riot/include/dpl/queue.h -@@ -0,0 +1,525 @@ -+/* -+ * Copyright (c) 1991, 1993 -+ * The Regents of the University of California. All rights reserved. -+ * -+ * Redistribution and use in source and binary forms, with or without -+ * modification, are permitted provided that the following conditions -+ * are met: -+ * 1. Redistributions of source code must retain the above copyright -+ * notice, this list of conditions and the following disclaimer. -+ * 2. Redistributions in binary form must reproduce the above copyright -+ * notice, this list of conditions and the following disclaimer in the -+ * documentation and/or other materials provided with the distribution. -+ * 4. Neither the name of the University nor the names of its contributors -+ * may be used to endorse or promote products derived from this software -+ * without specific prior written permission. -+ * -+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -+ * SUCH DAMAGE. -+ * -+ * @(#)queue.h 8.5 (Berkeley) 8/20/94 -+ * $FreeBSD: src/sys/sys/queue.h,v 1.32.2.7 2002/04/17 14:21:02 des Exp $ -+ */ -+ -+#ifndef DPL_QUEUE_H -+#define DPL_QUEUE_H -+ -+#ifdef __cplusplus -+extern "C" { -+#endif -+ -+/* -+ * This file defines five types of data structures: singly-linked lists, -+ * singly-linked tail queues, lists, tail queues, and circular queues. -+ * -+ * A singly-linked list is headed by a single forward pointer. The elements -+ * are singly linked for minimum space and pointer manipulation overhead at -+ * the expense of O(n) removal for arbitrary elements. New elements can be -+ * added to the list after an existing element or at the head of the list. -+ * Elements being removed from the head of the list should use the explicit -+ * macro for this purpose for optimum efficiency. A singly-linked list may -+ * only be traversed in the forward direction. Singly-linked lists are ideal -+ * for applications with large datasets and few or no removals or for -+ * implementing a LIFO queue. -+ * -+ * A singly-linked tail queue is headed by a pair of pointers, one to the -+ * head of the list and the other to the tail of the list. The elements are -+ * singly linked for minimum space and pointer manipulation overhead at the -+ * expense of O(n) removal for arbitrary elements. New elements can be added -+ * to the list after an existing element, at the head of the list, or at the -+ * end of the list. Elements being removed from the head of the tail queue -+ * should use the explicit macro for this purpose for optimum efficiency. -+ * A singly-linked tail queue may only be traversed in the forward direction. -+ * Singly-linked tail queues are ideal for applications with large datasets -+ * and few or no removals or for implementing a FIFO queue. -+ * -+ * A list is headed by a single forward pointer (or an array of forward -+ * pointers for a hash table header). The elements are doubly linked -+ * so that an arbitrary element can be removed without a need to -+ * traverse the list. New elements can be added to the list before -+ * or after an existing element or at the head of the list. A list -+ * may only be traversed in the forward direction. -+ * -+ * A tail queue is headed by a pair of pointers, one to the head of the -+ * list and the other to the tail of the list. The elements are doubly -+ * linked so that an arbitrary element can be removed without a need to -+ * traverse the list. New elements can be added to the list before or -+ * after an existing element, at the head of the list, or at the end of -+ * the list. A tail queue may be traversed in either direction. -+ * -+ * A circle queue is headed by a pair of pointers, one to the head of the -+ * list and the other to the tail of the list. The elements are doubly -+ * linked so that an arbitrary element can be removed without a need to -+ * traverse the list. New elements can be added to the list before or after -+ * an existing element, at the head of the list, or at the end of the list. -+ * A circle queue may be traversed in either direction, but has a more -+ * complex end of list detection. -+ * -+ * For details on the use of these macros, see the queue(3) manual page. -+ * -+ * -+ * SLIST LIST STAILQ TAILQ CIRCLEQ -+ * _HEAD + + + + + -+ * _HEAD_INITIALIZER + + + + + -+ * _ENTRY + + + + + -+ * _INIT + + + + + -+ * _EMPTY + + + + + -+ * _FIRST + + + + + -+ * _NEXT + + + + + -+ * _PREV - - - + + -+ * _LAST - - + + + -+ * _FOREACH + + + + + -+ * _FOREACH_REVERSE - - - + + -+ * _INSERT_HEAD + + + + + -+ * _INSERT_BEFORE - + - + + -+ * _INSERT_AFTER + + + + + -+ * _INSERT_TAIL - - + + + -+ * _REMOVE_HEAD + - + - - -+ * _REMOVE + + + + + -+ * -+ */ -+ -+/* -+ * Singly-linked List declarations. -+ */ -+#define SLIST_HEAD(name, type) \ -+struct name { \ -+ struct type *slh_first; /* first element */ \ -+} -+ -+#define SLIST_HEAD_INITIALIZER(head) \ -+ { NULL } -+ -+#define SLIST_ENTRY(type) \ -+struct { \ -+ struct type *sle_next; /* next element */ \ -+} -+ -+/* -+ * Singly-linked List functions. -+ */ -+#define SLIST_EMPTY(head) ((head)->slh_first == NULL) -+ -+#define SLIST_FIRST(head) ((head)->slh_first) -+ -+#define SLIST_FOREACH(var, head, field) \ -+ for ((var) = SLIST_FIRST((head)); \ -+ (var); \ -+ (var) = SLIST_NEXT((var), field)) -+ -+#define SLIST_INIT(head) do { \ -+ SLIST_FIRST((head)) = NULL; \ -+} while (0) -+ -+#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ -+ SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \ -+ SLIST_NEXT((slistelm), field) = (elm); \ -+} while (0) -+ -+#define SLIST_INSERT_HEAD(head, elm, field) do { \ -+ SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \ -+ SLIST_FIRST((head)) = (elm); \ -+} while (0) -+ -+#define SLIST_NEXT(elm, field) ((elm)->field.sle_next) -+ -+#define SLIST_REMOVE(head, elm, type, field) do { \ -+ if (SLIST_FIRST((head)) == (elm)) { \ -+ SLIST_REMOVE_HEAD((head), field); \ -+ } \ -+ else { \ -+ struct type *curelm = SLIST_FIRST((head)); \ -+ while (SLIST_NEXT(curelm, field) != (elm)) \ -+ curelm = SLIST_NEXT(curelm, field); \ -+ SLIST_NEXT(curelm, field) = \ -+ SLIST_NEXT(SLIST_NEXT(curelm, field), field); \ -+ } \ -+} while (0) -+ -+#define SLIST_REMOVE_HEAD(head, field) do { \ -+ SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \ -+} while (0) -+ -+/* -+ * Singly-linked Tail queue declarations. -+ */ -+#define STAILQ_HEAD(name, type) \ -+struct name { \ -+ struct type *stqh_first;/* first element */ \ -+ struct type **stqh_last;/* addr of last next element */ \ -+} -+ -+#define STAILQ_HEAD_INITIALIZER(head) \ -+ { NULL, &(head).stqh_first } -+ -+#define STAILQ_ENTRY(type) \ -+struct { \ -+ struct type *stqe_next; /* next element */ \ -+} -+ -+/* -+ * Singly-linked Tail queue functions. -+ */ -+#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL) -+ -+#define STAILQ_FIRST(head) ((head)->stqh_first) -+ -+#define STAILQ_FOREACH(var, head, field) \ -+ for((var) = STAILQ_FIRST((head)); \ -+ (var); \ -+ (var) = STAILQ_NEXT((var), field)) -+ -+#define STAILQ_INIT(head) do { \ -+ STAILQ_FIRST((head)) = NULL; \ -+ (head)->stqh_last = &STAILQ_FIRST((head)); \ -+} while (0) -+ -+#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \ -+ if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\ -+ (head)->stqh_last = &STAILQ_NEXT((elm), field); \ -+ STAILQ_NEXT((tqelm), field) = (elm); \ -+} while (0) -+ -+#define STAILQ_INSERT_HEAD(head, elm, field) do { \ -+ if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \ -+ (head)->stqh_last = &STAILQ_NEXT((elm), field); \ -+ STAILQ_FIRST((head)) = (elm); \ -+} while (0) -+ -+#define STAILQ_INSERT_TAIL(head, elm, field) do { \ -+ STAILQ_NEXT((elm), field) = NULL; \ -+ *(head)->stqh_last = (elm); \ -+ (head)->stqh_last = &STAILQ_NEXT((elm), field); \ -+} while (0) -+ -+#define STAILQ_LAST(head, type, field) \ -+ (STAILQ_EMPTY(head) ? \ -+ NULL : \ -+ ((struct type *) \ -+ ((char *)((head)->stqh_last) - offsetof(struct type, field)))) -+ -+#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) -+ -+#define STAILQ_REMOVE(head, elm, type, field) do { \ -+ if (STAILQ_FIRST((head)) == (elm)) { \ -+ STAILQ_REMOVE_HEAD(head, field); \ -+ } \ -+ else { \ -+ struct type *curelm = STAILQ_FIRST((head)); \ -+ while (STAILQ_NEXT(curelm, field) != (elm)) \ -+ curelm = STAILQ_NEXT(curelm, field); \ -+ if ((STAILQ_NEXT(curelm, field) = \ -+ STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\ -+ (head)->stqh_last = &STAILQ_NEXT((curelm), field);\ -+ } \ -+} while (0) -+ -+#define STAILQ_REMOVE_HEAD(head, field) do { \ -+ if ((STAILQ_FIRST((head)) = \ -+ STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \ -+ (head)->stqh_last = &STAILQ_FIRST((head)); \ -+} while (0) -+ -+#define STAILQ_REMOVE_HEAD_UNTIL(head, elm, field) do { \ -+ if ((STAILQ_FIRST((head)) = STAILQ_NEXT((elm), field)) == NULL) \ -+ (head)->stqh_last = &STAILQ_FIRST((head)); \ -+} while (0) -+ -+#define STAILQ_REMOVE_AFTER(head, elm, field) do { \ -+ if ((STAILQ_NEXT(elm, field) = \ -+ STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL) \ -+ (head)->stqh_last = &STAILQ_NEXT((elm), field); \ -+} while (0) -+ -+ -+#ifndef __KERNEL__ -+/* -+ * List declarations. -+ */ -+#define LIST_HEAD(name, type) \ -+struct name { \ -+ struct type *lh_first; /* first element */ \ -+} -+ -+#define LIST_HEAD_INITIALIZER(head) \ -+ { NULL } -+ -+#define LIST_ENTRY(type) \ -+struct { \ -+ struct type *le_next; /* next element */ \ -+ struct type **le_prev; /* address of previous next element */ \ -+} -+ -+/* -+ * List functions. -+ */ -+ -+#define LIST_EMPTY(head) ((head)->lh_first == NULL) -+ -+#define LIST_FIRST(head) ((head)->lh_first) -+ -+#define LIST_FOREACH(var, head, field) \ -+ for ((var) = LIST_FIRST((head)); \ -+ (var); \ -+ (var) = LIST_NEXT((var), field)) -+ -+#define LIST_INIT(head) do { \ -+ LIST_FIRST((head)) = NULL; \ -+} while (0) -+ -+#define LIST_INSERT_AFTER(listelm, elm, field) do { \ -+ if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\ -+ LIST_NEXT((listelm), field)->field.le_prev = \ -+ &LIST_NEXT((elm), field); \ -+ LIST_NEXT((listelm), field) = (elm); \ -+ (elm)->field.le_prev = &LIST_NEXT((listelm), field); \ -+} while (0) -+ -+#define LIST_INSERT_BEFORE(listelm, elm, field) do { \ -+ (elm)->field.le_prev = (listelm)->field.le_prev; \ -+ LIST_NEXT((elm), field) = (listelm); \ -+ *(listelm)->field.le_prev = (elm); \ -+ (listelm)->field.le_prev = &LIST_NEXT((elm), field); \ -+} while (0) -+ -+#define LIST_INSERT_HEAD(head, elm, field) do { \ -+ if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \ -+ LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\ -+ LIST_FIRST((head)) = (elm); \ -+ (elm)->field.le_prev = &LIST_FIRST((head)); \ -+} while (0) -+ -+#define LIST_NEXT(elm, field) ((elm)->field.le_next) -+ -+#define LIST_REMOVE(elm, field) do { \ -+ if (LIST_NEXT((elm), field) != NULL) \ -+ LIST_NEXT((elm), field)->field.le_prev = \ -+ (elm)->field.le_prev; \ -+ *(elm)->field.le_prev = LIST_NEXT((elm), field); \ -+} while (0) -+#endif -+ -+/* -+ * Tail queue declarations. -+ */ -+#define TAILQ_HEAD(name, type) \ -+struct name { \ -+ struct type *tqh_first; /* first element */ \ -+ struct type **tqh_last; /* addr of last next element */ \ -+} -+ -+#define TAILQ_HEAD_INITIALIZER(head) \ -+ { NULL, &(head).tqh_first } -+ -+#define TAILQ_ENTRY(type) \ -+struct { \ -+ struct type *tqe_next; /* next element */ \ -+ struct type **tqe_prev; /* address of previous next element */ \ -+} -+ -+/* -+ * Tail queue functions. -+ */ -+#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL) -+ -+#define TAILQ_FIRST(head) ((head)->tqh_first) -+ -+#define TAILQ_FOREACH(var, head, field) \ -+ for ((var) = TAILQ_FIRST((head)); \ -+ (var); \ -+ (var) = TAILQ_NEXT((var), field)) -+ -+#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ -+ for ((var) = TAILQ_LAST((head), headname); \ -+ (var); \ -+ (var) = TAILQ_PREV((var), headname, field)) -+ -+#define TAILQ_INIT(head) do { \ -+ TAILQ_FIRST((head)) = NULL; \ -+ (head)->tqh_last = &TAILQ_FIRST((head)); \ -+} while (0) -+ -+#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ -+ if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\ -+ TAILQ_NEXT((elm), field)->field.tqe_prev = \ -+ &TAILQ_NEXT((elm), field); \ -+ else \ -+ (head)->tqh_last = &TAILQ_NEXT((elm), field); \ -+ TAILQ_NEXT((listelm), field) = (elm); \ -+ (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \ -+} while (0) -+ -+#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ -+ (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ -+ TAILQ_NEXT((elm), field) = (listelm); \ -+ *(listelm)->field.tqe_prev = (elm); \ -+ (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \ -+} while (0) -+ -+#define TAILQ_INSERT_HEAD(head, elm, field) do { \ -+ if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \ -+ TAILQ_FIRST((head))->field.tqe_prev = \ -+ &TAILQ_NEXT((elm), field); \ -+ else \ -+ (head)->tqh_last = &TAILQ_NEXT((elm), field); \ -+ TAILQ_FIRST((head)) = (elm); \ -+ (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \ -+} while (0) -+ -+#define TAILQ_INSERT_TAIL(head, elm, field) do { \ -+ TAILQ_NEXT((elm), field) = NULL; \ -+ (elm)->field.tqe_prev = (head)->tqh_last; \ -+ *(head)->tqh_last = (elm); \ -+ (head)->tqh_last = &TAILQ_NEXT((elm), field); \ -+} while (0) -+ -+#define TAILQ_LAST(head, headname) \ -+ (*(((struct headname *)((head)->tqh_last))->tqh_last)) -+ -+#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) -+ -+#define TAILQ_PREV(elm, headname, field) \ -+ (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) -+ -+#define TAILQ_REMOVE(head, elm, field) do { \ -+ if ((TAILQ_NEXT((elm), field)) != NULL) \ -+ TAILQ_NEXT((elm), field)->field.tqe_prev = \ -+ (elm)->field.tqe_prev; \ -+ else \ -+ (head)->tqh_last = (elm)->field.tqe_prev; \ -+ *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \ -+} while (0) -+ -+/* -+ * Circular queue declarations. -+ */ -+#define CIRCLEQ_HEAD(name, type) \ -+struct name { \ -+ struct type *cqh_first; /* first element */ \ -+ struct type *cqh_last; /* last element */ \ -+} -+ -+#define CIRCLEQ_HEAD_INITIALIZER(head) \ -+ { (void *)&(head), (void *)&(head) } -+ -+#define CIRCLEQ_ENTRY(type) \ -+struct { \ -+ struct type *cqe_next; /* next element */ \ -+ struct type *cqe_prev; /* previous element */ \ -+} -+ -+/* -+ * Circular queue functions. -+ */ -+#define CIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head)) -+ -+#define CIRCLEQ_FIRST(head) ((head)->cqh_first) -+ -+#define CIRCLEQ_FOREACH(var, head, field) \ -+ for ((var) = CIRCLEQ_FIRST((head)); \ -+ (var) != (void *)(head) || ((var) = NULL); \ -+ (var) = CIRCLEQ_NEXT((var), field)) -+ -+#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \ -+ for ((var) = CIRCLEQ_LAST((head)); \ -+ (var) != (void *)(head) || ((var) = NULL); \ -+ (var) = CIRCLEQ_PREV((var), field)) -+ -+#define CIRCLEQ_INIT(head) do { \ -+ CIRCLEQ_FIRST((head)) = (void *)(head); \ -+ CIRCLEQ_LAST((head)) = (void *)(head); \ -+} while (0) -+ -+#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ -+ CIRCLEQ_NEXT((elm), field) = CIRCLEQ_NEXT((listelm), field); \ -+ CIRCLEQ_PREV((elm), field) = (listelm); \ -+ if (CIRCLEQ_NEXT((listelm), field) == (void *)(head)) \ -+ CIRCLEQ_LAST((head)) = (elm); \ -+ else \ -+ CIRCLEQ_PREV(CIRCLEQ_NEXT((listelm), field), field) = (elm);\ -+ CIRCLEQ_NEXT((listelm), field) = (elm); \ -+} while (0) -+ -+#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \ -+ CIRCLEQ_NEXT((elm), field) = (listelm); \ -+ CIRCLEQ_PREV((elm), field) = CIRCLEQ_PREV((listelm), field); \ -+ if (CIRCLEQ_PREV((listelm), field) == (void *)(head)) \ -+ CIRCLEQ_FIRST((head)) = (elm); \ -+ else \ -+ CIRCLEQ_NEXT(CIRCLEQ_PREV((listelm), field), field) = (elm);\ -+ CIRCLEQ_PREV((listelm), field) = (elm); \ -+} while (0) -+ -+#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \ -+ CIRCLEQ_NEXT((elm), field) = CIRCLEQ_FIRST((head)); \ -+ CIRCLEQ_PREV((elm), field) = (void *)(head); \ -+ if (CIRCLEQ_LAST((head)) == (void *)(head)) \ -+ CIRCLEQ_LAST((head)) = (elm); \ -+ else \ -+ CIRCLEQ_PREV(CIRCLEQ_FIRST((head)), field) = (elm); \ -+ CIRCLEQ_FIRST((head)) = (elm); \ -+} while (0) -+ -+#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \ -+ CIRCLEQ_NEXT((elm), field) = (void *)(head); \ -+ CIRCLEQ_PREV((elm), field) = CIRCLEQ_LAST((head)); \ -+ if (CIRCLEQ_FIRST((head)) == (void *)(head)) \ -+ CIRCLEQ_FIRST((head)) = (elm); \ -+ else \ -+ CIRCLEQ_NEXT(CIRCLEQ_LAST((head)), field) = (elm); \ -+ CIRCLEQ_LAST((head)) = (elm); \ -+} while (0) -+ -+#define CIRCLEQ_LAST(head) ((head)->cqh_last) -+ -+#define CIRCLEQ_NEXT(elm,field) ((elm)->field.cqe_next) -+ -+#define CIRCLEQ_PREV(elm,field) ((elm)->field.cqe_prev) -+ -+#define CIRCLEQ_REMOVE(head, elm, field) do { \ -+ if (CIRCLEQ_NEXT((elm), field) == (void *)(head)) \ -+ CIRCLEQ_LAST((head)) = CIRCLEQ_PREV((elm), field); \ -+ else \ -+ CIRCLEQ_PREV(CIRCLEQ_NEXT((elm), field), field) = \ -+ CIRCLEQ_PREV((elm), field); \ -+ if (CIRCLEQ_PREV((elm), field) == (void *)(head)) \ -+ CIRCLEQ_FIRST((head)) = CIRCLEQ_NEXT((elm), field); \ -+ else \ -+ CIRCLEQ_NEXT(CIRCLEQ_PREV((elm), field), field) = \ -+ CIRCLEQ_NEXT((elm), field); \ -+} while (0) -+ -+#ifdef __cplusplus -+} -+#endif -+ -+#endif /* DPL_QUEUE_H */ -diff --git a/porting/dpl/riot/src/config.c b/porting/dpl/riot/src/config.c -new file mode 100644 -index 0000000..9e4bde1 ---- /dev/null -+++ b/porting/dpl/riot/src/config.c -@@ -0,0 +1,83 @@ -+/* -+ * Licensed to the Apache Software Foundation (ASF) under one -+ * or more contributor license agreements. See the NOTICE file -+ * distributed with this work for additional information -+ * regarding copyright ownership. The ASF licenses this file -+ * to you under the Apache License, Version 2.0 (the -+ * "License"); you may not use this file except in compliance -+ * with the License. You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, -+ * software distributed under the License is distributed on an -+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -+ * KIND, either express or implied. See the License for the -+ * specific language governing permissions and limitations -+ * under the License. -+ */ -+ -+#include "config/config.h" -+#include -+#include -+#include -+#include -+ -+int conf_value_from_str(char *val_str, enum conf_type type, void *vp, int maxlen) -+{ -+ int32_t val; -+ int64_t val64; -+ char *eptr; -+ -+ if (!val_str) { -+ goto err; -+ } -+ switch (type) { -+ case CONF_INT8: -+ case CONF_INT16: -+ case CONF_INT32: -+ case CONF_BOOL: -+ val = strtol(val_str, &eptr, 0); -+ if (*eptr != '\0') { -+ goto err; -+ } -+ if (type == CONF_BOOL) { -+ if (val < 0 || val > 1) { -+ goto err; -+ } -+ *(bool *)vp = val; -+ } else if (type == CONF_INT8) { -+ if (val < INT8_MIN || val > UINT8_MAX) { -+ goto err; -+ } -+ *(int8_t *)vp = val; -+ } else if (type == CONF_INT16) { -+ if (val < INT16_MIN || val > UINT16_MAX) { -+ goto err; -+ } -+ *(int16_t *)vp = val; -+ } else if (type == CONF_INT32) { -+ *(int32_t *)vp = val; -+ } -+ break; -+ case CONF_INT64: -+ val64 = strtoll(val_str, &eptr, 0); -+ if (*eptr != '\0') { -+ goto err; -+ } -+ *(int64_t *)vp = val64; -+ break; -+ case CONF_STRING: -+ val = strlen(val_str); -+ if (val + 1 > maxlen) { -+ goto err; -+ } -+ strcpy(vp, val_str); -+ break; -+ default: -+ goto err; -+ } -+ return 0; -+err: -+ return EINVAL; -+} --- -2.28.0 - diff --git a/pkg/uwb-dw1000/Makefile b/pkg/uwb-dw1000/Makefile index cccafb6b37..9c08e859cc 100644 --- a/pkg/uwb-dw1000/Makefile +++ b/pkg/uwb-dw1000/Makefile @@ -1,10 +1,11 @@ PKG_NAME=uwb-dw1000 PKG_URL=https://github.com/Decawave/uwb-dw1000/ -PKG_VERSION=6eaa85e6d429450d19a6ddeb2de05303016c0dd2 +PKG_VERSION=d44078a96349b7a40e9c2393ea83ca4c2d53ab92 PKG_LICENSE=Apache-2.0 include $(RIOTBASE)/pkg/pkg.mk +CFLAGS += -Wno-enum-compare CFLAGS += -Wno-address-of-packed-member CFLAGS += -Wno-enum-conversion CFLAGS += -Wno-maybe-uninitialized diff --git a/pkg/uwb-dw1000/Makefile.dep b/pkg/uwb-dw1000/Makefile.dep index b64241bd0b..2f7e3f9ec4 100644 --- a/pkg/uwb-dw1000/Makefile.dep +++ b/pkg/uwb-dw1000/Makefile.dep @@ -1,13 +1,10 @@ USEMODULE += uwb-dw1000_hal DEFAULT_MODULE += auto_init_uwb-dw1000 -USEMODULE += xtimer +USEPKG += mynewt-core FEATURES_REQUIRED += periph_gpio_irq FEATURES_REQUIRED += periph_spi # Some of the pkg operation would overflow on 16bit FEATURES_REQUIRED += arch_32bit - -# LLVM ARM shows issues with missing definitions for stdatomic -TOOLCHAINS_BLACKLIST += llvm diff --git a/pkg/uwb-dw1000/include/hal/hal_timer.h b/pkg/uwb-dw1000/include/hal/hal_timer.h deleted file mode 100644 index a3b72c3bb5..0000000000 --- a/pkg/uwb-dw1000/include/hal/hal_timer.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2020 Inria - * - * 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 pkg_uwb_dw1000 - * @{ - * - * @file - * @brief Timer abstraction layer RIOT adaption - * - * @author Francisco Molina - * @} - */ - -#ifndef HAL_HAL_TIMER_H -#define HAL_HAL_TIMER_H - -#include "xtimer.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief HAL timer callback - */ -typedef xtimer_callback_t hal_timer_cb; - -/** - * @brief The HAL timer structure. - */ -struct hal_timer { - xtimer_t timer; /**< the timer */ -}; - -#ifdef __cplusplus -} -#endif - -#endif /* HAL_HAL_TIMER_H */ diff --git a/pkg/uwb-dw1000/patches/0001-uwb_dw1000-include-dw1000-dw1000_dev-add-linked-list.patch b/pkg/uwb-dw1000/patches/0001-uwb_dw1000-include-dw1000-dw1000_dev-add-linked-list.patch index 9b39d60598..8a6587220b 100644 --- a/pkg/uwb-dw1000/patches/0001-uwb_dw1000-include-dw1000-dw1000_dev-add-linked-list.patch +++ b/pkg/uwb-dw1000/patches/0001-uwb_dw1000-include-dw1000-dw1000_dev-add-linked-list.patch @@ -1,4 +1,4 @@ -From 068dbad87ebebc9cf5d91bb9397dbd148420769e Mon Sep 17 00:00:00 2001 +From fe110d931bfa6c2b02cb99293d59dc1daee4e00a Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Fri, 14 Aug 2020 13:38:05 +0200 Subject: [PATCH 1/5] uwb_dw1000/include/dw1000/dw1000_dev: add linked list diff --git a/pkg/uwb-dw1000/patches/0002-uwb_dw1000-dw1000_hal-send-spi-cmd-and-data-separetl.patch b/pkg/uwb-dw1000/patches/0002-uwb_dw1000-dw1000_hal-send-spi-cmd-and-data-separetl.patch index 38356d4e37..0e5bfec6cb 100644 --- a/pkg/uwb-dw1000/patches/0002-uwb_dw1000-dw1000_hal-send-spi-cmd-and-data-separetl.patch +++ b/pkg/uwb-dw1000/patches/0002-uwb_dw1000-dw1000_hal-send-spi-cmd-and-data-separetl.patch @@ -1,4 +1,4 @@ -From 8fc632df3880e9bc53766b8e2559c6e71c4d3c28 Mon Sep 17 00:00:00 2001 +From 3a3f9c49095768d2dc908f240ca02ee998c3d9b9 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Fri, 14 Aug 2020 13:55:11 +0200 Subject: [PATCH 2/5] uwb_dw1000/dw1000_hal: send spi cmd and data separetly @@ -9,15 +9,15 @@ Subject: [PATCH 2/5] uwb_dw1000/dw1000_hal: send spi cmd and data separetly 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/drivers/uwb/uwb_dw1000/src/dw1000_hal.c b/hw/drivers/uwb/uwb_dw1000/src/dw1000_hal.c -index c9107fa..b85e32a 100644 +index 2390635..b195c23 100644 --- a/hw/drivers/uwb/uwb_dw1000/src/dw1000_hal.c +++ b/hw/drivers/uwb/uwb_dw1000/src/dw1000_hal.c @@ -310,7 +310,7 @@ hal_dw1000_read(struct _dw1000_dev_instance_t * inst, - + hal_gpio_write(inst->ss_pin, 0); - + -#if !defined(MYNEWT) -+#if !defined(MYNEWT) && !defined(RIOT) ++#if !defined(MYNEWT) && !defined(RIOT_VERSION) /* Linux mode really, for when we can't split the command and data */ assert(cmd_size + length < inst->uwb_dev.txbuf_size); assert(cmd_size + length < MYNEWT_VAL(DW1000_HAL_SPI_MAX_CNT)); @@ -31,11 +31,11 @@ index c9107fa..b85e32a 100644 int step = (inst->uwb_dev.txbuf_size > MYNEWT_VAL(DW1000_HAL_SPI_MAX_CNT)) ? MYNEWT_VAL(DW1000_HAL_SPI_MAX_CNT) : inst->uwb_dev.txbuf_size; @@ -537,7 +537,7 @@ hal_dw1000_write(struct _dw1000_dev_instance_t * inst, const uint8_t * cmd, uint - + hal_gpio_write(inst->ss_pin, 0); - + -#if !defined(MYNEWT) -+#if !defined(MYNEWT) && !defined(RIOT) ++#if !defined(MYNEWT) && !defined(RIOT_VERSION) /* Linux mode really, for when we can't split the command and data */ assert(cmd_size + length < inst->uwb_dev.txbuf_size); assert(cmd_size + length < MYNEWT_VAL(DW1000_HAL_SPI_MAX_CNT)); @@ -51,7 +51,7 @@ index c9107fa..b85e32a 100644 + hal_spi_txrx(inst->spi_num, (void*)buffer, NULL, length); } #endif - --- + +-- 2.28.0 diff --git a/pkg/uwb-dw1000/patches/0003-uwb_dw1000-dw1000_hal-define-even-if-DW1000_DEVICE_0.patch b/pkg/uwb-dw1000/patches/0003-uwb_dw1000-dw1000_hal-define-even-if-DW1000_DEVICE_0.patch index c103f8d71b..f3355e05f3 100644 --- a/pkg/uwb-dw1000/patches/0003-uwb_dw1000-dw1000_hal-define-even-if-DW1000_DEVICE_0.patch +++ b/pkg/uwb-dw1000/patches/0003-uwb_dw1000-dw1000_hal-define-even-if-DW1000_DEVICE_0.patch @@ -1,4 +1,4 @@ -From ed15486f7890a3ffb0426c153cefb951d822e93e Mon Sep 17 00:00:00 2001 +From d6bc7b9e752f3d4418b1ef4e3468e8b2077a7ed1 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Fri, 14 Aug 2020 13:56:25 +0200 Subject: [PATCH 3/5] uwb_dw1000/dw1000_hal: define even if DW1000_DEVICE_0 is @@ -13,7 +13,7 @@ The rest of the api should still be defined 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/drivers/uwb/uwb_dw1000/src/dw1000_hal.c b/hw/drivers/uwb/uwb_dw1000/src/dw1000_hal.c -index b85e32a..90ccd6c 100644 +index b195c23..9268193 100644 --- a/hw/drivers/uwb/uwb_dw1000/src/dw1000_hal.c +++ b/hw/drivers/uwb/uwb_dw1000/src/dw1000_hal.c @@ -262,6 +262,8 @@ hal_dw1000_inst(uint8_t idx) diff --git a/pkg/uwb-dw1000/patches/0005-uwb_dw1000-dw1000_hal-os_sr_t-by-dpl_sr_t.patch b/pkg/uwb-dw1000/patches/0004-uwb_dw1000-dw1000_hal-os_sr_t-by-dpl_sr_t.patch similarity index 80% rename from pkg/uwb-dw1000/patches/0005-uwb_dw1000-dw1000_hal-os_sr_t-by-dpl_sr_t.patch rename to pkg/uwb-dw1000/patches/0004-uwb_dw1000-dw1000_hal-os_sr_t-by-dpl_sr_t.patch index 0c48acdbd1..8878c56341 100644 --- a/pkg/uwb-dw1000/patches/0005-uwb_dw1000-dw1000_hal-os_sr_t-by-dpl_sr_t.patch +++ b/pkg/uwb-dw1000/patches/0004-uwb_dw1000-dw1000_hal-os_sr_t-by-dpl_sr_t.patch @@ -1,14 +1,14 @@ -From 715f6687e3b2b77f63303e3c231fbeb2c8588e97 Mon Sep 17 00:00:00 2001 +From 4e384bd9c5cb1b34c8371c43e82add678d717946 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Thu, 17 Sep 2020 12:26:44 +0200 -Subject: [PATCH 5/5] uwb_dw1000/dw1000_hal: os_sr_t by dpl_sr_t +Subject: [PATCH 4/5] uwb_dw1000/dw1000_hal: os_sr_t by dpl_sr_t --- hw/drivers/uwb/uwb_dw1000/src/dw1000_hal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/drivers/uwb/uwb_dw1000/src/dw1000_hal.c b/hw/drivers/uwb/uwb_dw1000/src/dw1000_hal.c -index 30539a5..4cff459 100644 +index 9268193..3a93800 100644 --- a/hw/drivers/uwb/uwb_dw1000/src/dw1000_hal.c +++ b/hw/drivers/uwb/uwb_dw1000/src/dw1000_hal.c @@ -715,7 +715,7 @@ int diff --git a/pkg/uwb-dw1000/patches/0004-uwb_dw1000-dw1000_hal-replace-OS_-_CRTICAL-with-DPL_.patch b/pkg/uwb-dw1000/patches/0004-uwb_dw1000-dw1000_hal-replace-OS_-_CRTICAL-with-DPL_.patch deleted file mode 100644 index 26c64f4c27..0000000000 --- a/pkg/uwb-dw1000/patches/0004-uwb_dw1000-dw1000_hal-replace-OS_-_CRTICAL-with-DPL_.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 445e0e92d874d9af5b4e679328e07ec32e79b07a Mon Sep 17 00:00:00 2001 -From: Francisco Molina -Date: Fri, 14 Aug 2020 15:19:26 +0200 -Subject: [PATCH 4/5] uwb_dw1000/dw1000_hal: replace OS_%_CRTICAL with - DPL_%_CRITICAL - ---- - hw/drivers/uwb/uwb_dw1000/src/dw1000_hal.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/hw/drivers/uwb/uwb_dw1000/src/dw1000_hal.c b/hw/drivers/uwb/uwb_dw1000/src/dw1000_hal.c -index 90ccd6c..30539a5 100644 ---- a/hw/drivers/uwb/uwb_dw1000/src/dw1000_hal.c -+++ b/hw/drivers/uwb/uwb_dw1000/src/dw1000_hal.c -@@ -723,7 +723,7 @@ hal_dw1000_wakeup(struct _dw1000_dev_instance_t * inst) - goto early_exit; - } - -- OS_ENTER_CRITICAL(sr); -+ DPL_ENTER_CRITICAL(sr); - - hal_spi_disable(inst->spi_num); - hal_gpio_write(inst->ss_pin, 0); -@@ -738,7 +738,7 @@ hal_dw1000_wakeup(struct _dw1000_dev_instance_t * inst) - // (check PLL bit in IRQ?) - dpl_cputime_delay_usecs(5000); - -- OS_EXIT_CRITICAL(sr); -+ DPL_EXIT_CRITICAL(sr); - - rc = dpl_sem_release(inst->spi_sem); - assert(rc == DPL_OK); --- -2.28.0 - diff --git a/pkg/uwb-dw1000/patches/0006-dw1000-dw1000_dev-use-gpio_t-types-for-dev_cfg.patch b/pkg/uwb-dw1000/patches/0005-dw1000-dw1000_dev-use-gpio_t-types-for-dev_cfg.patch similarity index 90% rename from pkg/uwb-dw1000/patches/0006-dw1000-dw1000_dev-use-gpio_t-types-for-dev_cfg.patch rename to pkg/uwb-dw1000/patches/0005-dw1000-dw1000_dev-use-gpio_t-types-for-dev_cfg.patch index f8f8656392..d276e65dd0 100644 --- a/pkg/uwb-dw1000/patches/0006-dw1000-dw1000_dev-use-gpio_t-types-for-dev_cfg.patch +++ b/pkg/uwb-dw1000/patches/0005-dw1000-dw1000_dev-use-gpio_t-types-for-dev_cfg.patch @@ -1,7 +1,7 @@ -From e8207fa0b9ececc5e1d5e3c4fe1bc491b4d74884 Mon Sep 17 00:00:00 2001 +From 888fecffc4faafef81a0ac6eafdc74f6f1c932b4 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Wed, 7 Oct 2020 14:11:43 +0200 -Subject: [PATCH 6/6] dw1000/dw1000_dev: use gpio_t types for dev_cfg +Subject: [PATCH 5/5] dw1000/dw1000_dev: use gpio_t types for dev_cfg --- hw/drivers/uwb/uwb_dw1000/include/dw1000/dw1000_dev.h | 6 +++--- diff --git a/pkg/uwb-dw1000/patches/0007-uwb_dw1000-dw1000_mac-avoid-conflict-with-msp430-N.patch b/pkg/uwb-dw1000/patches/0007-uwb_dw1000-dw1000_mac-avoid-conflict-with-msp430-N.patch deleted file mode 100644 index 30b0dfd633..0000000000 --- a/pkg/uwb-dw1000/patches/0007-uwb_dw1000-dw1000_mac-avoid-conflict-with-msp430-N.patch +++ /dev/null @@ -1,47 +0,0 @@ -From cea55ec226b13c3c57c492af76d08573e834f164 Mon Sep 17 00:00:00 2001 -From: Francisco Molina -Date: Wed, 7 Oct 2020 16:14:22 +0200 -Subject: [PATCH 7/7] uwb_dw1000/dw1000_mac: avoid conflict with msp430 #N - ---- - hw/drivers/uwb/uwb_dw1000/src/dw1000_mac.c | 10 +++++----- - 1 file changed, 5 insertions(+), 5 deletions(-) - -diff --git a/hw/drivers/uwb/uwb_dw1000/src/dw1000_mac.c b/hw/drivers/uwb/uwb_dw1000/src/dw1000_mac.c -index c4e5a3e..0d520b9 100644 ---- a/hw/drivers/uwb/uwb_dw1000/src/dw1000_mac.c -+++ b/hw/drivers/uwb/uwb_dw1000/src/dw1000_mac.c -@@ -1841,25 +1841,25 @@ dpl_float32_t - dw1000_calc_fppl(struct _dw1000_dev_instance_t * inst, - struct _dw1000_dev_rxdiag_t * diag) - { -- dpl_float32_t A, N, v, fppl; -+ dpl_float32_t A, n, v, fppl; - if (diag->pacc_cnt == 0 || - (!diag->fp_amp && !diag->fp_amp2 && !diag->fp_amp3)) { - return DPL_FLOAT32_NAN(); - } - A = (inst->uwb_dev.config.prf == DWT_PRF_16M) ? DPL_FLOAT32_INIT(113.77f) : DPL_FLOAT32_INIT(121.74f); - #ifdef __KERNEL__ -- N = ui32_to_f32(diag->pacc_cnt); -+ n = ui32_to_f32(diag->pacc_cnt); - v = f32_add(f32_add(ui32_to_f32(diag->fp_amp*diag->fp_amp), - ui32_to_f32(diag->fp_amp2*diag->fp_amp2)), - ui32_to_f32(diag->fp_amp3*diag->fp_amp3)); -- v = f32_div(v, f32_mul(N, N)); -+ v = f32_div(v, f32_mul(n, n)); - fppl = f32_sub(f32_mul(DPL_FLOAT32_INIT(10.0), f64_to_f32(log10_soft(f32_to_f64(v)))), A); - #else -- N = (float)(diag->pacc_cnt); -+ n = (float)(diag->pacc_cnt); - v = (float)(diag->fp_amp*diag->fp_amp) + - (float)(diag->fp_amp2*diag->fp_amp2) + - (float)(diag->fp_amp3*diag->fp_amp3); -- v /= N * N; -+ v /= n * n; - fppl = 10.0f * log10f(v) - A; - #endif - return fppl; --- -2.28.0 - diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index 553fad2945..ef3ee300a2 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -123,6 +123,11 @@ void auto_init(void) extern void openwsn_bootstrap(void); openwsn_bootstrap(); } + if (IS_USED(MODULE_AUTO_INIT_MYNEWT_CORE)) { + LOG_DEBUG("Bootstrapping mynewt-core.\n"); + extern void mynewt_core_init(void); + mynewt_core_init(); + } if (IS_USED(MODULE_AUTO_INIT_UWB_CORE)) { LOG_DEBUG("Bootstrapping uwb core.\n"); extern void uwb_core_init(void);