Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

netdev_event_thread: add support for event_thread irq handler #13573

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ ifneq (,$(filter gnrc_netdev_default,$(USEMODULE)))
USEMODULE += gnrc_netif
endif

ifneq (,$(filter netdev_event_thread,$(USEMODULE)))
USEMODULE += event_thread_highest
endif

ifneq (,$(filter netdev_ieee802154,$(USEMODULE)))
USEMODULE += ieee802154
USEMODULE += random
Expand Down
4 changes: 0 additions & 4 deletions cpu/native/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ ifeq ($(OS),Darwin)
CFLAGS += -D_XOPEN_SOURCE=600 -D_DARWIN_C_SOURCE
endif

ifneq (,$(filter netdev_tap,$(USEMODULE)))
DIRS += netdev_tap
endif

ifneq (,$(filter socket_zep,$(USEMODULE)))
DIRS += socket_zep
endif
Expand Down
3 changes: 0 additions & 3 deletions cpu/native/netdev_tap/Makefile

This file was deleted.

4 changes: 4 additions & 0 deletions drivers/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -737,3 +737,7 @@ ifneq (,$(filter xbee,$(USEMODULE)))
USEMODULE += xtimer
USEMODULE += netif
endif

ifneq (,$(filter netdev_%,$(USEMODULE)))
USEMODULE += netdev
endif
39 changes: 39 additions & 0 deletions drivers/include/net/netdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,17 @@ extern "C" {
#include "iolist.h"
#include "net/netopt.h"

#include "kernel_defines.h"

#ifdef MODULE_L2FILTER
#include "net/l2filter.h"
#endif

#if IS_USED(MODULE_NETDEV_EVENT_THREAD)
#include "event.h"
#include "event/thread.h"
#endif

/**
* @name Network device types
* @anchor net_netdev_type
Expand Down Expand Up @@ -290,6 +297,9 @@ struct netdev {
#ifdef MODULE_L2FILTER
l2filter_t filter[L2FILTER_LISTSIZE]; /**< link layer address filters */
#endif
#if IS_USED(MODULE_NETDEV_EVENT_THREAD)
event_t irq_handler; /**< event that stores the irq handler */
#endif
};

/**
Expand Down Expand Up @@ -469,6 +479,31 @@ static inline int netdev_set_notsup(netdev_t *dev, netopt_t opt,
return -ENOTSUP;
}

#if IS_USED(MODULE_NETDEV_EVENT_THREAD) || DOXYGEN

/**
* @brief default event handler for the `netdev_event_thread` module.
*
* @param event pointer to the irq handler event.
*/
extern void netdev_event_thread_handler(event_t *event);

/**
* @brief Initialize the event handler for a given device.
*
* This function is only available if the `netdev_event_thread` module
* is used.
*
* @note This function MUST be called before `dev->driver->init`.
*
* @param netdev network device descriptor
*/
static inline void netdev_event_thread_init(netdev_t *netdev)
{
netdev->irq_handler.handler = netdev_event_thread_handler;
}
#endif

/**
* @brief Informs netdev there was an interrupt request from the network device.
*
Expand All @@ -479,9 +514,13 @@ static inline int netdev_set_notsup(netdev_t *dev, netopt_t opt,
*/
static inline void netdev_trigger_event_isr(netdev_t *netdev)
{
#if IS_USED(MODULE_NETDEV_EVENT_THREAD)
event_post(EVENT_PRIO_HIGHEST, &netdev->irq_handler);
#else
if (netdev->event_callback) {
netdev->event_callback(netdev, NETDEV_EVENT_ISR);
}
#endif
}
#ifdef __cplusplus
}
Expand Down
4 changes: 4 additions & 0 deletions drivers/netdev/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SUBMODULES := 1
SUBMODULES_NOFORCE := 1

include $(RIOTBASE)/Makefile.base
File renamed without changes.
22 changes: 22 additions & 0 deletions drivers/netdev/event_thread.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2020 HAW Hamburg
*
* 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 drivers_netdev
* @{
*
* @file
* @author José I. Alamos <[email protected]>
*/

#include "net/netdev.h"

void netdev_event_thread_handler(event_t *event) {
netdev_t *dev = container_of(event, netdev_t, irq_handler);
dev->driver->isr(dev);
}
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion drivers/netdev_eth/Makefile

This file was deleted.

1 change: 0 additions & 1 deletion drivers/netdev_ieee802154/Makefile

This file was deleted.

1 change: 0 additions & 1 deletion drivers/netdev_layer/Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion makefiles/pseudomodules.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ PSEUDOMODULES += log_color
PSEUDOMODULES += lora
PSEUDOMODULES += mpu_stack_guard
PSEUDOMODULES += nanocoap_%
PSEUDOMODULES += netdev_default
PSEUDOMODULES += netdev_%
PSEUDOMODULES += netstats
PSEUDOMODULES += netstats_l2
PSEUDOMODULES += netstats_ipv6
Expand Down