annotate osdep/timer-lx.c @ 9420:8a1a8f5e9c91

variable subpacket size support
author michael
date Fri, 14 Feb 2003 11:11:11 +0000
parents edfe34c5405d
children f9755d9c479a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 // Precise timer routines for LINUX (C) LGB & A'rpi/ASTRAL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 #include <unistd.h>
5297
f297030ef5ab include stdlib.h
arpi
parents: 4385
diff changeset
4 #include <stdlib.h>
2476
a6c5a537f30a a few warning fixes (missing #include's)
pl
parents: 2273
diff changeset
5 #include <time.h>
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 #include <sys/time.h>
3090
57abb24ac58b HAVE_NANOSLEEP
alex
parents: 2476
diff changeset
7 #include "../config.h"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8
2273
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
9 int usec_sleep(int usec_delay)
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
10 {
3090
57abb24ac58b HAVE_NANOSLEEP
alex
parents: 2476
diff changeset
11 #ifdef HAVE_NANOSLEEP
2273
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
12 struct timespec ts;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
13 ts.tv_sec = usec_delay / 1000000;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
14 ts.tv_nsec = (usec_delay % 1000000) * 1000;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
15 return nanosleep(&ts, NULL);
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
16 #else
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
17 return usleep(usec_delay);
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
18 #endif
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
19 }
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
20
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
21
99
fb1fc94eaff0 removed redundancy...
arpi_esp
parents: 1
diff changeset
22 // Returns current time in microseconds
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 unsigned int GetTimer(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 struct timeval tv;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 struct timezone tz;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 // float s;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 gettimeofday(&tv,&tz);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 return (tv.tv_sec*1000000+tv.tv_usec);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31
4385
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
32 // Returns current time in milliseconds
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
33 unsigned int GetTimerMS(){
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
34 struct timeval tv;
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
35 struct timezone tz;
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
36 // float s;
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
37 gettimeofday(&tv,&tz);
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
38 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
39 return (tv.tv_sec*1000+tv.tv_usec/1000);
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
40 }
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
41
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 static unsigned int RelativeTime=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 // Returns time spent between now and last call in seconds
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 float GetRelativeTime(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 unsigned int t,r;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 t=GetTimer();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 // t*=16;printf("time=%ud\n",t);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 r=t-RelativeTime;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 RelativeTime=t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 return (float)r * 0.000001F;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 // Initialize timer, must be called at least once at start
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 void InitTimer(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 GetRelativeTime();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 void main(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 float t=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 InitTimer();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 while(1){ t+=GetRelativeTime();printf("time= %10.6f\r",t);fflush(stdout); }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67