-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTiming.h
64 lines (52 loc) · 931 Bytes
/
Timing.h
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
/*
* Timing.h
*
* Author: Andrew D. Horchler, horchler @ gmail . com
* Created: 2-12-15, modified: 5-8-16
*/
#include "Energia.h"
#ifndef TIMING_H_
#define TIMING_H_
#if defined(__cplusplus)
extern "C" {
#endif
/*
* Elapsed time in microseconds
*/
static unsigned long usElapsed(void)
{
unsigned long t_prv;
static unsigned long t_now = 0;
static int isInit = 1;
if (isInit) {
isInit = 0;
t_now = micros();
return 0;
} else {
t_prv = t_now;
t_now = micros();
return t_now - t_prv;
}
}
/*
* Elapsed time in milliseconds
*/
static unsigned long msElapsed(void)
{
unsigned long t_prv;
static unsigned long t_now = 0;
static int isInit = 1;
if (isInit) {
isInit = 0;
t_now = millis();
return 0;
} else {
t_prv = t_now;
t_now = millis();
return t_now - t_prv;
}
}
#if defined(__cplusplus)
}
#endif
#endif /* TIMING_H_ */