distortos  v0.5.0
object-oriented C++ RTOS for microcontrollers
SoftwareTimer.hpp
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_SOFTWARETIMER_HPP_
13 #define INCLUDE_DISTORTOS_SOFTWARETIMER_HPP_
14 
15 #include "distortos/TickClock.hpp"
16 
17 namespace distortos
18 {
19 
27 {
28 public:
29 
34  virtual ~SoftwareTimer() = 0;
35 
40  virtual bool isRunning() const = 0;
41 
54  int start(TickClock::duration duration, TickClock::duration period = {});
55 
73  template<typename Rep1, typename Period1, typename Rep2 = TickClock::rep, typename Period2 = TickClock::period>
74  int start(const std::chrono::duration<Rep1, Period1> duration,
75  const std::chrono::duration<Rep2, Period2> period = {})
76  {
77  return start(std::chrono::duration_cast<TickClock::duration>(duration),
78  std::chrono::duration_cast<TickClock::duration>(period));
79  }
80 
91  virtual int start(TickClock::time_point timePoint, TickClock::duration period = {}) = 0;
92 
107  template<typename Duration, typename Rep = TickClock::rep, typename Period = TickClock::period>
108  int start(const std::chrono::time_point<TickClock, Duration> timePoint,
109  const std::chrono::duration<Rep, Period> period = {})
110  {
111  return start(std::chrono::time_point_cast<TickClock::duration>(timePoint),
112  std::chrono::duration_cast<TickClock::duration>(period));
113  }
114 
121  virtual int stop() = 0;
122 
123 protected:
124 
131  static void softwareTimerRunner(SoftwareTimer& softwareTimer);
132 
133 private:
134 
141  virtual void run() = 0;
142 };
143 
144 } // namespace distortos
145 
146 #endif // INCLUDE_DISTORTOS_SOFTWARETIMER_HPP_
virtual ~SoftwareTimer()=0
SoftwareTimer&#39;s destructor.
Definition: SoftwareTimer.cpp:21
std::chrono::time_point< TickClock > time_point
basic time_point type of clock
Definition: TickClock.hpp:42
int start(TickClock::duration duration, TickClock::duration period={})
Starts the timer.
Definition: SoftwareTimer.cpp:26
TickClock class header.
int start(const std::chrono::duration< Rep1, Period1 > duration, const std::chrono::duration< Rep2, Period2 > period={})
Starts the timer.
Definition: SoftwareTimer.hpp:74
virtual bool isRunning() const =0
virtual int stop()=0
Stops the timer.
Top-level namespace of distortos project.
virtual void run()=0
"Run" function of software timer
int start(const std::chrono::time_point< TickClock, Duration > timePoint, const std::chrono::duration< Rep, Period > period={})
Starts the timer.
Definition: SoftwareTimer.hpp:108
std::chrono::duration< rep, period > duration
basic duration type of clock
Definition: TickClock.hpp:39
static void softwareTimerRunner(SoftwareTimer &softwareTimer)
Software timer&#39;s function runner.
Definition: SoftwareTimer.cpp:36
SoftwareTimer class is an abstract interface for software timers.
Definition: SoftwareTimer.hpp:26