From 4d9f96515972c49eed0498fffcfde6160dec9eb0 Mon Sep 17 00:00:00 2001 From: Oleg Hahm <oleg@hobbykeller.org> Date: Wed, 27 May 2015 21:58:38 +0200 Subject: [PATCH] auto_init: initialize ng_netdev_eth --- sys/auto_init/auto_init.c | 5 ++ sys/auto_init/netif/auto_init_ng_netdev_eth.c | 60 +++++++++++++++++++ tests/driver_netdev_eth/Makefile | 1 + tests/driver_netdev_eth/main.c | 21 ------- 4 files changed, 66 insertions(+), 21 deletions(-) create mode 100644 sys/auto_init/netif/auto_init_ng_netdev_eth.c diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index 02463662ce..1f21226c6a 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -335,6 +335,11 @@ void auto_init(void) auto_init_kw2xrf(); #endif +#ifdef MODULE_NG_NETDEV_ETH + extern void auto_init_ng_netdev_eth(void); + auto_init_ng_netdev_eth(); +#endif + #endif /* MODULE_AUTO_INIT_NG_NETIF */ #ifdef MODULE_NG_IPV6_NETIF diff --git a/sys/auto_init/netif/auto_init_ng_netdev_eth.c b/sys/auto_init/netif/auto_init_ng_netdev_eth.c new file mode 100644 index 0000000000..19803a5fb4 --- /dev/null +++ b/sys/auto_init/netif/auto_init_ng_netdev_eth.c @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de> + * + * 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 auto_init_ng_netif + * @{ + * + * @file + * @brief Auto initialization for netdev Ethernet network interfaces + * + * @author Kaspar Schleiser <kaspar@schleiser.de> + * @author Oliver Hahm <oliver.hahm@inria.fr> + */ + +#ifdef MODULE_NG_NETDEV_ETH + +#include "board.h" +#include "net/ng_nomac.h" +#include "net/ng_netbase.h" + +#include "net/ng_netdev_eth.h" +#include "net/dev_eth.h" +#include "dev_eth_tap.h" + +#define ENABLE_DEBUG (0) +#include "debug.h" + +/** + * @brief Define stack parameters for the MAC layer thread + * @{ + */ +#define NETDEV_ETH_MAC_STACKSIZE (THREAD_STACKSIZE_DEFAULT) +#define NETDEV_ETH_MAC_PRIO (THREAD_PRIORITY_MAIN - 3) + +static char _nomac_stack[NETDEV_ETH_MAC_STACKSIZE]; + +void auto_init_ng_netdev_eth(void) +{ + DEBUG("Initializing NETDEV_ETH device\n"); + int res = ng_netdev_eth_init(&ng_netdev_eth, (dev_eth_t*)&dev_eth_tap); + + if (res < 0) { + DEBUG("Error initializing NETDEV_ETH device!"); + } + else { + ng_nomac_init(_nomac_stack, NETDEV_ETH_MAC_STACKSIZE, NETDEV_ETH_MAC_PRIO, + "tapnet", (ng_netdev_t *)&ng_netdev_eth); + } +} +#else +typedef int dont_be_pedantic; +#endif /* MODULE_NG_NETDEV_ETH */ + +/** @} */ diff --git a/tests/driver_netdev_eth/Makefile b/tests/driver_netdev_eth/Makefile index 1ed37331c4..30d326d8bf 100644 --- a/tests/driver_netdev_eth/Makefile +++ b/tests/driver_netdev_eth/Makefile @@ -8,6 +8,7 @@ USEMODULE += ng_netbase USEMODULE += ng_nomac USEMODULE += ng_pktdump USEMODULE += ng_netdev_eth +USEMODULE += auto_init_ng_netif USEMODULE += shell USEMODULE += shell_commands diff --git a/tests/driver_netdev_eth/main.c b/tests/driver_netdev_eth/main.c index f7c1fca7b4..89cd0affd0 100644 --- a/tests/driver_netdev_eth/main.c +++ b/tests/driver_netdev_eth/main.c @@ -38,11 +38,6 @@ */ #define SHELL_BUFSIZE (64U) -/** - * @brief Stack for the nomac thread - */ -static char nomac_stack[THREAD_STACKSIZE_DEFAULT]; - /** * @brief Read chars from STDIO */ @@ -64,15 +59,11 @@ void shell_put(int c) */ int main(void) { - int res; shell_t shell; ng_netreg_entry_t dump; puts("netdev ethernet device driver test"); - /* initialize network module(s) */ - ng_netif_init(); - /* initialize and register pktdump */ dump.pid = ng_pktdump_init(); dump.demux_ctx = NG_NETREG_DEMUX_CTX_ALL; @@ -84,18 +75,6 @@ int main(void) ng_netreg_register(NG_NETTYPE_UNDEF, &dump); - /* initialize netdev_eth layer */ - ng_netdev_eth_init(&ng_netdev_eth, (dev_eth_t*)&dev_eth_tap); - - /* start MAC layer */ - res = ng_nomac_init(nomac_stack, sizeof(nomac_stack), THREAD_PRIORITY_MAIN - 3, - "tapnet_l2", (ng_netdev_t *)&ng_netdev_eth); - - if (res < 0) { - printf("Error starting nomac thread. res=%i\n", res); - return -1; - } - /* start the shell */ shell_init(&shell, NULL, SHELL_BUFSIZE, shell_read, shell_put); shell_run(&shell); -- GitLab