From e7d0fbbc71d7e57f574b3a92dfae3af1ea945a38 Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Mon, 14 Nov 2022 07:27:37 +0100 Subject: [PATCH] sys/net/gnrc/netif: add tinyUSB netdev to auto_init --- .../init_devs/auto_init_tinyusb_netdev.c | 61 +++++++++++++++++++ sys/net/gnrc/netif/init_devs/init.c | 6 ++ 2 files changed, 67 insertions(+) create mode 100644 sys/net/gnrc/netif/init_devs/auto_init_tinyusb_netdev.c diff --git a/sys/net/gnrc/netif/init_devs/auto_init_tinyusb_netdev.c b/sys/net/gnrc/netif/init_devs/auto_init_tinyusb_netdev.c new file mode 100644 index 0000000000..aece7bc08b --- /dev/null +++ b/sys/net/gnrc/netif/init_devs/auto_init_tinyusb_netdev.c @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2019 Koen Zandberg + * 2022 Gunar Schorcht + * + * 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_gnrc_netif + * @{ + * + * @file + * @brief Auto initialization for tinyUSB CDC ECM module + * + * @author Koen Zandberg + * @author Gunar Schorcht + */ + +#define USB_H_USER_IS_RIOT_INTERNAL + +#include "include/init_devs.h" +#include "log.h" +#include "net/gnrc/netif/ethernet.h" +#include "tinyusb_netdev.h" + +/** + * @brief global cdc ecm object, declared in the usb auto init file + */ +extern tinyusb_netdev_t tinyusb_netdev; + +/** + * @brief Define stack parameters for the MAC layer thread + * @{ + */ +#define TUSB_NETDEV_STACKSIZE (GNRC_NETIF_STACKSIZE_DEFAULT) +#ifndef TUSB_NETDEV_PRIO +#define TUSB_NETDEV_PRIO (GNRC_NETIF_PRIO) +#endif + +/** + * @brief Stacks for the MAC layer threads + */ +static char _netdev_eth_stack[TUSB_NETDEV_STACKSIZE]; +static gnrc_netif_t _netif; + +extern void tinyusb_netdev_setup(tinyusb_netdev_t *dev); + +void auto_init_tinyusb_netdev(void) +{ + LOG_DEBUG("[auto_init_netif] initializing tinyUSB netdev #0\n"); + + tinyusb_netdev_setup(&tinyusb_netdev); + /* initialize netdev<->gnrc adapter state */ + gnrc_netif_ethernet_create(&_netif, _netdev_eth_stack, + TUSB_NETDEV_STACKSIZE, TUSB_NETDEV_PRIO, + "tinyusb_netdev", &tinyusb_netdev.netdev); +} +/** @} */ diff --git a/sys/net/gnrc/netif/init_devs/init.c b/sys/net/gnrc/netif/init_devs/init.c index 67df6e0a1a..8360365cbf 100644 --- a/sys/net/gnrc/netif/init_devs/init.c +++ b/sys/net/gnrc/netif/init_devs/init.c @@ -171,4 +171,10 @@ void gnrc_netif_init_devs(void) extern void auto_init_sx126x(void); auto_init_sx126x(); } + + if (IS_USED(MODULE_TINYUSB_NETDEV)) { + extern void auto_init_tinyusb_netdev(void); + auto_init_tinyusb_netdev(); + } + }