Changeset 1294

Show
Ignore:
Timestamp:
07/13/08 15:26:12 (16 years ago)
Author:
ppalmers
Message:

(re: #145) try to fix focusrite saffire pro clock source selection. Not 100% sure it works properly though.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/libffado-2.0/src/bebob/focusrite/focusrite_saffirepro.cpp

    r1292 r1294  
    2626 
    2727#include "devicemanager.h" 
    28 #include "libutil/Time.h" 
     28#include "libutil/SystemTimeSource.h" 
    2929 
    3030#include "libutil/ByteSwap.h" 
     
    367367void 
    368368SaffireProDevice::updateClockSources() { 
     369    m_active_clocksource = &m_internal_clocksource; 
     370 
    369371    m_internal_clocksource.type = FFADODevice::eCT_Internal; 
     372    m_internal_clocksource.active = false; 
    370373    m_internal_clocksource.valid = true; 
    371374    m_internal_clocksource.locked = true; 
     
    375378 
    376379    m_spdif_clocksource.type = FFADODevice::eCT_SPDIF; 
     380    m_spdif_clocksource.active = false; 
    377381    m_spdif_clocksource.valid = true; 
    378382    m_spdif_clocksource.locked = false; 
     
    382386 
    383387    m_wordclock_clocksource.type = FFADODevice::eCT_WordClock; 
     388    m_wordclock_clocksource.active = false; 
    384389    m_wordclock_clocksource.valid = true; 
    385390    m_wordclock_clocksource.locked = false; 
     
    390395    if(isPro26()) { 
    391396        m_adat1_clocksource.type = FFADODevice::eCT_ADAT; 
     397        m_adat1_clocksource.active = false; 
    392398        m_adat1_clocksource.valid = true; 
    393399        m_adat1_clocksource.locked = false; 
     
    397403 
    398404        m_adat2_clocksource.type = FFADODevice::eCT_ADAT; 
     405        m_adat2_clocksource.active = false; 
    399406        m_adat2_clocksource.valid = true; 
    400407        m_adat2_clocksource.locked = false; 
     
    403410        m_adat2_clocksource.description = "ADAT 2"; 
    404411    } 
    405 
    406  
    407 FFADODevice::ClockSource 
    408 SaffireProDevice::getActiveClockSource() 
    409 
     412 
     413    // figure out the active source 
    410414    uint32_t sync; 
    411415    if ( !getSpecificValue(FR_SAFFIREPRO_CMD_ID_SYNC_CONFIG, &sync ) ){ 
    412416        debugError( "getSpecificValue failed\n" ); 
    413         return ClockSource(); 
    414     } 
    415  
    416     updateClockSources(); // make sure the current state is reflected in the clocksources 
    417  
    418     switch(sync) { 
    419         case FR_SAFFIREPRO_CMD_SYNC_CONFIG_INTERNAL: 
    420             return m_internal_clocksource; 
    421         case FR_SAFFIREPRO_CMD_SYNC_CONFIG_SPDIF: 
    422             return m_spdif_clocksource; 
    423         case FR_SAFFIREPRO_CMD_SYNC_CONFIG_ADAT1: 
    424             return m_adat1_clocksource; 
    425         case FR_SAFFIREPRO_CMD_SYNC_CONFIG_ADAT2: 
    426             return m_adat2_clocksource; 
    427         case FR_SAFFIREPRO_CMD_SYNC_CONFIG_WORDCLOCK: 
    428             return m_wordclock_clocksource; 
     417        m_internal_clocksource.active=true; 
     418        return; 
     419    } 
     420    debugOutput(DEBUG_LEVEL_VERBOSE, "SYNC_CONFIG field value: %08lX\n", sync ); 
     421 
     422    switch(sync & 0xFF) { 
    429423        default: 
    430424            debugWarning( "Unexpected SYNC_CONFIG field value: %08lX\n", sync ); 
    431             return ClockSource(); 
    432     } 
     425        case FR_SAFFIREPRO_CMD_SYNC_CONFIG_INTERNAL: 
     426            m_internal_clocksource.active=true; 
     427            m_active_clocksource = &m_internal_clocksource; 
     428            break; 
     429        case FR_SAFFIREPRO_CMD_SYNC_CONFIG_SPDIF: 
     430            m_spdif_clocksource.active=true; 
     431            m_active_clocksource = &m_spdif_clocksource; 
     432            break; 
     433        case FR_SAFFIREPRO_CMD_SYNC_CONFIG_ADAT1: 
     434            m_wordclock_clocksource.active=true; 
     435            m_active_clocksource = &m_wordclock_clocksource; 
     436            break; 
     437        case FR_SAFFIREPRO_CMD_SYNC_CONFIG_ADAT2: 
     438            m_adat1_clocksource.active=true; 
     439            m_active_clocksource = &m_adat1_clocksource; 
     440            break; 
     441        case FR_SAFFIREPRO_CMD_SYNC_CONFIG_WORDCLOCK: 
     442            m_adat2_clocksource.active=true; 
     443            m_active_clocksource = &m_adat2_clocksource; 
     444            break; 
     445    } 
     446    switch((sync >> 8) & 0xFF) { 
     447        case FR_SAFFIREPRO_CMD_SYNC_CONFIG_INTERNAL: 
     448            // always locked 
     449            break; 
     450        case FR_SAFFIREPRO_CMD_SYNC_CONFIG_SPDIF: 
     451            m_spdif_clocksource.locked=true; 
     452            break; 
     453        case FR_SAFFIREPRO_CMD_SYNC_CONFIG_ADAT1: 
     454            m_wordclock_clocksource.locked=true; 
     455            break; 
     456        case FR_SAFFIREPRO_CMD_SYNC_CONFIG_ADAT2: 
     457            m_adat1_clocksource.locked=true; 
     458            break; 
     459        case FR_SAFFIREPRO_CMD_SYNC_CONFIG_WORDCLOCK: 
     460            m_adat2_clocksource.locked=true; 
     461            break; 
     462        default: 
     463            debugWarning( "Unexpected SYNC_CONFIG_STATE field value: %08lX\n", sync ); 
     464    } 
     465
     466 
     467FFADODevice::ClockSource 
     468SaffireProDevice::getActiveClockSource() 
     469
     470    updateClockSources(); 
     471    return *m_active_clocksource; 
    433472} 
    434473 
     
    436475SaffireProDevice::setActiveClockSource(ClockSource s) 
    437476{ 
     477    // prevent busresets from being handled immediately 
     478    getDeviceManager().lockBusResetHandler(); 
     479    unsigned int gen_before = get1394Service().getGeneration(); 
     480 
     481    debugOutput(DEBUG_LEVEL_VERBOSE, "set active source to %d...\n", s.id); 
    438482    if ( !setSpecificValue(FR_SAFFIREPRO_CMD_ID_SYNC_CONFIG, s.id ) ){ 
    439         debugError( "detSpecificValue failed\n" ); 
    440         return false; 
    441     } 
     483        debugError( "setSpecificValue failed\n" ); 
     484        getDeviceManager().unlockBusResetHandler(); 
     485        return false; 
     486    } 
     487 
     488    // the device can do a bus reset at this moment 
     489    Util::SystemTimeSource::SleepUsecRelative(1000 * 1000); 
     490    if(!get1394Service().waitForBusResetStormToEnd(10, 2000)) { 
     491        debugWarning("Device doesn't stop bus-resetting\n"); 
     492    } 
     493    unsigned int gen_after = get1394Service().getGeneration(); 
     494    debugOutput(DEBUG_LEVEL_VERBOSE, " gen: %d=>%d\n", gen_before, gen_after); 
     495 
     496    getDeviceManager().unlockBusResetHandler(); 
    442497    return true; 
    443498} 
     
    446501SaffireProDevice::getSupportedClockSources() 
    447502{ 
     503    debugOutput(DEBUG_LEVEL_VERBOSE, "listing...\n"); 
    448504    FFADODevice::ClockSourceVector r; 
    449505    r.push_back(m_internal_clocksource); 
     
    591647 
    592648                // the device needs quite some time to reboot 
    593                 SleepRelativeUsec(2 * 1000 * 1000); 
     649                Util::SystemTimeSource::SleepUsecRelative(2 * 1000 * 1000); 
    594650 
    595651                int timeout = 5; // multiples of 1s 
     
    599655                { 
    600656                    // wait for a while 
    601                     SleepRelativeUsec(1000 * 1000); 
     657                    Util::SystemTimeSource::SleepUsecRelative(1000 * 1000); 
    602658                } 
    603659                if (!timeout) { 
     
    606662 
    607663                    // the device needs quite some time to reboot 
    608                     SleepRelativeUsec(2 * 1000 * 1000); 
     664                    Util::SystemTimeSource::SleepUsecRelative(2 * 1000 * 1000); 
    609665 
    610666                    // wait for the device to finish the reboot 
     
    614670                    { 
    615671                        // wait for a while 
    616                         SleepRelativeUsec(1000 * 1000); 
     672                        Util::SystemTimeSource::SleepUsecRelative(1000 * 1000); 
    617673                    } 
    618674                    if (!timeout) { 
     
    625681                // so we know the device is rebooting 
    626682                // now wait until it stops generating busresets 
    627                 timeout = 10; 
    628                 unsigned int gen_current; 
    629                 do { 
    630                     gen_current=get1394Service().getGeneration(); 
    631                     debugOutput(DEBUG_LEVEL_VERBOSE, "Waiting... (gen: %u)\n", gen_current); 
    632  
    633                     // wait for a while 
    634                     SleepRelativeUsec(4 * 1000 * 1000); 
    635                 } while (gen_current != get1394Service().getGeneration() 
    636                          && --timeout); 
    637  
    638                 if (!timeout) { 
    639                     debugError( "Device did not recover from reboot...\n"); 
     683                if(!get1394Service().waitForBusResetStormToEnd(20, 4000)) { 
     684                    debugError("The device keeps behaving like a pig...\n"); 
    640685                    getDeviceManager().unlockBusResetHandler(); 
    641686                    return false; 
    642687                } 
    643  
    644688                debugOutput(DEBUG_LEVEL_VERBOSE, "Device available (gen: %u => %u)...\n",  
    645689                    gen_before, get1394Service().getGeneration()); 
    646690 
    647691                // wait some more 
    648                 SleepRelativeUsec(1 * 1000 * 1000); 
     692                Util::SystemTimeSource::SleepUsecRelative(1 * 1000 * 1000); 
    649693 
    650694                // we have to rediscover the device 
  • branches/libffado-2.0/src/bebob/focusrite/focusrite_saffirepro.h

    r1249 r1294  
    421421    ClockSource m_adat1_clocksource; 
    422422    ClockSource m_adat2_clocksource; 
     423    ClockSource *m_active_clocksource; 
    423424 
    424425    Control::Container *m_MixerContainer; 
  • branches/libffado-2.0/src/libieee1394/ieee1394service.cpp

    r1292 r1294  
    147147    debugOutput(DEBUG_LEVEL_VERBOSE, "Issue bus reset on service %p (port %d).\n", this, getPort()); 
    148148    raw1394_reset_bus(m_handle); 
     149} 
     150 
     151/** 
     152 * This function waits until there are no bus resets generated in a sleep_time_ms interval 
     153 * @param nb_tries number of tries to take 
     154 * @param sleep_time_ms sleep between tries 
     155 * @return true if the storm passed 
     156 */ 
     157bool 
     158Ieee1394Service::waitForBusResetStormToEnd( int nb_tries, int sleep_time_ms ) { 
     159    unsigned int gen_current; 
     160    do { 
     161        gen_current = getGeneration(); 
     162        debugOutput(DEBUG_LEVEL_VERBOSE, "Waiting... (gen: %u)\n", gen_current); 
     163 
     164        // wait for a while 
     165        Util::SystemTimeSource::SleepUsecRelative( sleep_time_ms * 1000); 
     166    } while (gen_current != getGeneration() && --nb_tries); 
     167 
     168    if (!nb_tries) { 
     169        debugError( "Bus reset storm did not stop on time...\n"); 
     170        return false; 
     171    } 
     172    return true; 
    149173} 
    150174 
  • branches/libffado-2.0/src/libieee1394/ieee1394service.h

    r1292 r1294  
    233233 
    234234    void doBusReset(); 
     235    bool waitForBusResetStormToEnd( int nb_tries, int sleep_time_ms ); 
    235236 
    236237    /** 
  • branches/libffado-2.0/src/libieee1394/IsoHandler.cpp

    r1292 r1294  
    442442        && dropped_cycles == 0)  
    443443    { 
    444         debugOutput(DEBUG_LEVEL_VERBOSE, "Special non-unwrapping happened\n"); 
     444        debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "Special non-unwrapping happened\n"); 
    445445    } 
    446446    #endif