time.h 1.4 KB

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