Skip to content

Commit

Permalink
config: convert 'clock_servo' to the new scheme.
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Cochran <[email protected]>
  • Loading branch information
richardcochran committed Aug 23, 2015
1 parent ed56651 commit 8836f3c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 22 deletions.
3 changes: 2 additions & 1 deletion clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,12 @@ 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,
struct default_ds *dds, enum servo_type servo)
struct default_ds *dds)
{
enum timestamp_type timestamping =
config_get_int(config, NULL, "time_stamping");
int fadj = 0, max_adj = 0, sw_ts = timestamping == TS_SOFTWARE ? 1 : 0;
enum servo_type servo = config_get_int(config, NULL, "clock_servo");
struct clock *c = &the_clock;
struct port *p;
char phc[32];
Expand Down
3 changes: 1 addition & 2 deletions clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,11 @@ struct config *clock_config(struct clock *c);
* Pass -1 to select CLOCK_REALTIME.
* @param ifaces A queue of network interfaces.
* @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,
struct default_ds *dds, enum servo_type servo);
struct default_ds *dds);

/**
* Obtains a clock's default data set.
Expand Down
21 changes: 9 additions & 12 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ struct config_item {
#define PORT_ITEM_INT(label, _default, min, max) \
CONFIG_ITEM_INT(label, 1, _default, min, max)

static struct config_enum clock_servo_enu[] = {
{ "pi", CLOCK_SERVO_PI },
{ "linreg", CLOCK_SERVO_LINREG },
{ "ntpshm", CLOCK_SERVO_NTPSHM },
{ "nullf", CLOCK_SERVO_NULLF },
{ NULL, 0 },
};

static struct config_enum delay_filter_enu[] = {
{ "moving_average", FILTER_MOVING_AVERAGE },
{ "moving_median", FILTER_MOVING_MEDIAN },
Expand Down Expand Up @@ -152,6 +160,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_INT("check_fup_sync", 0, 0, 1),
GLOB_ITEM_INT("clockAccuracy", 0xfe, 0, UINT8_MAX),
GLOB_ITEM_INT("clockClass", 248, 0, UINT8_MAX),
GLOB_ITEM_ENU("clock_servo", CLOCK_SERVO_PI, clock_servo_enu),
PORT_ITEM_INT("delayAsymmetry", 0, INT_MIN, INT_MAX),
PORT_ITEM_ENU("delay_filter", FILTER_MOVING_MEDIAN, delay_filter_enu),
PORT_ITEM_INT("delay_filter_length", 10, 1, INT_MAX),
Expand Down Expand Up @@ -445,18 +454,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, "clock_servo")) {
if (!strcasecmp("pi", value))
cfg->clock_servo = CLOCK_SERVO_PI;
else if (!strcasecmp("linreg", value))
cfg->clock_servo = CLOCK_SERVO_LINREG;
else if (!strcasecmp("ntpshm", value))
cfg->clock_servo = CLOCK_SERVO_NTPSHM;
else if (!strcasecmp("nullf", value))
cfg->clock_servo = CLOCK_SERVO_NULLF;
else
return BAD_VALUE;

} else if (!strcmp(option, "productDescription")) {
if (count_char(value, ';') != 2)
return BAD_VALUE;
Expand Down
2 changes: 0 additions & 2 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ struct config {

/* the rest are legacy fields */
struct default_ds dds;
enum servo_type clock_servo;

unsigned char *ptp_dst_mac;
unsigned char *p2p_dst_mac;
char *uds_address;
Expand Down
7 changes: 2 additions & 5 deletions ptp4l.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ static struct config cfg_settings = {
},
},

.clock_servo = CLOCK_SERVO_PI,

.ptp_dst_mac = ptp_dst_mac,
.p2p_dst_mac = p2p_dst_mac,
.uds_address = uds_path,
Expand Down Expand Up @@ -236,7 +234,7 @@ int main(int argc, char *argv[])
ds->flags & DDS_SLAVE_ONLY) {
ds->clockQuality.clockClass = 255;
}
if (cfg_settings.clock_servo == CLOCK_SERVO_NTPSHM) {
if (config_get_int(cfg, NULL, "clock_servo") == CLOCK_SERVO_NTPSHM) {
config_set_int(cfg, "kernel_leap", 0);
config_set_int(cfg, "sanity_freq_limit", 0);
}
Expand Down Expand Up @@ -332,8 +330,7 @@ int main(int argc, char *argv[])

clock = clock_create(&cfg_settings,
phc_index, &cfg_settings.interfaces,
&cfg_settings.dds,
cfg_settings.clock_servo);
&cfg_settings.dds);
if (!clock) {
fprintf(stderr, "failed to create a clock\n");
return -1;
Expand Down

0 comments on commit 8836f3c

Please sign in to comment.