libpropeller
Making PropellerGCC Easier
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
scheduler.h
Go to the documentation of this file.
1 #ifndef LIBPROPELLER_SCHEDULER_H_
2 #define LIBPROPELLER_SCHEDULER_H_
3 
4 
5 #ifndef UNIT_TEST
6 #include <propeller.h>
7 #endif
8 
9 #ifdef UNIT_TEST
10 #define CNT unit_CNT
11 #define CLKFREQ unit_CLKFREQ
12 extern unsigned volatile int unit_CNT;
13 extern unsigned volatile int unit_CLKFREQ;
14 #endif
15 
25 class Scheduler {
26 public:
27 
39  Scheduler(const int deci_hz) {
40  period_ticks_ = GetTicksPerPeriod(deci_hz);
41  start_CNT_ = CNT;
42  }
43 
59  bool Run(void) {
60  if ((CNT - start_CNT_) >= period_ticks_) {
61  start_CNT_ += period_ticks_;
62  return true;
63  } else {
64  return false;
65  }
66  }
67 
75  static unsigned int GetTicksPerPeriod(const int deci_hz) {
76  return (CLKFREQ * 10) / deci_hz;
77  }
78 
79 private:
80  unsigned int next_read_time_;
81  unsigned int start_CNT_;
82  unsigned int period_ticks_;
83 };
84 
85 #endif // LIBPROPELLER_SCHEDULER_H_