blob: 47b0bb502f248c4d43f81730ac3e4aafb1359544 (
plain)
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
|
/* ptpd_timer.c */
#include "../ptpd.h"
static int iElapsedMilliSeconds = 0;
void initTimer(void)
{
DBG("initTimer\n");
iElapsedMilliSeconds = 0;
}
void timerTick(int iTickMilliSeconds)
{
iElapsedMilliSeconds += iTickMilliSeconds;
}
void timerUpdate(IntervalTimer *itimer)
{
int i, delta;
delta = iElapsedMilliSeconds / 1000;
if(delta <= 0)
return;
iElapsedMilliSeconds %= 1000;
for(i = 0; i < TIMER_ARRAY_SIZE; ++i)
{
if(itimer[i].interval > 0 && (itimer[i].left -= delta) <= 0)
{
itimer[i].left = itimer[i].interval;
itimer[i].expire = TRUE;
DBGV("timerUpdate: timer %u expired\n", i);
}
}
}
void timerStop(UInteger16 index, IntervalTimer *itimer)
{
if(index >= TIMER_ARRAY_SIZE)
return;
itimer[index].interval = 0;
}
void timerStart(UInteger16 index, UInteger16 interval, IntervalTimer *itimer)
{
if(index >= TIMER_ARRAY_SIZE)
return;
itimer[index].expire = FALSE;
itimer[index].left = interval;
itimer[index].interval = itimer[index].left;
DBGV("timerStart: set timer %d to %d\n", index, interval);
}
Boolean timerExpired(UInteger16 index, IntervalTimer *itimer)
{
timerUpdate(itimer);
if(index >= TIMER_ARRAY_SIZE)
return FALSE;
if(!itimer[index].expire)
return FALSE;
itimer[index].expire = FALSE;
return TRUE;
}
|