From caba2ad6168634e7031d10d62ddad01a9138a556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Fri, 30 Sep 2022 12:03:09 +0200 Subject: [PATCH] kernel: events: add function to clear events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Shortcut making it easier to clear events than with k_event_set_masked. Signed-off-by: Martin Jäger --- include/zephyr/kernel.h | 10 ++++++++++ kernel/events.c | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/zephyr/kernel.h b/include/zephyr/kernel.h index a19ed49af2..78dde677f6 100644 --- a/include/zephyr/kernel.h +++ b/include/zephyr/kernel.h @@ -2142,6 +2142,16 @@ __syscall void k_event_set(struct k_event *event, uint32_t events); __syscall void k_event_set_masked(struct k_event *event, uint32_t events, uint32_t events_mask); +/** + * @brief Clear the events in an event object + * + * This routine clears (resets) the specified events stored in an event object. + * + * @param event Address of the event object + * @param events Set of events to clear in @a event + */ +__syscall void k_event_clear(struct k_event *event, uint32_t events); + /** * @brief Wait for any of the specified events * diff --git a/kernel/events.c b/kernel/events.c index 914364e4c5..5a23390286 100644 --- a/kernel/events.c +++ b/kernel/events.c @@ -188,6 +188,20 @@ void z_vrfy_k_event_set_masked(struct k_event *event, uint32_t events, #include #endif +void z_impl_k_event_clear(struct k_event *event, uint32_t events) +{ + k_event_post_internal(event, 0, events); +} + +#ifdef CONFIG_USERSPACE +void z_vrfy_k_event_clear(struct k_event *event, uint32_t events) +{ + Z_OOPS(Z_SYSCALL_OBJ(event, K_OBJ_EVENT)); + z_impl_k_event_clear(event, events); +} +#include +#endif + static uint32_t k_event_wait_internal(struct k_event *event, uint32_t events, unsigned int options, k_timeout_t timeout) {