-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sys_util: wait_for, spin on an expression
Hardware has asynchronous actions where the expectation is to spin on registers and expressions against those registers for completion of the action. This provides a common macro to spin, with a delay and timeout, on such expressions. Signed-off-by: Tom Burdick <[email protected]>
- Loading branch information
Showing
6 changed files
with
104 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
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 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(sys_util) | ||
|
||
target_sources(app PRIVATE | ||
src/main.c | ||
src/wait_for.c | ||
) |
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 @@ | ||
CONFIG_ZTEST=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,22 @@ | ||
/* | ||
* Copyright (c) 2022 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <ztest.h> | ||
|
||
extern void test_wait_for(void); | ||
|
||
/** | ||
* @defgroup sys_util_tests Sys Util Tests | ||
* @ingroup all_tests | ||
* @{ | ||
* @} | ||
*/ | ||
|
||
void test_main(void) | ||
{ | ||
ztest_test_suite(sys_util, ztest_unit_test(test_wait_for)); | ||
ztest_run_test_suite(sys_util); | ||
} |
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,42 @@ | ||
/* | ||
* Copyright (c) 2022 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <sys/util.h> | ||
#include <kernel.h> | ||
#include <ztest.h> | ||
|
||
/** | ||
* @addtogroup sys_util_tests | ||
* @{ | ||
*/ | ||
|
||
/** | ||
* @brief Test wait_for works as expected with typical use cases | ||
* | ||
* @see wait_for() | ||
*/ | ||
void test_wait_for(void) | ||
{ | ||
uint32_t start, end, expected; | ||
|
||
zassert_true(wait_for(true, 0, NULL), "true, no wait, NULL"); | ||
zassert_true(wait_for(true, 0, k_yield()), "true, no wait, yield"); | ||
zassert_false(wait_for(false, 0, k_yield()), "false, no wait, yield"); | ||
zassert_true(wait_for(true, 1, k_yield()), "true, 1usec, yield"); | ||
zassert_false(wait_for(false, 1, k_yield()), "false, 1usec, yield"); | ||
zassert_true(wait_for(true, 1000, k_yield()), "true, 1msec, yield"); | ||
|
||
|
||
expected = 1000*(sys_clock_hw_cycles_per_sec()/USEC_PER_SEC); | ||
start = k_cycle_get_32(); | ||
zassert_false(wait_for(false, 1000, k_yield()), "true, 1msec, yield"); | ||
end = k_cycle_get_32(); | ||
zassert_true(end-start >= expected, "wait for 1ms"); | ||
} | ||
|
||
/** | ||
* @} | ||
*/ |
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,4 @@ | ||
tests: | ||
lib.sys_util: | ||
platform_exclude: native_posix native_posix_64 | ||
tags: sys_util |