gnrc_netif: add message bus to interface
Allow threads to listen for events on an interface.
This commit is contained in:
parent
c29f133a63
commit
85100ad61a
@ -196,6 +196,10 @@ ifneq (,$(filter gnrc_netif,$(USEMODULE)))
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifneq (,$(filter gnrc_netif_bus,$(USEMODULE)))
|
||||||
|
USEMODULE += core_msg_bus
|
||||||
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter gnrc_netif_events,$(USEMODULE)))
|
ifneq (,$(filter gnrc_netif_events,$(USEMODULE)))
|
||||||
USEMODULE += core_thread_flags
|
USEMODULE += core_thread_flags
|
||||||
USEMODULE += event
|
USEMODULE += event
|
||||||
|
|||||||
@ -31,6 +31,7 @@ PSEUDOMODULES += gnrc_netdev_default
|
|||||||
PSEUDOMODULES += gnrc_neterr
|
PSEUDOMODULES += gnrc_neterr
|
||||||
PSEUDOMODULES += gnrc_netapi_callbacks
|
PSEUDOMODULES += gnrc_netapi_callbacks
|
||||||
PSEUDOMODULES += gnrc_netapi_mbox
|
PSEUDOMODULES += gnrc_netapi_mbox
|
||||||
|
PSEUDOMODULES += gnrc_netif_bus
|
||||||
PSEUDOMODULES += gnrc_netif_events
|
PSEUDOMODULES += gnrc_netif_events
|
||||||
PSEUDOMODULES += gnrc_pktbuf_cmd
|
PSEUDOMODULES += gnrc_pktbuf_cmd
|
||||||
PSEUDOMODULES += gnrc_netif_6lo
|
PSEUDOMODULES += gnrc_netif_6lo
|
||||||
|
|||||||
@ -30,6 +30,9 @@
|
|||||||
|
|
||||||
#include "kernel_types.h"
|
#include "kernel_types.h"
|
||||||
#include "msg.h"
|
#include "msg.h"
|
||||||
|
#ifdef MODULE_GNRC_NETIF_BUS
|
||||||
|
#include "msg_bus.h"
|
||||||
|
#endif
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "net/ipv6/addr.h"
|
#include "net/ipv6/addr.h"
|
||||||
#include "net/gnrc/netapi.h"
|
#include "net/gnrc/netapi.h"
|
||||||
@ -64,6 +67,13 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Per-Interface Event Message Busses
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
GNRC_NETIF_BUS_NUMOF
|
||||||
|
} gnrc_netif_bus_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Operations to an interface
|
* @brief Operations to an interface
|
||||||
*/
|
*/
|
||||||
@ -87,8 +97,11 @@ typedef struct {
|
|||||||
gnrc_netif_ipv6_t ipv6; /**< IPv6 component */
|
gnrc_netif_ipv6_t ipv6; /**< IPv6 component */
|
||||||
#endif
|
#endif
|
||||||
#if IS_USED(MODULE_GNRC_NETIF_MAC) || defined(DOXYGEN)
|
#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) */
|
#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
|
* @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);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -67,6 +67,11 @@ int gnrc_netif_create(gnrc_netif_t *netif, char *stack, int stacksize,
|
|||||||
"more than one interface is being registered.\n");
|
"more than one interface is being registered.\n");
|
||||||
assert(netif_iter(NULL) == NULL);
|
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);
|
rmutex_init(&netif->mutex);
|
||||||
netif->ops = ops;
|
netif->ops = ops;
|
||||||
netif_register((netif_t*) netif);
|
netif_register((netif_t*) netif);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user