diff --git a/sys/include/net/gnrc/netif.h b/sys/include/net/gnrc/netif.h index 9247e00f45842..923a745539ea3 100644 --- a/sys/include/net/gnrc/netif.h +++ b/sys/include/net/gnrc/netif.h @@ -76,6 +76,25 @@ extern "C" { #endif +/** + * @brief Index of the high priority queue + */ +#define GNRC_NETIF_EVQ_INDEX_PRIO_HIGH (0) + +/** + * @brief Index of the low priority queue + */ +#if IS_USED(MODULE_BHP_EVENT) +#define GNRC_NETIF_EVQ_INDEX_PRIO_LOW (GNRC_NETIF_EVQ_INDEX_PRIO_HIGH + 1) +#else +#define GNRC_NETIF_EVQ_INDEX_PRIO_LOW GNRC_NETIF_EVQ_INDEX_PRIO_HIGH +#endif + +/** + * @brief Number of event queues + */ +#define GNRC_NETIF_EVQ_NUMOF (GNRC_NETIF_EVQ_INDEX_PRIO_LOW + 1) + /** * @brief Per-Interface Event Message Buses */ @@ -142,7 +161,7 @@ typedef struct { /** * @brief Event queue for asynchronous events */ - event_queue_t evq; + event_queue_t evq[GNRC_NETIF_EVQ_NUMOF]; /** * @brief ISR event for the network device */ diff --git a/sys/net/gnrc/netif/gnrc_netif.c b/sys/net/gnrc/netif/gnrc_netif.c index 408417c23dd3a..cecd2ed13bc38 100644 --- a/sys/net/gnrc/netif/gnrc_netif.c +++ b/sys/net/gnrc/netif/gnrc_netif.c @@ -1675,6 +1675,17 @@ static void _process_receive_stats(gnrc_netif_t *netdev, gnrc_pktsnip_t *pkt) netstats_nb_update_rx(&netdev->netif, src, src_len, hdr->rssi, hdr->lqi); } +static event_t *_gnrc_netif_fetch_event(gnrc_netif_t *netif) +{ + /* Iterate from highest priority to lowest priority */ + for (int i = 0; i < GNRC_NETIF_EVQ_NUMOF; i++) { + if ((ev = event_get(&netif->evq[i]))) { + return ev; + } + } + return NULL; +} + /** * @brief Process any pending events and wait for IPC messages * @@ -1697,8 +1708,7 @@ static void _process_events_await_msg(gnrc_netif_t *netif, msg_t *msg) event_t *evp; /* We can not use event_loop() or event_wait() because then we would not * wake up when a message arrives */ - event_queue_t *evq = &netif->evq; - while ((evp = event_get(evq))) { + while (_gnrc_netif_fetch_event(netif)) { DEBUG("gnrc_netif: event %p\n", (void *)evp); if (evp->handler) { evp->handler(evp); @@ -1844,7 +1854,7 @@ static void *_gnrc_netif_thread(void *args) netif->event_isr.handler = _event_handler_isr, /* set up the event queue */ - event_queue_init(&netif->evq); + event_queues_init(netif->evq, GNRC_NETIF_EVQ_NUMOF); /* setup the link-layer's message queue */ msg_init_queue(msg_queue, GNRC_NETIF_MSG_QUEUE_SIZE); @@ -1957,7 +1967,7 @@ static void _event_cb(netdev_t *dev, netdev_event_t event) gnrc_netif_t *netif = (gnrc_netif_t *) dev->context; if (event == NETDEV_EVENT_ISR) { - event_post(&netif->evq, &netif->event_isr); + event_post(&netif->evq[GNRC_NETIF_EVQ_INDEX_PRIO_LOW], &netif->event_isr); } else { DEBUG("gnrc_netif: event triggered -> %i\n", event);