root/trunk/libffado/tests/SytMonitor.cpp

Revision 742, 4.4 kB (checked in by ppalmers, 13 years ago)

- Remove some obsolete support files and dirs

- Clean up the license statements in the source files. Everything is

GPL version 3 now.

- Add license and copyright notices to scons scripts

- Clean up some other text files

Line 
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 #include "SytMonitor.h"
25
26 #include <netinet/in.h>
27 #include <assert.h>
28
29
30 IMPL_DEBUG_MODULE( SytMonitor, SytMonitor, DEBUG_LEVEL_VERBOSE );
31
32
33 /* --------------------- RECEIVE ----------------------- */
34
35 SytMonitor::SytMonitor(int port)
36     : IsoStream(IsoStream::eST_Receive, port) {
37     m_cinfo_buffer=ffado_ringbuffer_create(16384*sizeof(struct cycle_info));
38
39 }
40
41 SytMonitor::~SytMonitor() {
42     ffado_ringbuffer_free(m_cinfo_buffer);
43
44 }
45
46 enum raw1394_iso_disposition
47 SytMonitor::putPacket(unsigned char *data, unsigned int length,
48                   unsigned char channel, unsigned char tag, unsigned char sy,
49                   unsigned int cycle, unsigned int dropped) {
50     enum raw1394_iso_disposition retval=RAW1394_ISO_OK;
51
52     struct iec61883_packet *packet = (struct iec61883_packet *) data;
53     unsigned int syt_timestamp=ntohs(packet->syt);
54
55     if (syt_timestamp == 0xFFFF) {
56         return RAW1394_ISO_OK;
57     }
58
59     uint32_t m_full_timestamp;
60     uint32_t m_full_timestamp_ticks;
61
62     debugOutput(DEBUG_LEVEL_VERBOSE,"%2u,%2u: CY=%4u, SYT=%08X (%3u secs + %4u cycles + %04u ticks)\n",
63         m_port,channel,
64         cycle,syt_timestamp,
65         CYCLE_TIMER_GET_SECS(syt_timestamp),
66         CYCLE_TIMER_GET_CYCLES(syt_timestamp),
67         CYCLE_TIMER_GET_OFFSET(syt_timestamp)
68
69         );
70
71     // reconstruct the full cycle
72     unsigned int cc=m_handler->getCycleTimer();
73
74     unsigned int cc_cycles=CYCLE_TIMER_GET_CYCLES(cc);
75
76     unsigned int cc_seconds=CYCLE_TIMER_GET_SECS(cc);
77
78
79     // the cycletimer has wrapped since this packet was received
80     // we want cc_seconds to reflect the 'seconds' at the point this
81     // was received
82     if (cycle>cc_cycles) cc_seconds--;
83
84     m_full_timestamp_ticks=sytRecvToFullTicks((uint32_t)syt_timestamp, cycle, cc);
85     m_full_timestamp=TICKS_TO_CYCLE_TIMER(m_full_timestamp_ticks);
86
87     struct cycle_info cif;
88     cif.cycle=cycle;
89     cif.seconds=cc_seconds;
90
91     cif.syt=packet->syt;
92     cif.full_syt=m_full_timestamp;
93
94     // now we reconstruct the presentation time
95     cif.pres_seconds = CYCLE_TIMER_GET_SECS(m_full_timestamp);
96     cif.pres_cycle   = CYCLE_TIMER_GET_CYCLES(m_full_timestamp);
97     cif.pres_offset  = CYCLE_TIMER_GET_OFFSET(m_full_timestamp);
98     cif.pres_ticks   = m_full_timestamp_ticks;
99
100     if (cif.pres_offset != (syt_timestamp & 0xFFF)) {
101         debugOutput(DEBUG_LEVEL_NORMAL,"P-offset error: %04X != %04X (P: %08X, R: %08X)\n",
102         cif.pres_offset, syt_timestamp & 0xFFF, m_full_timestamp, syt_timestamp);
103     }
104     if ((cif.pres_cycle & 0xF) != ((syt_timestamp & 0xF000)>>12)) {
105         debugOutput(DEBUG_LEVEL_NORMAL,"P-cycle error: %01X != %01X (P: %08X, R: %08X)\n",
106             cif.pres_cycle &0xF, (syt_timestamp & 0xF000)>>12, m_full_timestamp, syt_timestamp);
107     }
108
109     putCycleInfo(&cif);
110
111     return retval;
112 }
113
114 bool SytMonitor::putCycleInfo(struct cycle_info *cif) {
115     if(ffado_ringbuffer_write(m_cinfo_buffer,(char *)cif,sizeof(struct cycle_info))
116         !=sizeof(struct cycle_info)) {
117         return false;
118     }
119     return true;
120 }
121
122 bool SytMonitor::readNextCycleInfo(struct cycle_info *cif) {
123     if(ffado_ringbuffer_peek(m_cinfo_buffer,(char *)cif,sizeof(struct cycle_info))
124         !=sizeof(struct cycle_info)) {
125         return false;
126     }
127     return true;
128
129 }
130
131 bool SytMonitor::consumeNextCycleInfo() {
132     struct cycle_info cif;
133     if(ffado_ringbuffer_read(m_cinfo_buffer,(char *)&cif,sizeof(struct cycle_info))
134         !=sizeof(struct cycle_info)) {
135         return false;
136     }
137     return true;
138 }
139
140 void SytMonitor::dumpInfo()
141 {
142     IsoStream::dumpInfo();
143     debugOutputShort( DEBUG_LEVEL_NORMAL, "  Ringbuffer fill: %d\n",
144        ffado_ringbuffer_read_space(m_cinfo_buffer)/sizeof(struct cycle_info));
145 };
Note: See TracBrowser for help on using the browser.