From 3726bf62d341a586ba74a1dfeb5608efee342ca1 Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Wed, 27 Feb 2019 22:23:14 +0100 Subject: [PATCH] usbus_cdc_ecm: provide auto init integration --- sys/auto_init/auto_init.c | 5 +++ sys/auto_init/netif/auto_init_cdcecm.c | 59 ++++++++++++++++++++++++++ sys/auto_init/usb/auto_init_usb.c | 9 ++++ 3 files changed, 73 insertions(+) create mode 100644 sys/auto_init/netif/auto_init_cdcecm.c diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index 30a2106e7c..8a75f881c6 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -261,6 +261,11 @@ void auto_init(void) auto_init_kw2xrf(); #endif +#ifdef MODULE_USBUS_CDC_ECM + extern void auto_init_netdev_cdcecm(void); + auto_init_netdev_cdcecm(); +#endif + #ifdef MODULE_NETDEV_TAP extern void auto_init_netdev_tap(void); auto_init_netdev_tap(); diff --git a/sys/auto_init/netif/auto_init_cdcecm.c b/sys/auto_init/netif/auto_init_cdcecm.c new file mode 100644 index 0000000000..5bf9e2229c --- /dev/null +++ b/sys/auto_init/netif/auto_init_cdcecm.c @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2019 Koen Zandberg + * + * 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 USB CDC ECM module + * + * @author Koen Zandberg + */ + +#ifdef MODULE_USBUS_CDC_ECM + +#include "log.h" +#include "usb/usbus/cdc/ecm.h" +#include "net/gnrc/netif/ethernet.h" + +/** + * @brief global cdc ecm object, declared in the usb auto init file + */ +extern usbus_cdcecm_device_t cdcecm; + +/** + * @brief Define stack parameters for the MAC layer thread + * @{ + */ +#define CDCECM_MAC_STACKSIZE (THREAD_STACKSIZE_DEFAULT) +#ifndef CDCECM_MAC_PRIO +#define CDCECM_MAC_PRIO (GNRC_NETIF_PRIO) +#endif + +/** + * @brief Stacks for the MAC layer threads + */ +static char _netdev_eth_stack[CDCECM_MAC_STACKSIZE]; +extern void cdcecm_netdev_setup(usbus_cdcecm_device_t *cdcecm); + +void auto_init_netdev_cdcecm(void) +{ + LOG_DEBUG("[auto_init_netif] initializing cdc ecm #0\n"); + + cdcecm_netdev_setup(&cdcecm); + /* initialize netdev<->gnrc adapter state */ + gnrc_netif_ethernet_create(_netdev_eth_stack, CDCECM_MAC_STACKSIZE, + CDCECM_MAC_PRIO, "cdcecm", &cdcecm.netdev); +} + +#else +typedef int dont_be_pedantic; +#endif /* MODULE_CDC_ECM */ +/** @} */ diff --git a/sys/auto_init/usb/auto_init_usb.c b/sys/auto_init/usb/auto_init_usb.c index 5eb5d1edad..6d85d3622b 100644 --- a/sys/auto_init/usb/auto_init_usb.c +++ b/sys/auto_init/usb/auto_init_usb.c @@ -24,6 +24,11 @@ #include "usb/usbus.h" +#ifdef MODULE_USBUS_CDC_ECM +#include "usb/usbus/cdc/ecm.h" +usbus_cdcecm_device_t cdcecm; +#endif + static char _stack[USBUS_STACKSIZE]; static usbus_t usbus; @@ -36,6 +41,10 @@ void auto_init_usb(void) /* Initialize basic usbus struct, don't start the thread yet */ usbus_init(&usbus, usbdev); + /* USBUS function handlers initialization */ +#ifdef MODULE_USBUS_CDC_ECM + usbus_cdcecm_init(&usbus, &cdcecm); +#endif /* Finally initialize USBUS thread */ usbus_create(_stack, USBUS_STACKSIZE, USBUS_PRIO, USBUS_TNAME, &usbus);