root/branches/api-cleanup/src/motu/motu_avdevice.cpp

Revision 809, 35.4 kB (checked in by ppalmers, 14 years ago)

First round of cleanup:
- make Ports auto-register to a PortManager?
- remove the different 'signal' types, everything is now period-signaled.
- removed obsolete streaming test programs

Line 
1 /*
2  * Copyright (C) 2005-2007 by Pieter Palmers
3  * Copyright (C) 2005-2007 by Jonathan Woithe
4  *
5  * This file is part of FFADO
6  * FFADO = Free Firewire (pro-)audio drivers for linux
7  *
8  * FFADO is based upon FreeBoB.
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 #include "motu/motu_avdevice.h"
26
27 #include "libieee1394/configrom.h"
28 #include "libieee1394/ieee1394service.h"
29
30 #include "libavc/avc_definitions.h"
31
32 #include "debugmodule/debugmodule.h"
33
34 #include "libstreaming/motu/MotuReceiveStreamProcessor.h"
35 #include "libstreaming/motu/MotuTransmitStreamProcessor.h"
36 #include "libstreaming/motu/MotuPort.h"
37
38 #include "libutil/DelayLockedLoop.h"
39 #include "libutil/Time.h"
40
41 #include <string>
42 #include <stdint.h>
43 #include <assert.h>
44 #include <netinet/in.h>
45 #include <iostream>
46 #include <sstream>
47
48 #include <libraw1394/csr.h>
49
50 namespace Motu {
51
52 // to define the supported devices
53 static VendorModelEntry supportedDeviceList[] =
54 {
55 //  {vendor_id, model_id, unit_version, unit_specifier_id, model, vendor_name,model_name}
56     {FW_VENDORID_MOTU, 0, 0x00000003, 0x000001f2, MOTUFW_MODEL_828mkII, "MOTU", "828MkII"},
57     {FW_VENDORID_MOTU, 0, 0x00000009, 0x000001f2, MOTUFW_MODEL_TRAVELER, "MOTU", "Traveler"},
58     {FW_VENDORID_MOTU, 0, 0x0000000d, 0x000001f2, MOTUFW_MODEL_ULTRALITE, "MOTU", "UltraLite"},
59     {FW_VENDORID_MOTU, 0, 0x0000000f, 0x000001f2, MOTUFW_MODEL_8PRE, "MOTU", "8pre"},
60 };
61
62 // Ports declarations
63 const PortEntry Ports_828MKII[] =
64 {
65     {"Main-L", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 40},
66     {"Main-R", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 43},
67     {"Mix-L", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 10},
68     {"Mix-R", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 13},
69     {"Analog1", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 16},
70     {"Analog2", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 19},
71     {"Analog3", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 22},
72     {"Analog4", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 25},
73     {"Analog5", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 28},
74     {"Analog6", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 31},
75     {"Analog7", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 34},
76     {"Analog8", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 37},
77     {"Phones-L", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 10},
78     {"Phones-R", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 13},
79     {"Mic1", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 40},
80     {"Mic2", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 43},
81     {"SPDIF1", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 46},
82     {"SPDIF2", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 49},
83     {"ADAT1", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ADAT, 52},
84     {"ADAT2", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ADAT, 55},
85     {"ADAT3", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ADAT, 58},
86     {"ADAT4", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ADAT, 61},
87     {"ADAT5", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x|MOTUFW_PA_OPTICAL_ADAT, 63},
88     {"ADAT6", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x|MOTUFW_PA_OPTICAL_ADAT, 66},
89     {"ADAT7", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x|MOTUFW_PA_OPTICAL_ADAT, 69},
90     {"ADAT8", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x|MOTUFW_PA_OPTICAL_ADAT, 72},
91 };
92
93 const PortEntry Ports_TRAVELER[] =
94 {
95     {"Mix-L", MOTUFW_DIR_IN, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ANY, 10},
96     {"Mix-R", MOTUFW_DIR_IN, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ANY, 13},
97     {"Phones-L", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ANY, 10},
98     {"Phones-R", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ANY, 13},
99     {"Analog1", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 16},
100     {"Analog2", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 19},
101     {"Analog3", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 22},
102     {"Analog4", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 25},
103     {"Analog5", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 28},
104     {"Analog6", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 31},
105     {"Analog7", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 34},
106     {"Analog8", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 37},
107     {"AES/EBU1", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ANY, 40},
108     {"AES/EBU2", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ANY, 43},
109     {"SPDIF1", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_OFF|MOTUFW_PA_OPTICAL_ADAT, 46},
110     {"SPDIF2", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_OFF|MOTUFW_PA_OPTICAL_ADAT, 49},
111     {"Toslink1", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_TOSLINK, 46},
112     {"Toslink2", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_TOSLINK, 49},
113     {"ADAT1", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ADAT, 52},
114     {"ADAT2", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ADAT, 55},
115     {"ADAT3", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ADAT, 58},
116     {"ADAT4", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x2x|MOTUFW_PA_OPTICAL_ADAT, 61},
117     {"ADAT5", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x|MOTUFW_PA_OPTICAL_ADAT, 63},
118     {"ADAT6", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x|MOTUFW_PA_OPTICAL_ADAT, 66},
119     {"ADAT7", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x|MOTUFW_PA_OPTICAL_ADAT, 69},
120     {"ADAT8", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_1x|MOTUFW_PA_OPTICAL_ADAT, 72},
121 };
122
123 const PortEntry Ports_ULTRALITE[] =
124 {
125     {"Main-L", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 40},
126     {"Main-R", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 43},
127     {"Mix-L", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 10},
128     {"Mix-R", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 13},
129     {"Mic1", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 16},
130     {"Mic2", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 19},
131     {"Analog1", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 16},
132     {"Analog2", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 19},
133     {"Analog3", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 22},
134     {"Analog4", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 25},
135     {"Analog5", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 28},
136     {"Analog6", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 31},
137     {"Analog7", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 34},
138     {"Analog8", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 37},
139     {"Phones-L", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 10},
140     {"Phones-R", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 13},
141     {"SPDIF1", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 40},
142     {"SPDIF2", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 43},
143     {"SPDIF1", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 46},
144     {"SPDIF2", MOTUFW_DIR_INOUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 49},
145 };
146
147 const PortEntry Ports_8PRE[] =
148 {
149     {"Analog1", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 16},
150     {"Analog2", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 19},
151     {"Analog3", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 22},
152     {"Analog4", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 25},
153     {"Analog5", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 28},
154     {"Analog6", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 31},
155     {"Analog7", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 34},
156     {"Analog8", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 37},
157     {"Mix-L", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 10},
158     {"Mix-R", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 13},
159     {"Main-L", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 16},
160     {"Main-R", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 19},
161     {"Phones-L", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 10},
162     {"Phones-R", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ANY, 13},
163     {"ADAT1", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ADAT, 40},
164     {"ADAT1", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ADAT, 22},
165     {"ADAT2", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ADAT, 43},
166     {"ADAT2", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ADAT, 25},
167     {"ADAT3", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ADAT, 46},
168     {"ADAT3", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ADAT, 28},
169     {"ADAT4", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ADAT, 49},
170     {"ADAT4", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ADAT, 31},
171     {"ADAT5", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ADAT, 52},
172     {"ADAT5", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ADAT, 34},
173     {"ADAT6", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ADAT, 55},
174     {"ADAT6", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ADAT, 37},
175     {"ADAT7", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ADAT, 58},
176     {"ADAT7", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ADAT, 40},
177     {"ADAT8", MOTUFW_DIR_IN, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ADAT, 61},
178     {"ADAT8", MOTUFW_DIR_OUT, MOTUFW_PA_RATE_ANY|MOTUFW_PA_OPTICAL_ADAT, 43},
179 };
180
181 const DevicePropertyEntry DevicesProperty[] = {
182 //  { Ports_map,       sizeof( Ports_map ),        MaxSR },
183     { Ports_828MKII,   sizeof( Ports_828MKII ),    96000 },
184     { Ports_TRAVELER,  sizeof( Ports_TRAVELER ),  192000 },
185     { Ports_ULTRALITE, sizeof( Ports_ULTRALITE ),  96000 },
186     { Ports_8PRE,      sizeof( Ports_8PRE ),       96000 },
187 };
188
189 MotuDevice::MotuDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ))
190     : FFADODevice( d, configRom )
191     , m_motu_model( MOTUFW_MODEL_NONE )
192     , m_iso_recv_channel ( -1 )
193     , m_iso_send_channel ( -1 )
194     , m_rx_bandwidth ( -1 )
195     , m_tx_bandwidth ( -1 )
196     , m_receiveProcessor ( 0 )
197     , m_transmitProcessor ( 0 )
198
199 {
200     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Motu::MotuDevice (NodeID %d)\n",
201                  getConfigRom().getNodeId() );
202
203 }
204
205 MotuDevice::~MotuDevice()
206 {
207     delete m_receiveProcessor;
208     delete m_transmitProcessor;
209
210     // Free ieee1394 bus resources if they have been allocated
211     if (m_iso_recv_channel>=0 && !get1394Service().freeIsoChannel(m_iso_recv_channel)) {
212         debugOutput(DEBUG_LEVEL_VERBOSE, "Could not free recv iso channel %d\n", m_iso_recv_channel);
213     }
214     if (m_iso_send_channel>=0 && !get1394Service().freeIsoChannel(m_iso_send_channel)) {
215         debugOutput(DEBUG_LEVEL_VERBOSE, "Could not free send iso channel %d\n", m_iso_send_channel);
216     }
217 }
218
219 bool
220 MotuDevice::probe( ConfigRom& configRom )
221 {
222     unsigned int vendorId = configRom.getNodeVendorId();
223 //     unsigned int modelId = configRom.getModelId();
224     unsigned int unitVersion = configRom.getUnitVersion();
225     unsigned int unitSpecifierId = configRom.getUnitSpecifierId();
226
227     for ( unsigned int i = 0;
228           i < ( sizeof( supportedDeviceList )/sizeof( VendorModelEntry ) );
229           ++i )
230     {
231         if ( ( supportedDeviceList[i].vendor_id == vendorId )
232 //              && ( supportedDeviceList[i].model_id == modelId )
233              && ( supportedDeviceList[i].unit_version == unitVersion )
234              && ( supportedDeviceList[i].unit_specifier_id == unitSpecifierId )
235            )
236         {
237             return true;
238         }
239     }
240
241     return false;
242 }
243
244 FFADODevice *
245 MotuDevice::createDevice(DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ))
246 {
247     return new MotuDevice(d, configRom);
248 }
249
250 bool
251 MotuDevice::discover()
252 {
253     unsigned int vendorId = getConfigRom().getNodeVendorId();
254 //     unsigned int modelId = getConfigRom().getModelId();
255     unsigned int unitVersion = getConfigRom().getUnitVersion();
256     unsigned int unitSpecifierId = getConfigRom().getUnitSpecifierId();
257
258     for ( unsigned int i = 0;
259           i < ( sizeof( supportedDeviceList )/sizeof( VendorModelEntry ) );
260           ++i )
261     {
262         if ( ( supportedDeviceList[i].vendor_id == vendorId )
263 //              && ( supportedDeviceList[i].model_id == modelId )
264              && ( supportedDeviceList[i].unit_version == unitVersion )
265              && ( supportedDeviceList[i].unit_specifier_id == unitSpecifierId )
266            )
267         {
268             m_model = &(supportedDeviceList[i]);
269             m_motu_model=supportedDeviceList[i].model;
270         }
271     }
272
273     if (m_model != NULL) {
274         debugOutput( DEBUG_LEVEL_VERBOSE, "found %s %s\n",
275                 m_model->vendor_name, m_model->model_name);
276         return true;
277     }
278
279     return false;
280 }
281
282 int
283 MotuDevice::getSamplingFrequency( ) {
284 /*
285  * Retrieve the current sample rate from the MOTU device.
286  */
287     quadlet_t q = ReadRegister(MOTUFW_REG_CLK_CTRL);
288     int rate = 0;
289
290     switch (q & MOTUFW_RATE_BASE_MASK) {
291         case MOTUFW_RATE_BASE_44100:
292             rate = 44100;
293             break;
294         case MOTUFW_RATE_BASE_48000:
295             rate = 48000;
296             break;
297     }
298     switch (q & MOTUFW_RATE_MULTIPLIER_MASK) {
299         case MOTUFW_RATE_MULTIPLIER_2X:
300             rate *= 2;
301             break;
302         case MOTUFW_RATE_MULTIPLIER_4X:
303             rate *= 4;
304             break;
305     }
306     return rate;
307 }
308
309 int
310 MotuDevice::getConfigurationId()
311 {
312     return 0;
313 }
314
315 bool
316 MotuDevice::setSamplingFrequency( int samplingFrequency )
317 {
318 /*
319  * Set the MOTU device's samplerate.
320  */
321     char *src_name;
322     quadlet_t q, new_rate=0;
323     int i, supported=true, cancel_adat=false;
324
325     if ( samplingFrequency > DevicesProperty[m_motu_model-1].MaxSampleRate )
326        return false;
327
328     switch ( samplingFrequency ) {
329         case 22050:
330         case 24000:
331         case 32000:
332             supported=false;
333             break;
334         case 44100:
335             new_rate = MOTUFW_RATE_BASE_44100 | MOTUFW_RATE_MULTIPLIER_1X;
336             break;
337         case 48000:
338             new_rate = MOTUFW_RATE_BASE_48000 | MOTUFW_RATE_MULTIPLIER_1X;
339             break;
340         case 88200:
341             new_rate = MOTUFW_RATE_BASE_44100 | MOTUFW_RATE_MULTIPLIER_2X;
342             break;
343         case 96000:
344             new_rate = MOTUFW_RATE_BASE_48000 | MOTUFW_RATE_MULTIPLIER_2X;
345             break;
346         case 176400:
347             new_rate = MOTUFW_RATE_BASE_44100 | MOTUFW_RATE_MULTIPLIER_4X;
348             cancel_adat = true;  // current ADAT protocol doesn't support sample rate > 96000
349             break;
350         case 192000:
351             new_rate = MOTUFW_RATE_BASE_48000 | MOTUFW_RATE_MULTIPLIER_4X;
352             cancel_adat = true;
353             break;
354         default:
355             supported=false;
356     }
357
358     // Update the clock control register.  FIXME: while this is now rather
359     // comprehensive there may still be a need to manipulate MOTUFW_REG_CLK_CTRL
360     // a little more than we do.
361     if (supported) {
362         quadlet_t value=ReadRegister(MOTUFW_REG_CLK_CTRL);
363
364         // If optical port must be disabled (because a 4x sample rate has
365         // been selected) then do so before changing the sample rate.  At
366         // this stage it will be up to the user to re-enable the optical
367         // port if the sample rate is set to a 1x or 2x rate later.
368         if (cancel_adat) {
369             setOpticalMode(MOTUFW_DIR_INOUT, MOTUFW_OPTICAL_MODE_OFF);
370         }
371
372         value &= ~(MOTUFW_RATE_BASE_MASK|MOTUFW_RATE_MULTIPLIER_MASK);
373         value |= new_rate;
374
375         // In other OSes bit 26 of MOTUFW_REG_CLK_CTRL always seems
376         // to be set when this register is written to although the
377         // reason isn't currently known.  When we set it, it appears
378         // to prevent output being produced so we'll leave it unset
379         // until we work out what's going on.  Other systems write
380         // to MOTUFW_REG_CLK_CTRL multiple times, so that may be
381         // part of the mystery.
382         //   value |= 0x04000000;
383         if (WriteRegister(MOTUFW_REG_CLK_CTRL, value) == 0) {
384             supported=true;
385         } else {
386             supported=false;
387         }
388         // A write to the rate/clock control register requires the
389         // textual name of the current clock source be sent to the
390         // clock source name registers.
391         switch (value & MOTUFW_CLKSRC_MASK) {
392             case MOTUFW_CLKSRC_INTERNAL:
393                 src_name = "Internal        ";
394                 break;
395             case MOTUFW_CLKSRC_ADAT_OPTICAL:
396                 src_name = "ADAT Optical    ";
397                 break;
398             case MOTUFW_CLKSRC_SPDIF_TOSLINK:
399                 if (getOpticalMode(MOTUFW_DIR_IN)  == MOTUFW_OPTICAL_MODE_TOSLINK)
400                     src_name = "TOSLink         ";
401                 else
402                     src_name = "SPDIF           ";
403                 break;
404             case MOTUFW_CLKSRC_SMTPE:
405                 src_name = "SMPTE           ";
406                 break;
407             case MOTUFW_CLKSRC_WORDCLOCK:
408                 src_name = "Word Clock In   ";
409                 break;
410             case MOTUFW_CLKSRC_ADAT_9PIN:
411                 src_name = "ADAT 9-pin      ";
412                 break;
413             case MOTUFW_CLKSRC_AES_EBU:
414                 src_name = "AES-EBU         ";
415                 break;
416             default:
417                 src_name = "Unknown         ";
418         }
419         for (i=0; i<16; i+=4) {
420             q = (src_name[i]<<24) | (src_name[i+1]<<16) |
421                 (src_name[i+2]<<8) | src_name[i+3];
422             WriteRegister(MOTUFW_REG_CLKSRC_NAME0+i, q);
423         }
424     }
425     return supported;
426 }
427
428 FFADODevice::ClockSourceVector
429 MotuDevice::getSupportedClockSources() {
430     FFADODevice::ClockSourceVector r;
431     return r;
432 }
433
434 bool
435 MotuDevice::setActiveClockSource(ClockSource s) {
436     return false;
437 }
438
439 FFADODevice::ClockSource
440 MotuDevice::getActiveClockSource() {
441     ClockSource s;
442     return s;
443 }
444
445 bool
446 MotuDevice::lock() {
447
448     return true;
449 }
450
451
452 bool
453 MotuDevice::unlock() {
454
455     return true;
456 }
457
458 void
459 MotuDevice::showDevice()
460 {
461     debugOutput(DEBUG_LEVEL_VERBOSE,
462         "%s %s at node %d\n", m_model->vendor_name, m_model->model_name,
463         getNodeId());
464 }
465
466 bool
467 MotuDevice::prepare() {
468
469     int samp_freq = getSamplingFrequency();
470     unsigned int optical_in_mode = getOpticalMode(MOTUFW_DIR_IN);
471     unsigned int optical_out_mode = getOpticalMode(MOTUFW_DIR_OUT);
472     unsigned int event_size_in = getEventSize(MOTUFW_DIR_IN);
473     unsigned int event_size_out= getEventSize(MOTUFW_DIR_OUT);
474
475     debugOutput(DEBUG_LEVEL_NORMAL, "Preparing MotuDevice...\n" );
476
477     // Allocate bandwidth if not previously done.
478     // FIXME: The bandwidth allocation calculation can probably be
479     // refined somewhat since this is currently based on a rudimentary
480     // understanding of the ieee1394 iso protocol.
481     // Currently we assume the following.
482     //   * Ack/iso gap = 0.05 us
483     //   * DATA_PREFIX = 0.16 us
484     //   * DATA_END    = 0.26 us
485     // These numbers are the worst-case figures given in the ieee1394
486     // standard.  This gives approximately 0.5 us of overheads per packet -
487     // around 25 bandwidth allocation units (from the ieee1394 standard 1
488     // bandwidth allocation unit is 125/6144 us).  We further assume the
489     // MOTU is running at S400 (which it should be) so one allocation unit
490     // is equivalent to 1 transmitted byte; thus the bandwidth allocation
491     // required for the packets themselves is just the size of the packet.
492     // We used to allocate based on the maximum packet size (1160 bytes at
493     // 192 kHz for the traveler) but now do this based on the actual device
494     // state by utilising the result from getEventSize() and remembering
495     // that each packet has an 8 byte CIP header.  Note that bandwidth is
496     // allocated on a *per stream* basis - it must be allocated for both the
497     // transmit and receive streams.  While most MOTU modules are close to
498     // symmetric in terms of the number of in/out channels there are
499     // exceptions, so we deal with receive and transmit bandwidth separately.
500     signed int n_events_per_packet = samp_freq<=48000?8:(samp_freq<=96000?16:32);
501     m_rx_bandwidth = 25 + (n_events_per_packet*event_size_in);
502     m_tx_bandwidth = 25 + (n_events_per_packet*event_size_out);
503
504     // Assign iso channels if not already done
505     if (m_iso_recv_channel < 0)
506         m_iso_recv_channel = get1394Service().allocateIsoChannelGeneric(m_rx_bandwidth);
507
508     if (m_iso_send_channel < 0)
509         m_iso_send_channel = get1394Service().allocateIsoChannelGeneric(m_tx_bandwidth);
510
511     debugOutput(DEBUG_LEVEL_VERBOSE, "recv channel = %d, send channel = %d\n",
512         m_iso_recv_channel, m_iso_send_channel);
513
514     if (m_iso_recv_channel<0 || m_iso_send_channel<0) {
515         // be nice and deallocate
516         if (m_iso_recv_channel >= 0)
517             get1394Service().freeIsoChannel(m_iso_recv_channel);
518         if (m_iso_send_channel >= 0)
519             get1394Service().freeIsoChannel(m_iso_send_channel);
520
521         debugFatal("Could not allocate iso channels!\n");
522         return false;
523     }
524
525     m_receiveProcessor=new Streaming::MotuReceiveStreamProcessor(*this, event_size_in);
526
527     // The first thing is to initialize the processor.  This creates the
528     // data structures.
529     if(!m_receiveProcessor->init()) {
530         debugFatal("Could not initialize receive processor!\n");
531         return false;
532     }
533     m_receiveProcessor->setVerboseLevel(getDebugLevel());
534
535     // Now we add ports to the processor
536     debugOutput(DEBUG_LEVEL_VERBOSE,"Adding ports to receive processor\n");
537
538     char *buff;
539     Streaming::Port *p=NULL;
540
541     // retrieve the ID
542     std::string id=std::string("dev?");
543     if(!getOption("id", id)) {
544         debugWarning("Could not retrieve id parameter, defauling to 'dev?'\n");
545     }
546
547     // Add audio capture ports
548     if (!addDirPorts(Streaming::Port::E_Capture, samp_freq, optical_in_mode)) {
549         return false;
550     }
551
552     // Add MIDI port.  The MOTU only has one MIDI input port, with each
553     // MIDI byte sent using a 3 byte sequence starting at byte 4 of the
554     // event data.
555     asprintf(&buff,"%s_cap_MIDI0",id.c_str());
556     p = new Streaming::MotuMidiPort(*m_receiveProcessor, buff,
557         Streaming::Port::E_Capture, 4);
558     if (!p) {
559         debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n", buff);
560     }
561     free(buff);
562
563     // example of adding an control port:
564 //    asprintf(&buff,"%s_cap_%s",id.c_str(),"myportnamehere");
565 //    p=new Streaming::MotuControlPort(
566 //            buff,
567 //            Streaming::Port::E_Capture,
568 //            0 // you can add all other port specific stuff you
569 //              // need to pass by extending MotuXXXPort and MotuPortInfo
570 //    );
571 //    free(buff);
572 //
573 //    if (!p) {
574 //        debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",buff);
575 //    } else {
576 //
577 //        if (!m_receiveProcessor->addPort(p)) {
578 //            debugWarning("Could not register port with stream processor\n");
579 //            return false;
580 //        } else {
581 //            debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",buff);
582 //        }
583 //    }
584
585     // Do the same for the transmit processor
586     m_transmitProcessor=new Streaming::MotuTransmitStreamProcessor(*this, event_size_out);
587
588     m_transmitProcessor->setVerboseLevel(getDebugLevel());
589
590     if(!m_transmitProcessor->init()) {
591         debugFatal("Could not initialize transmit processor!\n");
592         return false;
593     }
594
595     // Now we add ports to the processor
596     debugOutput(DEBUG_LEVEL_VERBOSE,"Adding ports to transmit processor\n");
597
598     // Add audio playback ports
599     if (!addDirPorts(Streaming::Port::E_Playback, samp_freq, optical_out_mode)) {
600         return false;
601     }
602
603     // Add MIDI port.  The MOTU only has one output MIDI port, with each
604     // MIDI byte transmitted using a 3 byte sequence starting at byte 4
605     // of the event data.
606     asprintf(&buff,"%s_pbk_MIDI0",id.c_str());
607     p = new Streaming::MotuMidiPort(*m_transmitProcessor, buff,
608         Streaming::Port::E_Capture, 4);
609     if (!p) {
610         debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n", buff);
611     }
612     free(buff);
613
614     // example of adding an control port:
615 //    asprintf(&buff,"%s_pbk_%s",id.c_str(),"myportnamehere");
616 //
617 //    p=new Streaming::MotuControlPort(
618 //            buff,
619 //            Streaming::Port::E_Playback,
620 //            0 // you can add all other port specific stuff you
621 //              // need to pass by extending MotuXXXPort and MotuPortInfo
622 //    );
623 //    free(buff);
624 //
625 //    if (!p) {
626 //        debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",buff);
627 //    } else {
628 //        if (!m_transmitProcessor->addPort(p)) {
629 //            debugWarning("Could not register port with stream processor\n");
630 //            return false;
631 //        } else {
632 //            debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",buff);
633 //        }
634 //    }
635
636     return true;
637 }
638
639 int
640 MotuDevice::getStreamCount() {
641      return 2; // one receive, one transmit
642 }
643
644 Streaming::StreamProcessor *
645 MotuDevice::getStreamProcessorByIndex(int i) {
646     switch (i) {
647     case 0:
648         return m_receiveProcessor;
649     case 1:
650          return m_transmitProcessor;
651     default:
652         return NULL;
653     }
654     return 0;
655 }
656
657 bool
658 MotuDevice::startStreamByIndex(int i) {
659
660 quadlet_t isoctrl = ReadRegister(MOTUFW_REG_ISOCTRL);
661
662     // NOTE: this assumes that you have two streams
663     switch (i) {
664     case 0:
665         // TODO: do the stuff that is nescessary to make the device
666         // receive a stream
667
668         // Set the streamprocessor channel to the one obtained by
669         // the connection management
670         m_receiveProcessor->setChannel(m_iso_recv_channel);
671
672         // Mask out current transmit settings of the MOTU and replace
673         // with new ones.  Turn bit 24 on to enable changes to the
674         // MOTU's iso transmit settings when the iso control register
675         // is written.  Bit 23 enables iso transmit from the MOTU.
676         isoctrl &= 0xff00ffff;
677         isoctrl |= (m_iso_recv_channel << 16);
678         isoctrl |= 0x00c00000;
679         WriteRegister(MOTUFW_REG_ISOCTRL, isoctrl);
680         break;
681     case 1:
682         // TODO: do the stuff that is nescessary to make the device
683         // transmit a stream
684
685         // Set the streamprocessor channel to the one obtained by
686         // the connection management
687         m_transmitProcessor->setChannel(m_iso_send_channel);
688
689         // Mask out current receive settings of the MOTU and replace
690         // with new ones.  Turn bit 31 on to enable changes to the
691         // MOTU's iso receive settings when the iso control register
692         // is written.  Bit 30 enables iso receive by the MOTU.
693         isoctrl &= 0x00ffffff;
694         isoctrl |= (m_iso_send_channel << 24);
695         isoctrl |= 0xc0000000;
696         WriteRegister(MOTUFW_REG_ISOCTRL, isoctrl);
697         break;
698
699     default: // Invalid stream index
700         return false;
701     }
702
703     return true;
704 }
705
706 bool
707 MotuDevice::stopStreamByIndex(int i) {
708
709 quadlet_t isoctrl = ReadRegister(MOTUFW_REG_ISOCTRL);
710
711     // TODO: connection management: break connection
712     // cfr the start function
713
714     // NOTE: this assumes that you have two streams
715     switch (i) {
716     case 0:
717         // Turn bit 22 off to disable iso send by the MOTU.  Turn
718         // bit 23 on to enable changes to the MOTU's iso transmit
719         // settings when the iso control register is written.
720         isoctrl &= 0xffbfffff;
721         isoctrl |= 0x00800000;
722         WriteRegister(MOTUFW_REG_ISOCTRL, isoctrl);
723         break;
724     case 1:
725         // Turn bit 30 off to disable iso receive by the MOTU.  Turn
726         // bit 31 on to enable changes to the MOTU's iso receive
727         // settings when the iso control register is written.
728         isoctrl &= 0xbfffffff;
729         isoctrl |= 0x80000000;
730         WriteRegister(MOTUFW_REG_ISOCTRL, isoctrl);
731         break;
732
733     default: // Invalid stream index
734         return false;
735     }
736
737     return true;
738 }
739
740 signed int MotuDevice::getIsoRecvChannel(void) {
741     return m_iso_recv_channel;
742 }
743
744 signed int MotuDevice::getIsoSendChannel(void) {
745     return m_iso_send_channel;
746 }
747
748 unsigned int MotuDevice::getOpticalMode(unsigned int dir) {
749     unsigned int reg = ReadRegister(MOTUFW_REG_ROUTE_PORT_CONF);
750
751 debugOutput(DEBUG_LEVEL_VERBOSE, "optical mode: %x %x %x %x\n",dir, reg, reg & MOTUFW_OPTICAL_IN_MODE_MASK,
752 reg & MOTUFW_OPTICAL_OUT_MODE_MASK);
753
754     if (dir == MOTUFW_DIR_IN)
755         return (reg & MOTUFW_OPTICAL_IN_MODE_MASK) >> 8;
756     else
757         return (reg & MOTUFW_OPTICAL_OUT_MODE_MASK) >> 10;
758 }
759
760 signed int MotuDevice::setOpticalMode(unsigned int dir, unsigned int mode) {
761     unsigned int reg = ReadRegister(MOTUFW_REG_ROUTE_PORT_CONF);
762     unsigned int opt_ctrl = 0x0000002;
763
764     // Set up the optical control register value according to the current
765     // optical port modes.  At this stage it's not completely understood
766     // what the "Optical control" register does, so the values it's set to
767     // are more or less "magic" numbers.
768     if (reg & MOTUFW_OPTICAL_IN_MODE_MASK != (MOTUFW_OPTICAL_MODE_ADAT<<8))
769         opt_ctrl |= 0x00000080;
770     if (reg & MOTUFW_OPTICAL_OUT_MODE_MASK != (MOTUFW_OPTICAL_MODE_ADAT<<10))
771         opt_ctrl |= 0x00000040;
772
773     if (mode & MOTUFW_DIR_IN) {
774         reg &= ~MOTUFW_OPTICAL_IN_MODE_MASK;
775         reg |= (mode << 8) & MOTUFW_OPTICAL_IN_MODE_MASK;
776         if (mode != MOTUFW_OPTICAL_MODE_ADAT)
777             opt_ctrl |= 0x00000080;
778         else
779             opt_ctrl &= ~0x00000080;
780     }
781     if (mode & MOTUFW_DIR_OUT) {
782         reg &= ~MOTUFW_OPTICAL_OUT_MODE_MASK;
783         reg |= (mode <<10) & MOTUFW_OPTICAL_OUT_MODE_MASK;
784         if (mode != MOTUFW_OPTICAL_MODE_ADAT)
785             opt_ctrl |= 0x00000040;
786         else
787             opt_ctrl &= ~0x00000040;
788     }
789
790     // FIXME: there seems to be more to it than this, but for
791     // the moment at least this seems to work.
792     WriteRegister(MOTUFW_REG_ROUTE_PORT_CONF, reg);
793     return WriteRegister(MOTUFW_REG_OPTICAL_CTRL, opt_ctrl);
794 }
795
796 signed int MotuDevice::getEventSize(unsigned int direction) {
797 //
798 // Return the size in bytes of a single event sent to (dir==MOTUFW_OUT) or
799 // from (dir==MOTUFW_IN) the MOTU as part of an iso data packet.
800 //
801 // FIXME: for performance it may turn out best to calculate the event
802 // size in setOpticalMode and cache the result in a data field.  However,
803 // as it stands this will not adapt to dynamic changes in sample rate - we'd
804 // need a setFrameRate() for that.
805 //
806 // At the very least an event consists of the SPH (4 bytes) and the control/MIDI
807 // bytes (6 bytes).
808 // Note that all audio channels are sent using 3 bytes.
809 signed int sample_rate = getSamplingFrequency();
810 signed int optical_mode = getOpticalMode(direction);
811 signed int size = 4+6;
812
813 unsigned int i;
814 unsigned int dir = direction==Streaming::Port::E_Capture?MOTUFW_DIR_IN:MOTUFW_DIR_OUT;
815 unsigned int flags = (1 << ( optical_mode + 4 ));
816
817     if ( sample_rate > 96000 )
818         flags |= MOTUFW_PA_RATE_4x;
819     else if ( sample_rate > 48000 )
820         flags |= MOTUFW_PA_RATE_2x;
821     else
822         flags |= MOTUFW_PA_RATE_1x;
823
824     for (i=0; i < ( DevicesProperty[m_motu_model-1].PortsListLength /sizeof( PortEntry ) ); i++) {
825         if (( DevicesProperty[m_motu_model-1].PortsList[i].port_dir & dir ) &&
826            ( DevicesProperty[m_motu_model-1].PortsList[i].port_flags & MOTUFW_PA_RATE_MASK & flags ) &&
827            ( DevicesProperty[m_motu_model-1].PortsList[i].port_flags & MOTUFW_PA_OPTICAL_MASK & flags )) {
828             size += 3;
829         }
830     }
831
832     // Finally round size up to the next quadlet boundary
833     return ((size+3)/4)*4;
834 }
835 /* ======================================================================= */
836
837 bool MotuDevice::addPort(Streaming::StreamProcessor *s_processor,
838   char *name, enum Streaming::Port::E_Direction direction,
839   int position, int size) {
840 /*
841  * Internal helper function to add a MOTU port to a given stream processor.
842  * This just saves the unnecessary replication of what is essentially
843  * boilerplate code.  Note that the port name is freed by this function
844  * prior to exit.
845  */
846 Streaming::Port *p=NULL;
847
848     p = new Streaming::MotuAudioPort(*s_processor, name, direction, position, size);
849
850     if (!p) {
851         debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",name);
852     }
853     free(name);
854     return true;
855 }
856 /* ======================================================================= */
857
858 bool MotuDevice::addDirPorts(
859   enum Streaming::Port::E_Direction direction,
860   unsigned int sample_rate, unsigned int optical_mode) {
861 /*
862  * Internal helper method: adds all required ports for the given direction
863  * based on the indicated sample rate and optical mode.
864  *
865  * Notes: currently ports are not created if they are disabled due to sample
866  * rate or optical mode.  However, it might be better to unconditionally
867  * create all ports and just disable those which are not active.
868  */
869 const char *mode_str = direction==Streaming::Port::E_Capture?"cap":"pbk";
870 Streaming::StreamProcessor *s_processor;
871 unsigned int i;
872 char *buff;
873 unsigned int dir = direction==Streaming::Port::E_Capture?MOTUFW_DIR_IN:MOTUFW_DIR_OUT;
874 unsigned int flags = (1 << ( optical_mode + 4 ));
875
876     if ( sample_rate > 96000 )
877         flags |= MOTUFW_PA_RATE_4x;
878     else if ( sample_rate > 48000 )
879         flags |= MOTUFW_PA_RATE_2x;
880     else
881         flags |= MOTUFW_PA_RATE_1x;
882
883     // retrieve the ID
884     std::string id=std::string("dev?");
885     if(!getOption("id", id)) {
886         debugWarning("Could not retrieve id parameter, defauling to 'dev?'\n");
887     }
888
889     if (direction == Streaming::Port::E_Capture) {
890         s_processor = m_receiveProcessor;
891     } else {
892         s_processor = m_transmitProcessor;
893     }
894
895     for (i=0; i < ( DevicesProperty[m_motu_model-1].PortsListLength /sizeof( PortEntry ) ); i++) {
896         if (( DevicesProperty[m_motu_model-1].PortsList[i].port_dir & dir ) &&
897            ( DevicesProperty[m_motu_model-1].PortsList[i].port_flags & MOTUFW_PA_RATE_MASK & flags ) &&
898            ( DevicesProperty[m_motu_model-1].PortsList[i].port_flags & MOTUFW_PA_OPTICAL_MASK & flags )) {
899             asprintf(&buff,"%s_%s_%s" , id.c_str(), mode_str,
900               DevicesProperty[m_motu_model-1].PortsList[i].port_name);
901             if (!addPort(s_processor, buff, direction, DevicesProperty[m_motu_model-1].PortsList[i].port_offset, 0))
902                 return false;
903         }
904     }
905    
906     return true;
907 }
908 /* ======================================================================== */
909
910 unsigned int MotuDevice::ReadRegister(unsigned int reg) {
911 /*
912  * Attempts to read the requested register from the MOTU.
913  */
914
915   quadlet_t quadlet;
916
917   quadlet = 0;
918   // Note: 1394Service::read() expects a physical ID, not the node id
919   if (get1394Service().read(0xffc0 | getNodeId(), MOTUFW_BASE_ADDR+reg, 1, &quadlet) < 0) {
920     debugError("Error doing motu read from register 0x%06x\n",reg);
921   }
922
923   return ntohl(quadlet);
924 }
925
926 signed int MotuDevice::WriteRegister(unsigned int reg, quadlet_t data) {
927 /*
928  * Attempts to write the given data to the requested MOTU register.
929  */
930
931   unsigned int err = 0;
932   data = htonl(data);
933
934   // Note: 1394Service::write() expects a physical ID, not the node id
935   if (get1394Service().write(0xffc0 | getNodeId(), MOTUFW_BASE_ADDR+reg, 1, &data) < 0) {
936     err = 1;
937     debugError("Error doing motu write to register 0x%06x\n",reg);
938   }
939
940   SleepRelativeUsec(100);
941   return (err==0)?0:-1;
942 }
943
944 }
Note: See TracBrowser for help on using the browser.