timer.h 869 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef TIMER_H_
  2. #define TIMER_H_
  3. #include "util.h"
  4. #ifndef TIMER_CPS
  5. # define TIMER_CPS 1000
  6. #endif
  7. #define TIMERCPS ((_timcnt_t)(TIMER_CPS))
  8. #ifndef TIMER_BITLEN
  9. # define TIMER_BITLEN 16
  10. #endif
  11. #if TIMER_BITLEN == 16
  12. typedef uint16_t _timcnt_t;
  13. typedef int16_t _signed_timcnt_t;
  14. #elif TIMER_BITLEN == 24
  15. typedef uint24_t _timcnt_t;
  16. typedef int24_t _signed_timcnt_t;
  17. #elif TIMER_BITLEN == 32
  18. typedef uint32_t _timcnt_t;
  19. typedef int32_t _signed_timcnt_t;
  20. #else
  21. # error "Invalid TIMER_BITLEN"
  22. #endif
  23. struct timer {
  24. _timcnt_t count;
  25. };
  26. _timcnt_t timer_now(void);
  27. bool timer_expired(const struct timer *timer);
  28. int32_t timer_ms_since(const struct timer *timer);
  29. void timer_arm(struct timer *timer, int32_t millisec);
  30. void timer_set_now(struct timer *timer);
  31. void timer_add(struct timer *timer, int32_t millisec);
  32. void timer_init(void);
  33. #endif /* TIMER_H_ */