Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/libcsp: add sock_udp [demonstrator] #18010

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions makefiles/pseudomodules.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ PSEUDOMODULES += test_utils_interactive_sync_shell
# All auto_init modules are pseudomodules
PSEUDOMODULES += auto_init_%
NO_PSEUDOMODULES += auto_init_can
NO_PSEUDOMODULES += auto_init_csp
NO_PSEUDOMODULES += auto_init_loramac
NO_PSEUDOMODULES += auto_init_multimedia
NO_PSEUDOMODULES += auto_init_security
Expand Down
24 changes: 24 additions & 0 deletions pkg/libcsp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
PKG_NAME=libcsp
PKG_URL=https://github.com/libcsp/libcsp.git
PKG_VERSION=f429e14f71d9f1cb5187eb6db29b7fcfa8cc373b
PKG_LICENSE=MIT

include $(RIOTBASE)/pkg/pkg.mk

CFLAGS += -Wno-unused-parameter
CFLAGS += -Wno-format

IGNORE_MODULES := libcsp_contrib \
libcsp_drivers_can \
libcsp_shell \
libcsp_shell_server \
libcsp_sock_udp \
#

LIBCSP_MODULES := $(filter-out $(IGNORE_MODULES),$(filter libcsp_%,$(USEMODULE)))

