xref: /openbmc/u-boot/include/time.h (revision 3ebd892f)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 
3 #ifndef _TIME_H
4 #define _TIME_H
5 
6 #include <linux/typecheck.h>
7 
8 unsigned long get_timer(unsigned long base);
9 
10 /*
11  * Return the current value of a monotonically increasing microsecond timer.
12  * Granularity may be larger than 1us if hardware does not support this.
13  */
14 unsigned long timer_get_us(void);
15 
16 /*
17  *	These inlines deal with timer wrapping correctly. You are
18  *	strongly encouraged to use them
19  *	1. Because people otherwise forget
20  *	2. Because if the timer wrap changes in future you won't have to
21  *	   alter your driver code.
22  *
23  * time_after(a,b) returns true if the time a is after time b.
24  *
25  * Do this with "<0" and ">=0" to only test the sign of the result. A
26  * good compiler would generate better code (and a really good compiler
27  * wouldn't care). Gcc is currently neither.
28  */
29 #define time_after(a,b)		\
30 	(typecheck(unsigned long, a) && \
31 	 typecheck(unsigned long, b) && \
32 	 ((long)((b) - (a)) < 0))
33 #define time_before(a,b)	time_after(b,a)
34 
35 #define time_after_eq(a,b)	\
36 	(typecheck(unsigned long, a) && \
37 	 typecheck(unsigned long, b) && \
38 	 ((long)((a) - (b)) >= 0))
39 #define time_before_eq(a,b)	time_after_eq(b,a)
40 
41 /*
42  * Calculate whether a is in the range of [b, c].
43  */
44 #define time_in_range(a,b,c) \
45 	(time_after_eq(a,b) && \
46 	 time_before_eq(a,c))
47 
48 /*
49  * Calculate whether a is in the range of [b, c).
50  */
51 #define time_in_range_open(a,b,c) \
52 	(time_after_eq(a,b) && \
53 	 time_before(a,c))
54 
55 #endif /* _TIME_H */
56