From 37c4810fbac0998d72ef86116319607fe6a52339 Mon Sep 17 00:00:00 2001 From: Toon Stegen Date: Thu, 7 Jul 2016 17:29:44 +0200 Subject: [PATCH] cpu/native: allow multiple netdev2 tap devices With arg added to async_read callback in 7020b7c0, we don't need to keep track of netdev2_tap locally. As a result we can use multiple netdev2_tap instances. --- cpu/native/async_read.c | 5 +++-- cpu/native/include/netdev2_tap.h | 12 ----------- cpu/native/include/tty_uart.h | 5 ----- cpu/native/netdev2_tap/netdev2_tap.c | 30 ++-------------------------- cpu/native/periph/pm.c | 8 ++------ cpu/native/periph/uart.c | 10 ---------- 6 files changed, 7 insertions(+), 63 deletions(-) diff --git a/cpu/native/async_read.c b/cpu/native/async_read.c index 0cf950b0ef20..d2d25802ef10 100644 --- a/cpu/native/async_read.c +++ b/cpu/native/async_read.c @@ -69,11 +69,12 @@ void native_async_read_setup(void) { void native_async_read_cleanup(void) { unregister_interrupt(SIGIO); -#ifdef __MACH__ for (int i = 0; i < _next_index; i++) { +#ifdef __MACH__ kill(_sigio_child_pids[i], SIGKILL); - } #endif + real_close(_fds[i]); + } } void native_async_read_continue(int fd) { diff --git a/cpu/native/include/netdev2_tap.h b/cpu/native/include/netdev2_tap.h index 39d8dd16a015..312101498140 100644 --- a/cpu/native/include/netdev2_tap.h +++ b/cpu/native/include/netdev2_tap.h @@ -54,11 +54,6 @@ typedef struct { inteface to bind to. */ } netdev2_tap_params_t; -/** - * @brief global device struct. driver only supports one tap device as of now. - */ -extern netdev2_tap_t netdev2_tap; - /** * @brief Setup netdev2_tap_t structure. * @@ -67,13 +62,6 @@ extern netdev2_tap_t netdev2_tap; */ void netdev2_tap_setup(netdev2_tap_t *dev, const netdev2_tap_params_t *params); -/** - * @brief Cleanup tap resources - * - * @param dev the netdev2_tap device handle to cleanup - */ -void netdev2_tap_cleanup(netdev2_tap_t *dev); - #ifdef __cplusplus } #endif diff --git a/cpu/native/include/tty_uart.h b/cpu/native/include/tty_uart.h index 0c9feaef41cd..73d2547ff4c2 100644 --- a/cpu/native/include/tty_uart.h +++ b/cpu/native/include/tty_uart.h @@ -33,11 +33,6 @@ extern "C" { */ void tty_uart_setup(uart_t uart, const char *name); -/** - * @brief closes files opened - */ -void uart_cleanup(void); - #ifdef __cplusplus } #endif diff --git a/cpu/native/netdev2_tap/netdev2_tap.c b/cpu/native/netdev2_tap/netdev2_tap.c index 18c5fc5c9662..6aa2797218bf 100644 --- a/cpu/native/netdev2_tap/netdev2_tap.c +++ b/cpu/native/netdev2_tap/netdev2_tap.c @@ -60,9 +60,6 @@ #define ENABLE_DEBUG (0) #include "debug.h" -/* support one tap interface for now */ -netdev2_tap_t netdev2_tap; - /* netdev2 interface */ static int _init(netdev2_t *netdev); static int _send(netdev2_t *netdev, const struct iovec *vector, unsigned n); @@ -107,10 +104,6 @@ static inline void _isr(netdev2_t *netdev) static int _get(netdev2_t *dev, netopt_t opt, void *value, size_t max_len) { - if (dev != (netdev2_t *)&netdev2_tap) { - return -ENODEV; - } - int res = 0; switch (opt) { @@ -138,11 +131,6 @@ static int _get(netdev2_t *dev, netopt_t opt, void *value, size_t max_len) static int _set(netdev2_t *dev, netopt_t opt, void *value, size_t value_len) { (void)value_len; - - if (dev != (netdev2_t *)&netdev2_tap) { - return -ENODEV; - } - int res = 0; switch (opt) { @@ -307,9 +295,8 @@ void netdev2_tap_setup(netdev2_tap_t *dev, const netdev2_tap_params_t *params) { static void _tap_isr(int fd, void *arg) { (void) fd; - (void) arg; - netdev2_t *netdev = (netdev2_t *)&netdev2_tap; + netdev2_t *netdev = (netdev2_t *)arg; if (netdev->event_callback) { netdev->event_callback(netdev, NETDEV2_EVENT_ISR); @@ -392,7 +379,7 @@ static int _init(netdev2_t *netdev) /* configure signal handler for fds */ native_async_read_setup(); - native_async_read_add_handler(dev->tap_fd, NULL, _tap_isr); + native_async_read_add_handler(dev->tap_fd, netdev, _tap_isr); #ifdef MODULE_NETSTATS_L2 memset(&netdev->stats, 0, sizeof(netstats_t)); @@ -401,16 +388,3 @@ static int _init(netdev2_t *netdev) return 0; } -void netdev2_tap_cleanup(netdev2_tap_t *dev) -{ - /* Do we have a device */ - if (!dev) { - return; - } - - /* cleanup signal handling */ - native_async_read_cleanup(); - - /* close the tap device */ - real_close(dev->tap_fd); -} diff --git a/cpu/native/periph/pm.c b/cpu/native/periph/pm.c index 032abc005e56..d5791fada04e 100644 --- a/cpu/native/periph/pm.c +++ b/cpu/native/periph/pm.c @@ -22,7 +22,7 @@ #include "periph/pm.h" #include "native_internal.h" -#include "netdev2_tap.h" +#include "async_read.h" #include "tty_uart.h" #define ENABLE_DEBUG (0) @@ -50,11 +50,7 @@ void pm_reboot(void) { printf("\n\n\t\t!! REBOOT !!\n\n"); -#ifdef MODULE_NETDEV2_TAP - netdev2_tap_cleanup(&netdev2_tap); -#endif - - uart_cleanup(); + native_async_read_cleanup(); if (real_execve(_native_argv[0], _native_argv, NULL) == -1) { err(EXIT_FAILURE, "reboot: execve"); diff --git a/cpu/native/periph/uart.c b/cpu/native/periph/uart.c index 926ccb930b2a..e365b5d8d25a 100644 --- a/cpu/native/periph/uart.c +++ b/cpu/native/periph/uart.c @@ -175,14 +175,4 @@ void uart_write(uart_t uart, const uint8_t *data, size_t len) _native_write(tty_fds[uart], data, len); } -void uart_cleanup(void) { - native_async_read_cleanup(); - - for (uart_t uart = 0; uart < UART_NUMOF; uart++) { - if (uart_config[uart].rx_cb != NULL) { - real_close(tty_fds[uart]); - } - } -} - /** @} */