periodic_callback.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 ML!PA Consulting GmbH
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
25 #ifndef EVENT_PERIODIC_CALLBACK_H
26 #define EVENT_PERIODIC_CALLBACK_H
27 
28 #include "event/callback.h"
29 #include "event/periodic.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
38 typedef struct {
42 
50 {
51  return event->event.arg;
52 }
53 
66  ztimer_clock_t *clock, event_queue_t *queue,
67  void (*callback)(void *), void *arg)
68 {
69  memset(&event->event, 0, sizeof(event->event));
70  event->event.super.handler = _event_callback_handler;
71  event->event.callback = callback;
72  event->event.arg = arg;
73 
74  event_periodic_init(&event->periodic, clock, queue, &event->event.super);
75 }
76 
95  uint32_t interval)
96 {
97  event_periodic_start(&event->periodic, interval);
98 }
99 
108  uint32_t count)
109 {
110  event_periodic_set_count(&event->periodic, count);
111 }
112 
128 {
129  event_periodic_stop(&event->periodic);
130 }
131 
132 #ifdef __cplusplus
133 }
134 #endif
135 #endif /* EVENT_PERIODIC_CALLBACK_H */
Provides a callback-with-argument event type.
void _event_callback_handler(event_t *event)
event callback handler function (used internally)
Provides functionality to trigger periodic events.
static void event_periodic_stop(event_periodic_t *event_periodic)
Stop a periodic timeout event.
Definition: periodic.h:124
static void event_periodic_set_count(event_periodic_t *event_periodic, uint32_t count)
Set the amount of times the periodic event should repeat itself.
Definition: periodic.h:102
static void event_periodic_start(event_periodic_t *event_periodic, uint32_t interval)
Starts a periodic timeout.
Definition: periodic.h:89
void event_periodic_init(event_periodic_t *event_periodic, ztimer_clock_t *clock, event_queue_t *queue, event_t *event)
Initialize a periodic event timeout.
static void event_periodic_callback_init(event_periodic_callback_t *event, ztimer_clock_t *clock, event_queue_t *queue, void(*callback)(void *), void *arg)
Initialize a periodic callback event.
static void event_periodic_callback_stop(event_periodic_callback_t *event)
Stop a periodic callback event.
static void * event_periodic_callback_get_arg(event_periodic_callback_t *event)
Get user context from Periodic Callback Event.
static void event_periodic_callback_start(event_periodic_callback_t *event, uint32_t interval)
Starts a periodic callback event.
static void event_periodic_callback_set_count(event_periodic_callback_t *event, uint32_t count)
Set the amount of times the periodic callback event should repeat itself.
event queue structure
Definition: event.h:155
Callback Event structure definition.
Definition: callback.h:48
Periodic Callback Event structure.
event_callback_t event
callback event portion
event_periodic_t periodic
periodic event portion
Timeout Event structure.
Definition: periodic.h:54
event structure
Definition: event.h:147
ztimer device structure
Definition: ztimer.h:383