1 // Precise timer routines for LINUX (C) LGB & A'rpi/ASTRAL
9 int usec_sleep(int usec_delay
)
13 ts
.tv_sec
= usec_delay
/ 1000000;
14 ts
.tv_nsec
= (usec_delay
% 1000000) * 1000;
15 return nanosleep(&ts
, NULL
);
17 return usleep(usec_delay
);
22 // Returns current time in microseconds
23 unsigned int GetTimer(){
27 gettimeofday(&tv
,&tz
);
28 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
29 return (tv
.tv_sec
*1000000+tv
.tv_usec
);
32 // Returns current time in milliseconds
33 unsigned int GetTimerMS(){
37 gettimeofday(&tv
,&tz
);
38 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
39 return (tv
.tv_sec
*1000+tv
.tv_usec
/1000);
42 static unsigned int RelativeTime
=0;
44 // Returns time spent between now and last call in seconds
45 float GetRelativeTime(){
48 // t*=16;printf("time=%ud\n",t);
51 return (float)r
* 0.000001F
;
54 // Initialize timer, must be called at least once at start
64 while(1){ t
+=GetRelativeTime();printf("time= %10.6f\r",t
);fflush(stdout
); }