1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

pkg/openwsn: add riot based openwsn scheduler

This commit is contained in:
Francisco Molina 2020-08-19 17:20:22 +02:00
parent 006cdeb37e
commit 19494a4db3
No known key found for this signature in database
GPG Key ID: 3E94EAC3DBDEEDA8
8 changed files with 205 additions and 17 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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