PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
libpropeller
libpropeller
scheduler
scheduler.h
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
16
namespace
libpropeller
{
17
27
class
Scheduler
{
28
public
:
29
41
Scheduler
(
const
int
deci_hz) {
42
period_ticks_ =
GetTicksPerPeriod
(deci_hz);
43
start_CNT_ =
CNT
;
44
}
45
66
inline
__attribute__
((always_inline))
bool
Run(
void
) {
67
if
((
CNT
- start_CNT_) >= period_ticks_) {
68
start_CNT_ += period_ticks_;
69
return
true
;
70
}
else
{
71
return
false
;
72
}
73
}
74
82
static
unsigned
int
GetTicksPerPeriod
(
const
int
deci_hz) {
83
return
(
CLKFREQ
* 10) / deci_hz;
84
}
85
86
private
:
87
unsigned
int
next_read_time_;
88
unsigned
int
start_CNT_;
89
unsigned
int
period_ticks_;
90
};
91
92
}
93
94
#endif // LIBPROPELLER_SCHEDULER_H_
libpropeller::Scheduler
Definition:
scheduler.h:27
CLKFREQ
#define CLKFREQ
Returns the current clock frequency.
Definition:
propeller.h:46
libpropeller::Scheduler::GetTicksPerPeriod
static unsigned int GetTicksPerPeriod(const int deci_hz)
Definition:
scheduler.h:82
CNT
#define CNT
The system clock count.
Definition:
propeller1.h:151
libpropeller
Definition:
board_unit_tester.h:4
libpropeller::Scheduler::Scheduler
Scheduler(const int deci_hz)
Definition:
scheduler.h:41
libpropeller::Scheduler::__attribute__
__attribute__((always_inline)) bool Run(void)
Definition:
scheduler.h:66
Generated on Fri May 20 2022 16:48:01 for PropWare by
1.8.17