root/branches/streaming-rework/src/libutil/Time.c

Revision 360, 2.2 kB (checked in by pieterpalmers, 17 years ago)

- temporary commit to backup some work

- Started a framework to synchronize IsoHandlers? to

any generic TimeSource?. The idea is to introduce
one overall time reference, and resynchronize all
other timed events to this time source.
This will, on the long run, allow:

  • combining devices on multiple FW busses together,
    as these are not synched by hardware.
  • synchronizing to the system clock
  • synchronizing to any other time source (e.g.
    when implementing a jackd client, i.e. using
    the freebob devices as jackd clients).

- Implemented a realtime safe way to read the cycle

timer for an IsoHandler?. (+ test application)

- Implemented tests/test-sytmonitor:

Monitors 2 or more channels and reports the average
SYT timestamp difference between both.

- Messed around with SYT timestamping for AMDTP. Doesn't

work (yet).

Line 
1 /*      Time.c
2         FreeBob Streaming API
3         FreeBob = Firewire (pro-)audio for linux
4
5         http://freebob.sf.net
6
7         Copyright (C) 2005,2006 Pieter Palmers <pieterpalmers@users.sourceforge.net>
8
9        
10         Based upon JackTime.c from the jackdmp package.
11         Original Copyright:
12
13         Copyright (C) 2001-2003 Paul Davis
14         Copyright (C) 2004-2006 Grame
15
16
17         This program is free software; you can redistribute it and/or modify
18     it under the terms of the GNU General Public License as published by
19     the Free Software Foundation; either version 2 of the License, or
20     (at your option) any later version.
21
22     This program is distributed in the hope that it will be useful,
23     but WITHOUT ANY WARRANTY; without even the implied warranty of
24     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25     GNU General Public License for more details.
26
27     You should have received a copy of the GNU General Public License
28     along with this program; if not, write to the Free Software
29     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30
31 */
32
33 #include "Time.h"
34
35 #ifdef GETCYCLE_TIME
36
37 #include <stdio.h>
38 freebob_microsecs_t GetMhz(void)
39 {
40         FILE *f = fopen("/proc/cpuinfo", "r");
41         if (f == 0)
42         {
43                 perror("can't open /proc/cpuinfo\n");
44                 exit(1);
45         }
46
47         for ( ; ; )
48         {
49                 freebob_microsecs_t mhz;
50                 int ret;
51                 char buf[1000];
52
53                 if (fgets(buf, sizeof(buf), f) == NULL) {
54                         fprintf (stderr,"FATAL: cannot locate cpu MHz in "
55                                     "/proc/cpuinfo\n");
56                         exit(1);
57                 }
58
59 #if defined(__powerpc__)
60                 ret = sscanf(buf, "clock\t: %" SCNu64 "MHz", &mhz);
61 #elif defined( __i386__ ) || defined (__hppa__)  || defined (__ia64__) || \
62       defined(__x86_64__)
63                 ret = sscanf(buf, "cpu MHz         : %" SCNu64, &mhz);
64 #elif defined( __sparc__ )
65                 ret = sscanf(buf, "Cpu0Bogo        : %" SCNu64, &mhz);
66 #elif defined( __mc68000__ )
67                 ret = sscanf(buf, "Clocking:       %" SCNu64, &mhz);
68 #elif defined( __s390__  )
69                 ret = sscanf(buf, "bogomips per cpu: %" SCNu64, &mhz);
70 #else /* MIPS, ARM, alpha */
71                 ret = sscanf(buf, "BogoMIPS        : %" SCNu64, &mhz);
72 #endif
73                 if (ret == 1)
74                 {
75                         fclose(f);
76                         return (freebob_microsecs_t)mhz;
77                 }
78         }
79 }
80
81 freebob_microsecs_t __freebob_cpu_mhz;
82
83 void InitTime()
84 {
85         __freebob_cpu_mhz = GetMhz();
86 }
87
88 #else
89 void InitTime()
90 {}
91
92 #endif
93
Note: See TracBrowser for help on using the browser.