Loading...
Searching...
No Matches
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 <assert.h>
29#include "event/callback.h"
30#include "event/periodic.h"
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
43
51{
52 return event->event.arg;
53}
54
67 ztimer_clock_t *clock, event_queue_t *queue,
68 void (*callback)(void *), void *arg)
69{
70 memset(&event->event, 0, sizeof(event->event));
71 event->event.super.handler = _event_callback_handler;
72 event->event.callback = callback;
73 event->event.arg = arg;
74
75 event_periodic_init(&event->periodic, clock, queue, &event->event.super);
76}
77
96 uint32_t interval)
97{
98 assert(event->event.callback);
99 event_periodic_start(&event->periodic, interval);
100}
101
116 ztimer_clock_t *clock, uint32_t interval,
117 event_queue_t *queue,
118 void (*callback)(void *), void *arg)
119{
120 event_periodic_callback_init(event, clock, queue, callback, arg);
122}
123
132{
133 return event->periodic.timer.interval;
134}
135
144 uint32_t count)
145{
146 event_periodic_set_count(&event->periodic, count);
147}
148
157{
158 return event->periodic.count;
159}
160
179
180#ifdef __cplusplus
181}
182#endif
183#endif /* EVENT_PERIODIC_CALLBACK_H */
POSIX.1-2008 compliant version of the assert macro.
#define assert(cond)
abort the program if assertion is false
Definition assert.h:136
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:146
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:124
static void event_periodic_start(event_periodic_t *event_periodic, uint32_t interval)
Starts a periodic timeout.
Definition periodic.h:111
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_get_arg(event_periodic_callback_t *event)
Get user context from Periodic Callback Event.
static void event_periodic_callback_stop(event_periodic_callback_t *event)
Stop a periodic callback event.
static uint32_t event_periodic_callback_get_interval(const event_periodic_callback_t *event)
Get the interval in which the periodic callback event repeats.
static uint32_t event_periodic_callback_get_count(const event_periodic_callback_t *event)
Get the amount of times the periodic callback event should repeat itself.
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.
static void event_periodic_callback_create(event_periodic_callback_t *event, ztimer_clock_t *clock, uint32_t interval, event_queue_t *queue, void(*callback)(void *), void *arg)
Initialize and start a periodic callback event.
event queue structure
Definition event.h:156
Callback Event structure definition.
Definition callback.h:49
void * arg
callback function argument
Definition callback.h:52
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:148
ztimer device structure
Definition ztimer.h:369