IntervalTimer.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * IntervalTimer.hpp:
  3. *
  4. * Interval timer provides timing over a set interval to the caller. It is one of the core Os
  5. * package supplied items.
  6. */
  7. #ifndef _IntervalTimer_hpp_
  8. #define _IntervalTimer_hpp_
  9. #include <FpConfig.hpp>
  10. namespace Os {
  11. class IntervalTimer {
  12. public:
  13. /**
  14. * RawTime:
  15. *
  16. * Most time is stored as an upper and lower part of this raw time object. The
  17. * semantic meaning of this "RawTime" is platform-dependent.
  18. */
  19. typedef struct {
  20. U32 upper; //!< Upper 32-bits part of time value. Platform dependent.
  21. U32 lower; //!< Lower 32-bits part of time value. Platform dependent.
  22. } RawTime;
  23. IntervalTimer(); //!< Constructor
  24. virtual ~IntervalTimer(); //!< Destructor
  25. //------------ Common Functions ------------
  26. // Common functions, typically do not need to be implemented by an OS support package.
  27. // Common implementations in IntervalTimerCommon.cpp.
  28. //------------------------------------------
  29. /**
  30. * Capture a start time of the interval timed by the interval timer. This fills the
  31. * start RawTime of the interval.
  32. */
  33. void start();
  34. /**
  35. * Capture a stop time of the interval timed by the interval timer. This fills the
  36. * stop RawTime of the interval.
  37. */
  38. void stop();
  39. /**
  40. * Returns the difference in usecond difference between start and stop times. The caller
  41. * must have called start and stop previously.
  42. * \return U32: microseconds difference in the interval
  43. */
  44. U32 getDiffUsec();
  45. //------------ Platform Functions ------------
  46. // Platform functions, typically do need to be implemented by an OS support package, as
  47. // they are dependent on the platform definition of "RawTime".
  48. //------------------------------------------
  49. /**
  50. * Returns the difference in microseconds between the supplied times t1, and t2. This
  51. * calculation is done with respect to the semantic meaning of the times, and thus is
  52. * dependent on the platform's representation of the RawTime object.
  53. * \return U32 microsecond difference between two supplied values, t1-t2.
  54. */
  55. static U32 getDiffUsec(const RawTime& t1, const RawTime& t2);
  56. /**
  57. * Fills the RawTime object supplied with the current raw time in a platform dependent
  58. * way.
  59. */
  60. static void getRawTime(RawTime& time);
  61. PRIVATE:
  62. //------------ Internal Member Variables ------------
  63. RawTime m_startTime; //!< Stored start time
  64. RawTime m_stopTime; //!< Stored end time
  65. //------------ Disabled (private) Copy Constructor ------------
  66. IntervalTimer(IntervalTimer&); //!< Disabled copy constructor
  67. };
  68. }
  69. #endif