1 /* SPDX-License-Identifier: GPL-2.0+ */
6 #include <linux/typecheck.h>
7 #include <linux/types.h>
11 unsigned long get_timer(unsigned long base);
14 * Return the current value of a monotonically increasing microsecond timer.
15 * Granularity may be larger than 1us if hardware does not support this.
17 unsigned long timer_get_us(void);
18 uint64_t get_timer_us(uint64_t base);
21 * timer_test_add_offset()
23 * Allow tests to add to the time reported through lib/time.c functions
24 * offset: number of milliseconds to advance the system time
26 void timer_test_add_offset(unsigned long offset);
29 * usec_to_tick() - convert microseconds to clock ticks
31 * @usec: duration in microseconds
32 * Return: duration in clock ticks
34 uint64_t usec_to_tick(unsigned long usec);
37 * These inlines deal with timer wrapping correctly. You are
38 * strongly encouraged to use them
39 * 1. Because people otherwise forget
40 * 2. Because if the timer wrap changes in future you won't have to
41 * alter your driver code.
43 * time_after(a,b) returns true if the time a is after time b.
45 * Do this with "<0" and ">=0" to only test the sign of the result. A
46 * good compiler would generate better code (and a really good compiler
47 * wouldn't care). Gcc is currently neither.
49 #define time_after(a,b) \
50 (typecheck(unsigned long, a) && \
51 typecheck(unsigned long, b) && \
52 ((long)((b) - (a)) < 0))
53 #define time_before(a,b) time_after(b,a)
55 #define time_after_eq(a,b) \
56 (typecheck(unsigned long, a) && \
57 typecheck(unsigned long, b) && \
58 ((long)((a) - (b)) >= 0))
59 #define time_before_eq(a,b) time_after_eq(b,a)
62 * Calculate whether a is in the range of [b, c].
64 #define time_in_range(a,b,c) \
65 (time_after_eq(a,b) && \
69 * Calculate whether a is in the range of [b, c).
71 #define time_in_range_open(a,b,c) \
72 (time_after_eq(a,b) && \
76 * usec2ticks() - Convert microseconds to internal ticks
78 * @usec: Value of microseconds to convert
79 * @return Corresponding internal ticks value, calculated using get_tbclk()
81 ulong usec2ticks(unsigned long usec);
84 * ticks2usec() - Convert internal ticks to microseconds
86 * @ticks: Value of ticks to convert
87 * @return Corresponding microseconds value, calculated using get_tbclk()
89 ulong ticks2usec(unsigned long ticks);
92 * wait_ticks() - waits a given number of ticks
94 * This is an internal function typically used to implement udelay() and
95 * similar. Normally you should use udelay() or mdelay() instead.
97 * @ticks: Number of ticks to wait
99 void wait_ticks(unsigned long ticks);
102 * timer_get_us() - Get monotonic microsecond timer
104 * @return value of monotonic microsecond timer
106 unsigned long timer_get_us(void);
109 * get_ticks() - Get the current tick value
111 * This is an internal value used by the timer on the system. Ticks increase
112 * monotonically at the rate given by get_tbclk().
114 * @return current tick value
116 uint64_t get_ticks(void);