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

Merge pull request #20847 from benpicco/event_assert

sys/event: add assertion that event has a handler
This commit is contained in:
Teufelchen 2024-10-25 08:11:51 +00:00 committed by GitHub
commit b376bec667
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 30 additions and 7 deletions

View File

@ -146,7 +146,7 @@ static bool _complete_cb(struct uwb_dev *inst, struct uwb_mac_interface *cbs)
if (inst->fctrl != FCNTL_IEEE_RANGE_16 && if (inst->fctrl != FCNTL_IEEE_RANGE_16 &&
inst->fctrl != (FCNTL_IEEE_RANGE_16 | UWB_FCTRL_ACK_REQUESTED)) { inst->fctrl != (FCNTL_IEEE_RANGE_16 | UWB_FCTRL_ACK_REQUESTED)) {
/* on completion of a range request setup an event to keep listening */ /* 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; 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) && 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->src_address != _udev->uid) ||
(frame->code >= UWB_DATA_CODE_DS_TWR && frame->dst_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; return true;
} }
@ -183,9 +183,9 @@ static bool _complete_cb(struct uwb_dev *inst, struct uwb_mac_interface *cbs)
#endif #endif
/* offload range data printing */ /* offload range data printing */
memcpy(&_rng_data, &data, sizeof(uwb_core_rng_data_t)); 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 */ /* 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; return true;
} }
@ -201,7 +201,7 @@ static bool _rx_timeout_cb(struct uwb_dev *inst, struct uwb_mac_interface *cbs)
{ {
(void)inst; (void)inst;
(void)cbs; (void)cbs;
event_post(uwb_core_get_eventq(), &_rng_listen_event.super); event_callback_post(uwb_core_get_eventq(), &_rng_listen_event);
return true; return true;
} }
@ -238,7 +238,7 @@ void uwb_core_rng_listen_enable(void)
{ {
_status |= TWR_STATUS_RESPONDER; _status |= TWR_STATUS_RESPONDER;
/* post event to start listening */ /* 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) void uwb_core_rng_listen_disable(void)

View File

@ -37,6 +37,7 @@
void event_post(event_queue_t *queue, event_t *event) void event_post(event_queue_t *queue, event_t *event)
{ {
assert(queue && event); assert(queue && event);
assert(event->handler);
unsigned state = irq_disable(); unsigned state = irq_disable();
if (!event->list_node.next) { if (!event->list_node.next) {

View File

@ -36,6 +36,7 @@
#ifndef EVENT_CALLBACK_H #ifndef EVENT_CALLBACK_H
#define EVENT_CALLBACK_H #define EVENT_CALLBACK_H
#include <assert.h>
#include "event.h" #include "event.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -60,6 +61,25 @@ typedef struct {
*/ */
void event_callback_init(event_callback_t *event_callback, void (*callback)(void *), void *arg); 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 * @brief Generate a one-shot callback event on @p queue
* *

View File

@ -25,6 +25,7 @@
#ifndef EVENT_PERIODIC_CALLBACK_H #ifndef EVENT_PERIODIC_CALLBACK_H
#define EVENT_PERIODIC_CALLBACK_H #define EVENT_PERIODIC_CALLBACK_H
#include <assert.h>
#include "event/callback.h" #include "event/callback.h"
#include "event/periodic.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, static inline void event_periodic_callback_start(event_periodic_callback_t *event,
uint32_t interval) uint32_t interval)
{ {
assert(event->event.callback);
event_periodic_start(&event->periodic, interval); event_periodic_start(&event->periodic, interval);
} }

View File

@ -1858,7 +1858,7 @@ ssize_t gcoap_req_send(const uint8_t *buf, size_t len,
event_callback_init(&_receive_from_cache, event_callback_init(&_receive_from_cache,
_receive_from_cache_cb, _receive_from_cache_cb,
memo); memo);
event_post(&_queue, &_receive_from_cache.super); event_callback_post(&_queue, &_receive_from_cache);
return len; return len;
} }
} }