diff --git a/pkg/openwsn/Makefile b/pkg/openwsn/Makefile index a36255d908..953c5c3e9c 100644 --- a/pkg/openwsn/Makefile +++ b/pkg/openwsn/Makefile @@ -12,6 +12,7 @@ IGNORE_MODULES := openwsn_leds \ openwsn_icmpv6_echo \ openwsn_iee802154e_security \ openwsn_radio \ + openwsn_riotos \ openwsn_serial \ openwsn_sctimer \ openwsn_sctimer_rtt \ @@ -41,7 +42,7 @@ OPENWSN_PATH_openapps = openapps OPENWSN_PATH_openweb = openweb OPENWSN_PATH_drivers = drivers/common OPENWSN_PATH_crypto = drivers/common/crypto -OPENWSN_PATH_scheduler = kernel/openos +OPENWSN_PATH_openos = kernel/openos OPENWSN_PATH_cjoin = openapps/cjoin OPENWSN_PATH_opencoap = openweb/opencoap OPENWSN_PATH_mac_low = openstack/02a-MAClow diff --git a/pkg/openwsn/Makefile.dep b/pkg/openwsn/Makefile.dep index 69685b4d16..04bff6eb11 100644 --- a/pkg/openwsn/Makefile.dep +++ b/pkg/openwsn/Makefile.dep @@ -12,6 +12,7 @@ ifneq (,$(filter openwsn_openstack,$(USEMODULE))) USEMODULE += openwsn_openweb USEMODULE += openwsn_openapps + USEMODULE += openwsn_scheduler DEFAULT_MODULE += auto_init_openwsn @@ -19,14 +20,26 @@ ifneq (,$(filter openwsn_openstack,$(USEMODULE))) USEMODULE += netdev_default endif -ifneq (,$(filter openwsn_ipv6,$(USEMODULE))) - DEFAULT_MODULE += openwsn_icmpv6_echo +ifneq (,$(filter openwsn_scheduler,$(USEMODULE))) + ifeq (,$(filter openwsn_openos,$(USEMODULE))) + USEMODULE += openwsn_riotos + endif endif -ifneq (,$(filter openwsn_scheduler,$(USEMODULE))) +ifneq (,$(filter openwsn_openos,$(USEMODULE))) USEMODULE += core_thread_flags endif +ifneq (,$(filter openwsn_riotos,$(USEMODULE))) + USEMODULE += event + USEMODULE += event_callback + USEMODULE += memarray +endif + +ifneq (,$(filter openwsn_ipv6,$(USEMODULE))) + DEFAULT_MODULE += openwsn_icmpv6_echo +endif + ifneq (,$(filter openwsn_cjoin,$(USEMODULE))) USEMODULE += openwsn_opencoap USEMODULE += openwsn_crypto diff --git a/pkg/openwsn/Makefile.include b/pkg/openwsn/Makefile.include index 63fcc756b4..2c2f202a58 100644 --- a/pkg/openwsn/Makefile.include +++ b/pkg/openwsn/Makefile.include @@ -1,3 +1,18 @@ +PSEUDOMODULES += openwsn_serial \ + openwsn_debugpins \ + openwsn_6lo_frag \ + openwsn_icmpv6_echo \ + openwsn_iee802154e_security \ + openwsn_leds \ + openwsn_scheduler \ + openwsn_sctimer \ + openwsn_sctimer_rtt \ + openwsn_sctimer_ztimer \ + openwsn_radio \ + # + +DIRS += $(RIOTBASE)/pkg/openwsn/contrib + INCLUDES += -I$(PKGDIRBASE)/openwsn \ -I$(PKGDIRBASE)/openwsn/kernel \ -I$(PKGDIRBASE)/openwsn/inc \ @@ -17,19 +32,14 @@ INCLUDES += -I$(PKGDIRBASE)/openwsn \ -I$(PKGDIRBASE)/openwsn/openweb/opencoap \ -I$(RIOTBASE)/pkg/openwsn/include \ -DIRS += $(RIOTBASE)/pkg/openwsn/contrib +ifneq (,$(filter openwsn_openos,$(USEMODULE))) + INCLUDES += -I$(PKGDIRBASE)/openwsn/kernel/openos +endif -PSEUDOMODULES += openwsn_serial \ - openwsn_debugpins \ - openwsn_6lo_frag \ - openwsn_icmpv6_echo \ - openwsn_iee802154e_security \ - openwsn_leds \ - openwsn_sctimer \ - openwsn_sctimer_rtt \ - openwsn_sctimer_ztimer \ - openwsn_radio \ - # +ifneq (,$(filter openwsn_riotos,$(USEMODULE))) + INCLUDES += -I$(RIOTBASE)/pkg/openwsn/scheduler + DIRS += $(RIOTBASE)/pkg/openwsn/scheduler +endif # Set OpenWSN configurations flags, see $(PKG_SOURCE_DIR)/openwsn-fw/inc/config.h diff --git a/pkg/openwsn/scheduler/Makefile b/pkg/openwsn/scheduler/Makefile new file mode 100644 index 0000000000..338fc068a8 --- /dev/null +++ b/pkg/openwsn/scheduler/Makefile @@ -0,0 +1,3 @@ +MODULE = openwsn_riotos + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/openwsn/scheduler/scheduler.c b/pkg/openwsn/scheduler/scheduler.c new file mode 100644 index 0000000000..7fee1702dd --- /dev/null +++ b/pkg/openwsn/scheduler/scheduler.c @@ -0,0 +1,99 @@ +/* + * 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_openwsn + * @{ + * + * @file + * @brief Event based implementation of OpenWSN scheduler + * + * @author Francisco Molina + * + * @} + */ +#include "event.h" +#include "event/callback.h" +#include "memarray.h" +#include "periph/pm.h" + +#include "scheduler.h" +#include "debugpins.h" +#include "leds.h" + +#ifndef LOG_LEVEL +#define LOG_LEVEL LOG_ERROR +#endif +#include "log.h" + +static scheduler_vars_t _scheduler_vars; +/* event queues for every priority */ +static event_queue_t _queues[TASKPRIO_MAX]; + +#if SCHEDULER_DEBUG_ENABLE +scheduler_dbg_t scheduler_dbg; +#endif + +void scheduler_init(void) +{ +#if SCHEDULER_DEBUG_ENABLE + memset(&scheduler_dbg, 0, sizeof(scheduler_dbg_t)); +#endif + memset(&_scheduler_vars, 0, sizeof(scheduler_vars_t)); + memarray_init(&_scheduler_vars.memarray, &_scheduler_vars.task_buff, + sizeof(event_callback_t), TASK_LIST_DEPTH); + + event_queues_init_detached(_queues, TASKPRIO_MAX); +} + +void scheduler_start(unsigned state) +{ + irq_restore(state); + + /* claim all queues */ + event_queues_claim(_queues, TASKPRIO_MAX); + + /* wait for events */ + event_t *event; + while ((event = event_wait_multi(_queues, TASKPRIO_MAX))) { + debugpins_task_clr(); + event->handler(event); + /* remove from task list */ + memarray_free(&_scheduler_vars.memarray, event); +#if SCHEDULER_DEBUG_ENABLE + scheduler_dbg.numTasksCur--; +#endif + debugpins_task_set(); + } +} + +void scheduler_push_task(task_cbt cb, task_prio_t prio) +{ + unsigned state = irq_disable(); + /* get a free event from the queue */ + event_callback_t *event = memarray_calloc(&_scheduler_vars.memarray); + + if (!event) { + /* task list has overflown. This should never happen! */ + LOG_ERROR("[openos/scheduler]: critical, task list overflow\n"); + leds_error_blink(); + pm_off(); + } + + event_callback_init(event, (void (*)(void *)) cb, NULL); + event_post(&_queues[prio], (event_t *)event); + +#if SCHEDULER_DEBUG_ENABLE + scheduler_dbg.numTasksCur++; + if (scheduler_dbg.numTasksCur > scheduler_dbg.numTasksMax) { + scheduler_dbg.numTasksMax = scheduler_dbg.numTasksCur; + } +#endif + + irq_restore(state); +} diff --git a/pkg/openwsn/scheduler/scheduler_types.h b/pkg/openwsn/scheduler/scheduler_types.h new file mode 100644 index 0000000000..0dbfa7267d --- /dev/null +++ b/pkg/openwsn/scheduler/scheduler_types.h @@ -0,0 +1,56 @@ +/* + * 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_openwsn + * @{ + * + * + * @file + * @brief RIOT scheduler types variable declaration + * + * @author Francisco Molina + * + * @} + */ + +#ifndef SCHEDULER_TYPES_H +#define SCHEDULER_TYPES_H + +#include "opendefs.h" +#include "scheduler.h" +#include "event/callback.h" +#include "memarray.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief OpenWSN scheduler variables structure + */ +typedef struct { + event_callback_t task_buff[TASK_LIST_DEPTH]; /**< Task buffer */ + memarray_t memarray; /**< Memarray management */ +} scheduler_vars_t; + +#if SCHEDULER_DEBUG_ENABLE +/** + * @brief OpenWSN scheduler debug variables + */ +typedef struct { + uint8_t numTasksCur; /**< Current task number */ + uint8_t numTasksMax; /**< Current peak queued tasks */ +} scheduler_dbg_t; +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* SCHEDULER_TYPES_H */ diff --git a/sys/shell/commands/sc_openwsn.c b/sys/shell/commands/sc_openwsn.c index 7b908112d4..70841af929 100644 --- a/sys/shell/commands/sc_openwsn.c +++ b/sys/shell/commands/sc_openwsn.c @@ -541,6 +541,7 @@ static int _queue_cmd(int argc, char **argv) return -1; } +#if SCHEDULER_DEBUG_ENABLE static int _scheduler_cmd(char *arg) { (void)arg; @@ -551,6 +552,7 @@ static int _scheduler_cmd(char *arg) return 0; } +#endif static void _print_usage(void) { @@ -559,7 +561,9 @@ static void _print_usage(void) puts("\topenwsn queue: Openqueue management commands"); puts("\topenwsn cell: cell management commands"); puts("\topenwsn 6top: 6top request commands"); +#if SCHEDULER_DEBUG_ENABLE puts("\topenwsn sched: show openos scheduler information"); +#endif } int _openwsn_handler(int argc, char **argv) @@ -585,9 +589,11 @@ int _openwsn_handler(int argc, char **argv) return _cell_cmd(argc - 1, &argv[1]); } +#if SCHEDULER_DEBUG_ENABLE if (!strcmp(argv[1], "sched")) { return _scheduler_cmd(NULL); } +#endif if (!strcmp(argv[1], "6top")) { if (!ieee154e_isSynch()) { diff --git a/tests/pkg_openwsn/Makefile b/tests/pkg_openwsn/Makefile index 1e733f0d50..a34e83c84b 100644 --- a/tests/pkg_openwsn/Makefile +++ b/tests/pkg_openwsn/Makefile @@ -15,7 +15,7 @@ BOARD_WHITELIST = \ # OpenWSN Modules USEPKG += openwsn USEMODULE += openwsn_openstack -USEMODULE += openwsn_scheduler + # Optional OpenWSN Modules ## Enable Constrained Join Protocol (CoJP) USEMODULE += openwsn_cjoin