1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-26 23:11:19 +01:00

Merge pull request #16348 from fjmolinas/pr_pkg_mynewt_core

pkg/mynewt-core: initial commit
This commit is contained in:
Kaspar Schleiser 2021-07-07 10:55:53 +02:00 committed by GitHub
commit fe22ba428d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
91 changed files with 3000 additions and 2583 deletions

View File

@ -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

View File

@ -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 */

View File

@ -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
/**

46
pkg/mynewt-core/Makefile Normal file
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 <francois-xavier.molina@inria.fr>
* @}
*/
#include <assert.h>
#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));
}

View File

@ -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 <francois-xavier.molina@inria.fr>
* @}
*/
#include <assert.h>
#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
}

View File

@ -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 <francois-xavier.molina@inria.fr>
* @}
*/
#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);
}

View File

@ -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) {

View File

@ -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 <hauke.petersen@fu-berlin.de>
* @}
*/
#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;
}
}

View File

@ -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 <francois-xavier.molina@inria.fr>
* @}
*/
#include <stdio.h>
#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;
}

View File

@ -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();
}

12
pkg/mynewt-core/doc.txt Normal file
View File

@ -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.

View File

@ -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 <francois-xavier.molina@inria.fr>
* @}
*/
#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 */

View File

@ -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 <francois-xavier.molina@inria.fr>
* @}
*/
#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 */

View File

@ -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 <francois-xavier.molina@inria.fr>
* @}
*/
#ifndef STATS_STATS_H
#define STATS_STATS_H
#ifndef OS_MYNEWT_H
#define OS_MYNEWT_H
#include <stdlib.h>
#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 */

View File

@ -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 <assert.h>
#include <stdint.h>
#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 */

View File

@ -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 */
};
/**

View File

@ -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 <francois-xavier.molina@inria.fr>
* @}
*/
#ifndef OS_OS_EVENTQ_H
#define OS_OS_EVENTQ_H
#include <os/os_types.h>
#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 */

View File

@ -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 <francois-xavier.molina@inria.fr>
* @}
*/
#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 */

View File

@ -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 <francois-xavier.molina@inria.fr>
* @}
*/
#ifndef OS_OS_TYPES_H
#define OS_OS_TYPES_H
#include <stdint.h>
#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 */

View File

@ -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 */

View File

@ -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

View File

@ -0,0 +1,5 @@
MODULE = mynewt-core_nrf5x_hal
SRC := hal_timer.c
include $(RIOTBASE)/Makefile.base

View File

@ -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

View File

@ -0,0 +1,5 @@
MODULE = mynewt-core_util
SRC := mem.c
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,76 @@
From 37f6d02ec7bedd03d36f261322043675a3a37180 Mon Sep 17 00:00:00 2001
From: Francisco Molina <femolina@uc.cl>
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 <assert.h>
#include <errno.h>
#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 <assert.h>
#include <errno.h>
#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

View File

@ -0,0 +1,293 @@
From e02018ca20f3a7192764973cf47ef27520dd50bf Mon Sep 17 00:00:00 2001
From: Francisco Molina <femolina@uc.cl>
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 <inttypes.h>
#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 <stddef.h>
/**
@@ -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 <assert.h>
#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

View File

@ -0,0 +1,48 @@
From fe5793956395153af816d3336db99850335f20f5 Mon Sep 17 00:00:00 2001
From: Francisco Molina <femolina@uc.cl>
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 <inttypes.h>
#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

View File

@ -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=$@

View File

@ -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)))

View File

@ -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

View File

@ -0,0 +1,5 @@
ifneq (,$(filter mynewt-core,$(USEMODULE)))
SRC = nimble_port.c
endif
include $(RIOTBASE)/Makefile.base

View File

@ -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 <hauke.petersen@fu-berlin.de>
* @}
*/
#ifndef NIMBLE_NIMBLE_NPL_OS_H
#define NIMBLE_NIMBLE_NPL_OS_H
#include <stdint.h>
#include <stdbool.h>
#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 */

View File

@ -0,0 +1,27 @@
From 395209627ba495309098459173d40d490f680b8b Mon Sep 17 00:00:00 2001
From: Francisco Molina <femolina@uc.cl>
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

View File

@ -0,0 +1,21 @@
From 40012b6fad9772cb38547abff42149b7ce1ca8d1 Mon Sep 17 00:00:00 2001
From: Francisco Molina <femolina@uc.cl>
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

View File

@ -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

View File

@ -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

View File

@ -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 \
#

View File

@ -17,13 +17,14 @@
* @}
*/
#include <stdatomic.h>
#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 */

View File

@ -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
}

View File

@ -1,3 +0,0 @@
MODULE = uwb-core_dpl
include $(RIOTBASE)/Makefile.base

View File

