File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ include ../Makefile.sys_common
2+
3+ USEMODULE += ztimer_usec
4+
5+ include $(RIOTBASE ) /Makefile.include
Original file line number Diff line number Diff line change 1+ BOARD_INSUFFICIENT_MEMORY := \
2+ atmega8 \
3+ #
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (C) 2024 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+
9+ /**
10+ * @ingroup tests
11+ * @{
12+ *
13+ * @file
14+ * @brief Busy Wait loop Test Application
15+ *
16+ * This can be used to determine `CPU_CYCLES_PER_LOOP` by
17+ * comparing the time the busy wait loop took with the
18+ * actual µsec timer.
19+ *
20+ * @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
21+ * @}
22+ */
23+
24+ #include <stdio.h>
25+ #include "busy_wait.h"
26+ #include "ztimer/stopwatch.h"
27+
28+ static inline void _measure_interval (ztimer_stopwatch_t * clock , unsigned usec )
29+ {
30+ unsigned usec_real ;
31+
32+ printf ("waiting for %u µs…\n" , usec );
33+ ztimer_stopwatch_start (clock );
34+ busy_wait_us (usec );
35+ usec_real = ztimer_stopwatch_measure (clock );
36+ printf ("took %u µs (diff: %d µs)\n" , usec_real , (int )usec_real - usec );
37+ }
38+
39+ int main (void )
40+ {
41+ ztimer_stopwatch_t clock ;
42+ ztimer_stopwatch_init (ZTIMER_USEC , & clock );
43+
44+ _measure_interval (& clock , 10 );
45+ _measure_interval (& clock , 100 );
46+ _measure_interval (& clock , 1000 );
47+ _measure_interval (& clock , 10000 );
48+
49+ return 0 ;
50+ }
You can’t perform that action at this time.
0 commit comments