Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys: move WAIT_FOR into time_units.h #62580

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drivers/dai/intel/dmic/dmic.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ LOG_MODULE_REGISTER(LOG_DOMAIN);
#include <zephyr/devicetree.h>
#include <zephyr/pm/device.h>
#include <zephyr/pm/device_runtime.h>
#include <zephyr/sys/time_units.h>

#include <zephyr/drivers/dai.h>
#include <zephyr/irq.h>
Expand Down
1 change: 1 addition & 0 deletions drivers/dai/intel/ssp/ssp.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <zephyr/devicetree.h>
#include <zephyr/pm/device.h>
#include <zephyr/pm/device_runtime.h>
#include <zephyr/sys/time_units.h>
#define LOG_DOMAIN dai_intel_ssp
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(LOG_DOMAIN);
Expand Down
1 change: 1 addition & 0 deletions drivers/dma/dma_dw_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <zephyr/init.h>
#include <zephyr/drivers/dma.h>
#include <zephyr/pm/device_runtime.h>
#include <zephyr/sys/time_units.h>
#include <soc.h>
#include "dma_dw_common.h"

Expand Down
1 change: 1 addition & 0 deletions drivers/dma/dma_intel_adsp_gpdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <adsp_interrupt.h>
#include <zephyr/drivers/dma.h>
#include <zephyr/sys/time_units.h>
#include <zephyr/cache.h>

#define DT_DRV_COMPAT intel_adsp_gpdma
Expand Down
1 change: 1 addition & 0 deletions drivers/power_domain/power_domain_intel_adsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <zephyr/kernel.h>
#include <zephyr/pm/device.h>
#include <zephyr/pm/device_runtime.h>
#include <zephyr/sys/time_units.h>
#include <adsp_shim.h>

#include <zephyr/logging/log.h>
Expand Down
26 changes: 26 additions & 0 deletions include/zephyr/sys/time_units.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Comment on lines +1436 to +1451
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really happy with this movement, even though I understand the motivation/details. I wonder if time_units.h could be made independent of util.h by having a few internal macro copies from util.h... or, another solution would be to create a 3rd "common util" header (meant to be internal) that is included by util.h and time_units.h...

({ \
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); \
})

/**
* @}
*/
Expand Down
31 changes: 0 additions & 31 deletions include/zephyr/sys/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <zephyr/sys/time_units.h>

fabiobaltieri marked this conversation as resolved.
Show resolved Hide resolved
#endif /* !_ASMLANGUAGE */

/** @brief Number of bytes in @p x kibibytes */
Expand Down Expand Up @@ -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); \
})

/**
* @}
*/
Expand Down
1 change: 1 addition & 0 deletions soc/xtensa/intel_adsp/ace/comm_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <zephyr/cache.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/time_units.h>

#define CW_DT_NODE DT_NODELABEL(ace_comm_widget)
#define CW_BASE DT_REG_ADDR(CW_DT_NODE)
Expand Down
1 change: 1 addition & 0 deletions soc/xtensa/intel_adsp/ace/multiprocessing.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <zephyr/sys/check.h>
#include <zephyr/arch/cpu.h>
#include <zephyr/pm/pm.h>
#include <zephyr/sys/time_units.h>

#include <soc.h>
#include <adsp_boot.h>
Expand Down
1 change: 1 addition & 0 deletions soc/xtensa/intel_adsp/ace/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <zephyr/pm/pm.h>
#include <zephyr/device.h>
#include <zephyr/debug/sparse.h>
#include <zephyr/sys/time_units.h>
#include <zephyr/cache.h>
#include <cpu_init.h>
#include <soc_util.h>
Expand Down
1 change: 1 addition & 0 deletions soc/xtensa/intel_adsp/common/clk.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <zephyr/kernel.h>
#include <zephyr/spinlock.h>
#include <zephyr/sys/util.h>
#include <zephyr/sys/time_units.h>

#include <adsp_clk.h>
#include <adsp_shim.h>
Expand Down
1 change: 1 addition & 0 deletions subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/ticker.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stdbool.h>

#include <zephyr/sys/util.h>
#include <zephyr/sys/time_units.h>

#include "hal/cntr.h"

Expand Down
1 change: 1 addition & 0 deletions tests/boards/intel_adsp/hda/src/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <zephyr/cache.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/time_units.h>
#include <zephyr/ztest.h>
#include <intel_adsp_ipc.h>
#include <zephyr/drivers/dma.h>
Expand Down
1 change: 1 addition & 0 deletions tests/boards/intel_adsp/hda/src/smoke.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <zephyr/cache.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/time_units.h>
#include <zephyr/ztest.h>
#include <intel_adsp_ipc.h>
#include <zephyr/devicetree.h>
Expand Down
1 change: 1 addition & 0 deletions tests/drivers/can/shell/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <zephyr/fff.h>
#include <zephyr/shell/shell.h>
#include <zephyr/shell/shell_dummy.h>
#include <zephyr/sys/time_units.h>
#include <zephyr/ztest.h>

/**
Expand Down
1 change: 1 addition & 0 deletions tests/drivers/eeprom/shell/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <zephyr/shell/shell.h>
#include <zephyr/shell/shell_dummy.h>
#include <zephyr/sys/util.h>
#include <zephyr/sys/time_units.h>
#include <zephyr/ztest.h>

#define FAKE_EEPROM_NAME DEVICE_DT_NAME(DT_NODELABEL(fake_eeprom))
Expand Down
1 change: 1 addition & 0 deletions tests/drivers/rtc/shell/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <zephyr/fff.h>
#include <zephyr/shell/shell.h>
#include <zephyr/shell/shell_dummy.h>
#include <zephyr/sys/time_units.h>
#include <zephyr/ztest.h>

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/

#include <zephyr/ztest.h>
#include <zephyr/sys/util.h>
#include <zephyr/sys/time_units.h>
#include <zephyr/kernel.h>

/**
* @addtogroup sys_util_tests
* @addtogroup time_units_tests
* @{
*/

Expand All @@ -19,7 +19,7 @@
* @see WAIT_FOR()
*/

ZTEST(sys_util, test_wait_for)
ZTEST(time_units, test_wait_for)
{
uint32_t start, end, expected;

Expand All @@ -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);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests:
libraries.sys_util:
tags: sys_util
libraries.time_units:
tags: time_units
integration_platforms:
- native_posix
1 change: 1 addition & 0 deletions tests/subsys/shell/shell/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

#include <zephyr/kernel.h>
#include <zephyr/sys/time_units.h>
#include <zephyr/ztest.h>

#include <zephyr/shell/shell.h>
Expand Down
Loading