-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/sys/busy_wait: add test for busy wait
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
include ../Makefile.sys_common | ||
|
||
USEMODULE += ztimer_usec | ||
|
||
include $(RIOTBASE)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (C) 2024 ML!PA Consulting GmbH | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup tests | ||
* @{ | ||
* | ||
* @file | ||
* @brief Busy Wait loop Test Application | ||
* | ||
* This can be used to determine `CPU_CYCLES_PER_LOOP` by | ||
* comparing the time the busy wait loop took with the | ||
* actual µsec timer. | ||
* | ||
* @author Benjamin Valentin <[email protected]> | ||
* @} | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include "busy_wait.h" | ||
#include "ztimer/stopwatch.h" | ||
|
||
static inline void _measure_interval(ztimer_stopwatch_t *clock, unsigned usec) | ||
{ | ||
unsigned usec_real; | ||
|
||
printf("waiting for %u µs…\n", usec); | ||
ztimer_stopwatch_start(clock); | ||
busy_wait_us(usec); | ||
usec_real = ztimer_stopwatch_measure(clock); | ||
printf("took %u µs (diff: %d µs)\n", usec_real, (int)usec_real - usec); | ||
} | ||
|
||
int main(void) | ||
{ | ||
ztimer_stopwatch_t clock; | ||
ztimer_stopwatch_init(ZTIMER_USEC, &clock); | ||
|
||
_measure_interval(&clock, 10); | ||
_measure_interval(&clock, 100); | ||
_measure_interval(&clock, 1000); | ||
_measure_interval(&clock, 10000); | ||
|
||
return 0; | ||
} |