root/trunk/libffado/src/rme/rme_avdevice.cpp

Revision 1688, 23.9 kB (checked in by jwoithe, 14 years ago)

RME: more work on the streaming system.

Line 
1 /*
2  * Copyright (C) 2005-2009 by Jonathan Woithe
3  * Copyright (C) 2005-2008 by Pieter Palmers
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 2 of the License, or
13  * (at your option) version 3 of the License.
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 #warning RME support is at an early development stage and is not functional
26
27 #include "config.h"
28
29 #include "rme/rme_avdevice.h"
30 #include "rme/fireface_def.h"
31 #include "rme/fireface_settings_ctrls.h"
32
33 #include "libieee1394/configrom.h"
34 #include "libieee1394/ieee1394service.h"
35
36 #include "debugmodule/debugmodule.h"
37
38 #include "devicemanager.h"
39
40 #include <string>
41 #include <stdint.h>
42 #include <assert.h>
43 #include "libutil/ByteSwap.h"
44
45 #include <iostream>
46 #include <sstream>
47
48 #include <libraw1394/csr.h>
49
50 // Known values for the unit version of RME devices
51 #define RME_UNITVERSION_FF800  0x0001
52 #define RME_UNITVERSION_FF400  0x0002
53
54 namespace Rme {
55
56 // The RME devices expect async packet data in little endian format (as
57 // opposed to bus order, which is big endian).  Therefore define our own
58 // 32-bit byteswap function to do this.
59 #if __BYTE_ORDER == __BIG_ENDIAN
60 static inline uint32_t
61 ByteSwapToDevice32(uint32_t d)
62 {
63     return byteswap_32(d);
64 }
65 ByteSwapFromDevice32(uint32_t d)
66 {
67     return byteswap_32(d);
68 }
69 #else
70 static inline uint32_t
71 ByteSwapToDevice32(uint32_t d)
72 {
73     return d;
74 }
75 static inline uint32_t
76 ByteSwapFromDevice32(uint32_t d)
77 {
78     return d;
79 }
80 #endif
81
82 Device::Device( DeviceManager& d,
83                       std::auto_ptr<ConfigRom>( configRom ))
84     : FFADODevice( d, configRom )
85     , m_rme_model( RME_MODEL_NONE )
86     , num_channels( 0 )
87     , frames_per_packet( 0 )
88     , speed800( 0 )
89     , iso_tx_channel( -1 )
90     , iso_rx_channel( -1 )
91     , m_receiveProcessor( NULL )
92     , m_transmitProcessor( NULL )
93     , m_MixerContainer( NULL )
94     , m_ControlContainer( NULL )
95 {
96     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Rme::Device (NodeID %d)\n",
97                  getConfigRom().getNodeId() );
98 }
99
100 Device::~Device()
101 {
102     if (iso_tx_channel>=0 && !get1394Service().freeIsoChannel(iso_tx_channel)) {
103         debugOutput(DEBUG_LEVEL_VERBOSE, "Could not free tx iso channel %d\n", iso_tx_channel);
104     }
105     if (iso_rx_channel>=0 && !get1394Service().freeIsoChannel(iso_rx_channel)) {
106         debugOutput(DEBUG_LEVEL_VERBOSE, "Could not free rx iso channel %d\n", iso_rx_channel);
107     }
108
109     destroyMixer();
110
111     if (dev_config != NULL) {
112         switch (rme_shm_close(dev_config)) {
113             case RSO_CLOSE:
114                 debugOutput( DEBUG_LEVEL_VERBOSE, "Configuration shared data object closed\n");
115                 break;
116             case RSO_CLOSE_DELETE:
117                 debugOutput( DEBUG_LEVEL_VERBOSE, "Configuration shared data object closed and deleted (no other users)\n");
118                 break;
119         }
120     }
121 }
122
123 bool
124 Device::buildMixer() {
125     signed int i;
126     bool result = true;
127
128     destroyMixer();
129     debugOutput(DEBUG_LEVEL_VERBOSE, "Building an RME mixer...\n");
130
131
132     // Non-mixer device controls
133     m_ControlContainer = new Control::Container(this, "Control");
134     if (!m_ControlContainer) {
135         debugError("Could not create control container\n");
136         destroyMixer();
137         return false;
138     }
139
140     result &= m_ControlContainer->addElement(
141         new RmeSettingsCtrl(*this, RME_CTRL_INFO_MODEL, 0,
142             "Model", "Model ID", ""));
143     result &= m_ControlContainer->addElement(
144         new RmeSettingsCtrl(*this, RME_CTRL_INFO_TCO_PRESENT, 0,
145             "TCO_present", "TCO is present", ""));
146
147     result &= m_ControlContainer->addElement(
148         new RmeSettingsCtrl(*this, RME_CTRL_PHANTOM_SW, 0,
149             "Phantom", "Phantom switches", ""));
150     result &= m_ControlContainer->addElement(
151         new RmeSettingsCtrl(*this, RME_CTRL_INPUT_LEVEL, 0,
152             "Input_level", "Input level", ""));
153     result &= m_ControlContainer->addElement(
154         new RmeSettingsCtrl(*this, RME_CTRL_OUTPUT_LEVEL, 0,
155             "Output_level", "Output level", ""));
156     result &= m_ControlContainer->addElement(
157         new RmeSettingsCtrl(*this, RME_CTRL_PHONES_LEVEL, 0,
158             "Phones_level", "Phones level", ""));
159
160     if (m_rme_model == RME_MODEL_FIREFACE400) {
161         // Instrument input options
162         for (i=3; i<=4; i++) {
163             char path[32], desc[64];
164             snprintf(path, sizeof(path), "Chan%d_opt_instr", i);
165             snprintf(desc, sizeof(desc), "Chan%d instrument option", i);
166             result &= m_ControlContainer->addElement(
167                 new RmeSettingsCtrl(*this, RME_CTRL_FF400_INSTR_SW, i,
168                     path, desc, ""));
169             snprintf(path, sizeof(path), "Chan%d_opt_pad", i);
170             snprintf(desc, sizeof(desc), "Chan%d pad option", i);
171             result &= m_ControlContainer->addElement(
172                 new RmeSettingsCtrl(*this, RME_CTRL_FF400_PAD_SW, i,
173                     path, desc, ""));
174         }
175
176         // Input/output gains
177         result &= m_ControlContainer->addElement(
178             new RmeSettingsMatrixCtrl(*this, RME_MATRIXCTRL_GAINS, "Gains"));
179     }
180
181     if (!result) {
182         debugWarning("One or more device control elements could not be created\n");
183         destroyMixer();
184         return false;
185     }
186
187     if (!addElement(m_ControlContainer)) {
188         debugWarning("Could not register mixer to device\n");
189         // clean up
190         destroyMixer();
191         return false;
192     }
193
194     return true;
195 }
196
197 bool
198 Device::destroyMixer() {
199     bool ret = true;
200     debugOutput(DEBUG_LEVEL_VERBOSE, "destroy mixer...\n");
201
202     if (m_MixerContainer == NULL) {
203         debugOutput(DEBUG_LEVEL_VERBOSE, "no mixer to destroy...\n");
204     } else
205     if (!deleteElement(m_MixerContainer)) {
206         debugError("Mixer present but not registered to the avdevice\n");
207         ret = false;
208     } else {
209         // remove and delete (as in free) child control elements
210         m_MixerContainer->clearElements(true);
211         delete m_MixerContainer;
212         m_MixerContainer = NULL;
213     }
214
215     // remove control container
216     if (m_ControlContainer == NULL) {
217         debugOutput(DEBUG_LEVEL_VERBOSE, "no controls to destroy...\n");
218     } else
219     if (!deleteElement(m_ControlContainer)) {
220         debugError("Controls present but not registered to the avdevice\n");
221         ret = false;
222     } else {
223         // remove and delete (as in free) child control elements
224         m_ControlContainer->clearElements(true);
225         delete m_ControlContainer;
226         m_ControlContainer = NULL;
227     }
228
229     return false;
230 }
231
232 bool
233 Device::probe( Util::Configuration& c, ConfigRom& configRom, bool generic )
234 {
235     if (generic) {
236         return false;
237     } else {
238         // check if device is in supported devices list.  Note that the RME
239         // devices use the unit version to identify the individual devices.
240         // To avoid having to extend the configuration file syntax to
241         // include this at this point, we'll use the configuration file
242         // model ID to test against the device unit version.  This can be
243         // tidied up if the configuration file is extended at some point to
244         // include the unit version.
245         unsigned int vendorId = configRom.getNodeVendorId();
246         unsigned int unitVersion = configRom.getUnitVersion();
247
248         Util::Configuration::VendorModelEntry vme = c.findDeviceVME( vendorId, unitVersion );
249         return c.isValid(vme) && vme.driver == Util::Configuration::eD_RME;
250     }
251 }
252
253 FFADODevice *
254 Device::createDevice(DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ))
255 {
256     return new Device(d, configRom );
257 }
258
259 bool
260 Device::discover()
261 {
262     signed int i;
263     unsigned int vendorId = getConfigRom().getNodeVendorId();
264     // See note in Device::probe() about why we use the unit version here.
265     unsigned int unitVersion = getConfigRom().getUnitVersion();
266
267     Util::Configuration &c = getDeviceManager().getConfiguration();
268     Util::Configuration::VendorModelEntry vme = c.findDeviceVME( vendorId, unitVersion );
269
270     if (c.isValid(vme) && vme.driver == Util::Configuration::eD_RME) {
271         debugOutput( DEBUG_LEVEL_VERBOSE, "found %s %s\n",
272                      vme.vendor_name.c_str(),
273                      vme.model_name.c_str());
274     } else {
275         debugWarning("Device '%s %s' unsupported by RME driver (no generic RME support)\n",
276                      getConfigRom().getVendorName().c_str(), getConfigRom().getModelName().c_str());
277     }
278
279     if (unitVersion == RME_UNITVERSION_FF800) {
280         m_rme_model = RME_MODEL_FIREFACE800;
281     } else
282     if (unitVersion == RME_MODEL_FIREFACE400) {
283         m_rme_model = RME_MODEL_FIREFACE400;
284     } else {
285         debugError("Unsupported model\n");
286         return false;
287     }
288
289     // Set up the shared data object for configuration data
290     i = rme_shm_open(&dev_config);
291     if (i == RSO_OPEN_CREATED) {
292         debugOutput( DEBUG_LEVEL_VERBOSE, "New configuration shared data object created\n");
293     } else
294     if (i == RSO_OPEN_ATTACHED) {
295         debugOutput( DEBUG_LEVEL_VERBOSE, "Attached to existing configuration shared data object\n");
296     }
297     if (dev_config == NULL) {
298         debugOutput( DEBUG_LEVEL_WARNING, "Could not create/access shared configuration memory object, using process-local storage\n");
299         memset(&local_dev_config_obj, 0, sizeof(local_dev_config_obj));
300         dev_config = &local_dev_config_obj;
301     }
302     settings = &dev_config->settings;
303     tco_settings = &dev_config->tco_settings;
304
305     // If device is FF800, check to see if the TCO is fitted
306     if (m_rme_model == RME_MODEL_FIREFACE800) {
307         dev_config->tco_present = (read_tco(NULL, 0) == 0);
308     }
309     debugOutput(DEBUG_LEVEL_VERBOSE, "TCO present: %s\n",
310       dev_config->tco_present?"yes":"no");
311
312     init_hardware();
313
314     if (!buildMixer()) {
315         debugWarning("Could not build mixer\n");
316     }
317
318     // This is just for testing
319     read_device_flash_settings(NULL);
320
321     return true;
322 }
323
324 int
325 Device::getSamplingFrequency( ) {
326
327     // Retrieve the current sample rate.  For practical purposes this
328     // is the software rate currently in use.
329     return dev_config->software_freq;
330 }
331
332 int
333 Device::getConfigurationId()
334 {
335     return 0;
336 }
337
338 bool
339 Device::setDDSFrequency( int dds_freq )
340 {
341     // Set a fixed DDS frequency.  If the device is the clock master this
342     // will immediately be copied to the hardware DDS register.  Otherwise
343     // it will take effect as required at the time the sampling rate is
344     // changed or streaming is started.
345
346     // If the device is streaming, the new DDS rate must have the same
347     // multiplier as the software sample rate
348     if (hardware_is_streaming()) {
349         if (multiplier_of_freq(dds_freq) != multiplier_of_freq(dev_config->software_freq))
350             return false;
351     }
352
353     dev_config->dds_freq = dds_freq;
354     if (settings->clock_mode == FF_STATE_CLOCKMODE_MASTER) {
355         if (set_hardware_dds_freq(dds_freq) != 0)
356             return false;
357     }
358
359     return true;
360 }
361
362 bool
363 Device::setSamplingFrequency( int samplingFrequency )
364 {
365     // Request a sampling rate on behalf of software.  Software is limited
366     // to sample rates of 32k, 44.1k, 48k and the 2x/4x multiples of these.
367     // The user may lock the device to a much wider range of frequencies via
368     // the explicit DDS controls in the control panel.  If the explicit DDS
369     // control is active the software is limited to the "standard" speeds
370     // corresponding to the multiplier in use by the DDS.
371     //
372     // Similarly, if the device is externally clocked the software is
373     // limited to the external clock frequency.
374     //
375     // Otherwise the software has free choice of the software speeds noted
376     // above.
377
378     bool ret = -1;
379     signed int i, j;
380     signed int mult[3] = {1, 2, 4};
381     signed int base_freq[3] = {32000, 44100, 48000};
382     signed int freq = samplingFrequency;
383     FF_state_t state;
384     signed int fixed_freq = 0;
385
386     get_hardware_state(&state);
387
388     // If device is locked to a frequency via external clock, explicit
389     // setting of the DDS or by virtue of streaming being active, get that
390     // frequency.
391     if (state.clock_mode == FF_STATE_CLOCKMODE_AUTOSYNC) {
392         // FIXME: if synced to TCO, is autosync_freq valid?
393         fixed_freq = state.autosync_freq;
394     } else
395     if (dev_config->dds_freq > 0) {
396         fixed_freq = dev_config->dds_freq;
397     } else
398     if (hardware_is_streaming()) {
399         fixed_freq = dev_config->software_freq;
400     }
401
402     // If the device is running to a fixed frequency, software can only
403     // request frequencies with the same multiplier.  Similarly, the
404     // multiplier is locked in "master" clock mode if the device is
405     // streaming.
406     if (fixed_freq > 0) {
407         signed int fixed_mult = multiplier_of_freq(fixed_freq);
408         if (multiplier_of_freq(freq) != multiplier_of_freq(fixed_freq))
409             return -1;
410         for (j=0; j<3; j++) {
411             if (freq == base_freq[j]*fixed_mult) {
412                 ret = 0;
413                 break;
414             }
415         }
416     } else {
417         for (i=0; i<3; i++) {
418             for (j=0; j<3; j++) {
419                 if (freq == base_freq[j]*mult[i]) {
420                     ret = 0;
421                     break;
422                 }
423             }
424         }
425     }
426     // If requested frequency is unavailable, return -1
427     if (ret == -1)
428         return false;
429
430     // If a DDS frequency has been explicitly requested this is always
431     // used to programm the hardware DDS regardless of the rate requested
432     // by the software.  Otherwise we use the requested sampling rate.
433     if (dev_config->dds_freq > 0)
434         freq = dev_config->dds_freq;
435     if (set_hardware_dds_freq(freq) != 0)
436         return false;
437
438     dev_config->software_freq = samplingFrequency;
439     return true;
440 }
441
442 std::vector<int>
443 Device::getSupportedSamplingFrequencies()
444 {
445     std::vector<int> frequencies;
446     signed int i, j;
447     signed int mult[3] = {1, 2, 4};
448     signed int freq[3] = {32000, 44100, 48000};
449     FF_state_t state;
450
451     get_hardware_state(&state);
452
453     // Generate the list of supported frequencies.  If the device is
454     // externally clocked the frequency is limited to the external clock
455     // frequency.  If the device is running the multiplier is fixed.
456     if (state.clock_mode == FF_STATE_CLOCKMODE_AUTOSYNC) {
457         // FIXME: if synced to TCO, is autosync_freq valid?
458         frequencies.push_back(state.autosync_freq);
459     } else
460     if (state.is_streaming) {
461         unsigned int fixed_mult = multiplier_of_freq(dev_config->software_freq);
462         for (j=0; j<3; j++) {
463             frequencies.push_back(freq[j]*fixed_mult);
464         }
465     } else {
466         for (i=0; i<3; i++) {
467             for (j=0; j<3; j++) {
468                 frequencies.push_back(freq[j]*mult[i]);
469             }
470         }
471     }
472     return frequencies;
473 }
474
475 FFADODevice::ClockSourceVector
476 Device::getSupportedClockSources() {
477     FFADODevice::ClockSourceVector r;
478     return r;
479 }
480
481 bool
482 Device::setActiveClockSource(ClockSource s) {
483     return false;
484 }
485
486 FFADODevice::ClockSource
487 Device::getActiveClockSource() {
488     ClockSource s;
489     return s;
490 }
491
492 bool
493 Device::lock() {
494
495     return true;
496 }
497
498
499 bool
500 Device::unlock() {
501
502     return true;
503 }
504
505 void
506 Device::showDevice()
507 {
508     unsigned int vendorId = getConfigRom().getNodeVendorId();
509     unsigned int modelId = getConfigRom().getModelId();
510
511     Util::Configuration &c = getDeviceManager().getConfiguration();
512     Util::Configuration::VendorModelEntry vme = c.findDeviceVME( vendorId, modelId );
513
514     debugOutput(DEBUG_LEVEL_VERBOSE,
515         "%s %s at node %d\n", vme.vendor_name.c_str(), vme.model_name.c_str(), getNodeId());
516 }
517
518 bool
519 Device::prepare() {
520
521     signed int mult, bandwidth;
522     signed int freq;
523     signed int err = 0;
524
525     debugOutput(DEBUG_LEVEL_NORMAL, "Preparing Device...\n" );
526
527     freq = getSamplingFrequency();
528     if (freq <= 0) {
529         debugOutput(DEBUG_LEVEL_ERROR, "Can't continue: sampling frequency not set\n");
530         return false;
531     }
532
533     // The number of frames transmitted in a single packet is solely
534     // determined by the sample rate.
535     mult = multiplier_of_freq(getSamplingFrequency());
536     switch (mult) {
537         case 2: frames_per_packet = 15; break;
538         case 4: frames_per_packet = 25; break;
539     default:
540         frames_per_packet = 7;
541     }
542
543     // The number of active channels depends on sample rate and whether
544     // bandwidth limitation is active.  First set up the number of analog
545     // channels (which differs between devices), then add SPDIF channels if
546     // relevant.  Finally, the number of channels available from each ADAT
547     // interface depends on sample rate: 0 at 4x, 4 at 2x and 8 at 1x.
548     if (m_rme_model == RME_MODEL_FIREFACE800)
549         num_channels = 10;
550     else
551         num_channels = 8;
552     if (settings->limit_bandwidth != FF_SWPARAM_BWLIMIT_ANALOG_ONLY)
553         num_channels += 2;
554     if (settings->limit_bandwidth==FF_SWPARAM_BWLIMIT_NO_ADAT2 ||
555         settings->limit_bandwidth==FF_SWPARAM_BWLIMIT_SEND_ALL_CHANNELS)
556         num_channels += (mult==4?0:(mult==2?4:8));
557     if (settings->limit_bandwidth==FF_SWPARAM_BWLIMIT_SEND_ALL_CHANNELS)
558         num_channels += (mult==4?0:(mult==2?4:8));
559
560     // Bandwidth is calculated here.  For the moment we assume the device
561     // is connected at S400, so 1 allocation unit is 1 transmitted byte.
562     // There is 25 allocation units of protocol overhead per packet.  Each
563     // channel of audio data is sent/received as a 32 bit integer.
564     bandwidth = 25 + num_channels*4*frames_per_packet;
565
566     // Both the FF400 and FF800 require we allocate a tx iso channel.  The
567     // rx channel is also allocated for the FF400.  The FF800 chooses
568     // the rx channel to be used but does not handle the bus-level
569     // channel/bandwidth allocation.
570     if (iso_tx_channel < 0) {
571         iso_tx_channel = get1394Service().allocateIsoChannelGeneric(bandwidth);
572     }
573
574     if (iso_rx_channel < 0) {
575         if (m_rme_model == RME_MODEL_FIREFACE800) {
576             unsigned int stat[4];
577             get_hardware_streaming_status(stat, 4);
578             // CHECKME: does this work before streaming has been initialised?
579             iso_rx_channel = stat[2] & 63;
580             iso_rx_channel = get1394Service().allocateFixedIsoChannelGeneric(iso_rx_channel, bandwidth);
581         } else {
582             iso_rx_channel = get1394Service().allocateIsoChannelGeneric(bandwidth);
583         }
584     }
585  
586     if (iso_tx_channel>=0 && iso_rx_channel>=0) {
587         err = hardware_init_streaming(dev_config->hardware_freq, iso_tx_channel) != 0;
588         if (err) {
589             debugFatal("Could not intialise device streaming system\n");
590         }
591     } else {
592         err = 1;
593         debugFatal("Could not allocate iso channels\n");
594     }
595
596     if (err) {
597         if (iso_tx_channel >= 0)
598             get1394Service().freeIsoChannel(iso_tx_channel);
599         if (iso_rx_channel >= 0)
600             get1394Service().freeIsoChannel(iso_rx_channel);
601         return false;
602     }
603
604     // get the device specific and/or global SP configuration
605     Util::Configuration &config = getDeviceManager().getConfiguration();
606     // base value is the config.h value
607     float recv_sp_dll_bw = STREAMPROCESSOR_DLL_BW_HZ;
608     float xmit_sp_dll_bw = STREAMPROCESSOR_DLL_BW_HZ;
609
610     // we can override that globally
611     config.getValueForSetting("streaming.spm.recv_sp_dll_bw", recv_sp_dll_bw);
612     config.getValueForSetting("streaming.spm.xmit_sp_dll_bw", xmit_sp_dll_bw);
613
614     // or override in the device section
615     config.getValueForDeviceSetting(getConfigRom().getNodeVendorId(), getConfigRom().getModelId(), "recv_sp_dll_bw", recv_sp_dll_bw);
616     config.getValueForDeviceSetting(getConfigRom().getNodeVendorId(), getConfigRom().getModelId(), "xmit_sp_dll_bw", xmit_sp_dll_bw);
617
618     // Set up receive stream processor, initialise it and set DLL bw
619     // TODO: set event_size properly; the value below is just a placeholder.
620     signed int event_size = 0x150;
621     #warning event_size needs setting up
622     m_receiveProcessor = new Streaming::RmeReceiveStreamProcessor(*this,
623       m_rme_model, event_size);
624     m_receiveProcessor->setVerboseLevel(getDebugLevel());
625     if (!m_receiveProcessor->init()) {
626         debugFatal("Could not initialize receive processor!\n");
627         return false;
628     }
629     if (!m_receiveProcessor->setDllBandwidth(recv_sp_dll_bw)) {
630         debugFatal("Could not set DLL bandwidth\n");
631         delete m_receiveProcessor;
632         m_receiveProcessor = NULL;
633         return false;
634     }
635
636
637     // Add ports to the processor - TODO
638     std::string id=std::string("dev?");
639     if (!getOption("id", id)) {
640         debugWarning("Could not retrieve id parameter, defaulting to 'dev?'\n");
641     }
642
643     // Other things to be done:
644     //  * create a transmit stream processor, set DLL bandwidth, add ports
645
646     return true;
647 }
648
649 int
650 Device::getStreamCount() {
651 // Only rx implemented at present
652         return 1; // one receive, one transmit
653 }
654
655 Streaming::StreamProcessor *
656 Device::getStreamProcessorByIndex(int i) {
657     switch (i) {
658         case 0:
659             return m_receiveProcessor;
660         case 1:
661             return m_transmitProcessor;
662         default:
663             debugWarning("Invalid stream index %d\n", i);
664     }
665     return NULL;
666 }
667
668 bool
669 Device::startStreamByIndex(int i) {
670     // The RME does not allow separate enabling of the transmit and receive
671     // streams.  Therefore we start all streaming when index 0 is referenced
672     // and silently ignore the start requests for other streams
673     // (unconditionally flagging them as being successful).
674     if (i == 0) {
675         m_receiveProcessor->setChannel(iso_rx_channel);
676         // m_transmitProcessor->setChannel(iso_tx_channel);
677         if (hardware_start_streaming(iso_rx_channel) != 0)
678             return false;
679     }
680     return true;
681 }
682
683 bool
684 Device::stopStreamByIndex(int i) {
685     // See comments in startStreamByIndex() as to why we act only when stream
686     // 0 is requested.
687     if (i == 0) {
688         if (hardware_stop_streaming() != 0)
689             return false;
690     }
691     return true;
692 }
693
694 unsigned int
695 Device::readRegister(fb_nodeaddr_t reg) {
696
697     quadlet_t quadlet;
698    
699     quadlet = 0;
700     if (get1394Service().read(0xffc0 | getNodeId(), reg, 1, &quadlet) <= 0) {
701         debugError("Error doing RME read from register 0x%06x\n",reg);
702     }
703     return ByteSwapFromDevice32(quadlet);
704 }
705
706 signed int
707 Device::readBlock(fb_nodeaddr_t reg, quadlet_t *buf, unsigned int n_quads) {
708
709     unsigned int i;
710
711     if (get1394Service().read(0xffc0 | getNodeId(), reg, n_quads, buf) <= 0) {
712         debugError("Error doing RME block read of %d quadlets from register 0x%06x\n",
713             n_quads, reg);
714         return -1;
715     }
716     for (i=0; i<n_quads; i++) {
717        buf[i] = ByteSwapFromDevice32(buf[i]);
718     }
719
720     return 0;
721 }
722
723 signed int
724 Device::writeRegister(fb_nodeaddr_t reg, quadlet_t data) {
725
726     unsigned int err = 0;
727     data = ByteSwapToDevice32(data);
728     if (get1394Service().write(0xffc0 | getNodeId(), reg, 1, &data) <= 0) {
729         err = 1;
730         debugError("Error doing RME write to register 0x%06x\n",reg);
731     }
732     return (err==0)?0:-1;
733 }
734
735 signed int
736 Device::writeBlock(fb_nodeaddr_t reg, quadlet_t *data, unsigned int n_quads) {
737 //
738 // Write a block of data to the device starting at address "reg".  Note that
739 // the conditional byteswap is done "in place" on data, so the contents of
740 // data may be modified by calling this function.
741 //
742     unsigned int err = 0;
743     unsigned int i;
744
745     for (i=0; i<n_quads; i++) {
746       data[i] = ByteSwapToDevice32(data[i]);
747     }
748     if (get1394Service().write(0xffc0 | getNodeId(), reg, n_quads, data) <= 0) {
749         err = 1;
750         debugError("Error doing RME block write of %d quadlets to register 0x%06x\n",
751           n_quads, reg);
752     }
753     return (err==0)?0:-1;
754 }
755                  
756 }
Note: See TracBrowser for help on using the browser.