diff --git a/cpu/native/async_read.c b/cpu/native/async_read.c index 12ee95999bfc..0cf950b0ef20 100644 --- a/cpu/native/async_read.c +++ b/cpu/native/async_read.c @@ -28,6 +28,7 @@ static int _next_index; static int _fds[ASYNC_READ_NUMOF]; +static void *_args[ASYNC_READ_NUMOF]; static native_async_read_callback_t _native_async_read_callbacks[ASYNC_READ_NUMOF]; #ifdef __MACH__ @@ -55,7 +56,7 @@ static void _async_io_isr(void) { if (real_select(max_fd + 1, &rfds, NULL, NULL, &timeout) > 0) { for (int i = 0; i < _next_index; i++) { if (FD_ISSET(_fds[i], &rfds)) { - _native_async_read_callbacks[i](_fds[i]); + _native_async_read_callbacks[i](_fds[i], _args[i]); } } } @@ -86,12 +87,13 @@ void native_async_read_continue(int fd) { #endif } -void native_async_read_add_handler(int fd, native_async_read_callback_t handler) { +void native_async_read_add_handler(int fd, void *arg, native_async_read_callback_t handler) { if (_next_index >= ASYNC_READ_NUMOF) { err(EXIT_FAILURE, "native_async_read_add_handler(): too many callbacks"); } _fds[_next_index] = fd; + _args[_next_index] = arg; _native_async_read_callbacks[_next_index] = handler; #ifdef __MACH__ diff --git a/cpu/native/include/async_read.h b/cpu/native/include/async_read.h index 0a1edf237cd7..0f61d1a6a6fe 100644 --- a/cpu/native/include/async_read.h +++ b/cpu/native/include/async_read.h @@ -32,7 +32,7 @@ extern "C" { /** * @brief asynchronus read callback type */ -typedef void (*native_async_read_callback_t)(int fd); +typedef void (*native_async_read_callback_t)(int fd, void *arg); /** * @brief initialize asynchronus read system @@ -61,10 +61,11 @@ void native_async_read_continue(int fd); * @brief start monitoring of file descriptor * * @param[in] fd The file descriptor to monitor + * @param[in] arg Pointer to be passed as arguments to the callback * @param[in] handler The callback function to be called when the file * descriptor is ready to read. */ -void native_async_read_add_handler(int fd, native_async_read_callback_t handler); +void native_async_read_add_handler(int fd, void *arg, native_async_read_callback_t handler); #ifdef __cplusplus } diff --git a/cpu/native/netdev2_tap/netdev2_tap.c b/cpu/native/netdev2_tap/netdev2_tap.c index b59f8f21b2d2..734211f1ecd5 100644 --- a/cpu/native/netdev2_tap/netdev2_tap.c +++ b/cpu/native/netdev2_tap/netdev2_tap.c @@ -307,8 +307,9 @@ void netdev2_tap_setup(netdev2_tap_t *dev, const netdev2_tap_params_t *params) { strncpy(dev->tap_name, *(params->tap_name), IFNAMSIZ); } -static void _tap_isr(int fd) { +static void _tap_isr(int fd, void *arg) { (void) fd; + (void) arg; netdev2_t *netdev = (netdev2_t *)&netdev2_tap; @@ -393,7 +394,7 @@ static int _init(netdev2_t *netdev) /* configure signal handler for fds */ native_async_read_setup(); - native_async_read_add_handler(dev->tap_fd, _tap_isr); + native_async_read_add_handler(dev->tap_fd, NULL, _tap_isr); #ifdef MODULE_NETSTATS_L2 memset(&netdev->stats, 0, sizeof(netstats_t)); diff --git a/cpu/native/periph/uart.c b/cpu/native/periph/uart.c index fcbc5e89729d..04ce96cefe1d 100644 --- a/cpu/native/periph/uart.c +++ b/cpu/native/periph/uart.c @@ -51,9 +51,10 @@ void tty_uart_setup(uart_t uart, const char *filename) tty_device_filenames[uart] = strndup(filename, PATH_MAX - 1); } -static void io_signal_handler(int fd) +static void io_signal_handler(int fd, void *arg) { uart_t uart; + (void) arg; for (uart = 0; uart < UART_NUMOF; uart++) { if (tty_fds[uart] == fd) { @@ -151,7 +152,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg) uart_config[uart].arg = arg; native_async_read_setup(); - native_async_read_add_handler(tty_fds[uart], io_signal_handler); + native_async_read_add_handler(tty_fds[uart], NULL, io_signal_handler); return 0; }