diff --git a/examples/twr_aloha/control.c b/examples/twr_aloha/control.c index 42d1332d04e1..5672f6a9060f 100644 --- a/examples/twr_aloha/control.c +++ b/examples/twr_aloha/control.c @@ -146,7 +146,7 @@ static bool _complete_cb(struct uwb_dev *inst, struct uwb_mac_interface *cbs) if (inst->fctrl != FCNTL_IEEE_RANGE_16 && inst->fctrl != (FCNTL_IEEE_RANGE_16 | UWB_FCTRL_ACK_REQUESTED)) { /* on completion of a range request setup an event to keep listening */ - event_post(uwb_core_get_eventq(), &_rng_listen_event.super); + event_callback_post(uwb_core_get_eventq(), &_rng_listen_event); return false; } @@ -163,7 +163,7 @@ static bool _complete_cb(struct uwb_dev *inst, struct uwb_mac_interface *cbs) if (IS_ACTIVE(CONFIG_TWR_PRINTF_INITIATOR_ONLY) && ((frame->code < UWB_DATA_CODE_DS_TWR && frame->src_address != _udev->uid) || (frame->code >= UWB_DATA_CODE_DS_TWR && frame->dst_address != _udev->uid))) { - event_post(uwb_core_get_eventq(), &_rng_listen_event.super); + event_callback_post(uwb_core_get_eventq(), &_rng_listen_event); return true; } @@ -183,9 +183,9 @@ static bool _complete_cb(struct uwb_dev *inst, struct uwb_mac_interface *cbs) #endif /* offload range data printing */ memcpy(&_rng_data, &data, sizeof(uwb_core_rng_data_t)); - event_post(uwb_core_get_eventq(), &_print_rng_data_event.super); + event_callback_post(uwb_core_get_eventq(), &_print_rng_data_event); /* on completion of a range request setup an event to keep listening */ - event_post(uwb_core_get_eventq(), &_rng_listen_event.super); + event_callback_post(uwb_core_get_eventq(), &_rng_listen_event); return true; } @@ -201,7 +201,7 @@ static bool _rx_timeout_cb(struct uwb_dev *inst, struct uwb_mac_interface *cbs) { (void)inst; (void)cbs; - event_post(uwb_core_get_eventq(), &_rng_listen_event.super); + event_callback_post(uwb_core_get_eventq(), &_rng_listen_event); return true; } @@ -238,7 +238,7 @@ void uwb_core_rng_listen_enable(void) { _status |= TWR_STATUS_RESPONDER; /* post event to start listening */ - event_post(uwb_core_get_eventq(), &_rng_listen_event.super); + event_callback_post(uwb_core_get_eventq(), &_rng_listen_event); } void uwb_core_rng_listen_disable(void) diff --git a/sys/event/event.c b/sys/event/event.c index 2a73ebe3495b..e9bd1ce313af 100644 --- a/sys/event/event.c +++ b/sys/event/event.c @@ -37,6 +37,7 @@ void event_post(event_queue_t *queue, event_t *event) { assert(queue && event); + assert(event->handler); unsigned state = irq_disable(); if (!event->list_node.next) { diff --git a/sys/include/event/callback.h b/sys/include/event/callback.h index eb46a815308a..ffed28db3b3a 100644 --- a/sys/include/event/callback.h +++ b/sys/include/event/callback.h @@ -36,6 +36,7 @@ #ifndef EVENT_CALLBACK_H #define EVENT_CALLBACK_H +#include #include "event.h" #ifdef __cplusplus @@ -60,6 +61,25 @@ typedef struct { */ void event_callback_init(event_callback_t *event_callback, void (*callback)(void *), void *arg); +/** + * @brief Queue an event + * + * The given event will be posted on the given @p queue. If the event is already + * queued when calling this function, the event will not be touched and remain + * in the previous position on the queue. So reposting an event while it is + * already on the queue will have no effect. + * + * @pre queue should be initialized + * + * @param[in] queue event queue to queue event in + * @param[in] event event to queue in event queue + */ +static inline void event_callback_post(event_queue_t *queue, event_callback_t *event) +{ + assert(event->callback); + event_post(queue, &event->super); +} + /** * @brief Generate a one-shot callback event on @p queue * diff --git a/sys/include/event/periodic_callback.h b/sys/include/event/periodic_callback.h index 26ff293f9f74..81a48aba7a79 100644 --- a/sys/include/event/periodic_callback.h +++ b/sys/include/event/periodic_callback.h @@ -25,6 +25,7 @@ #ifndef EVENT_PERIODIC_CALLBACK_H #define EVENT_PERIODIC_CALLBACK_H +#include #include "event/callback.h" #include "event/periodic.h" @@ -94,6 +95,7 @@ static inline void event_periodic_callback_init(event_periodic_callback_t *event static inline void event_periodic_callback_start(event_periodic_callback_t *event, uint32_t interval) { + assert(event->event.callback); event_periodic_start(&event->periodic, interval); } diff --git a/sys/net/application_layer/gcoap/gcoap.c b/sys/net/application_layer/gcoap/gcoap.c index 6ff37f74348b..10efb6a215d3 100644 --- a/sys/net/application_layer/gcoap/gcoap.c +++ b/sys/net/application_layer/gcoap/gcoap.c @@ -1858,7 +1858,7 @@ ssize_t gcoap_req_send(const uint8_t *buf, size_t len, event_callback_init(&_receive_from_cache, _receive_from_cache_cb, memo); - event_post(&_queue, &_receive_from_cache.super); + event_callback_post(&_queue, &_receive_from_cache); return len; } }