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 * get_timer_us_long() - Get the number of elapsed microseconds
23 * This uses 32-bit arithmetic on 32-bit machines, which is enough to handle
24 * delays of over an hour. For 64-bit machines it uses a 64-bit value.
26 *@base: Base time to consider
27 *@return elapsed time since @base
29 unsigned long get_timer_us_long(unsigned long base);
32 * timer_test_add_offset()
34 * Allow tests to add to the time reported through lib/time.c functions
35 * offset: number of milliseconds to advance the system time
37 void timer_test_add_offset(unsigned long offset);
40 * usec_to_tick() - convert microseconds to clock ticks
42 * @usec: duration in microseconds
43 * Return: duration in clock ticks
45 uint64_t usec_to_tick(unsigned long usec);
48 * These inlines deal with timer wrapping correctly. You are
49 * strongly encouraged to use them
50 * 1. Because people otherwise forget
51 * 2. Because if the timer wrap changes in future you won't have to
52 * alter your driver code.
54 * time_after(a,b) returns true if the time a is after time b.
56 * Do this with "<0" and ">=0" to only test the sign of the result. A
57 * good compiler would generate better code (and a really good compiler
58 * wouldn't care). Gcc is currently neither.
60 #define time_after(a,b) \
61 (typecheck(unsigned long, a) && \
62 typecheck(unsigned long, b) && \
63 ((long)((b) - (a)) < 0))
64 #define time_before(a,b) time_after(b,a)
66 #define time_after_eq(a,b) \
67 (typecheck(unsigned long, a) && \
68 typecheck(unsigned long, b) && \
69 ((long)((a) - (b)) >= 0))
70 #define time_before_eq(a,b) time_after_eq(b,a)
73 * Calculate whether a is in the range of [b, c].
75 #define time_in_range(a,b,c) \
76 (time_after_eq(a,b) && \
80 * Calculate whether a is in the range of [b, c).
82 #define time_in_range_open(a,b,c) \
83 (time_after_eq(a,b) && \
87 * usec2ticks() - Convert microseconds to internal ticks
89 * @usec: Value of microseconds to convert
90 * @return Corresponding internal ticks value, calculated using get_tbclk()
92 ulong usec2ticks(unsigned long usec);
95 * ticks2usec() - Convert internal ticks to microseconds
97 * @ticks: Value of ticks to convert
98 * @return Corresponding microseconds value, calculated using get_tbclk()
100 ulong ticks2usec(unsigned long ticks);
103 * wait_ticks() - waits a given number of ticks
105 * This is an internal function typically used to implement udelay() and
106 * similar. Normally you should use udelay() or mdelay() instead.
108 * @ticks: Number of ticks to wait
110 void wait_ticks(unsigned long ticks);
113 * timer_get_us() - Get monotonic microsecond timer
115 * @return value of monotonic microsecond timer
117 unsigned long timer_get_us(void);
120 * get_ticks() - Get the current tick value
122 * This is an internal value used by the timer on the system. Ticks increase
123 * monotonically at the rate given by get_tbclk().
125 * @return current tick value
127 uint64_t get_ticks(void);