timer.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef TIMER_H
  2. #define TIMER_H
  3. #include <stdint.h>
  4. typedef unsigned int tick_t;
  5. extern volatile tick_t ticks;
  6. #define HZ 100
  7. /**
  8. * getticks - return the current system tick count
  9. *
  10. * This inline function returns the current system tick count.
  11. */
  12. static inline tick_t getticks(void) {
  13. return ticks;
  14. }
  15. #define MS_TO_TICKS(x) (x/10)
  16. /* Adapted from Linux 2.6 include/linux/jiffies.h:
  17. *
  18. * These inlines deal with timer wrapping correctly. You are
  19. * strongly encouraged to use them
  20. * 1. Because people otherwise forget
  21. * 2. Because if the timer wrap changes in future you won't have to
  22. * alter your driver code.
  23. *
  24. * time_after(a,b) returns true if the time a is after time b.
  25. *
  26. * Do this with "<0" and ">=0" to only test the sign of the result. A
  27. * good compiler would generate better code (and a really good compiler
  28. * wouldn't care). Gcc is currently neither.
  29. * (">=0" refers to the time_after_eq macro which wasn't copied)
  30. */
  31. #define time_after(a,b) \
  32. ((int)(b) - (int)(a) < 0)
  33. #define time_before(a,b) time_after(b,a)
  34. void timer_init(void);
  35. /* delay for "time" microseconds - uses the RIT */
  36. void delay_us(unsigned int time);
  37. /* delay for "time" milliseconds - uses the RIT */
  38. void delay_ms(unsigned int time);
  39. void sleep_ms(unsigned int time);
  40. #endif