timer.h 992 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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(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. 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. void *nullThread(void *threadid);
  37. #define SIG SIGRTMIN
  38. #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); } while (0)
  39. #define CLOCKID CLOCK_REALTIME
  40. #endif /* TIMER_H_ */