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 |
* FFADO 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 2 of the License, or |
---|
12 |
* (at your option) any later version. |
---|
13 |
* FFADO is distributed in the hope that it will be useful, |
---|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 |
* GNU General Public License for more details. |
---|
17 |
* |
---|
18 |
* You should have received a copy of the GNU General Public License |
---|
19 |
* along with FFADO; if not, write to the Free Software |
---|
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
---|
21 |
* MA 02111-1307 USA. |
---|
22 |
* |
---|
23 |
*/ |
---|
24 |
|
---|
25 |
#include "SytMonitor.h" |
---|
26 |
#include "src/libstreaming/IsoStream.h" |
---|
27 |
|
---|
28 |
#include <netinet/in.h> |
---|
29 |
#include <assert.h> |
---|
30 |
|
---|
31 |
|
---|
32 |
IMPL_DEBUG_MODULE( SytMonitor, SytMonitor, DEBUG_LEVEL_VERBOSE ); |
---|
33 |
|
---|
34 |
|
---|
35 |
/* --------------------- RECEIVE ----------------------- */ |
---|
36 |
|
---|
37 |
SytMonitor::SytMonitor(int port) |
---|
38 |
: IsoStream(IsoStream::EST_Receive, port) { |
---|
39 |
m_cinfo_buffer=ffado_ringbuffer_create(16384*sizeof(struct cycle_info)); |
---|
40 |
|
---|
41 |
} |
---|
42 |
|
---|
43 |
SytMonitor::~SytMonitor() { |
---|
44 |
ffado_ringbuffer_free(m_cinfo_buffer); |
---|
45 |
|
---|
46 |
} |
---|
47 |
|
---|
48 |
enum raw1394_iso_disposition |
---|
49 |
SytMonitor::putPacket(unsigned char *data, unsigned int length, |
---|
50 |
unsigned char channel, unsigned char tag, unsigned char sy, |
---|
51 |
unsigned int cycle, unsigned int dropped) { |
---|
52 |
enum raw1394_iso_disposition retval=RAW1394_ISO_OK; |
---|
53 |
|
---|
54 |
struct iec61883_packet *packet = (struct iec61883_packet *) data; |
---|
55 |
unsigned int syt_timestamp=ntohs(packet->syt); |
---|
56 |
|
---|
57 |
if (syt_timestamp == 0xFFFF) { |
---|
58 |
return RAW1394_ISO_OK; |
---|
59 |
} |
---|
60 |
|
---|
61 |
uint32_t m_full_timestamp; |
---|
62 |
uint32_t m_full_timestamp_ticks; |
---|
63 |
|
---|
64 |
debugOutput(DEBUG_LEVEL_VERBOSE,"%2u,%2u: CY=%4u, SYT=%08X (%3u secs + %4u cycles + %04u ticks)\n", |
---|
65 |
m_port,channel, |
---|
66 |
cycle,syt_timestamp, |
---|
67 |
CYCLE_TIMER_GET_SECS(syt_timestamp), |
---|
68 |
CYCLE_TIMER_GET_CYCLES(syt_timestamp), |
---|
69 |
CYCLE_TIMER_GET_OFFSET(syt_timestamp) |
---|
70 |
|
---|
71 |
); |
---|
72 |
|
---|
73 |
// reconstruct the full cycle |
---|
74 |
unsigned int cc=m_handler->getCycleTimer(); |
---|
75 |
|
---|
76 |
unsigned int cc_cycles=CYCLE_TIMER_GET_CYCLES(cc); |
---|
77 |
|
---|
78 |
unsigned int cc_seconds=CYCLE_TIMER_GET_SECS(cc); |
---|
79 |
|
---|
80 |
|
---|
81 |
// the cycletimer has wrapped since this packet was received |
---|
82 |
// we want cc_seconds to reflect the 'seconds' at the point this |
---|
83 |
// was received |
---|
84 |
if (cycle>cc_cycles) cc_seconds--; |
---|
85 |
|
---|
86 |
m_full_timestamp_ticks=sytRecvToFullTicks((uint32_t)syt_timestamp, cycle, cc); |
---|
87 |
m_full_timestamp=TICKS_TO_CYCLE_TIMER(m_full_timestamp_ticks); |
---|
88 |
|
---|
89 |
struct cycle_info cif; |
---|
90 |
cif.cycle=cycle; |
---|
91 |
cif.seconds=cc_seconds; |
---|
92 |
|
---|
93 |
cif.syt=packet->syt; |
---|
94 |
cif.full_syt=m_full_timestamp; |
---|
95 |
|
---|
96 |
// now we reconstruct the presentation time |
---|
97 |
cif.pres_seconds = CYCLE_TIMER_GET_SECS(m_full_timestamp); |
---|
98 |
cif.pres_cycle = CYCLE_TIMER_GET_CYCLES(m_full_timestamp); |
---|
99 |
cif.pres_offset = CYCLE_TIMER_GET_OFFSET(m_full_timestamp); |
---|
100 |
cif.pres_ticks = m_full_timestamp_ticks; |
---|
101 |
|
---|
102 |
if (cif.pres_offset != (syt_timestamp & 0xFFF)) { |
---|
103 |
debugOutput(DEBUG_LEVEL_NORMAL,"P-offset error: %04X != %04X (P: %08X, R: %08X)\n", |
---|
104 |
cif.pres_offset, syt_timestamp & 0xFFF, m_full_timestamp, syt_timestamp); |
---|
105 |
} |
---|
106 |
if ((cif.pres_cycle & 0xF) != ((syt_timestamp & 0xF000)>>12)) { |
---|
107 |
debugOutput(DEBUG_LEVEL_NORMAL,"P-cycle error: %01X != %01X (P: %08X, R: %08X)\n", |
---|
108 |
cif.pres_cycle &0xF, (syt_timestamp & 0xF000)>>12, m_full_timestamp, syt_timestamp); |
---|
109 |
} |
---|
110 |
|
---|
111 |
putCycleInfo(&cif); |
---|
112 |
|
---|
113 |
return retval; |
---|
114 |
} |
---|
115 |
|
---|
116 |
bool SytMonitor::putCycleInfo(struct cycle_info *cif) { |
---|
117 |
if(ffado_ringbuffer_write(m_cinfo_buffer,(char *)cif,sizeof(struct cycle_info)) |
---|
118 |
!=sizeof(struct cycle_info)) { |
---|
119 |
return false; |
---|
120 |
} |
---|
121 |
return true; |
---|
122 |
} |
---|
123 |
|
---|
124 |
bool SytMonitor::readNextCycleInfo(struct cycle_info *cif) { |
---|
125 |
if(ffado_ringbuffer_peek(m_cinfo_buffer,(char *)cif,sizeof(struct cycle_info)) |
---|
126 |
!=sizeof(struct cycle_info)) { |
---|
127 |
return false; |
---|
128 |
} |
---|
129 |
return true; |
---|
130 |
|
---|
131 |
} |
---|
132 |
|
---|
133 |
bool SytMonitor::consumeNextCycleInfo() { |
---|
134 |
struct cycle_info cif; |
---|
135 |
if(ffado_ringbuffer_read(m_cinfo_buffer,(char *)&cif,sizeof(struct cycle_info)) |
---|
136 |
!=sizeof(struct cycle_info)) { |
---|
137 |
return false; |
---|
138 |
} |
---|
139 |
return true; |
---|
140 |
} |
---|
141 |
|
---|
142 |
void SytMonitor::dumpInfo() |
---|
143 |
{ |
---|
144 |
IsoStream::dumpInfo(); |
---|
145 |
debugOutputShort( DEBUG_LEVEL_NORMAL, " Ringbuffer fill: %d\n", |
---|
146 |
ffado_ringbuffer_read_space(m_cinfo_buffer)/sizeof(struct cycle_info)); |
---|
147 |
}; |
---|