2011-11-13 00:41:20 +08:00
|
|
|
/**
|
2012-03-21 20:57:05 +08:00
|
|
|
* @file ptp4l.c
|
|
|
|
* @brief PTP Boundary Clock main program
|
2011-11-13 00:41:20 +08:00
|
|
|
* @note Copyright (C) 2011 Richard Cochran <richardcochran@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2014-02-22 01:18:08 +08:00
|
|
|
#include <limits.h>
|
2012-08-28 03:07:38 +08:00
|
|
|
#include <signal.h>
|
2011-11-13 00:41:20 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2012-11-14 05:35:10 +08:00
|
|
|
#include <linux/net_tstamp.h>
|
2011-11-13 00:41:20 +08:00
|
|
|
|
|
|
|
#include "clock.h"
|
2011-12-31 16:18:25 +08:00
|
|
|
#include "config.h"
|
2014-06-12 00:07:08 +08:00
|
|
|
#include "ntpshm.h"
|
2012-08-25 15:19:29 +08:00
|
|
|
#include "pi.h"
|
2011-11-13 00:41:20 +08:00
|
|
|
#include "print.h"
|
2012-08-25 15:24:08 +08:00
|
|
|
#include "raw.h"
|
2012-03-17 21:53:10 +08:00
|
|
|
#include "sk.h"
|
2011-11-13 00:41:20 +08:00
|
|
|
#include "transport.h"
|
2012-11-26 03:30:14 +08:00
|
|
|
#include "udp6.h"
|
2013-09-30 02:57:00 +08:00
|
|
|
#include "uds.h"
|
2012-08-05 20:11:18 +08:00
|
|
|
#include "util.h"
|
2012-12-10 17:28:28 +08:00
|
|
|
#include "version.h"
|
2011-11-13 00:41:20 +08:00
|
|
|
|
2012-10-18 19:15:06 +08:00
|
|
|
int assume_two_step = 0;
|
2012-03-21 03:16:58 +08:00
|
|
|
|
2011-11-13 00:41:20 +08:00
|
|
|
static int running = 1;
|
2012-08-21 01:56:29 +08:00
|
|
|
|
|
|
|
static struct config cfg_settings = {
|
|
|
|
.dds = {
|
2012-12-01 04:52:37 +08:00
|
|
|
.dds = {
|
|
|
|
.flags = DDS_TWO_STEP_FLAG,
|
|
|
|
.priority1 = 128,
|
|
|
|
.clockQuality.clockClass = 248,
|
|
|
|
.clockQuality.clockAccuracy = 0xfe,
|
|
|
|
.clockQuality.offsetScaledLogVariance = 0xffff,
|
|
|
|
.priority2 = 128,
|
|
|
|
.domainNumber = 0,
|
|
|
|
},
|
2012-10-18 19:15:06 +08:00
|
|
|
.free_running = 0,
|
2012-08-21 23:14:15 +08:00
|
|
|
.freq_est_interval = 1,
|
2013-12-02 03:32:05 +08:00
|
|
|
.grand_master_capable = 1,
|
2013-02-09 17:45:30 +08:00
|
|
|
.stats_interval = 0,
|
2013-03-08 00:27:33 +08:00
|
|
|
.kernel_leap = 1,
|
2013-10-23 00:57:15 +08:00
|
|
|
.sanity_freq_limit = 200000000,
|
2013-07-06 02:43:45 +08:00
|
|
|
.time_source = INTERNAL_OSCILLATOR,
|
2013-02-04 06:01:51 +08:00
|
|
|
.clock_desc = {
|
|
|
|
.productDescription = {
|
|
|
|
.max_symbols = 64,
|
2013-02-09 22:58:11 +08:00
|
|
|
.text = ";;",
|
|
|
|
.length = 2,
|
2013-02-04 06:01:51 +08:00
|
|
|
},
|
|
|
|
.revisionData = {
|
|
|
|
.max_symbols = 32,
|
2013-02-09 22:58:11 +08:00
|
|
|
.text = ";;",
|
|
|
|
.length = 2,
|
2013-02-04 06:01:51 +08:00
|
|
|
},
|
|
|
|
.userDescription = { .max_symbols = 128 },
|
|
|
|
.manufacturerIdentity = { 0, 0, 0 },
|
|
|
|
},
|
2013-10-29 18:58:20 +08:00
|
|
|
.delay_filter = FILTER_MOVING_MEDIAN,
|
|
|
|
.delay_filter_length = 10,
|
2012-08-21 01:56:29 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
.pod = {
|
|
|
|
.logAnnounceInterval = 1,
|
|
|
|
.logSyncInterval = 0,
|
|
|
|
.logMinDelayReqInterval = 0,
|
|
|
|
.logMinPdelayReqInterval = 0,
|
|
|
|
.announceReceiptTimeout = 3,
|
2013-08-26 20:36:49 +08:00
|
|
|
.syncReceiptTimeout = 0,
|
2012-08-21 01:56:29 +08:00
|
|
|
.transportSpecific = 0,
|
2014-01-09 01:52:36 +08:00
|
|
|
.announce_span = 1,
|
2012-08-21 01:56:29 +08:00
|
|
|
.path_trace_enabled = 0,
|
|
|
|
.follow_up_info = 0,
|
2012-10-18 19:15:06 +08:00
|
|
|
.freq_est_interval = 1,
|
2013-03-14 03:16:59 +08:00
|
|
|
/* Default to very a large neighborPropDelay threshold */
|
|
|
|
.neighborPropDelayThresh = 20000000,
|
2014-02-22 01:18:08 +08:00
|
|
|
.min_neighbor_prop_delay = -20000000,
|
2012-08-21 01:56:29 +08:00
|
|
|
},
|
|
|
|
|
2012-08-21 01:56:35 +08:00
|
|
|
.timestamping = TS_HARDWARE,
|
|
|
|
.dm = DM_E2E,
|
|
|
|
.transport = TRANS_UDP_IPV4,
|
|
|
|
|
2012-08-21 01:56:29 +08:00
|
|
|
.assume_two_step = &assume_two_step,
|
2013-04-05 23:52:14 +08:00
|
|
|
.tx_timestamp_timeout = &sk_tx_timeout,
|
2013-08-29 17:01:27 +08:00
|
|
|
.check_fup_sync = &sk_check_fupsync,
|
2012-09-29 02:45:54 +08:00
|
|
|
|
|
|
|
.clock_servo = CLOCK_SERVO_PI,
|
|
|
|
|
2014-03-14 01:34:17 +08:00
|
|
|
.step_threshold = &servo_step_threshold,
|
|
|
|
.first_step_threshold = &servo_first_step_threshold,
|
|
|
|
.max_frequency = &servo_max_frequency,
|
|
|
|
|
2012-08-21 01:56:29 +08:00
|
|
|
.pi_proportional_const = &configured_pi_kp,
|
|
|
|
.pi_integral_const = &configured_pi_ki,
|
2013-06-28 23:09:14 +08:00
|
|
|
.pi_proportional_scale = &configured_pi_kp_scale,
|
|
|
|
.pi_proportional_exponent = &configured_pi_kp_exponent,
|
|
|
|
.pi_proportional_norm_max = &configured_pi_kp_norm_max,
|
|
|
|
.pi_integral_scale = &configured_pi_ki_scale,
|
|
|
|
.pi_integral_exponent = &configured_pi_ki_exponent,
|
|
|
|
.pi_integral_norm_max = &configured_pi_ki_norm_max,
|
2014-06-12 00:07:08 +08:00
|
|
|
.ntpshm_segment = &ntpshm_segment,
|
2012-09-29 02:46:00 +08:00
|
|
|
|
2012-08-21 01:56:29 +08:00
|
|
|
.ptp_dst_mac = ptp_dst_mac,
|
|
|
|
.p2p_dst_mac = p2p_dst_mac,
|
2012-11-26 03:30:14 +08:00
|
|
|
.udp6_scope = &udp6_scope,
|
2013-09-30 02:57:00 +08:00
|
|
|
.uds_address = uds_path,
|
2012-08-21 01:56:56 +08:00
|
|
|
|
|
|
|
.print_level = LOG_INFO,
|
|
|
|
.use_syslog = 1,
|
|
|
|
.verbose = 0,
|
2012-08-21 01:57:01 +08:00
|
|
|
|
|
|
|
.cfg_ignore = 0,
|
2012-08-21 01:56:29 +08:00
|
|
|
};
|
2011-11-13 00:41:20 +08:00
|
|
|
|
2012-08-28 03:07:38 +08:00
|
|
|
static void handle_int_quit_term(int s)
|
|
|
|
{
|
|
|
|
pr_notice("caught signal %d", s);
|
|
|
|
running = 0;
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:41:20 +08:00
|
|
|
static void usage(char *progname)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"\nusage: %s [options]\n\n"
|
2012-08-22 00:00:14 +08:00
|
|
|
" Delay Mechanism\n\n"
|
2012-04-05 18:04:11 +08:00
|
|
|
" -A Auto, starting with E2E\n"
|
|
|
|
" -E E2E, delay request-response (default)\n"
|
|
|
|
" -P P2P, peer delay mechanism\n\n"
|
2012-08-22 00:00:14 +08:00
|
|
|
" Network Transport\n\n"
|
2011-11-13 00:41:20 +08:00
|
|
|
" -2 IEEE 802.3\n"
|
|
|
|
" -4 UDP IPV4 (default)\n"
|
|
|
|
" -6 UDP IPV6\n\n"
|
|
|
|
" Time Stamping\n\n"
|
2012-08-21 01:56:03 +08:00
|
|
|
" -H HARDWARE (default)\n"
|
|
|
|
" -S SOFTWARE\n"
|
|
|
|
" -L LEGACY HW\n\n"
|
2011-11-13 00:41:20 +08:00
|
|
|
" Other Options\n\n"
|
2011-12-31 16:18:25 +08:00
|
|
|
" -f [file] read configuration from 'file'\n"
|
2011-11-13 00:41:20 +08:00
|
|
|
" -i [dev] interface device to use, for example 'eth0'\n"
|
|
|
|
" (may be specified multiple times)\n"
|
2012-05-10 02:46:16 +08:00
|
|
|
" -p [dev] PTP hardware clock device to use, default auto\n"
|
2012-01-08 18:46:48 +08:00
|
|
|
" (ignored for SOFTWARE/LEGACY HW time stamping)\n"
|
2012-08-21 01:56:03 +08:00
|
|
|
" -s slave only mode (overrides configuration file)\n"
|
|
|
|
" -l [num] set the logging level to 'num'\n"
|
2012-12-10 17:28:28 +08:00
|
|
|
" -m print messages to stdout\n"
|
2012-08-21 01:56:08 +08:00
|
|
|
" -q do not print messages to the syslog\n"
|
2012-12-10 17:28:28 +08:00
|
|
|
" -v prints the software version and exits\n"
|
2012-08-21 01:56:03 +08:00
|
|
|
" -h prints this message and exits\n"
|
2012-01-08 18:46:48 +08:00
|
|
|
"\n",
|
2012-05-10 02:46:16 +08:00
|
|
|
progname);
|
2011-11-13 00:41:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2012-05-10 02:46:16 +08:00
|
|
|
char *config = NULL, *req_phc = NULL, *progname;
|
2012-08-21 01:57:17 +08:00
|
|
|
int c, i;
|
2012-08-21 01:56:24 +08:00
|
|
|
struct interface *iface = cfg_settings.iface;
|
2012-08-21 01:57:17 +08:00
|
|
|
char *ports[MAX_PORTS];
|
|
|
|
int nports = 0;
|
2012-08-21 01:57:01 +08:00
|
|
|
int *cfg_ignore = &cfg_settings.cfg_ignore;
|
2012-08-21 01:56:35 +08:00
|
|
|
enum delay_mechanism *dm = &cfg_settings.dm;
|
|
|
|
enum transport_type *transport = &cfg_settings.transport;
|
|
|
|
enum timestamp_type *timestamping = &cfg_settings.timestamping;
|
2011-11-13 00:41:20 +08:00
|
|
|
struct clock *clock;
|
2012-12-01 04:52:37 +08:00
|
|
|
struct defaultDS *ds = &cfg_settings.dds.dds;
|
2012-11-14 05:35:10 +08:00
|
|
|
int phc_index = -1, required_modes = 0;
|
2011-11-13 00:41:20 +08:00
|
|
|
|
2012-08-28 03:07:38 +08:00
|
|
|
if (SIG_ERR == signal(SIGINT, handle_int_quit_term)) {
|
|
|
|
fprintf(stderr, "cannot handle SIGINT\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (SIG_ERR == signal(SIGQUIT, handle_int_quit_term)) {
|
|
|
|
fprintf(stderr, "cannot handle SIGQUIT\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (SIG_ERR == signal(SIGTERM, handle_int_quit_term)) {
|
|
|
|
fprintf(stderr, "cannot handle SIGTERM\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-03-19 00:08:21 +08:00
|
|
|
/* Set fault timeouts to a default value */
|
|
|
|
for (i = 0; i < FT_CNT; i++) {
|
|
|
|
cfg_settings.pod.flt_interval_pertype[i].type = FTMO_LOG2_SECONDS;
|
|
|
|
cfg_settings.pod.flt_interval_pertype[i].val = 4;
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:41:20 +08:00
|
|
|
/* Process the command line arguments. */
|
|
|
|
progname = strrchr(argv[0], '/');
|
|
|
|
progname = progname ? 1+progname : argv[0];
|
2012-12-10 17:28:28 +08:00
|
|
|
while (EOF != (c = getopt(argc, argv, "AEP246HSLf:i:p:sl:mqvh"))) {
|
2011-11-13 00:41:20 +08:00
|
|
|
switch (c) {
|
2012-08-21 01:56:03 +08:00
|
|
|
case 'A':
|
2012-08-21 01:56:35 +08:00
|
|
|
*dm = DM_AUTO;
|
2012-08-21 01:57:01 +08:00
|
|
|
*cfg_ignore |= CFG_IGNORE_DM;
|
2012-08-21 01:56:03 +08:00
|
|
|
break;
|
|
|
|
case 'E':
|
2012-08-21 01:56:35 +08:00
|
|
|
*dm = DM_E2E;
|
2012-08-21 01:57:01 +08:00
|
|
|
*cfg_ignore |= CFG_IGNORE_DM;
|
2012-08-21 01:56:03 +08:00
|
|
|
break;
|
|
|
|
case 'P':
|
2012-08-21 01:56:35 +08:00
|
|
|
*dm = DM_P2P;
|
2012-08-21 01:57:01 +08:00
|
|
|
*cfg_ignore |= CFG_IGNORE_DM;
|
2012-08-21 01:56:03 +08:00
|
|
|
break;
|
2011-11-13 00:41:20 +08:00
|
|
|
case '2':
|
2012-08-21 01:56:35 +08:00
|
|
|
*transport = TRANS_IEEE_802_3;
|
2012-08-21 01:57:01 +08:00
|
|
|
*cfg_ignore |= CFG_IGNORE_TRANSPORT;
|
2011-11-13 00:41:20 +08:00
|
|
|
break;
|
|
|
|
case '4':
|
2012-08-21 01:56:35 +08:00
|
|
|
*transport = TRANS_UDP_IPV4;
|
2012-08-21 01:57:01 +08:00
|
|
|
*cfg_ignore |= CFG_IGNORE_TRANSPORT;
|
2011-11-13 00:41:20 +08:00
|
|
|
break;
|
|
|
|
case '6':
|
2012-08-21 01:56:35 +08:00
|
|
|
*transport = TRANS_UDP_IPV6;
|
2012-08-21 01:57:01 +08:00
|
|
|
*cfg_ignore |= CFG_IGNORE_TRANSPORT;
|
2011-11-13 00:41:20 +08:00
|
|
|
break;
|
2012-08-21 01:56:03 +08:00
|
|
|
case 'H':
|
2012-08-21 01:56:35 +08:00
|
|
|
*timestamping = TS_HARDWARE;
|
2012-08-21 01:57:01 +08:00
|
|
|
*cfg_ignore |= CFG_IGNORE_TIMESTAMPING;
|
2012-04-05 18:04:11 +08:00
|
|
|
break;
|
2012-08-21 01:56:03 +08:00
|
|
|
case 'S':
|
2012-08-21 01:56:35 +08:00
|
|
|
*timestamping = TS_SOFTWARE;
|
2012-08-21 01:57:01 +08:00
|
|
|
*cfg_ignore |= CFG_IGNORE_TIMESTAMPING;
|
2012-08-21 01:56:03 +08:00
|
|
|
break;
|
|
|
|
case 'L':
|
2012-08-21 01:56:35 +08:00
|
|
|
*timestamping = TS_LEGACY_HW;
|
2012-08-21 01:57:01 +08:00
|
|
|
*cfg_ignore |= CFG_IGNORE_TIMESTAMPING;
|
2012-04-05 18:04:11 +08:00
|
|
|
break;
|
2011-12-31 16:18:25 +08:00
|
|
|
case 'f':
|
|
|
|
config = optarg;
|
|
|
|
break;
|
2011-11-13 00:41:20 +08:00
|
|
|
case 'i':
|
2012-08-21 01:57:17 +08:00
|
|
|
ports[nports] = optarg;
|
|
|
|
nports++;
|
2011-11-13 00:41:20 +08:00
|
|
|
break;
|
2012-08-21 01:56:03 +08:00
|
|
|
case 'p':
|
|
|
|
req_phc = optarg;
|
2011-12-30 18:27:02 +08:00
|
|
|
break;
|
2012-08-21 01:56:03 +08:00
|
|
|
case 's':
|
2012-12-01 04:52:37 +08:00
|
|
|
ds->flags |= DDS_SLAVE_ONLY;
|
2012-08-21 01:57:01 +08:00
|
|
|
*cfg_ignore |= CFG_IGNORE_SLAVEONLY;
|
2011-12-28 02:18:52 +08:00
|
|
|
break;
|
2012-08-21 01:56:03 +08:00
|
|
|
case 'l':
|
2013-06-04 13:01:04 +08:00
|
|
|
if (get_arg_val_i(c, optarg, &cfg_settings.print_level,
|
|
|
|
PRINT_LEVEL_MIN, PRINT_LEVEL_MAX))
|
|
|
|
return -1;
|
2012-08-21 01:57:01 +08:00
|
|
|
*cfg_ignore |= CFG_IGNORE_PRINT_LEVEL;
|
2011-11-13 00:41:20 +08:00
|
|
|
break;
|
2012-12-10 17:28:28 +08:00
|
|
|
case 'm':
|
|
|
|
cfg_settings.verbose = 1;
|
|
|
|
*cfg_ignore |= CFG_IGNORE_VERBOSE;
|
|
|
|
break;
|
2012-01-08 18:46:48 +08:00
|
|
|
case 'q':
|
2012-08-21 01:56:56 +08:00
|
|
|
cfg_settings.use_syslog = 0;
|
2012-08-21 01:57:01 +08:00
|
|
|
*cfg_ignore |= CFG_IGNORE_USE_SYSLOG;
|
2012-01-08 18:46:48 +08:00
|
|
|
break;
|
|
|
|
case 'v':
|
2012-12-10 17:28:28 +08:00
|
|
|
version_show(stdout);
|
|
|
|
return 0;
|
2011-11-13 00:41:20 +08:00
|
|
|
case 'h':
|
|
|
|
usage(progname);
|
|
|
|
return 0;
|
|
|
|
case '?':
|
|
|
|
usage(progname);
|
|
|
|
return -1;
|
|
|
|
default:
|
|
|
|
usage(progname);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
if (config && (c = config_read(config, &cfg_settings))) {
|
|
|
|
return c;
|
2012-08-21 01:57:11 +08:00
|
|
|
}
|
2013-12-02 03:50:34 +08:00
|
|
|
if (!cfg_settings.dds.grand_master_capable &&
|
|
|
|
ds->flags & DDS_SLAVE_ONLY) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Cannot mix 1588 slaveOnly with 802.1AS !gmCapable.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!cfg_settings.dds.grand_master_capable ||
|
|
|
|
ds->flags & DDS_SLAVE_ONLY) {
|
2012-08-29 00:47:45 +08:00
|
|
|
ds->clockQuality.clockClass = 255;
|
|
|
|
}
|
2012-08-21 01:57:11 +08:00
|
|
|
|
2013-01-30 01:06:16 +08:00
|
|
|
print_set_progname(progname);
|
2012-08-28 01:20:41 +08:00
|
|
|
print_set_verbose(cfg_settings.verbose);
|
|
|
|
print_set_syslog(cfg_settings.use_syslog);
|
|
|
|
print_set_level(cfg_settings.print_level);
|
|
|
|
|
2012-08-21 01:57:17 +08:00
|
|
|
for (i = 0; i < nports; i++) {
|
|
|
|
if (config_create_interface(ports[i], &cfg_settings) < 0) {
|
|
|
|
fprintf(stderr, "too many interfaces\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cfg_settings.nports) {
|
2012-03-27 17:50:54 +08:00
|
|
|
fprintf(stderr, "no interface specified\n");
|
2011-11-13 00:41:20 +08:00
|
|
|
usage(progname);
|
|
|
|
return -1;
|
|
|
|
}
|
2012-05-10 02:46:16 +08:00
|
|
|
|
2012-12-01 04:52:37 +08:00
|
|
|
if (!(ds->flags & DDS_TWO_STEP_FLAG)) {
|
2012-11-30 04:01:16 +08:00
|
|
|
switch (*timestamping) {
|
|
|
|
case TS_SOFTWARE:
|
|
|
|
case TS_LEGACY_HW:
|
|
|
|
fprintf(stderr, "one step is only possible "
|
|
|
|
"with hardware time stamping\n");
|
|
|
|
return -1;
|
|
|
|
case TS_HARDWARE:
|
|
|
|
*timestamping = TS_ONESTEP;
|
|
|
|
break;
|
|
|
|
case TS_ONESTEP:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (*timestamping) {
|
|
|
|
case TS_SOFTWARE:
|
2012-11-14 05:35:10 +08:00
|
|
|
required_modes |= SOF_TIMESTAMPING_TX_SOFTWARE |
|
|
|
|
SOF_TIMESTAMPING_RX_SOFTWARE |
|
|
|
|
SOF_TIMESTAMPING_SOFTWARE;
|
2012-11-30 04:01:16 +08:00
|
|
|
break;
|
|
|
|
case TS_LEGACY_HW:
|
2012-11-14 05:35:10 +08:00
|
|
|
required_modes |= SOF_TIMESTAMPING_TX_HARDWARE |
|
|
|
|
SOF_TIMESTAMPING_RX_HARDWARE |
|
|
|
|
SOF_TIMESTAMPING_SYS_HARDWARE;
|
2012-11-30 04:01:16 +08:00
|
|
|
break;
|
|
|
|
case TS_HARDWARE:
|
|
|
|
case TS_ONESTEP:
|
2012-11-14 05:35:10 +08:00
|
|
|
required_modes |= SOF_TIMESTAMPING_TX_HARDWARE |
|
|
|
|
SOF_TIMESTAMPING_RX_HARDWARE |
|
|
|
|
SOF_TIMESTAMPING_RAW_HARDWARE;
|
2012-11-30 04:01:16 +08:00
|
|
|
break;
|
|
|
|
}
|
2012-11-14 05:35:10 +08:00
|
|
|
|
|
|
|
/* check whether timestamping mode is supported. */
|
|
|
|
for (i = 0; i < cfg_settings.nports; i++) {
|
|
|
|
if (iface[i].ts_info.valid &&
|
2013-07-27 08:37:44 +08:00
|
|
|
((iface[i].ts_info.so_timestamping & required_modes) != required_modes)) {
|
2012-11-14 05:35:10 +08:00
|
|
|
fprintf(stderr, "interface '%s' does not support "
|
|
|
|
"requested timestamping mode.\n",
|
|
|
|
iface[i].name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-10 02:46:16 +08:00
|
|
|
/* determine PHC Clock index */
|
2012-12-01 04:52:37 +08:00
|
|
|
if (cfg_settings.dds.free_running) {
|
2012-09-05 19:40:21 +08:00
|
|
|
phc_index = -1;
|
|
|
|
} else if (*timestamping == TS_SOFTWARE || *timestamping == TS_LEGACY_HW) {
|
2012-05-10 02:46:16 +08:00
|
|
|
phc_index = -1;
|
|
|
|
} else if (req_phc) {
|
|
|
|
if (1 != sscanf(req_phc, "/dev/ptp%d", &phc_index)) {
|
|
|
|
fprintf(stderr, "bad ptp device string\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2012-11-14 05:35:04 +08:00
|
|
|
} else if (iface[0].ts_info.valid) {
|
|
|
|
phc_index = iface[0].ts_info.phc_index;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "ptp device not specified and\n"
|
|
|
|
"automatic determination is not\n"
|
|
|
|
"supported. please specify ptp device\n");
|
2012-05-10 02:46:16 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (phc_index >= 0) {
|
2012-07-08 16:44:05 +08:00
|
|
|
pr_info("selected /dev/ptp%d as PTP clock", phc_index);
|
2011-11-13 00:41:20 +08:00
|
|
|
}
|
|
|
|
|
2012-08-21 01:56:29 +08:00
|
|
|
if (generate_clock_identity(&ds->clockIdentity, iface[0].name)) {
|
2011-11-13 00:41:20 +08:00
|
|
|
fprintf(stderr, "failed to generate a clock identity\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-08-21 01:57:17 +08:00
|
|
|
clock = clock_create(phc_index, iface, cfg_settings.nports,
|
2012-12-01 04:52:37 +08:00
|
|
|
*timestamping, &cfg_settings.dds,
|
2013-02-09 17:45:30 +08:00
|
|
|
cfg_settings.clock_servo);
|
2011-11-13 00:41:20 +08:00
|
|
|
if (!clock) {
|
|
|
|
fprintf(stderr, "failed to create a clock\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (running) {
|
|
|
|
if (clock_poll(clock))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-08-28 03:11:14 +08:00
|
|
|
clock_destroy(clock);
|
2011-11-13 00:41:20 +08:00
|
|
|
return 0;
|
|
|
|
}
|