1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Merge pull request #18656 from benpicco/event_periodic_callback_get_arg

event_periodic_callback: add getter for user context, one-shot event
This commit is contained in:
benpicco 2022-10-04 20:47:26 +02:00 committed by GitHub
commit 161172c678
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 0 deletions

View File

@ -60,6 +60,24 @@ typedef struct {
*/
void event_callback_init(event_callback_t *event_callback, void (*callback)(void *), void *arg);
/**
* @brief Generate a one-shot callback event on @p queue
*
* This will initialize @p event and post it immediately
*
* @param[in] event event_callback object to initialize
* @param[in] queue queue that the event will be added to
* @param[in] callback callback to set up
* @param[in] arg callback argument to set up
*/
static inline void event_callback_oneshot(event_callback_t *event,
event_queue_t *queue,
void (*callback)(void *), void *arg)
{
event_callback_init(event, callback, arg);
event_post(queue, &event->super);
}
/**
* @brief event callback handler function (used internally)
*

View File

@ -40,6 +40,17 @@ typedef struct {
event_callback_t event; /**< callback event portion */
} event_periodic_callback_t;
/**
* @brief Get user context from Periodic Callback Event
*
* @param[in] event event_periodic_callback object to initialize
* @return User supplied argument to the event
*/
static inline void *event_periodic_callback_get_arg(event_periodic_callback_t *event)
{
return event->event.arg;
}
/**
* @brief Initialize a periodic callback event
*

View File

@ -32,6 +32,9 @@ int main(void)
{
event_periodic_callback_t a, b, c;
event_callback_t oneshot;
event_callback_oneshot(&oneshot, EVENT_PRIO_MEDIUM, _event_cb, "event 0");
event_periodic_callback_init(&a, ZTIMER_MSEC, EVENT_PRIO_MEDIUM, _event_cb, "event A");
event_periodic_callback_init(&b, ZTIMER_MSEC, EVENT_PRIO_MEDIUM, _event_cb, "event B");
event_periodic_callback_init(&c, ZTIMER_MSEC, EVENT_PRIO_MEDIUM, _event_cb, "event C");

View File

@ -5,6 +5,7 @@ from testrunner import run
def testfunc(child):
child.expect_exact("event 0")
child.expect_exact("event A")
child.expect_exact("event B")
child.expect_exact("event A")