forked from martinmarinov/TempestSDR
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.c
More file actions
36 lines (27 loc) · 757 Bytes
/
Copy pathtimer.c
File metadata and controls
36 lines (27 loc) · 757 Bytes
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
#include "timer.h"
void timer_tick(TickTockTimer_t * timer) {
timer->started = 1;
gettimeofday(&timer->start, NULL);
}
float timer_tock(TickTockTimer_t * timer) {
struct timeval now;
struct timeval elapsed;
if (!timer->started) return -1;
gettimeofday(&now, NULL);
timersub(&now, &timer->start, &elapsed);
return (float) elapsed.tv_sec + (float) (elapsed.tv_usec) * (float) 1e-6;
}
float timer_ticktock(TickTockTimer_t * timer) {
struct timeval now;
struct timeval elapsed;
gettimeofday(&now, NULL);
if (!timer->started) {
timer->start = now;
timer->started = 1;
return 0;
} else {
timersub(&now, &timer->start, &elapsed);
timer->start = now;
return (float) elapsed.tv_sec + (float) (elapsed.tv_usec) * (float) 1e-6;;
}
}