From 4daaaccb0f16a1ffe6069edf9748e4f81cbfcd1a Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Wed, 17 Aug 2022 14:39:45 +0200 Subject: [PATCH] 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