Changeset 1294
- Timestamp:
- 07/13/08 15:26:12 (16 years ago)
- Files:
-
- branches/libffado-2.0/src/bebob/focusrite/focusrite_saffirepro.cpp (modified) (14 diffs)
- branches/libffado-2.0/src/bebob/focusrite/focusrite_saffirepro.h (modified) (1 diff)
- branches/libffado-2.0/src/libieee1394/ieee1394service.cpp (modified) (1 diff)
- branches/libffado-2.0/src/libieee1394/ieee1394service.h (modified) (1 diff)
- branches/libffado-2.0/src/libieee1394/IsoHandler.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/libffado-2.0/src/bebob/focusrite/focusrite_saffirepro.cpp
r1292 r1294 26 26 27 27 #include "devicemanager.h" 28 #include "libutil/ Time.h"28 #include "libutil/SystemTimeSource.h" 29 29 30 30 #include "libutil/ByteSwap.h" … … 367 367 void 368 368 SaffireProDevice::updateClockSources() { 369 m_active_clocksource = &m_internal_clocksource; 370 369 371 m_internal_clocksource.type = FFADODevice::eCT_Internal; 372 m_internal_clocksource.active = false; 370 373 m_internal_clocksource.valid = true; 371 374 m_internal_clocksource.locked = true; … … 375 378 376 379 m_spdif_clocksource.type = FFADODevice::eCT_SPDIF; 380 m_spdif_clocksource.active = false; 377 381 m_spdif_clocksource.valid = true; 378 382 m_spdif_clocksource.locked = false; … … 382 386 383 387 m_wordclock_clocksource.type = FFADODevice::eCT_WordClock; 388 m_wordclock_clocksource.active = false; 384 389 m_wordclock_clocksource.valid = true; 385 390 m_wordclock_clocksource.locked = false; … … 390 395 if(isPro26()) { 391 396 m_adat1_clocksource.type = FFADODevice::eCT_ADAT; 397 m_adat1_clocksource.active = false; 392 398 m_adat1_clocksource.valid = true; 393 399 m_adat1_clocksource.locked = false; … … 397 403 398 404 m_adat2_clocksource.type = FFADODevice::eCT_ADAT; 405 m_adat2_clocksource.active = false; 399 406 m_adat2_clocksource.valid = true; 400 407 m_adat2_clocksource.locked = false; … … 403 410 m_adat2_clocksource.description = "ADAT 2"; 404 411 } 405 } 406 407 FFADODevice::ClockSource 408 SaffireProDevice::getActiveClockSource() 409 { 412 413 // figure out the active source 410 414 uint32_t sync; 411 415 if ( !getSpecificValue(FR_SAFFIREPRO_CMD_ID_SYNC_CONFIG, &sync ) ){ 412 416 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) { 429 423 default: 430 424 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 467 FFADODevice::ClockSource 468 SaffireProDevice::getActiveClockSource() 469 { 470 updateClockSources(); 471 return *m_active_clocksource; 433 472 } 434 473 … … 436 475 SaffireProDevice::setActiveClockSource(ClockSource s) 437 476 { 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); 438 482 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(); 442 497 return true; 443 498 } … … 446 501 SaffireProDevice::getSupportedClockSources() 447 502 { 503 debugOutput(DEBUG_LEVEL_VERBOSE, "listing...\n"); 448 504 FFADODevice::ClockSourceVector r; 449 505 r.push_back(m_internal_clocksource); … … 591 647 592 648 // the device needs quite some time to reboot 593 SleepRelativeUsec(2 * 1000 * 1000);649 Util::SystemTimeSource::SleepUsecRelative(2 * 1000 * 1000); 594 650 595 651 int timeout = 5; // multiples of 1s … … 599 655 { 600 656 // wait for a while 601 SleepRelativeUsec(1000 * 1000);657 Util::SystemTimeSource::SleepUsecRelative(1000 * 1000); 602 658 } 603 659 if (!timeout) { … … 606 662 607 663 // the device needs quite some time to reboot 608 SleepRelativeUsec(2 * 1000 * 1000);664 Util::SystemTimeSource::SleepUsecRelative(2 * 1000 * 1000); 609 665 610 666 // wait for the device to finish the reboot … … 614 670 { 615 671 // wait for a while 616 SleepRelativeUsec(1000 * 1000);672 Util::SystemTimeSource::SleepUsecRelative(1000 * 1000); 617 673 } 618 674 if (!timeout) { … … 625 681 // so we know the device is rebooting 626 682 // 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"); 640 685 getDeviceManager().unlockBusResetHandler(); 641 686 return false; 642 687 } 643 644 688 debugOutput(DEBUG_LEVEL_VERBOSE, "Device available (gen: %u => %u)...\n", 645 689 gen_before, get1394Service().getGeneration()); 646 690 647 691 // wait some more 648 SleepRelativeUsec(1 * 1000 * 1000);692 Util::SystemTimeSource::SleepUsecRelative(1 * 1000 * 1000); 649 693 650 694 // we have to rediscover the device branches/libffado-2.0/src/bebob/focusrite/focusrite_saffirepro.h
r1249 r1294 421 421 ClockSource m_adat1_clocksource; 422 422 ClockSource m_adat2_clocksource; 423 ClockSource *m_active_clocksource; 423 424 424 425 Control::Container *m_MixerContainer; branches/libffado-2.0/src/libieee1394/ieee1394service.cpp
r1292 r1294 147 147 debugOutput(DEBUG_LEVEL_VERBOSE, "Issue bus reset on service %p (port %d).\n", this, getPort()); 148 148 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 */ 157 bool 158 Ieee1394Service::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; 149 173 } 150 174 branches/libffado-2.0/src/libieee1394/ieee1394service.h
r1292 r1294 233 233 234 234 void doBusReset(); 235 bool waitForBusResetStormToEnd( int nb_tries, int sleep_time_ms ); 235 236 236 237 /** branches/libffado-2.0/src/libieee1394/IsoHandler.cpp
r1292 r1294 442 442 && dropped_cycles == 0) 443 443 { 444 debugOutput(DEBUG_LEVEL_VER BOSE, "Special non-unwrapping happened\n");444 debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "Special non-unwrapping happened\n"); 445 445 } 446 446 #endif