2
2
* Copyright (C) 2005-2008 by Daniel Wagner
3
3
* Copyright (C) 2005-2008 by Pieter Palmers
4
* Copyright (C) 2012 by Jonathan Woithe
5
6
* This file is part of FFADO
6
7
* FFADO = Free Firewire (pro-)audio drivers for linux
47
48
#include <iostream>
51
// Permit linking against older libraw1394 which didn't include this
55
#define WEAK_ATTRIBUTE weak_import
57
#define WEAK_ATTRIBUTE __weak__
59
int raw1394_read_cycle_timer_and_clock(raw1394handle_t handle,
60
u_int32_t *cycle_timer, u_int64_t *local_time, clockid_t clk_id)
61
__attribute__((WEAK_ATTRIBUTE));
50
64
using namespace std;
52
66
IMPL_DEBUG_MODULE( Ieee1394Service, Ieee1394Service, DEBUG_LEVEL_NORMAL );
318
332
uint32_t cycle_timer;
319
333
uint64_t local_time;
334
m_have_read_ctr_and_clock = false;
320
335
err = raw1394_read_cycle_timer(m_util_handle, &cycle_timer, &local_time);
322
337
debugOutput(DEBUG_LEVEL_VERBOSE, "raw1394_read_cycle_timer failed.\n");
329
344
debugWarning("==================================================================\n");
330
345
m_have_new_ctr_read = false;
332
debugOutput(DEBUG_LEVEL_VERBOSE, "This system supports the raw1394_read_cycle_timer call, using it.\n");
333
347
m_have_new_ctr_read = true;
349
// Only if raw1394_read_cycle_timer() is present is it worth even
350
// considering the option that raw1394_read_cycle_timer_and_clock()
351
// might be available.
352
if (raw1394_read_cycle_timer_and_clock != NULL) {
353
err = raw1394_read_cycle_timer_and_clock(m_util_handle, &cycle_timer, &local_time, CLOCK_MONOTONIC);
354
if (!err && Util::SystemTimeSource::setSource(CLOCK_MONOTONIC)==true)
355
m_have_read_ctr_and_clock = true;
358
if (m_have_read_ctr_and_clock) {
359
debugOutput(DEBUG_LEVEL_VERBOSE, "This system supports the raw1394_read_cycle_timer_and_clock call and the\n");
360
debugOutput(DEBUG_LEVEL_VERBOSE, "CLOCK_MONOTONIC clock source; using them.\n");
362
debugOutput(DEBUG_LEVEL_VERBOSE, "This system supports the raw1394_read_cycle_timer call, using it.\n");
363
debugOutput(DEBUG_LEVEL_NORMAL, "The raw1394_read_cycle_timer_and_clock call and/or the CLOCK_MONOTONIC\n");
364
debugOutput(DEBUG_LEVEL_NORMAL, "clock source is not available.\n");
365
debugOutput(DEBUG_LEVEL_NORMAL, "Fallback to raw1394_read_cycle_timer.\n");
366
debugOutput(DEBUG_LEVEL_NORMAL, "FFADO may be susceptible to NTP-induced clock discontinuities.\n");
367
debugOutput(DEBUG_LEVEL_NORMAL, "If this is an issue, upgrade libraw1394 to version 2.1.0 or later and/or\n");
368
debugOutput(DEBUG_LEVEL_NORMAL, "kernel 2.6.36 or later.\n");
336
372
// obtain port name
373
409
debugOutput(DEBUG_LEVEL_VERBOSE, "Minimum SPLIT_TIMEOUT: %d. Current: %d\n", split_timeout, timeout);
374
410
if (timeout < split_timeout) {
375
411
if(!setSplitTimeoutUsecs(getLocalNodeId(), split_timeout+124)) {
376
debugWarning("Could not set SPLIT_TIMEOUT to min requested (%d)\n", split_timeout);
412
debugOutput(DEBUG_LEVEL_VERBOSE, "Could not set SPLIT_TIMEOUT to min requested (%d)\n", split_timeout);
378
414
timeout = getSplitTimeoutUsecs(getLocalNodeId());
379
415
if (timeout < split_timeout) {
380
debugWarning("Set SPLIT_TIMEOUT to min requested (%d) did not succeed\n", split_timeout);
416
debugOutput(DEBUG_LEVEL_VERBOSE, "Set SPLIT_TIMEOUT to min requested (%d) did not succeed\n", split_timeout);
504
540
Ieee1394Service::readCycleTimerReg(uint32_t *cycle_timer, uint64_t *local_time)
542
if (m_have_read_ctr_and_clock) {
544
err = raw1394_read_cycle_timer_and_clock(m_util_handle, cycle_timer, local_time,
545
Util::SystemTimeSource::getSource());
547
debugWarning("raw1394_read_cycle_timer_and_clock error: %s\n", strerror(errno));
506
552
if(m_have_new_ctr_read) {
508
554
err = raw1394_read_cycle_timer(m_util_handle, cycle_timer, local_time);
510
debugWarning("raw1394_read_cycle_timer: %s\n", strerror(err));
556
debugWarning("raw1394_read_cycle_timer error: %s\n", strerror(errno));