Skip to content

Commit

Permalink
cpu/native: allow multiple netdev2 tap devices
Browse files Browse the repository at this point in the history
With arg added to async_read callback in 7020b7c, we don't need to keep
track of netdev2_tap locally. As a result we can use multiple
netdev2_tap instances.
  • Loading branch information
Toon Stegen authored and miri64 committed Jan 18, 2017
1 parent a35709b commit 37c4810
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 63 deletions.
5 changes: 3 additions & 2 deletions cpu/native/async_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 0 additions & 12 deletions cpu/native/include/netdev2_tap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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
Expand Down
5 changes: 0 additions & 5 deletions cpu/native/include/tty_uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 2 additions & 28 deletions cpu/native/netdev2_tap/netdev2_tap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand All @@ -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);
}
8 changes: 2 additions & 6 deletions cpu/native/periph/pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down
10 changes: 0 additions & 10 deletions cpu/native/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
}

/** @} */

0 comments on commit 37c4810

Please sign in to comment.