config: convert 'time_stamping' to the new scheme.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2015-08-15 21:45:19 +02:00
parent b6a91303a9
commit ed566513e0
5 changed files with 24 additions and 38 deletions

View File

@ -800,9 +800,10 @@ static void clock_remove_port(struct clock *c, struct port *p)
struct clock *clock_create(struct config *config, int phc_index,
struct interfaces_head *ifaces,
enum timestamp_type timestamping,
struct default_ds *dds, enum servo_type servo)
{
enum timestamp_type timestamping =
config_get_int(config, NULL, "time_stamping");
int fadj = 0, max_adj = 0, sw_ts = timestamping == TS_SOFTWARE ? 1 : 0;
struct clock *c = &the_clock;
struct port *p;

View File

@ -72,14 +72,12 @@ struct config *clock_config(struct clock *c);
* @param phc_index PTP hardware clock device to use.
* Pass -1 to select CLOCK_REALTIME.
* @param ifaces A queue of network interfaces.
* @param timestamping The timestamping mode for this clock.
* @param dds A pointer to a default data set for the clock.
* @param servo The servo that this clock will use.
* @return A pointer to the single global clock instance.
*/
struct clock *clock_create(struct config *config, int phc_index,
struct interfaces_head *ifaces,
enum timestamp_type timestamping,
struct default_ds *dds, enum servo_type servo);
/**

View File

@ -130,6 +130,13 @@ static struct config_enum nw_trans_enu[] = {
{ NULL, 0 },
};
static struct config_enum timestamping_enu[] = {
{ "hardware", TS_HARDWARE },
{ "software", TS_SOFTWARE },
{ "legacy", TS_LEGACY_HW },
{ NULL, 0 },
};
static struct config_enum tsproc_enu[] = {
{ "filter", TSPROC_FILTER },
{ "raw", TSPROC_RAW },
@ -188,6 +195,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("summary_interval", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("syncReceiptTimeout", 0, 0, UINT8_MAX),
GLOB_ITEM_INT("timeSource", INTERNAL_OSCILLATOR, 0x10, 0xfe),
GLOB_ITEM_ENU("time_stamping", TS_HARDWARE, timestamping_enu),
PORT_ITEM_INT("transportSpecific", 0, 0, 0x0F),
PORT_ITEM_ENU("tsproc_mode", TSPROC_FILTER, tsproc_enu),
GLOB_ITEM_INT("twoStepFlag", 1, 0, 1),
@ -409,7 +417,7 @@ static enum parser_result parse_global_setting(const char *option,
const char *value,
struct config *cfg)
{
int i, cfg_ignore = cfg->cfg_ignore;
int i;
unsigned char mac[MAC_LEN];
unsigned char oui[OUI_LEN];
enum parser_result r;
@ -437,18 +445,6 @@ static enum parser_result parse_global_setting(const char *option,
return OUT_OF_RANGE;
strncpy(cfg->uds_address, value, MAX_IFNAME_SIZE);
} else if (!strcmp(option, "time_stamping")) {
if (!(cfg_ignore & CFG_IGNORE_TIMESTAMPING)) {
if (0 == strcasecmp("hardware", value))
cfg->timestamping = TS_HARDWARE;
else if (0 == strcasecmp("software", value))
cfg->timestamping = TS_SOFTWARE;
else if (0 == strcasecmp("legacy", value))
cfg->timestamping = TS_LEGACY_HW;
else
return BAD_VALUE;
}
} else if (!strcmp(option, "clock_servo")) {
if (!strcasecmp("pi", value))
cfg->clock_servo = CLOCK_SERVO_PI;

View File

@ -38,12 +38,7 @@ struct interface {
struct sk_ts_info ts_info;
};
#define CFG_IGNORE_TIMESTAMPING (1 << 2)
struct config {
/* configuration override */
int cfg_ignore;
/* configured interfaces */
STAILQ_HEAD(interfaces_head, interface) interfaces;
@ -51,7 +46,6 @@ struct config {
struct hash *htab;
/* the rest are legacy fields */
enum timestamp_type timestamping;
struct default_ds dds;
enum servo_type clock_servo;

29
ptp4l.c
View File

@ -59,14 +59,11 @@ static struct config cfg_settings = {
},
},
.timestamping = TS_HARDWARE,
.clock_servo = CLOCK_SERVO_PI,
.ptp_dst_mac = ptp_dst_mac,
.p2p_dst_mac = p2p_dst_mac,
.uds_address = uds_path,
.cfg_ignore = 0,
};
static void usage(char *progname)
@ -106,8 +103,6 @@ int main(int argc, char *argv[])
char *config = NULL, *req_phc = NULL, *progname;
int c;
struct interface *iface;
int *cfg_ignore = &cfg_settings.cfg_ignore;
enum timestamp_type *timestamping = &cfg_settings.timestamping;
struct clock *clock;
struct config *cfg = &cfg_settings;
struct defaultDS *ds = &cfg_settings.dds.dds;
@ -153,16 +148,16 @@ int main(int argc, char *argv[])
return -1;
break;
case 'H':
*timestamping = TS_HARDWARE;
*cfg_ignore |= CFG_IGNORE_TIMESTAMPING;
if (config_set_int(cfg, "time_stamping", TS_HARDWARE))
return -1;
break;
case 'S':
*timestamping = TS_SOFTWARE;
*cfg_ignore |= CFG_IGNORE_TIMESTAMPING;
if (config_set_int(cfg, "time_stamping", TS_SOFTWARE))
return -1;
break;
case 'L':
*timestamping = TS_LEGACY_HW;
*cfg_ignore |= CFG_IGNORE_TIMESTAMPING;
if (config_set_int(cfg, "time_stamping", TS_LEGACY_HW))
return -1;
break;
case 'f':
config = optarg;
@ -258,21 +253,22 @@ int main(int argc, char *argv[])
}
if (!(ds->flags & DDS_TWO_STEP_FLAG)) {
switch (*timestamping) {
switch (config_get_int(cfg, NULL, "time_stamping")) {
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;
if (config_set_int(cfg, "time_stamping", TS_ONESTEP))
return -1;
break;
case TS_ONESTEP:
break;
}
}
switch (*timestamping) {
switch (config_get_int(cfg, NULL, "time_stamping")) {
case TS_SOFTWARE:
required_modes |= SOF_TIMESTAMPING_TX_SOFTWARE |
SOF_TIMESTAMPING_RX_SOFTWARE |
@ -308,7 +304,8 @@ int main(int argc, char *argv[])
iface = STAILQ_FIRST(&cfg_settings.interfaces);
if (config_get_int(cfg, NULL, "free_running")) {
phc_index = -1;
} else if (*timestamping == TS_SOFTWARE || *timestamping == TS_LEGACY_HW) {
} else if (config_get_int(cfg, NULL, "time_stamping") == TS_SOFTWARE ||
config_get_int(cfg, NULL, "time_stamping") == TS_LEGACY_HW) {
phc_index = -1;
} else if (req_phc) {
if (1 != sscanf(req_phc, "/dev/ptp%d", &phc_index)) {
@ -335,7 +332,7 @@ int main(int argc, char *argv[])
clock = clock_create(&cfg_settings,
phc_index, &cfg_settings.interfaces,
*timestamping, &cfg_settings.dds,
&cfg_settings.dds,
cfg_settings.clock_servo);
if (!clock) {
fprintf(stderr, "failed to create a clock\n");