1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2016 Intel Corporation. All rights reserved.
4  *
5  * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
6  */
7 
8 /*
9  * Simple wait for event completion and signaling with timeouts.
10  */
11 
12 #ifndef __XTOS_RTOS_WAIT_H__
13 #define __XTOS_RTOS_WAIT_H__
14 
15 #include <stddef.h>
16 #include <stdint.h>
17 
18 #if !CONFIG_LIBRARY
19 #include <arch/lib/wait.h>
20 #include <rtos/interrupt.h>
21 #include <rtos/timer.h>
22 #include <rtos/spinlock.h>
23 #include <sof/trace/trace.h>
24 #include <user/trace.h>
25 
26 extern struct tr_ctx wait_tr;
27 
wait_for_interrupt(int level)28 static inline void wait_for_interrupt(int level)
29 {
30 	LOG_MODULE_DECLARE(wait, CONFIG_SOF_LOG_LEVEL);
31 
32 	tr_dbg(&wait_tr, "WFE");
33 #if CONFIG_DEBUG_LOCKS
34 	if (lock_dbg_atomic)
35 		tr_err_atomic(&wait_tr, "atm");
36 #endif
37 	platform_wait_for_interrupt(level);
38 	tr_dbg(&wait_tr, "WFX");
39 }
40 
41 /**
42  * \brief Waits at least passed number of clocks.
43  * \param[in] number_of_clks Minimum number of clocks to wait.
44  */
45 void wait_delay(uint64_t number_of_clks);
46 
47 /**
48  * \brief Waits at least passed number of milliseconds.
49  * \param[in] ms Minimum number of milliseconds to wait.
50  */
51 void wait_delay_ms(uint64_t ms);
52 
53 /**
54  * \brief Waits at least passed number of microseconds.
55  * \param[in] us Minimum number of microseconds to wait.
56  */
57 void wait_delay_us(uint64_t us);
58 #else
wait_delay(uint64_t number_of_clks)59 static inline void wait_delay(uint64_t number_of_clks) {}
wait_delay_ms(uint64_t ms)60 static inline void wait_delay_ms(uint64_t ms) {}
wait_delay_us(uint64_t us)61 static inline void wait_delay_us(uint64_t us) {}
62 #endif
63 
64 int poll_for_register_delay(uint32_t reg, uint32_t mask,
65 			    uint32_t val, uint64_t us);
66 
67 #endif /* __XTOS_RTOS_WAIT_H__ */
68