-
Notifications
You must be signed in to change notification settings - Fork 1
/
timer.c
49 lines (42 loc) · 787 Bytes
/
timer.c
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
#include "lpc17xx_systick.h" // Central include files
#include "utils.h" // Local functions
long totalCountOverflows;
long long totalCount;
long count;
void setupTimer()
{
count = 0;
SYSTICK_InternalInit(1);
SYSTICK_IntCmd(ENABLE);
SYSTICK_Cmd(ENABLE);
serialWrite("Timer setup");
}
double timeElapsed(void)
{
double time = count * 0.001;
return(time);
}
double totalTimeElapsed(void)
{
double time = totalCount * 0.001;
return(time);
}
void timerReset(void)
{
count = 0;
}
void timerSleep(int duration)
{
serialWrite("Sleeping");
timerReset();
while(timeElapsed() < 1){}
}
void SysTick_Handler(void)
{
count += 1;
totalCount += 1;
if(~totalCount == 0)
{
totalCountOverflows += 1;
}
}