From 844df61374e92f5e3bd5323627f8f254d52b4aab Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Wed, 13 Sep 2023 09:54:59 +0000 Subject: [PATCH] sys: move WAIT_FOR into time_units.h WAIT_FOR uses k_us_to_cyc_ceil32, which is defined in time_units.h, so right now time_units.h and util.h include each others, potentially causing issues due to inconsistent include ordering. Fix this by moving WAIT_FOR into time_units.h and dropping the time_units.h include from util.h. Fixes: commit fbf851cdc4d8f0a Signed-off-by: Fabio Baltieri --- drivers/dai/intel/dmic/dmic.c | 1 + drivers/dai/intel/ssp/ssp.c | 1 + drivers/dma/dma_dw_common.c | 1 + drivers/dma/dma_intel_adsp_gpdma.c | 1 + .../power_domain/power_domain_intel_adsp.c | 1 + include/zephyr/sys/time_units.h | 26 ++++++++++++++++ include/zephyr/sys/util.h | 31 ------------------- soc/xtensa/intel_adsp/ace/comm_widget.h | 1 + soc/xtensa/intel_adsp/ace/multiprocessing.c | 1 + soc/xtensa/intel_adsp/ace/power.c | 1 + soc/xtensa/intel_adsp/common/clk.c | 1 + .../controller/ll_sw/nordic/hal/nrf5/ticker.c | 1 + tests/boards/intel_adsp/hda/src/dma.c | 1 + tests/boards/intel_adsp/hda/src/smoke.c | 1 + tests/drivers/can/shell/src/main.c | 1 + tests/drivers/eeprom/shell/src/main.c | 1 + tests/drivers/rtc/shell/src/main.c | 1 + .../{sys_util => time_units}/CMakeLists.txt | 2 +- tests/lib/{sys_util => time_units}/prj.conf | 0 tests/lib/{sys_util => time_units}/src/main.c | 10 +++--- .../{sys_util => time_units}/testcase.yaml | 4 +-- tests/subsys/shell/shell/src/main.c | 1 + 22 files changed, 50 insertions(+), 39 deletions(-) rename tests/lib/{sys_util => time_units}/CMakeLists.txt (89%) rename tests/lib/{sys_util => time_units}/prj.conf (100%) rename tests/lib/{sys_util => time_units}/src/main.c (83%) rename tests/lib/{sys_util => time_units}/testcase.yaml (55%) diff --git a/drivers/dai/intel/dmic/dmic.c b/drivers/dai/intel/dmic/dmic.c index fcc9b119670851..2245a67e863928 100644 --- a/drivers/dai/intel/dmic/dmic.c +++ b/drivers/dai/intel/dmic/dmic.c @@ -17,6 +17,7 @@ LOG_MODULE_REGISTER(LOG_DOMAIN); #include #include #include +#include #include #include diff --git a/drivers/dai/intel/ssp/ssp.c b/drivers/dai/intel/ssp/ssp.c index 809cc9833eb025..5cca90840b811a 100644 --- a/drivers/dai/intel/ssp/ssp.c +++ b/drivers/dai/intel/ssp/ssp.c @@ -12,6 +12,7 @@ #include #include #include +#include #define LOG_DOMAIN dai_intel_ssp #include LOG_MODULE_REGISTER(LOG_DOMAIN); diff --git a/drivers/dma/dma_dw_common.c b/drivers/dma/dma_dw_common.c index e3210658dfcfba..c04d4c53845bd4 100644 --- a/drivers/dma/dma_dw_common.c +++ b/drivers/dma/dma_dw_common.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "dma_dw_common.h" diff --git a/drivers/dma/dma_intel_adsp_gpdma.c b/drivers/dma/dma_intel_adsp_gpdma.c index 1601d9af6ac6a4..da5e3119fb3680 100644 --- a/drivers/dma/dma_intel_adsp_gpdma.c +++ b/drivers/dma/dma_intel_adsp_gpdma.c @@ -6,6 +6,7 @@ #include #include +#include #include #define DT_DRV_COMPAT intel_adsp_gpdma diff --git a/drivers/power_domain/power_domain_intel_adsp.c b/drivers/power_domain/power_domain_intel_adsp.c index 21df893b127743..4de90b496e3a30 100644 --- a/drivers/power_domain/power_domain_intel_adsp.c +++ b/drivers/power_domain/power_domain_intel_adsp.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include diff --git a/include/zephyr/sys/time_units.h b/include/zephyr/sys/time_units.h index 527b7371f23d12..8cd364e589f431 100644 --- a/include/zephyr/sys/time_units.h +++ b/include/zephyr/sys/time_units.h @@ -1433,6 +1433,32 @@ static TIME_CONSTEXPR inline uint64_t k_ticks_to_cyc_ceil64(uint64_t t) #undef TIME_CONSTEXPR +/** + * @brief Wait for an expression to return true with a timeout + * + * Spin on an expression with a timeout and optional delay between iterations + * + * Commonly needed when waiting on hardware to complete an asynchronous + * request to read/write/initialize/reset, but useful for any expression. + * + * @param expr Truth expression upon which to poll, e.g.: XYZREG & XYZREG_EN + * @param timeout Timeout to wait for in microseconds, e.g.: 1000 (1ms) + * @param delay_stmt Delay statement to perform each poll iteration + * e.g.: NULL, k_yield(), k_msleep(1) or k_busy_wait(1) + * + * @retval expr As a boolean return, if false then it has timed out. + */ +#define WAIT_FOR(expr, timeout, delay_stmt) \ + ({ \ + uint32_t _wf_cycle_count = k_us_to_cyc_ceil32(timeout); \ + uint32_t _wf_start = k_cycle_get_32(); \ + while (!(expr) && (_wf_cycle_count > (k_cycle_get_32() - _wf_start))) { \ + delay_stmt; \ + Z_SPIN_DELAY(10); \ + } \ + (expr); \ + }) + /** * @} */ diff --git a/include/zephyr/sys/util.h b/include/zephyr/sys/util.h index db5d85eeb41c7c..ee521529783c4f 100644 --- a/include/zephyr/sys/util.h +++ b/include/zephyr/sys/util.h @@ -634,11 +634,6 @@ char *utf8_lcpy(char *dst, const char *src, size_t n); } #endif -/* This file must be included at the end of the !_ASMLANGUAGE guard. - * It depends on macros defined in this file above which cannot be forward declared. - */ -#include - #endif /* !_ASMLANGUAGE */ /** @brief Number of bytes in @p x kibibytes */ @@ -676,32 +671,6 @@ char *utf8_lcpy(char *dst, const char *src, size_t n); #define Z_SPIN_DELAY(t) #endif -/** - * @brief Wait for an expression to return true with a timeout - * - * Spin on an expression with a timeout and optional delay between iterations - * - * Commonly needed when waiting on hardware to complete an asynchronous - * request to read/write/initialize/reset, but useful for any expression. - * - * @param expr Truth expression upon which to poll, e.g.: XYZREG & XYZREG_EN - * @param timeout Timeout to wait for in microseconds, e.g.: 1000 (1ms) - * @param delay_stmt Delay statement to perform each poll iteration - * e.g.: NULL, k_yield(), k_msleep(1) or k_busy_wait(1) - * - * @retval expr As a boolean return, if false then it has timed out. - */ -#define WAIT_FOR(expr, timeout, delay_stmt) \ - ({ \ - uint32_t _wf_cycle_count = k_us_to_cyc_ceil32(timeout); \ - uint32_t _wf_start = k_cycle_get_32(); \ - while (!(expr) && (_wf_cycle_count > (k_cycle_get_32() - _wf_start))) { \ - delay_stmt; \ - Z_SPIN_DELAY(10); \ - } \ - (expr); \ - }) - /** * @} */ diff --git a/soc/xtensa/intel_adsp/ace/comm_widget.h b/soc/xtensa/intel_adsp/ace/comm_widget.h index 22b868527a87ab..9e64d7fd5af383 100644 --- a/soc/xtensa/intel_adsp/ace/comm_widget.h +++ b/soc/xtensa/intel_adsp/ace/comm_widget.h @@ -7,6 +7,7 @@ #include #include +#include #define CW_DT_NODE DT_NODELABEL(ace_comm_widget) #define CW_BASE DT_REG_ADDR(CW_DT_NODE) diff --git a/soc/xtensa/intel_adsp/ace/multiprocessing.c b/soc/xtensa/intel_adsp/ace/multiprocessing.c index e762245e669ecb..243156334be372 100644 --- a/soc/xtensa/intel_adsp/ace/multiprocessing.c +++ b/soc/xtensa/intel_adsp/ace/multiprocessing.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include diff --git a/soc/xtensa/intel_adsp/ace/power.c b/soc/xtensa/intel_adsp/ace/power.c index 7fe33c3feaf871..432dcdda3f2a80 100644 --- a/soc/xtensa/intel_adsp/ace/power.c +++ b/soc/xtensa/intel_adsp/ace/power.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include diff --git a/soc/xtensa/intel_adsp/common/clk.c b/soc/xtensa/intel_adsp/common/clk.c index fada03528bf0cf..370dd8312d4c46 100644 --- a/soc/xtensa/intel_adsp/common/clk.c +++ b/soc/xtensa/intel_adsp/common/clk.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.c b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.c index 482e48b198b644..6709e801568e98 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.c @@ -9,6 +9,7 @@ #include #include +#include #include "hal/cntr.h" diff --git a/tests/boards/intel_adsp/hda/src/dma.c b/tests/boards/intel_adsp/hda/src/dma.c index 47dc358cc723cb..547b1b6c2b9091 100644 --- a/tests/boards/intel_adsp/hda/src/dma.c +++ b/tests/boards/intel_adsp/hda/src/dma.c @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff --git a/tests/boards/intel_adsp/hda/src/smoke.c b/tests/boards/intel_adsp/hda/src/smoke.c index 6853c09a037d96..51fb3a9bdfa7ec 100644 --- a/tests/boards/intel_adsp/hda/src/smoke.c +++ b/tests/boards/intel_adsp/hda/src/smoke.c @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff --git a/tests/drivers/can/shell/src/main.c b/tests/drivers/can/shell/src/main.c index cf2f5cc348cde8..b5050c62e48702 100644 --- a/tests/drivers/can/shell/src/main.c +++ b/tests/drivers/can/shell/src/main.c @@ -11,6 +11,7 @@ #include #include #include +#include #include /** diff --git a/tests/drivers/eeprom/shell/src/main.c b/tests/drivers/eeprom/shell/src/main.c index d9da0a191927e3..25d9ee0049f78f 100644 --- a/tests/drivers/eeprom/shell/src/main.c +++ b/tests/drivers/eeprom/shell/src/main.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #define FAKE_EEPROM_NAME DEVICE_DT_NAME(DT_NODELABEL(fake_eeprom)) diff --git a/tests/drivers/rtc/shell/src/main.c b/tests/drivers/rtc/shell/src/main.c index 6b2c4f62d97030..f037fef2fcad98 100644 --- a/tests/drivers/rtc/shell/src/main.c +++ b/tests/drivers/rtc/shell/src/main.c @@ -11,6 +11,7 @@ #include #include #include +#include #include /** diff --git a/tests/lib/sys_util/CMakeLists.txt b/tests/lib/time_units/CMakeLists.txt similarity index 89% rename from tests/lib/sys_util/CMakeLists.txt rename to tests/lib/time_units/CMakeLists.txt index 5e1ef0784ab12c..a8bdee261b37e4 100644 --- a/tests/lib/sys_util/CMakeLists.txt +++ b/tests/lib/time_units/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(sys_util) +project(time_units) target_sources(app PRIVATE src/main.c diff --git a/tests/lib/sys_util/prj.conf b/tests/lib/time_units/prj.conf similarity index 100% rename from tests/lib/sys_util/prj.conf rename to tests/lib/time_units/prj.conf diff --git a/tests/lib/sys_util/src/main.c b/tests/lib/time_units/src/main.c similarity index 83% rename from tests/lib/sys_util/src/main.c rename to tests/lib/time_units/src/main.c index 9e1f7b5fa8c280..7339ef10477542 100644 --- a/tests/lib/sys_util/src/main.c +++ b/tests/lib/time_units/src/main.c @@ -5,11 +5,11 @@ */ #include -#include +#include #include /** - * @addtogroup sys_util_tests + * @addtogroup time_units_tests * @{ */ @@ -19,7 +19,7 @@ * @see WAIT_FOR() */ -ZTEST(sys_util, test_wait_for) +ZTEST(time_units, test_wait_for) { uint32_t start, end, expected; @@ -43,10 +43,10 @@ ZTEST(sys_util, test_wait_for) /** - * @defgroup sys_util_tests Sys Util Tests + * @defgroup time_units_tests Sys Util Tests * @ingroup all_tests * @{ * @} */ -ZTEST_SUITE(sys_util, NULL, NULL, NULL, NULL, NULL); +ZTEST_SUITE(time_units, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/lib/sys_util/testcase.yaml b/tests/lib/time_units/testcase.yaml similarity index 55% rename from tests/lib/sys_util/testcase.yaml rename to tests/lib/time_units/testcase.yaml index 251663d707d1a1..94e635870ddc85 100644 --- a/tests/lib/sys_util/testcase.yaml +++ b/tests/lib/time_units/testcase.yaml @@ -1,5 +1,5 @@ tests: - libraries.sys_util: - tags: sys_util + libraries.time_units: + tags: time_units integration_platforms: - native_posix diff --git a/tests/subsys/shell/shell/src/main.c b/tests/subsys/shell/shell/src/main.c index e5bc7d734beffd..0c8760893d9531 100644 --- a/tests/subsys/shell/shell/src/main.c +++ b/tests/subsys/shell/shell/src/main.c @@ -10,6 +10,7 @@ */ #include +#include #include #include