periodic.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2021 Inria
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
35 #include "event.h"
36 #include "ztimer/periodic.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
45 #define EVENT_PERIODIC_FOREVER 0
46 
50 typedef struct {
54  uint32_t count;
56 
69  event_queue_t *queue, event_t *event);
70 
87 static inline void event_periodic_start_now(event_periodic_t *event_periodic, uint32_t interval)
88 {
89  event_periodic->timer.interval = interval;
90  ztimer_periodic_start_now(&event_periodic->timer);
91 }
92 
107 static inline void event_periodic_start(event_periodic_t *event_periodic, uint32_t interval)
108 {
109  event_periodic->timer.interval = interval;
110  ztimer_periodic_start(&event_periodic->timer);
111 }
112 
120 static inline void event_periodic_set_count(event_periodic_t *event_periodic, uint32_t count)
121 {
122  unsigned state = irq_disable();
123 
124  event_periodic->count = count;
125  irq_restore(state);
126 }
127 
142 static inline void event_periodic_stop(event_periodic_t *event_periodic)
143 {
144  ztimer_periodic_stop(&event_periodic->timer);
145 }
146 
147 #ifdef __cplusplus
148 }
149 #endif
static void event_periodic_stop(event_periodic_t *event_periodic)
Stop a periodic timeout event.
Definition: periodic.h:142
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:87
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:120
static void event_periodic_start(event_periodic_t *event_periodic, uint32_t interval)
Starts a periodic timeout.
Definition: periodic.h:107
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:150
Timeout Event structure.
Definition: periodic.h:50
event_t * event
event to post after timeout
Definition: periodic.h:53
event_queue_t * queue
event queue to post event to
Definition: periodic.h:52
ztimer_periodic_t timer
ztimer object used for timeout
Definition: periodic.h:51
uint32_t count
times the event should repeat itself
Definition: periodic.h:54
event structure
Definition: event.h:142
ztimer device structure
Definition: ztimer.h:367
ztimer periodic structure
Definition: periodic.h:91
uint32_t interval
interval of this timer
Definition: periodic.h:94
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.