all: $(LIBCSP_MODULES)
$(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/src -f $(CURDIR)/$(PKG_NAME).mk

libcsp_%:
$(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/src/interfaces -f $(CURDIR)/$(PKG_NAME)_$*.mk
38 changes: 38 additions & 0 deletions pkg/libcsp/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
USEMODULE += libcsp_contrib
# currently only the can interace is supported
USEMODULE += libcsp_drivers_can
USEMODULE += luid
USEMODULE += l2util
USEMODULE += random

DEFAULT_MODULE += auto_init_csp

ifneq (,$(filter libcsp_contrib,$(USEMODULE)))
USEMODULE += ztimer_msec
USEMODULE += ztimer_sec
USEMODULE += tsrb
endif

ifneq (,$(filter libcsp_drivers_can,$(USEMODULE)))
USEMODULE += libcsp_interfaces
USEMODULE += conn_can
USEMODULE += can
USEMODULE += can_trx
DEFAULT_MODULE += auto_init_can
ifneq (,$(filter native,$(CPU)))
FEATURES_REQUIRED += periph_can
endif
endif

ifneq (,$(filter shell_commands,$(USEMODULE)))
DEFAULT_MODULE += libcsp_shell
DEFAULT_MODULE += libcsp_shell_server
endif

ifneq (,$(filter sock_udp,$(USEMODULE)))
USEMODULE += ipv6
USEMODULE += ipv6_addr
USEMODULE += netif
USEMODULE += libcsp_sock_udp
USEMODULE += sock_async
endif
27 changes: 27 additions & 0 deletions pkg/libcsp/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
INCLUDES += -I$(PKGDIRBASE)/libcsp/include \
-I$(PKGDIRBASE)/libcsp/src \
-I$(RIOTBASE)/pkg/libcsp/include

CFLAGS += -DCSP_RIOT=1
CFLAGS += -DCSP_ENABLE_CSP_PRINT=1

ifneq (,$(filter libcsp_contrib,$(USEMODULE)))
DIRS += $(RIOTPKG)/libcsp/contrib
endif

ifneq (,$(filter libcsp_drivers_can,$(USEMODULE)))
DIRS += $(RIOTPKG)/libcsp/drivers/can
endif

ifneq (,$(filter libcsp_sock_udp,$(USEMODULE)))
INCLUDES += -I$(RIOTBASE)/pkg/libcsp/sock
DIRS += $(RIOTPKG)/libcsp/sock
endif

ifneq (,$(filter auto_init_csp,$(USEMODULE)))
DIRS += $(RIOTPKG)/libcsp/init
endif

PSEUDOMODULES += libcsp_shell \
libcsp_shell_server \
#
9 changes: 9 additions & 0 deletions pkg/libcsp/contrib/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MODULE = libcsp_contrib

SUBMODULES = 1

BASE_MODULE = libcsp

SRC := $(filter-out shell.c,$(wildcard *.c))

include $(RIOTBASE)/Makefile.base
57 changes: 57 additions & 0 deletions pkg/libcsp/contrib/_netif.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2022 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.
*/

/**
* @{
*
* Implements @ref net_netif for @ref net_csp
*
* @file
*/

#include <errno.h>
#include <string.h>

#include "csp/csp_iflist.h"
#include "csp/csp_interface.h"
#include "net/netif.h"

int netif_get_name(netif_t *iface, char *name)
{
csp_iface_t *netif = (csp_iface_t *)iface;

if (strlen(netif->name) > CONFIG_NETIF_NAMELENMAX) {
return -ENOBUFS;
}
strcpy(name, netif->name);
return strlen(netif->name);
}

int16_t netif_get_id(const netif_t *netif)
{
csp_iface_t * iface = csp_iflist_get();
int16_t id = 0;

while ((void*)iface != (void*)netif) {
id++;
iface = iface->next;
}
return id;
}

netif_t *netif_get_by_id(int16_t id)
{
csp_iface_t * iface = csp_iflist_get();

while (iface && id) {
id--;
iface = iface->next;
}
return(netif_t*) iface;
}
/** @} */
96 changes: 96 additions & 0 deletions pkg/libcsp/contrib/csp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright (C) 2022 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.
*/

/**
* @{
* @file
* @brief LibCSP RIOT adaptation
*
* @author Francisco Molina <francois-xavier.molina@inria.fr>
*/

#include <errno.h>

#include "csp/csp.h"
#include "csp/csp_id.h"
#include "csp_conn.h"
#include "csp_qfifo.h"

#include "csp_riot.h"
#include "thread.h"

/**
* @brief Priority used for uwb-core event queue
*/
#ifndef CSP_ROUTE_PRIO
#define CSP_ROUTE_PRIO (THREAD_PRIORITY_MAIN - 3)
#endif

/**
* @brief Stacksize
*/
#ifndef CSP_ROUTE_STACKSIZE
#define CSP_ROUTE_STACKSIZE (THREAD_STACKSIZE_DEFAULT)
#endif

static char _stack_csp_route[CSP_ROUTE_STACKSIZE];

static void *_csp_route_thread(void *arg)
{
(void)arg;
while (1) {
csp_route_work();
}
return NULL;
}

csp_conf_t csp_conf = {
.version = 2,
.address = 0,
.hostname = RIOT_BOARD,
.model = RIOT_VERSION,
.revision = "",
.conn_dfl_so = CSP_O_NONE,
.dedup = CSP_DEDUP_OFF
};

void libcsp_set_dedup(enum csp_dedup_types type)
{
csp_conf.dedup = type;
}

enum csp_dedup_types libcsp_get_dedup(void)
{
return csp_conf.dedup;
}

uint8_t libcsp_get_csp_version(void)
{
return csp_conf.version;
}

int libcsp_set_csp_version(uint8_t version)
{
if (version == 2 || version == 1) {
csp_conf.version = version;
}
return -EINVAL;
}

void libcsp_init(void)
{
csp_buffer_init();
csp_conn_init();
csp_qfifo_init();

thread_create(_stack_csp_route, sizeof(_stack_csp_route),
CSP_ROUTE_PRIO,
THREAD_CREATE_STACKTEST,
_csp_route_thread, NULL,
"csp_route");
}
32 changes: 32 additions & 0 deletions pkg/libcsp/contrib/csp_clock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2022 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.
*/
/**
* @{
* @file
* @brief LibCSP clock implementation
*
* @author Pierre Millot <pierre.millot@grenoble-inp.org>
* @author Francisco Molina <francois-xavier.molina@inria.fr>
*/

#include "csp/csp_types.h"

#include "cpu.h"
#include "ztimer.h"

__attribute__((weak)) void csp_clock_get_time(csp_timestamp_t *time)
{
time->tv_sec = ztimer_now(ZTIMER_SEC);
time->tv_nsec = 0;
}

__attribute__((weak)) int csp_clock_set_time(const csp_timestamp_t *time)
{
(void)time;
return CSP_ERR_NOTSUP;
}
36 changes: 36 additions & 0 deletions pkg/libcsp/contrib/csp_hooks.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2022 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.
*/

/**
* @{
* @file
* @brief LibCSP
*
* @author Pierre Millot <pierre.millot@grenoble-inp.org>
* @author Francisco Molina <francois-xavier.molina@inria.fr>
*/

#include <csp/csp_hooks.h>
#include "cpu.h"

__attribute__((weak)) uint32_t csp_memfree_hook(void)
{
return 0;
}

__attribute__((weak)) unsigned int csp_ps_hook(csp_packet_t *packet)
{
(void)packet;
return 0;
}

__attribute__((weak)) void csp_reboot_hook(void)
{}

__attribute__((weak)) void csp_shutdown_hook(void)
{}
Loading