Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e12f587c3c63fcd36f0b912a51ec11ec25240425 (plain) (blame)
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
#include "platform/etTimer.h"

#include <sys/time.h>

#include "etGlobalFlags.h"

void etTimer_init(void){
}

uint64 getTargetTimeUs(void){
	struct timeval currentTime;
	gettimeofday(&currentTime, NULL);

	return currentTime.tv_sec * 1000000L + currentTime.tv_usec;
}

etBool etTimer_executeNeeded(void){

	static uint64 lastTime = 0L;

	uint64 currentTime = getTargetTimeUs();

	uint64 timestep = 1000000L/FREQUENCY;

	if (currentTime >= lastTime +  timestep) {
		lastTime = currentTime;
		return TRUE;
	}
	else {
		return FALSE;
	}
}

void getTimeFromTarget(etTargetTime_t *t){
	struct timeval currentTime;
	gettimeofday(&currentTime, NULL);
	t->sec = currentTime.tv_sec;
	t->nSec = currentTime.tv_usec*1000;
}

Back to the top