-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlnStopWatch.cpp
76 lines (70 loc) · 1.04 KB
/
lnStopWatch.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* (C) 2021 MEAN00 [email protected]
* See license file
*/
#include "lnStopWatch.h"
/**
*
* @param startAt
* @return
*/
uint32_t now(uint32_t startAt)
{
uint32_t tick = lnGetMs();
if (tick >= startAt)
return tick - startAt;
uint32_t wrap = 0xFFFFFFFFUL;
uint32_t val = wrap - startAt;
val += tick;
return val;
}
/**
*
* @param ms
*/
lnStopWatch::lnStopWatch(int ms)
{
_start = now(0);
_end = ms;
}
/**
*
* @param durationMs
* @return
*/
bool lnStopWatch::restart(int durationMs)
{
_start = now(0);
_end = durationMs;
return true;
}
/**
*
* @return
*/
bool lnStopWatch::elapsed()
{
uint32_t xnow = now(_start);
if (xnow > _end)
return true;
return false;
}
//---------------------------------
extern uint32_t lnGetCycle32();
lnCycleClock::lnCycleClock()
{
}
void lnCycleClock::restart()
{
_start = lnGetCycle32();
}
/**
*
* @return
*/
uint32_t lnCycleClock::elapsed()
{
uint32_t after = lnGetCycle32();
return after - _start; // to do : handle wrap
}
//