timer.h 1.3 KB

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