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.
This commit is contained in:
parent
a35709b4f8
commit
37c4810fba
@ -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) {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user