1 // Precise timer routines for LINUX (C) LGB & A'rpi/ASTRAL
5 #define usleep(t) snooze(t)
12 const char *timer_name
=
19 int usec_sleep(int usec_delay
)
23 ts
.tv_sec
= usec_delay
/ 1000000;
24 ts
.tv_nsec
= (usec_delay
% 1000000) * 1000;
25 return nanosleep(&ts
, NULL
);
27 return usleep(usec_delay
);
31 // Returns current time in microseconds
32 unsigned int GetTimer(void){
35 gettimeofday(&tv
,NULL
);
36 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
37 return (tv
.tv_sec
*1000000+tv
.tv_usec
);
40 // Returns current time in milliseconds
41 unsigned int GetTimerMS(void){
44 gettimeofday(&tv
,NULL
);
45 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
46 return (tv
.tv_sec
*1000+tv
.tv_usec
/1000);
49 static unsigned int RelativeTime
=0;
51 // Returns time spent between now and last call in seconds
52 float GetRelativeTime(void){
55 // t*=16;printf("time=%ud\n",t);
58 return (float)r
* 0.000001F
;
61 // Initialize timer, must be called at least once at start
72 while(1){ t
+=GetRelativeTime();printf("time= %10.6f\r",t
);fflush(stdout
); }