gitignore update
[apps/agl-service-can-low-level.git] / src / utils / timer.hpp
index 7d0e466..b34fdf6 100644 (file)
 
 #pragma once
 
-#include <sys/timeb.h>
-
 /*
  * @brief return epoch in milliseconds
  *
  * @return long long int epoch in milliseconds
  */
-typedef long long int (*TimeFunction)();
+typedef long long int (*time_function_t)();
+
+long long int system_time_us();
+long long int system_time_ms();
+long long int system_time_s();
 
 /**
- * @struct FrequencyClock 
+ * @class frequency_clock_t 
  * @brief A frequency counting clock.
  *
- * @var FrequencyClock::frequency
+ * @var frequency_clock_t::frequency
  *  the clock frequency in Hz.
- * @var FrequencyClock::last_time
+ * @var frequency_clock_t::last_time
  *  the last time (in milliseconds since startup) that the clock
  *     ticked.
- * @var FrequencyClock::time_function
+ * @var frequency_clock_t::time_function
  *  a function returning current time
  */
-typedef struct {
-               float frequency;
-               unsigned long lastTick;
-               TimeFunction timeFunction;
-} FrequencyClock;
\ No newline at end of file
+class frequency_clock_t
+{
+private:
+       float frequency_;
+       unsigned long last_tick_;
+       time_function_t time_function_;
+
+public:
+       frequency_clock_t();
+       frequency_clock_t(float frequency);
+       frequency_clock_t(float frequency, unsigned long last_tick, time_function_t time_function);
+
+       float get_frequency() const;
+       static float frequency_to_period(float frequency);
+       bool started();
+       time_function_t get_time_function();
+       bool elapsed(bool stagger);
+
+       void tick();
+};
\ No newline at end of file