Index: /trunk/libffado/src/rme/fireface_def.h =================================================================== --- /trunk/libffado/src/rme/fireface_def.h (revision 1657) +++ /trunk/libffado/src/rme/fireface_def.h (revision 1689) @@ -299,4 +299,5 @@ #define SR0_AUTOSYNC_SRC_WCLK SR0_SEL_SYNC_REF2 #define SR0_AUTOSYNC_SRC_TCO (SR0_SEL_SYNC_REF0|SR0_SEL_SYNC_REF2) +#define SR0_AUTOSYNC_SRC_NONE (SR0_SEL_SYNC_REF1|SR0_SEL_SYNC_REF2) #define SR0_AUTOSYNC_FREQ_MASK (SR0_INP_FREQ0|SR0_INP_FREQ1|SR0_INP_FREQ2|SR0_INP_FREQ3) Index: /trunk/libffado/src/rme/rme_avdevice.cpp =================================================================== --- /trunk/libffado/src/rme/rme_avdevice.cpp (revision 1688) +++ /trunk/libffado/src/rme/rme_avdevice.cpp (revision 1689) @@ -520,6 +520,7 @@ signed int mult, bandwidth; - signed int freq; + signed int freq, init_samplerate; signed int err = 0; + unsigned int stat[4]; debugOutput(DEBUG_LEVEL_NORMAL, "Preparing Device...\n" ); @@ -533,5 +534,5 @@ // The number of frames transmitted in a single packet is solely // determined by the sample rate. - mult = multiplier_of_freq(getSamplingFrequency()); + mult = multiplier_of_freq(freq); switch (mult) { case 2: frames_per_packet = 15; break; @@ -564,34 +565,51 @@ bandwidth = 25 + num_channels*4*frames_per_packet; - // Both the FF400 and FF800 require we allocate a tx iso channel. The - // rx channel is also allocated for the FF400. The FF800 chooses - // the rx channel to be used but does not handle the bus-level - // channel/bandwidth allocation. + // Both the FF400 and FF800 require we allocate a tx iso channel and + // then initialise the device. Device status is then read at least once + // regardless of which interface is in use. The rx channel is then + // allocated for the FF400 or acquired from the device in the case of + // the FF800. Even though the FF800 chooses the rx channel it does not + // handle the bus-level channel/bandwidth allocation so we must do that + // here. if (iso_tx_channel < 0) { iso_tx_channel = get1394Service().allocateIsoChannelGeneric(bandwidth); } - - if (iso_rx_channel < 0) { - if (m_rme_model == RME_MODEL_FIREFACE800) { - unsigned int stat[4]; - get_hardware_streaming_status(stat, 4); - // CHECKME: does this work before streaming has been initialised? - iso_rx_channel = stat[2] & 63; - iso_rx_channel = get1394Service().allocateFixedIsoChannelGeneric(iso_rx_channel, bandwidth); - } else { - iso_rx_channel = get1394Service().allocateIsoChannelGeneric(bandwidth); + if (iso_tx_channel < 0) { + debugFatal("Could not allocate iso tx channel\n"); + return false; + } + + err = hardware_init_streaming(dev_config->hardware_freq, iso_tx_channel) != 0; + if (err) { + debugFatal("Could not intialise device streaming system\n"); + } + + if (err == 0) { + signed int i; + for (i=0; i<100; i++) { + err = (get_hardware_streaming_status(stat, 4) != 0); + if (err) { + debugFatal("error reading status register\n"); + break; + } + if (m_rme_model == RME_MODEL_FIREFACE400) { + iso_rx_channel = get1394Service().allocateIsoChannelGeneric(bandwidth); + break; + } + // The Fireface-800 chooses its tx channel (our rx channel). + if (stat[2] == -1) { + // Device not ready; wait 5 ms and try again + usleep(5000); + } else { + iso_rx_channel = stat[2] & 63; + iso_rx_channel = get1394Service().allocateFixedIsoChannelGeneric(iso_rx_channel, bandwidth); + } } + if (iso_rx_channel < 0) { + debugFatal("Could not allocate/determine iso rx channel\n"); + err = 1; + } } - if (iso_tx_channel>=0 && iso_rx_channel>=0) { - err = hardware_init_streaming(dev_config->hardware_freq, iso_tx_channel) != 0; - if (err) { - debugFatal("Could not intialise device streaming system\n"); - } - } else { - err = 1; - debugFatal("Could not allocate iso channels\n"); - } - if (err) { if (iso_tx_channel >= 0) @@ -602,4 +620,15 @@ } + if ((stat[1] & SR1_CLOCK_MODE_MASTER) || + (stat[0] & SR0_AUTOSYNC_FREQ_MASK)==0 || + (stat[0] & SR0_AUTOSYNC_SRC_MASK)==SR0_AUTOSYNC_SRC_NONE) { + init_samplerate = dev_config->hardware_freq; + } else { + init_samplerate = (stat[0] & SR0_STREAMING_FREQ_MASK) * 250; + } + + debugOutput(DEBUG_LEVEL_VERBOSE, "sample rate on start: %d\n", + init_samplerate); + // get the device specific and/or global SP configuration Util::Configuration &config = getDeviceManager().getConfiguration(); @@ -618,5 +647,5 @@ // Set up receive stream processor, initialise it and set DLL bw // TODO: set event_size properly; the value below is just a placeholder. - signed int event_size = 0x150; + signed int event_size = 0x1000; #warning event_size needs setting up m_receiveProcessor = new Streaming::RmeReceiveStreamProcessor(*this,