@ -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 <francois-xavier.molina@inria.fr>
* @}
*/
#include <assert.h>
#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));
}

View File

@ -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 <francois-xavier.molina@inria.fr>
* @}
*/
#include <stdio.h>
#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;
}

View File

@ -32,7 +32,6 @@
#include "dpl/dpl_tasks.h"
#include "dpl/dpl_time.h"
#include "kernel_defines.h"
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -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
}

View File

@ -24,10 +24,7 @@
extern "C" {
#endif
#include <stdint.h>
#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

View File

@ -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
}

View File

@ -22,8 +22,8 @@
#include <dpl/dpl_types.h>
#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

View File

@ -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
}

View File

@ -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 <francois-xavier.molina@inria.fr>
* @}
@ -20,12 +20,7 @@
#ifndef DPL_DPL_OS_H
#define DPL_DPL_OS_H
#include <assert.h>
#include <stdint.h>
#include <stdatomic.h>
#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

View File

@ -22,10 +22,7 @@
#include <stdint.h>
#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
}

View File

@ -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
}

View File

@ -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

View File

@ -23,6 +23,8 @@
#include <stdint.h>
#include <math.h>
#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

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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 <francois-xavier.molina@inria.fr>
* @}
*/
#ifndef OS_OS_H
#define OS_OS_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* OS_OS_H */

View File

@ -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 <francois-xavier.molina@inria.fr>
* @}
*/
#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 */

View File

@ -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 <femolina@uc.cl>
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 <stdlib.h>
#endif
+
+#if !defined(RIOT)
+#if !defined(RIOT_VERSION)
struct uwb_dev*
uwb_dev_idx_lookup(int idx)
{

View File

@ -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 <femolina@uc.cl>
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 ++++----

View File

@ -1,758 +0,0 @@
From cac1c7aeb1db0732519fa6ae27f3f34234c83615 Mon Sep 17 00:00:00 2001
From: Francisco Molina <femolina@uc.cl>
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

View File

@ -1,25 +0,0 @@
From 478d952b17c33ed5644172c9b4aebf4cdf7bec62 Mon Sep 17 00:00:00 2001
From: Francisco Molina <femolina@uc.cl>
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

View File

@ -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 <femolina@uc.cl>
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 +++++

View File

@ -0,0 +1,479 @@
From 15d99a7e8e518f306bb0cebfc729e830eab81633 Mon Sep 17 00:00:00 2001
From: Francisco Molina <femolina@uc.cl>
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 <errno.h>
+#include <dpl/queue.h>
+#include <stdio.h>
+#include <stdint.h>
+
+#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 <stdio.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+
+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

View File

@ -1,25 +0,0 @@
From 2304bef6c63b15411fae3050554edc0538ae93d9 Mon Sep 17 00:00:00 2001
From: Francisco Molina <femolina@uc.cl>
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

View File

@ -0,0 +1,24 @@
From f87d1a3ca89118b654a32cea58f4b03774042c17 Mon Sep 17 00:00:00 2001
From: Francisco Molina <femolina@uc.cl>
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

View File

@ -1,78 +0,0 @@
From 86db74c73938d86a3bcf581af2174991cef632fe Mon Sep 17 00:00:00 2001
From: Francisco Molina <femolina@uc.cl>
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 <dpl/dpl.h>
#include <syscfg/syscfg.h>
#include <sysinit/sysinit.h>
-#include <log/log.h>
+#include <log/dpl_log.h>
#include <config/config.h>
#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 <stdio.h>
#include <dpl/dpl.h>
-#include <log/log.h>
+#include <log/dpl_log.h>
#include <syscfg/syscfg.h>
#include <sysinit/sysinit.h>
#include <config/config.h>
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 <log/log.h>
+#include <log/dpl_log.h>
#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

File diff suppressed because it is too large Load Diff

View File

@ -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

View File

@ -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

View File

@ -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 <francois-xavier.molina@inria.fr>
* @}
*/
#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 */

View File

@ -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 <femolina@uc.cl>
Date: Fri, 14 Aug 2020 13:38:05 +0200
Subject: [PATCH 1/5] uwb_dw1000/include/dw1000/dw1000_dev: add linked list

View File

@ -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 <femolina@uc.cl>
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

View File

@ -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 <femolina@uc.cl>
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)

View File

@ -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 <femolina@uc.cl>
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

View File

@ -1,35 +0,0 @@
From 445e0e92d874d9af5b4e679328e07ec32e79b07a Mon Sep 17 00:00:00 2001
From: Francisco Molina <femolina@uc.cl>
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

View File

@ -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 <femolina@uc.cl>
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 +++---

View File

@ -1,47 +0,0 @@
From cea55ec226b13c3c57c492af76d08573e834f164 Mon Sep 17 00:00:00 2001
From: Francisco Molina <femolina@uc.cl>
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

View File

@ -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);