-
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/ztimer_xsec: add a simple high level ztimer test
- Loading branch information
Showing
6 changed files
with
140 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,8 @@ | ||
include ../Makefile.tests_common | ||
|
||
USEMODULE += ztimer | ||
USEMODULE += ztimer_usec | ||
USEMODULE += ztimer_msec | ||
USEMODULE += ztimer_sec | ||
|
||
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,9 @@ | ||
BOARD_INSUFFICIENT_MEMORY := \ | ||
arduino-duemilanove \ | ||
arduino-leonardo \ | ||
arduino-nano \ | ||
arduino-uno \ | ||
atmega328p \ | ||
nucleo-f031k6 \ | ||
stm32f030f4-demo \ | ||
# |
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,10 @@ | ||
# Introduction | ||
|
||
This application tests the high abstraction level ztimer clocks usec, msec and sec | ||
by locking three mutexes and waiting for them to | ||
be unlocked by ZTIMER_USEC, ZTIMER_MSEC and ZTIMER_SEC | ||
The tests succeeds if the board running the test does not get stuck. | ||
|
||
ZTIMER_MSEC and ZTIMER_SEC will be configured following the rules of described | ||
in the ztimer documentation with LOG_LEVEL LOG_INFO some timing information | ||
for human analysis is provided |
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,7 @@ | ||
# this file enables modules defined in Kconfig. Do not use this file for | ||
# application configuration. This is only needed during migration. | ||
CONFIG_MODULE_ZTIMER=y | ||
CONFIG_MODULE_ZTIMER_PERIPH_TIMER=y | ||
CONFIG_MODULE_ZTIMER_USEC=y | ||
CONFIG_MODULE_ZTIMER_MSEC=y | ||
CONFIG_MODULE_ZTIMER_SEC=y |
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,83 @@ | ||
/* | ||
* Copyright (C) 2021 TUBA Freiberg | ||
* | ||
* 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 high level ztimer test application | ||
* | ||
* @author Karl Fessel <karl.fessel@ovgu.de> | ||
* | ||
* | ||
* @} | ||
*/ | ||
|
||
#include <stdio.h> | ||
|
||
#include "ztimer.h" | ||
#include "mutex.h" | ||
|
||
#ifndef LOG_LEVEL | ||
#define LOG_LEVEL LOG_WARNING | ||
#endif | ||
|
||
#include "log.h" | ||
|
||
typedef struct named_lock { | ||
char *name; | ||
mutex_t mut; | ||
} named_lock_t; | ||
|
||
void release(void *arg); | ||
|
||
static named_lock_t sec_lock = { .name = "SEC", .mut = MUTEX_INIT }; | ||
static named_lock_t msec_lock = { .name = "MSEC", .mut = MUTEX_INIT }; | ||
static named_lock_t usec_lock = { .name = "USEC", .mut = MUTEX_INIT }; | ||
|
||
static ztimer_t sec_tim = { .callback = release, .arg = &sec_lock }; | ||
static ztimer_t msec_tim = { .callback = release, .arg = &msec_lock }; | ||
static ztimer_t usec_tim = { .callback = release, .arg = &usec_lock }; | ||
|
||
|
||
void release(void *arg) | ||
{ | ||
named_lock_t *e = arg; | ||
|
||
LOG_INFO("time: %" PRIu32 "\n", ztimer_now(ZTIMER_USEC)); | ||
|
||
printf("unlocking %s\n", e->name); | ||
mutex_unlock(&e->mut); | ||
} | ||
|
||
int main(void) | ||
{ | ||
/*prelock*/ | ||
mutex_lock( &sec_lock.mut); | ||
mutex_lock(&msec_lock.mut); | ||
mutex_lock(&usec_lock.mut); | ||
|
||
puts("starting ztimers"); | ||
/* start a timer on each high level ztimer*/ | ||
ztimer_set(ZTIMER_SEC, &sec_tim, 1); | ||
ztimer_set(ZTIMER_MSEC, &msec_tim, 200); | ||
ztimer_set(ZTIMER_USEC, &usec_tim, 100000); | ||
|
||
LOG_INFO("time: %" PRIu32 "\n", ztimer_now(ZTIMER_USEC)); | ||
|
||
puts("waiting for locks"); | ||
// wait for mutexes | ||
mutex_lock( &sec_lock.mut); | ||
mutex_lock(&msec_lock.mut); | ||
mutex_lock(&usec_lock.mut); | ||
|
||
|
||
printf("SUCCESS!\n"); | ||
return 0; | ||
} |
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,23 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (C) 2021 TUBA Freiberg | ||
# | ||
# 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. | ||
|
||
import sys | ||
from testrunner import run | ||
|
||
|
||
def testfunc(child): | ||
child.expect_exact("starting ztimers") | ||
child.expect_exact("waiting for locks") | ||
child.expect_exact("unlocking USEC") | ||
child.expect_exact("unlocking MSEC") | ||
child.expect_exact("unlocking SEC") | ||
child.expect_exact("SUCCESS!") | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(run(testfunc)) |