Loading...
Searching...
No Matches
stopwatch.h
1/*
2 * Copyright (C) 2023 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
17#ifndef ZTIMER_STOPWATCH_H
18#define ZTIMER_STOPWATCH_H
19
20#include "ztimer.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
29typedef struct {
31 uint32_t start_time;
33
42{
43 timer->clock = clock;
44}
45
52{
53 ztimer_acquire(timer->clock);
54 timer->start_time = ztimer_now(timer->clock);
55}
56
64static inline uint32_t ztimer_stopwatch_measure(ztimer_stopwatch_t *timer)
65{
66 return ztimer_now(timer->clock) - timer->start_time;
67}
68
77static inline uint32_t ztimer_stopwatch_reset(ztimer_stopwatch_t *timer)
78{
79 uint32_t now = ztimer_now(timer->clock);
80 uint32_t diff = now - timer->start_time;
81
82 timer->start_time = now;
83 return diff;
84}
85
92static inline void ztimer_stopwatch_stop(ztimer_stopwatch_t *timer)
93{
94 ztimer_release(timer->clock);
95}
96
97#ifdef __cplusplus
98}
99#endif
100
101#endif /* ZTIMER_STOPWATCH_H */
static void ztimer_stopwatch_start(ztimer_stopwatch_t *timer)
Start the stop watch timer.
Definition stopwatch.h:51
static uint32_t ztimer_stopwatch_reset(ztimer_stopwatch_t *timer)
Reset the stop watch start time.
Definition stopwatch.h:77
static void ztimer_stopwatch_init(ztimer_clock_t *clock, ztimer_stopwatch_t *timer)
Initialize a ztimer stop watch The stop watch is not running yet.
Definition stopwatch.h:41
static uint32_t ztimer_stopwatch_measure(ztimer_stopwatch_t *timer)
Take a measurement from the stop watch timer.
Definition stopwatch.h:64
static void ztimer_stopwatch_stop(ztimer_stopwatch_t *timer)
Stop the stop watch.
Definition stopwatch.h:92
bool ztimer_release(ztimer_clock_t *clock)
Release a clock.
bool ztimer_acquire(ztimer_clock_t *clock)
Acquire a clock.
static ztimer_now_t ztimer_now(ztimer_clock_t *clock)
Get the current time from a clock.
Definition ztimer.h:680
ztimer device structure
Definition ztimer.h:383
ztimer stop watch struct
Definition stopwatch.h:29
uint32_t start_time
start of measurement
Definition stopwatch.h:31
ztimer_clock_t * clock
the clock to use
Definition stopwatch.h:30
ztimer API