diff --git a/boards/posix/nrf52_bsim/k_busy_wait.c b/boards/posix/nrf52_bsim/k_busy_wait.c index ba7db49f2d7..8e43ed777e3 100644 --- a/boards/posix/nrf52_bsim/k_busy_wait.c +++ b/boards/posix/nrf52_bsim/k_busy_wait.c @@ -14,9 +14,9 @@ * Will block this thread (and therefore the whole zephyr) during usec_to_wait * * Note that interrupts may be received in the meanwhile and that therefore this - * thread may loose context + * thread may lose context */ -void k_busy_wait(u32_t usec_to_wait) +void z_arch_busy_wait(u32_t usec_to_wait) { bs_time_t time_end = tm_get_hw_time() + usec_to_wait; diff --git a/drivers/timer/native_posix_timer.c b/drivers/timer/native_posix_timer.c index 7ac1d85bb3b..b7f0a30230a 100644 --- a/drivers/timer/native_posix_timer.c +++ b/drivers/timer/native_posix_timer.c @@ -125,7 +125,7 @@ int z_clock_driver_init(struct device *device) * Note that interrupts may be received in the meanwhile and that therefore this * thread may loose context */ -void k_busy_wait(u32_t usec_to_wait) +void z_arch_busy_wait(u32_t usec_to_wait) { u64_t time_end = hwm_get_time() + usec_to_wait; diff --git a/include/kernel.h b/include/kernel.h index 43dfd36d1cc..f85978420b0 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -800,7 +800,7 @@ __syscall s32_t k_sleep(s32_t duration); * * @return N/A */ -extern void k_busy_wait(u32_t usec_to_wait); +__syscall void k_busy_wait(u32_t usec_to_wait); /** * @brief Yield the current thread. diff --git a/kernel/include/kernel_internal.h b/kernel/include/kernel_internal.h index 3e239c41401..6ab76322969 100644 --- a/kernel/include/kernel_internal.h +++ b/kernel/include/kernel_internal.h @@ -227,6 +227,10 @@ extern u32_t z_early_boot_rand32_get(void); extern int z_stack_adjust_initialized; #endif +#if defined(CONFIG_ARCH_HAS_CUSTOM_BUSY_WAIT) +extern void z_arch_busy_wait(u32_t usec_to_wait); +#endif + #ifdef __cplusplus } #endif diff --git a/kernel/thread.c b/kernel/thread.c index 4417cbbc5ea..e035c24ff6f 100644 --- a/kernel/thread.c +++ b/kernel/thread.c @@ -94,9 +94,10 @@ int _is_thread_essential(void) return _current->base.user_options & K_ESSENTIAL; } -#if !defined(CONFIG_ARCH_HAS_CUSTOM_BUSY_WAIT) -void k_busy_wait(u32_t usec_to_wait) +#ifdef CONFIG_SYS_CLOCK_EXISTS +void _impl_k_busy_wait(u32_t usec_to_wait) { +#if !defined(CONFIG_ARCH_HAS_CUSTOM_BUSY_WAIT) /* use 64-bit math to prevent overflow when multiplying */ u32_t cycles_to_wait = (u32_t)( (u64_t)usec_to_wait * @@ -113,8 +114,19 @@ void k_busy_wait(u32_t usec_to_wait) break; } } +#else + z_arch_busy_wait(usec_to_wait); +#endif /* CONFIG_ARCH_HAS_CUSTOM_BUSY_WAIT */ } -#endif + +#ifdef CONFIG_USERSPACE +Z_SYSCALL_HANDLER(k_busy_wait, usec_to_wait) +{ + _impl_k_busy_wait(usec_to_wait); + return 0; +} +#endif /* CONFIG_USERSPACE */ +#endif /* CONFIG_SYS_CLOCK_EXISTS */ #ifdef CONFIG_THREAD_CUSTOM_DATA void _impl_k_thread_custom_data_set(void *value) diff --git a/soc/posix/inf_clock/posix_board_if.h b/soc/posix/inf_clock/posix_board_if.h index 3ebd2f78fa1..2d47e7b25af 100644 --- a/soc/posix/inf_clock/posix_board_if.h +++ b/soc/posix/inf_clock/posix_board_if.h @@ -25,10 +25,6 @@ void posix_irq_handler(void); void posix_exit(int exit_code); u64_t posix_get_hw_cycle(void); -#if defined(CONFIG_ARCH_HAS_CUSTOM_BUSY_WAIT) -void k_busy_wait(u32_t usec_to_wait); -#endif - #ifdef __cplusplus } #endif