PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
libpropeller
libpropeller
stopwatch
stopwatch.h
1
#ifndef LIBPROPELLER_STOPWATCH_H_
2
#define LIBPROPELLER_STOPWATCH_H_
3
4
5
#ifndef UNIT_TEST
6
#include <propeller.h>
7
#endif
8
9
// Yes, there is an compile warning here for redefine...
10
// It's because Unity includes propeller.h, which has CNT and CLKFREQ defined.
11
#ifdef UNIT_TEST
12
#define CNT unit_CNT
13
#define CLKFREQ unit_CLKFREQ
14
extern
unsigned
int
unit_CNT;
15
extern
unsigned
int
unit_CLKFREQ;
16
#endif
17
18
namespace
libpropeller
{
19
29
class
Stopwatch
{
30
public
:
31
35
Stopwatch
() {
36
// Optimization: doing this in a loop really slows things down. So
37
// let's cut out the divide, and put in here in the constructor.
38
kCyclesPerMillisecond =
CLKFREQ
/ 1000;
39
Start
();
//This call suppresses a warning.
40
Reset
();
41
}
42
45
void
Reset
(
void
) {
46
started_ =
false
;
47
}
48
51
void
Start
(
void
) {
52
start_CNT_ =
CNT
;
53
started_ =
true
;
54
}
55
60
int
GetElapsed
(
void
)
const
{
61
if
(started_ ==
true
) {
62
return
(
CNT
- start_CNT_) / kCyclesPerMillisecond;
63
}
else
{
64
return
0;
65
}
66
}
67
72
bool
GetStarted
(
void
)
const
{
73
return
started_;
74
}
75
76
private
:
77
unsigned
int
start_CNT_;
78
bool
started_;
79
int
kCyclesPerMillisecond;
80
81
};
82
83
}
84
85
#endif // LIBPROPELLER_STOPWATCH_H_
libpropeller::Stopwatch::GetElapsed
int GetElapsed(void) const
Definition:
stopwatch.h:60
libpropeller::Stopwatch::Reset
void Reset(void)
Definition:
stopwatch.h:45
libpropeller::Stopwatch::GetStarted
bool GetStarted(void) const
Definition:
stopwatch.h:72
libpropeller::Stopwatch::Start
void Start(void)
Definition:
stopwatch.h:51
CLKFREQ
#define CLKFREQ
Returns the current clock frequency.
Definition:
propeller.h:46
libpropeller::Stopwatch
Definition:
stopwatch.h:29
CNT
#define CNT
The system clock count.
Definition:
propeller1.h:151
libpropeller
Definition:
board_unit_tester.h:4
Generated on Fri May 20 2022 16:48:02 for PropWare by
1.8.17