1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

gnrc_netif: add message bus to interface

Allow threads to listen for events on an interface.
This commit is contained in:
Benjamin Valentin 2020-05-05 00:36:01 +02:00
parent c29f133a63
commit 85100ad61a
4 changed files with 41 additions and 1 deletions

View File

@ -196,6 +196,10 @@ ifneq (,$(filter gnrc_netif,$(USEMODULE)))
endif
endif
ifneq (,$(filter gnrc_netif_bus,$(USEMODULE)))
USEMODULE += core_msg_bus
endif
ifneq (,$(filter gnrc_netif_events,$(USEMODULE)))
USEMODULE += core_thread_flags
USEMODULE += event

View File

@ -31,6 +31,7 @@ PSEUDOMODULES += gnrc_netdev_default
PSEUDOMODULES += gnrc_neterr
PSEUDOMODULES += gnrc_netapi_callbacks
PSEUDOMODULES += gnrc_netapi_mbox
PSEUDOMODULES += gnrc_netif_bus
PSEUDOMODULES += gnrc_netif_events
PSEUDOMODULES += gnrc_pktbuf_cmd
PSEUDOMODULES += gnrc_netif_6lo

View File

@ -30,6 +30,9 @@
#include "kernel_types.h"
#include "msg.h"
#ifdef MODULE_GNRC_NETIF_BUS
#include "msg_bus.h"
#endif
#include "event.h"
#include "net/ipv6/addr.h"
#include "net/gnrc/netapi.h"
@ -64,6 +67,13 @@
extern "C" {
#endif
/**
* @brief Per-Interface Event Message Busses
*/
typedef enum {
GNRC_NETIF_BUS_NUMOF
} gnrc_netif_bus_t;
/**
* @brief Operations to an interface
*/
@ -87,8 +97,11 @@ typedef struct {
gnrc_netif_ipv6_t ipv6; /**< IPv6 component */
#endif
#if IS_USED(MODULE_GNRC_NETIF_MAC) || defined(DOXYGEN)
gnrc_netif_mac_t mac; /**< @ref net_gnrc_mac component */
gnrc_netif_mac_t mac; /**< @ref net_gnrc_mac component */
#endif /* IS_USED(MODULE_GNRC_NETIF_MAC) || defined(DOXYGEN) */
#if IS_USED(MODULE_GNRC_NETIF_BUS) || DOXYGEN
msg_bus_t bus[GNRC_NETIF_BUS_NUMOF]; /**< Event Message Bus */
#endif
/**
* @brief Flags for the interface
*
@ -566,6 +579,23 @@ static inline int gnrc_netif_send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt)
return gnrc_netapi_send(netif->pid, pkt);
}
#if defined(MODULE_GNRC_NETIF_BUS) || DOXYGEN
/**
* @brief Get a message bus of a given @ref gnrc_netif_t interface.
*
* @param netif pointer to the interface
* @param type GNRC message bus [type](@ref gnrc_netif_bus_t)
*
* @return the message bus for the interface
*/
static inline msg_bus_t* gnrc_netif_get_bus(gnrc_netif_t *netif,
gnrc_netif_bus_t type)
{
assert(type < GNRC_NETIF_BUS_NUMOF);
return &netif->bus[type];
}
#endif /* MODULE_GNRC_NETIF_BUS */
#ifdef __cplusplus
}
#endif

View File

@ -67,6 +67,11 @@ int gnrc_netif_create(gnrc_netif_t *netif, char *stack, int stacksize,
"more than one interface is being registered.\n");
assert(netif_iter(NULL) == NULL);
}
#ifdef MODULE_GNRC_NETIF_BUS
for (int i = 0; i < GNRC_NETIF_BUS_NUMOF; ++i) {
msg_bus_init(&netif->bus[i]);
}
#endif
rmutex_init(&netif->mutex);
netif->ops = ops;
netif_register((netif_t*) netif);