1 |
/* |
---|
2 |
* Copyright (C) 2005-2007 by Pieter Palmers |
---|
3 |
* |
---|
4 |
* This file is part of FFADO |
---|
5 |
* FFADO = Free Firewire (pro-)audio drivers for linux |
---|
6 |
* |
---|
7 |
* FFADO is based upon FreeBoB |
---|
8 |
* |
---|
9 |
* This program is free software: you can redistribute it and/or modify |
---|
10 |
* it under the terms of the GNU General Public License as published by |
---|
11 |
* the Free Software Foundation, either version 3 of the License, or |
---|
12 |
* (at your option) any later version. |
---|
13 |
* |
---|
14 |
* This program is distributed in the hope that it will be useful, |
---|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 |
* GNU General Public License for more details. |
---|
18 |
* |
---|
19 |
* You should have received a copy of the GNU General Public License |
---|
20 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
21 |
* |
---|
22 |
*/ |
---|
23 |
|
---|
24 |
/* |
---|
25 |
* Copied from the jackd/jackdmp sources |
---|
26 |
* function names changed in order to avoid naming problems when using this in |
---|
27 |
* a jackd backend. |
---|
28 |
*/ |
---|
29 |
|
---|
30 |
/* Original license: |
---|
31 |
* |
---|
32 |
* Copyright (C) 2001-2003 Paul Davis |
---|
33 |
* Copyright (C) 2004-2006 Grame |
---|
34 |
* |
---|
35 |
* This program is free software; you can redistribute it and/or modify |
---|
36 |
* it under the terms of the GNU General Public License as published by |
---|
37 |
* the Free Software Foundation; either version 2 of the License, or |
---|
38 |
* (at your option) any later version. |
---|
39 |
* |
---|
40 |
* This program is distributed in the hope that it will be useful, |
---|
41 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
42 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
43 |
* GNU General Public License for more details. |
---|
44 |
* |
---|
45 |
* You should have received a copy of the GNU General Public License |
---|
46 |
* along with this program; if not, write to the Free Software |
---|
47 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
48 |
* |
---|
49 |
*/ |
---|
50 |
|
---|
51 |
#ifndef __Time__ |
---|
52 |
#define __Time__ |
---|
53 |
|
---|
54 |
#include <stdio.h> |
---|
55 |
#include <inttypes.h> |
---|
56 |
|
---|
57 |
// #define GETCYCLE_TIME |
---|
58 |
|
---|
59 |
/** |
---|
60 |
* Type used to represent the value of free running |
---|
61 |
* monotonic clock with units of microseconds. |
---|
62 |
*/ |
---|
63 |
|
---|
64 |
typedef uint64_t ffado_microsecs_t; |
---|
65 |
|
---|
66 |
|
---|
67 |
#ifdef __cplusplus |
---|
68 |
extern "C" |
---|
69 |
{ |
---|
70 |
#endif |
---|
71 |
|
---|
72 |
|
---|
73 |
#include <unistd.h> |
---|
74 |
|
---|
75 |
static inline void FFADOSleep(long usec) { |
---|
76 |
usleep(usec); |
---|
77 |
} |
---|
78 |
|
---|
79 |
#ifdef GETCYCLE_TIME |
---|
80 |
#include "cycles.h" |
---|
81 |
extern ffado_microsecs_t __ffado_cpu_mhz; |
---|
82 |
extern ffado_microsecs_t GetMhz(); |
---|
83 |
extern void InitTime(); |
---|
84 |
static inline ffado_microsecs_t GetMicroSeconds (void) { |
---|
85 |
return get_cycles() / __ffado_cpu_mhz; |
---|
86 |
} |
---|
87 |
#else |
---|
88 |
#include <time.h> |
---|
89 |
extern void InitTime(); |
---|
90 |
static inline ffado_microsecs_t GetMicroSeconds (void) { |
---|
91 |
struct timespec ts; |
---|
92 |
clock_gettime(CLOCK_MONOTONIC, &ts); |
---|
93 |
return (ffado_microsecs_t)ts.tv_sec * 1000000LL + ts.tv_nsec / 1000; |
---|
94 |
} |
---|
95 |
#endif |
---|
96 |
|
---|
97 |
|
---|
98 |
#ifdef __cplusplus |
---|
99 |
} |
---|
100 |
#endif |
---|
101 |
|
---|
102 |
|
---|
103 |
#endif |
---|
104 |
|
---|
105 |
|
---|
106 |
|
---|