From 4daaaccb0f16a1ffe6069edf9748e4f81cbfcd1a Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Wed, 17 Aug 2022 14:39:45 +0200 Subject: [PATCH 1/3] pkg/lwip_netdev: add support for IPC based Bottom Half Processor --- pkg/lwip/Makefile.dep | 3 +++ pkg/lwip/contrib/netdev/lwip_netdev.c | 9 ++++++++- pkg/lwip/include/lwip/netif/compat.h | 24 ++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/pkg/lwip/Makefile.dep b/pkg/lwip/Makefile.dep index 07cf924753..29a1089e9e 100644 --- a/pkg/lwip/Makefile.dep +++ b/pkg/lwip/Makefile.dep @@ -89,6 +89,9 @@ endif ifneq (,$(filter lwip_contrib,$(USEMODULE))) USEMODULE += sema USEMODULE += ztimer_msec + ifneq (,$(filter bhp,$(USEMODULE))) + USEMODULE += bhp_msg + endif endif ifneq (,$(filter lwip_netif,$(USEMODULE))) diff --git a/pkg/lwip/contrib/netdev/lwip_netdev.c b/pkg/lwip/contrib/netdev/lwip_netdev.c index 7040229483..df035f30d7 100644 --- a/pkg/lwip/contrib/netdev/lwip_netdev.c +++ b/pkg/lwip/contrib/netdev/lwip_netdev.c @@ -87,7 +87,11 @@ err_t lwip_netdev_init(struct netif *netif) } } - /* initialize netdev and netif */ + /* initialize Bottom Half Processor, netdev and netif */ + if (IS_USED(MODULE_BHP_MSG)) { + bhp_msg_claim_thread(lwip_netif_get_bhp(netif), _pid); + } + netdev = netif->state; lwip_netif_dev_acquire(netif); netdev->driver->init(netdev); @@ -333,6 +337,9 @@ static void *_event_loop(void *arg) dev->driver->isr(dev); lwip_netif_dev_release(netif); } + else if (IS_USED(MODULE_BHP_MSG) && msg.type == BHP_MSG_BH_REQUEST) { + bhp_msg_handler(&msg); + } } return NULL; } diff --git a/pkg/lwip/include/lwip/netif/compat.h b/pkg/lwip/include/lwip/netif/compat.h index 507b3bb38a..a01952ae4a 100644 --- a/pkg/lwip/include/lwip/netif/compat.h +++ b/pkg/lwip/include/lwip/netif/compat.h @@ -22,6 +22,7 @@ #include "lwip/netif.h" #include "net/netif.h" +#include "bhp/msg.h" #ifdef __cplusplus extern "C" { @@ -34,6 +35,9 @@ typedef struct { netif_t common_netif; /**< network interface descriptor */ struct netif lwip_netif; /**< lwIP interface data */ rmutex_t lock; /**< lock for the interface */ +#if IS_USED(MODULE_BHP_MSG) + bhp_msg_t bhp; /**< IPC Bottom Half Processor */ +#endif } lwip_netif_t; /** @@ -69,6 +73,26 @@ static inline void lwip_netif_dev_release(struct netif *netif) rmutex_unlock(&compat_netif->lock); } +/** + * @brief Get the IPC based Bottom Half Processor for LWIP + * + * @param[in] netif pointer to the LWIP network interface + * + * @return pointer to the IPC based Bottom Half Processor descriptor, if + * @ref sys_bhp_msg is present. + * @return NULL otherwise + */ +static inline bhp_msg_t *lwip_netif_get_bhp(struct netif *netif) +{ +#if IS_USED(MODULE_BHP_MSG) + lwip_netif_t *compat_netif = container_of(netif, lwip_netif_t, lwip_netif); + return &compat_netif->bhp; +#else + (void) netif; + return NULL; +#endif +} + #ifdef __cplusplus } #endif From 9031773b7351563da1f7b2905ffd7fe09aae2fcc Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Wed, 17 Aug 2022 17:12:42 +0200 Subject: [PATCH 2/3] lwip/init_devs: add initial support for kw2xrf --- pkg/lwip/init_devs/auto_init_kw2xrf.c | 55 +++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 pkg/lwip/init_devs/auto_init_kw2xrf.c diff --git a/pkg/lwip/init_devs/auto_init_kw2xrf.c b/pkg/lwip/init_devs/auto_init_kw2xrf.c new file mode 100644 index 0000000000..6b5f1d12fa --- /dev/null +++ b/pkg/lwip/init_devs/auto_init_kw2xrf.c @@ -0,0 +1,55 @@ +/* +* Copyright (C) 2022 HAW Hamburg +* +* 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 sys_auto_init_lwip_netif + * @{ + * + * @file + * @brief Auto initialization for KW2XRF network interfaces + * + * @author José I. Álamos + */ + +#include "kw2xrf.h" +#include "kw2xrf_params.h" + +#include "lwip_init_devs.h" + +#include "bhp/msg.h" +#include "net/netdev/ieee802154_submac.h" + +#define ENABLE_DEBUG 0 +#include "debug.h" + +#define NETIF_KW2XRF_NUMOF ARRAY_SIZE(kw2xrf_params) + +static lwip_netif_t netif[NETIF_KW2XRF_NUMOF]; +static kw2xrf_t kw2xrf_devs[NETIF_KW2XRF_NUMOF]; +static netdev_ieee802154_submac_t kw2xrf_netdev[NETIF_KW2XRF_NUMOF]; + +static void auto_init_kw2xrf(void) +{ + for (unsigned i = 0; i < NETIF_KW2XRF_NUMOF; i++) { + bhp_msg_init(&netif[i].bhp, &kw2xrf_radio_hal_irq_handler, &kw2xrf_netdev[i].submac.dev); + kw2xrf_init(&kw2xrf_devs[i], &kw2xrf_params[i], &kw2xrf_netdev[i].submac.dev, + bhp_msg_isr_cb, &netif[i].bhp); + + netdev_register(&kw2xrf_netdev[i].dev.netdev, NETDEV_KW2XRF, i); + netdev_ieee802154_submac_init(&kw2xrf_netdev[i]); + + if (lwip_add_6lowpan(&netif[i], &kw2xrf_netdev[i].dev.netdev) == NULL) { + DEBUG("Could not add kw2xrf device\n"); + return; + } + } +} + +LWIP_INIT_6LOWPAN_NETIF(auto_init_kw2xrf); +/** @} */ From 744cf549000fcbf839ae9d414d2941b2720bc7f2 Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Fri, 19 Aug 2022 15:13:53 +0200 Subject: [PATCH 3/3] drivers/kw2xrf: remove unused kw2xrf_setup function --- drivers/include/kw2xrf.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/drivers/include/kw2xrf.h b/drivers/include/kw2xrf.h index 11aca9b00d..5527968f09 100644 --- a/drivers/include/kw2xrf.h +++ b/drivers/include/kw2xrf.h @@ -141,16 +141,6 @@ typedef struct { /** @} */ } kw2xrf_t; -/** - * @brief Setup an KW2XRF based device state - * - * @param[out] dev device descriptor - * @param[in] params parameters for device initialization - * @param[in] index index of @p params in a global parameter struct array. - * If initialized manually, pass a unique identifier instead. - */ -void kw2xrf_setup(kw2xrf_t *dev, const kw2xrf_params_t *params, uint8_t index); - /** * @brief Initialize the given KW2XRF device * @param[out] dev device descriptor