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

Revision 385, 2.8 kB (checked in by pieterpalmers, 16 years ago)

- fixed issues with SYT timestamp processing
- SYT based sync works if syncing to the received stream

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 cycle timer */
30
31 #ifndef __CYCLETIMER_H__
32 #define __CYCLETIMER_H__
33
34 #define CSR_CYCLE_TIME            0x200
35 #define CSR_REGISTER_BASE  0xfffff0000000ULL
36
37 #define CYCLES_PER_SECOND   8000U
38 #define TICKS_PER_CYCLE     3072U
39 #define TICKS_PER_SECOND    24576000UL
40 #define TICKS_PER_USEC     (24.576000)
41
42 #define USECS_PER_TICK     (1.0/TICKS_PER_USEC)
43 #define USECS_PER_CYCLE    (125U)
44
45 #define CYCLE_TIMER_GET_SECS(x)   ((((x) & 0xFE000000U) >> 25))
46 #define CYCLE_TIMER_GET_CYCLES(x) ((((x) & 0x01FFF000U) >> 12))
47 #define CYCLE_TIMER_GET_OFFSET(x)  ((((x) & 0x00000FFFU)))
48 #define CYCLE_TIMER_TO_TICKS(x) ((CYCLE_TIMER_GET_SECS(x)   * TICKS_PER_SECOND) +\
49                                    (CYCLE_TIMER_GET_CYCLES(x) * TICKS_PER_CYCLE ) +\
50                                    (CYCLE_TIMER_GET_OFFSET(x)            ))
51                                    
52 // non-efficient versions, to be avoided in critical code
53 #define TICKS_TO_SECS(x) ((x)/TICKS_PER_SECOND)
54 #define TICKS_TO_CYCLES(x) (((x)/TICKS_PER_CYCLE) % CYCLES_PER_SECOND)
55 #define TICKS_TO_OFFSET(x) (((x)%TICKS_PER_CYCLE))
56
57 #define TICKS_TO_CYCLE_TIMER(x) (  ((TICKS_TO_SECS(x) & 0x7F) << 25) \
58                                  | ((TICKS_TO_CYCLES(x) & 0x1FFF) << 12) \
59                                  | ((TICKS_TO_OFFSET(x) & 0xFFF)))
60                                  
61 #define TICKS_TO_SYT(x)         (((TICKS_TO_CYCLES(x) & 0xF) << 12) \
62                                  | ((TICKS_TO_OFFSET(x) & 0xFFF)))
63
64 #define CYCLE_TIMER_UNWRAP_TICKS(x) (((uint64_t)(x)) \
65                                        + (127ULL * TICKS_PER_SECOND) \
66                                        + (CYCLES_PER_SECOND * TICKS_PER_CYCLE) \
67                                        + (TICKS_PER_CYCLE) \
68                                       )
69 #define CYCLE_TIMER_WRAP_TICKS(x) ((x % TICKS_PER_SECOND))
70
71 #endif // __CYCLETIMER_H__
Note: See TracBrowser for help on using the browser.