root/branches/streaming-rework/src/libstreaming/cycletimer.h

Revision 383, 2.4 kB (checked in by pieterpalmers, 16 years ago)

mostly whitespace fixes

Line 
1 /* $Id$ */
2
3 /*
4  *   FreeBob Streaming API
5  *   FreeBob = Firewire (pro-)audio for linux
6  *
7  *   http://freebob.sf.net
8  *
9  *   Copyright (C) 2005,2006,2007 Pieter Palmers <pieterpalmers@users.sourceforge.net>
10  *
11  *   This program is free software {} you can redistribute it and/or modify
12  *   it under the terms of the GNU General Public License as published by
13  *   the Free Software Foundation {} either version 2 of the License, or
14  *   (at your option) any later version.
15  *
16  *   This program is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY {} without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with this program {} if not, write to the Free Software
23  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  *
25  *
26  *
27  */
28  
29 /* Definitions and utility macro's to handle the ISO cyclecounter */
30
31 #ifndef __CYCLECOUNTER_H__
32 #define __CYCLECOUNTER_H__
33
34 #define CSR_CYCLE_TIME            0x200
35 #define CSR_REGISTER_BASE  0xfffff0000000ULL
36
37 #define CYCLES_PER_SECOND   8000
38 #define TICKS_PER_CYCLE     3072
39 #define TICKS_PER_SECOND   (CYCLES_PER_SECOND * TICKS_PER_CYCLE)
40 #define TICKS_PER_USEC     (TICKS_PER_SECOND/1000000.0)
41
42 #define USECS_PER_TICK     (1.0/TICKS_PER_USEC)
43
44 #define CYCLE_COUNTER_GET_SECS(x)   ((((x) & 0xFE000000) >> 25))
45 #define CYCLE_COUNTER_GET_CYCLES(x) ((((x) & 0x01FFF000) >> 12))
46 #define CYCLE_COUNTER_GET_OFFSET(x)  ((((x) & 0x00000FFF)))
47 #define CYCLE_COUNTER_TO_TICKS(x) ((CYCLE_COUNTER_GET_SECS(x)   * TICKS_PER_SECOND) +\
48                                    (CYCLE_COUNTER_GET_CYCLES(x) * TICKS_PER_CYCLE ) +\
49                                    (CYCLE_COUNTER_GET_OFFSET(x)            ))
50                                    
51 // non-efficient versions, to be avoided in critical code
52 #define TICKS_TO_SECS(x) ((x)/TICKS_PER_SECOND)
53 #define TICKS_TO_CYCLES(x) (((x)/TICKS_PER_CYCLE) % CYCLES_PER_SECOND)
54 #define TICKS_TO_OFFSET(x) (((x)%TICKS_PER_CYCLE))
55
56 #define CYCLE_COUNTER_UNWRAP_TICKS(x) ((x) \
57                                        + (127 * TICKS_PER_SECOND) \
58                                        + (CYCLES_PER_SECOND * TICKS_PER_CYCLE) \
59                                        + (TICKS_PER_CYCLE) \
60                                       )
61
62 #endif // __CYCLECOUNTER_H__
Note: See TracBrowser for help on using the browser.