timer.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // timer.h :
  2. //
  3. #if !defined(AGD_TIMER_H__039EAF1D_4D42_44F5_9CAD_437128DA1BA9__INCLUDED_)
  4. #define AGD_TIMER_H__039EAF1D_4D42_44F5_9CAD_437128DA1BA9__INCLUDED_
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include "mutex.h"
  8. #include "gfatimer.h"
  9. /////////////////////////////////////////////////////////////////////////////
  10. // timer.h - Declarations:
  11. typedef struct _GFA_TIMER
  12. {
  13. int tf;
  14. unsigned long tw;
  15. pfnTIMERCALLBACK pfnCallback;
  16. void *pContext;
  17. bool bCallScheduled;
  18. }GFA_TIMER, *LPGFA_TIMER;
  19. typedef const GFA_TIMER *LPCGFA_TIMER;
  20. typedef struct _GFA_TIMER_PULSE_CALLBACK
  21. {
  22. pfnPULSECALLBACK pfnCallback;
  23. void *pContext;
  24. }GFA_TIMER_PULSE_CALLBACK, *LPGFA_TIMER_PULSE_CALLBACK;
  25. typedef const GFA_TIMER_PULSE_CALLBACK *LPCGFA_TIMER_PULSE_CALLBACK;
  26. /////////////////////////////////////////////////////////////////////////////
  27. class CGfaTimer
  28. {
  29. public:
  30. CGfaTimer(void);
  31. ~CGfaTimer(void);
  32. int Initialize(int nTimerCount, GfaTimerResolution res);
  33. void Release(void);
  34. void RegisterTimerCallback(int tnum, pfnTIMERCALLBACK pfnCallback, void *pContext);
  35. void RegisterClockPulseCallback(GfaTimerClockPulse cp, pfnPULSECALLBACK pfnCallback, void *pContext);
  36. int tf_test(int tnum);
  37. void tf_set(int tnum);
  38. void tf_clear(int tnum);
  39. void tf_store(int tnum, int fset);
  40. unsigned long tw_read(int tnum);
  41. void tw_set(int tnum, unsigned long val);
  42. int cp_test(GfaTimerClockPulse cp);
  43. private:
  44. bool ValidateTimer(int tnum, const char *pszCaller);
  45. static void* LordOfTheTimers(void *pParam);
  46. static void AddTimeSpecs(const struct timespec &ts1, const struct timespec &ts2, struct timespec &tsResult);
  47. private:
  48. LPGFA_TIMER m_pTimer;
  49. int m_nTimerCount;
  50. unsigned long m_nTimerIncrement;
  51. unsigned long long m_nClockCount;
  52. unsigned long m_nClockPulse;
  53. CLocalMutex m_mutex;
  54. pthread_t m_threadID;
  55. struct timespec m_timInterval;
  56. bool m_bProcessTimers;
  57. static const int m_nPulseFreq[];
  58. GFA_TIMER_PULSE_CALLBACK m_ClkPulseCallbackTable[GTCP_Last];
  59. };
  60. /////////////////////////////////////////////////////////////////////////////
  61. #endif // !defined(AGD_TIMER_H__039EAF1D_4D42_44F5_9CAD_437128DA1BA9__INCLUDED_)