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
9#pragma once
10
37
38#include "event.h"
39#include "ztimer/periodic.h"
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
48#define EVENT_PERIODIC_FOREVER 0
49
59
72 event_queue_t *queue, event_t *event);
73
90static inline void event_periodic_start_now(event_periodic_t *event_periodic, uint32_t interval)
91{
92 event_periodic->timer.interval = interval;
93 ztimer_periodic_start_now(&event_periodic->timer);
94}
95
110static inline void event_periodic_start(event_periodic_t *event_periodic, uint32_t interval)
111{
112 event_periodic->timer.interval = interval;
113 ztimer_periodic_start(&event_periodic->timer);
114}
115
123static inline void event_periodic_set_count(event_periodic_t *event_periodic, uint32_t count)
124{
125 unsigned state = irq_disable();
126
127 event_periodic->count = count;
128 irq_restore(state);
129}
130
145static inline void event_periodic_stop(event_periodic_t *event_periodic)
146{
147 ztimer_periodic_stop(&event_periodic->timer);
148}
149
150#ifdef __cplusplus
151}
152#endif
static void event_periodic_stop(event_periodic_t *event_periodic)
Stop a periodic timeout event.
Definition periodic.h:145
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:90
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:123
static void event_periodic_start(event_periodic_t *event_periodic, uint32_t interval)
Starts a periodic timeout.
Definition periodic.h:110
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.
struct PTRTAG event_queue_t
event queue structure
struct event event_t
event structure forward declaration
Definition event.h:135
struct ztimer_clock ztimer_clock_t
ztimer_clock_t forward declaration
Definition ztimer.h:290
Timeout Event structure.
Definition periodic.h:53
event_t * event
event to post after timeout
Definition periodic.h:56
event_queue_t * queue
event queue to post event to
Definition periodic.h:55
ztimer_periodic_t timer
ztimer object used for timeout
Definition periodic.h:54
uint32_t count
times the event should repeat itself
Definition periodic.h:57
event structure
Definition event.h:145
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.