123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- #ifndef ZEPHYR_INCLUDE_SYS_CLOCK_H_
- #define ZEPHYR_INCLUDE_SYS_CLOCK_H_
- #include <sys/util.h>
- #include <sys/dlist.h>
- #include <toolchain.h>
- #include <zephyr/types.h>
- #include <sys/time_units.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #ifdef CONFIG_TIMEOUT_64BIT
- typedef int64_t k_ticks_t;
- #else
- typedef uint32_t k_ticks_t;
- #endif
- #define K_TICKS_FOREVER ((k_ticks_t) -1)
- typedef struct {
- k_ticks_t ticks;
- } k_timeout_t;
- #define K_TIMEOUT_EQ(a, b) ((a).ticks == (b).ticks)
- #define Z_TIMEOUT_NO_WAIT ((k_timeout_t) {})
- #if defined(__cplusplus) && ((__cplusplus - 0) < 202002L)
- #define Z_TIMEOUT_TICKS(t) ((k_timeout_t) { (t) })
- #else
- #define Z_TIMEOUT_TICKS(t) ((k_timeout_t) { .ticks = (t) })
- #endif
- #define Z_FOREVER Z_TIMEOUT_TICKS(K_TICKS_FOREVER)
- #ifdef CONFIG_TIMEOUT_64BIT
- # define Z_TIMEOUT_MS(t) Z_TIMEOUT_TICKS((k_ticks_t)k_ms_to_ticks_ceil64(MAX(t, 0)))
- # define Z_TIMEOUT_US(t) Z_TIMEOUT_TICKS((k_ticks_t)k_us_to_ticks_ceil64(MAX(t, 0)))
- # define Z_TIMEOUT_NS(t) Z_TIMEOUT_TICKS((k_ticks_t)k_ns_to_ticks_ceil64(MAX(t, 0)))
- # define Z_TIMEOUT_CYC(t) Z_TIMEOUT_TICKS((k_ticks_t)k_cyc_to_ticks_ceil64(MAX(t, 0)))
- #else
- # define Z_TIMEOUT_MS(t) Z_TIMEOUT_TICKS((k_ticks_t)k_ms_to_ticks_ceil32(MAX(t, 0)))
- # define Z_TIMEOUT_US(t) Z_TIMEOUT_TICKS((k_ticks_t)k_us_to_ticks_ceil32(MAX(t, 0)))
- # define Z_TIMEOUT_NS(t) Z_TIMEOUT_TICKS((k_ticks_t)k_ns_to_ticks_ceil32(MAX(t, 0)))
- # define Z_TIMEOUT_CYC(t) Z_TIMEOUT_TICKS((k_ticks_t)k_cyc_to_ticks_ceil32(MAX(t, 0)))
- #endif
- #define Z_TICK_ABS(t) (K_TICKS_FOREVER - 1 - (t))
- #ifdef CONFIG_TICKLESS_KERNEL
- extern void z_enable_sys_clock(void);
- #endif
- #if defined(CONFIG_SYS_CLOCK_EXISTS) && \
- (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC == 0)
- #error "SYS_CLOCK_HW_CYCLES_PER_SEC must be non-zero!"
- #endif
- #define NSEC_PER_USEC 1000U
- #define USEC_PER_MSEC 1000U
- #define MSEC_PER_SEC 1000U
- #define USEC_PER_SEC ((USEC_PER_MSEC) * (MSEC_PER_SEC))
- #define NSEC_PER_SEC ((NSEC_PER_USEC) * (USEC_PER_MSEC) * (MSEC_PER_SEC))
- #ifdef CONFIG_SYS_CLOCK_EXISTS
- #if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME) || \
- (MSEC_PER_SEC % CONFIG_SYS_CLOCK_TICKS_PER_SEC) || \
- (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC % CONFIG_SYS_CLOCK_TICKS_PER_SEC)
- #define _NEED_PRECISE_TICK_MS_CONVERSION
- #endif
- #endif
- #define _TICK_ALIGN 1
- #define SYS_CLOCK_HW_CYCLES_TO_NS_AVG(X, NCYCLES) \
- (uint32_t)(k_cyc_to_ns_floor64(X) / NCYCLES)
- uint32_t sys_clock_tick_get_32(void);
- int64_t sys_clock_tick_get(void);
- #ifndef CONFIG_SYS_CLOCK_EXISTS
- #define sys_clock_tick_get() (0)
- #define sys_clock_tick_get_32() (0)
- #endif
- uint64_t sys_clock_timeout_end_calc(k_timeout_t timeout);
- #ifdef __cplusplus
- }
- #endif
- #endif
|