timer.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * timer.h
  3. *
  4. * Created on: Nov 9, 2015
  5. * Author: Philipp Hinz
  6. */
  7. #ifndef TIMER_H_
  8. #define TIMER_H_
  9. /**
  10. * Timer Class
  11. * This class allows the creation of multiple timers that are based
  12. * by a divider on a single system timer.
  13. */
  14. class timer {
  15. public:
  16. timer(void (*handler)(void));
  17. timer(void *(*handler)(void *));
  18. void setDivider(unsigned int divider);
  19. int getDivider();
  20. void call();
  21. void start();
  22. void stop();
  23. bool isActive();
  24. timer *next; /**< contains the pointer on the next timer element of the list */
  25. private:
  26. void (*handler)(void);
  27. void *(*thandler)(void *);
  28. unsigned int divider;
  29. int id = 0; /**< needed to identify the threads */
  30. bool active;
  31. bool asThread; /**< defines if the handler should be called or not */
  32. pthread_t thread;
  33. };
  34. void initTimers(void);
  35. void stopTimers(void);
  36. uint32_t ms2Divider(uint64_t millisec);
  37. void *nullThread(void *threadid);
  38. #define SIG SIGRTMIN
  39. #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); } while (0)
  40. #define CLOCKID CLOCK_REALTIME
  41. #endif /* TIMER_H_ */