timer.h 1.4 KB

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