Loading...
Searching...
No Matches
periodic.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Inria
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
36#ifndef EVENT_PERIODIC_H
37#define EVENT_PERIODIC_H
38
39#include "event.h"
40#include "ztimer/periodic.h"
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
49#define EVENT_PERIODIC_FOREVER 0
50
60
73 event_queue_t *queue, event_t *event);
74
91static inline void event_periodic_start_now(event_periodic_t *event_periodic, uint32_t interval)
92{
93 event_periodic->timer.interval = interval;
94 ztimer_periodic_start_now(&event_periodic->timer);
95}
96
111static inline void event_periodic_start(event_periodic_t *event_periodic, uint32_t interval)
112{
113 event_periodic->timer.interval = interval;
114 ztimer_periodic_start(&event_periodic->timer);
115}
116
124static inline void event_periodic_set_count(event_periodic_t *event_periodic, uint32_t count)
125{
126 unsigned state = irq_disable();
127
128 event_periodic->count = count;
129 irq_restore(state);
130}
131
146static inline void event_periodic_stop(event_periodic_t *event_periodic)
147{
148 ztimer_periodic_stop(&event_periodic->timer);
149}
150
151#ifdef __cplusplus
152}
153#endif
154#endif /* EVENT_PERIODIC_H */
static void event_periodic_stop(event_periodic_t *event_periodic)
Stop a periodic timeout event.
Definition periodic.h:146
static void event_periodic_start_now(event_periodic_t *event_periodic, uint32_t interval)
Starts a periodic timeout without delay for the first occurrence.
Definition periodic.h:91
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.
MAYBE_INLINE void irq_restore(unsigned state)
This function restores the IRQ disable bit in the status register to the value contained within passe...
MAYBE_INLINE unsigned irq_disable(void)
This function sets the IRQ disable bit in the status register.
event queue structure
Definition event.h:156
Timeout Event structure.
Definition periodic.h:54
event_t * event
event to post after timeout
Definition periodic.h:57
event_queue_t * queue
event queue to post event to
Definition periodic.h:56
ztimer_periodic_t timer
ztimer object used for timeout
Definition periodic.h:55
uint32_t count
times the event should repeat itself
Definition periodic.h:58
event structure
Definition event.h:148
ztimer device structure
Definition ztimer.h:369
ztimer periodic structure
Definition periodic.h:94
uint32_t interval
interval of this timer
Definition periodic.h:97
Periodic ztimer API.
void ztimer_periodic_stop(ztimer_periodic_t *timer)
Stop a periodic timer.
void ztimer_periodic_start_now(ztimer_periodic_t *timer)
Start or restart a periodic timer without initial timer delay.
void ztimer_periodic_start(ztimer_periodic_t *timer)
Start or restart a periodic timer.