Use the management message memory layout for the defaultDS.
Reforming the data structure in this way will greatly simplify the implementation of the management message for this data set. Signed-off-by: Richard Cochran <richardcochran@gmail.com>master
parent
b26a36d493
commit
d60ccc7484
17
clock.c
17
clock.c
|
@ -67,6 +67,8 @@ struct clock {
|
||||||
int fault_fd[CLK_N_PORTS];
|
int fault_fd[CLK_N_PORTS];
|
||||||
time_t fault_timeout;
|
time_t fault_timeout;
|
||||||
int nports; /* does not include the UDS port */
|
int nports; /* does not include the UDS port */
|
||||||
|
int free_running;
|
||||||
|
int freq_est_interval;
|
||||||
int utc_timescale;
|
int utc_timescale;
|
||||||
tmv_t master_offset;
|
tmv_t master_offset;
|
||||||
tmv_t path_delay;
|
tmv_t path_delay;
|
||||||
|
@ -398,7 +400,7 @@ UInteger8 clock_class(struct clock *c)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct clock *clock_create(int phc_index, struct interface *iface, int count,
|
struct clock *clock_create(int phc_index, struct interface *iface, int count,
|
||||||
enum timestamp_type timestamping, struct defaultDS *ds,
|
enum timestamp_type timestamping, struct default_ds *dds,
|
||||||
enum servo_type servo)
|
enum servo_type servo)
|
||||||
{
|
{
|
||||||
int i, fadj = 0, max_adj = 0.0, sw_ts = timestamping == TS_SOFTWARE ? 1 : 0;
|
int i, fadj = 0, max_adj = 0.0, sw_ts = timestamping == TS_SOFTWARE ? 1 : 0;
|
||||||
|
@ -415,7 +417,10 @@ struct clock *clock_create(int phc_index, struct interface *iface, int count,
|
||||||
if (c->nports)
|
if (c->nports)
|
||||||
clock_destroy(c);
|
clock_destroy(c);
|
||||||
|
|
||||||
if (c->dds.free_running) {
|
c->free_running = dds->free_running;
|
||||||
|
c->freq_est_interval = dds->freq_est_interval;
|
||||||
|
|
||||||
|
if (c->free_running) {
|
||||||
c->clkid = CLOCK_INVALID;
|
c->clkid = CLOCK_INVALID;
|
||||||
} else if (phc_index >= 0) {
|
} else if (phc_index >= 0) {
|
||||||
snprintf(phc, 31, "/dev/ptp%d", phc_index);
|
snprintf(phc, 31, "/dev/ptp%d", phc_index);
|
||||||
|
@ -449,7 +454,7 @@ struct clock *clock_create(int phc_index, struct interface *iface, int count,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
c->dds = *ds;
|
c->dds = dds->dds;
|
||||||
|
|
||||||
/* Initialize the parentDS. */
|
/* Initialize the parentDS. */
|
||||||
clock_update_grandmaster(c);
|
clock_update_grandmaster(c);
|
||||||
|
@ -788,7 +793,7 @@ void clock_remove_fda(struct clock *c, struct port *p, struct fdarray fda)
|
||||||
|
|
||||||
int clock_slave_only(struct clock *c)
|
int clock_slave_only(struct clock *c)
|
||||||
{
|
{
|
||||||
return c->dds.slaveOnly;
|
return c->dds.flags & DDS_SLAVE_ONLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInteger16 clock_steps_removed(struct clock *c)
|
UInteger16 clock_steps_removed(struct clock *c)
|
||||||
|
@ -828,7 +833,7 @@ enum servo_state clock_synchronize(struct clock *c,
|
||||||
if (!c->path_delay)
|
if (!c->path_delay)
|
||||||
return state;
|
return state;
|
||||||
|
|
||||||
if (c->dds.free_running)
|
if (c->free_running)
|
||||||
return clock_no_adjust(c);
|
return clock_no_adjust(c);
|
||||||
|
|
||||||
adj = servo_sample(c->servo, c->master_offset, ingress, &state);
|
adj = servo_sample(c->servo, c->master_offset, ingress, &state);
|
||||||
|
@ -853,7 +858,7 @@ enum servo_state clock_synchronize(struct clock *c,
|
||||||
|
|
||||||
void clock_sync_interval(struct clock *c, int n)
|
void clock_sync_interval(struct clock *c, int n)
|
||||||
{
|
{
|
||||||
int shift = c->dds.freq_est_interval - n;
|
int shift = c->freq_est_interval - n;
|
||||||
|
|
||||||
if (shift < 0)
|
if (shift < 0)
|
||||||
shift = 0;
|
shift = 0;
|
||||||
|
|
4
clock.h
4
clock.h
|
@ -65,12 +65,12 @@ UInteger8 clock_class(struct clock *c);
|
||||||
* @param interface An array of network interfaces.
|
* @param interface An array of network interfaces.
|
||||||
* @param count The number of elements in @a interfaces.
|
* @param count The number of elements in @a interfaces.
|
||||||
* @param timestamping The timestamping mode for this clock.
|
* @param timestamping The timestamping mode for this clock.
|
||||||
* @param ds A pointer to a default data set for the clock.
|
* @param dds A pointer to a default data set for the clock.
|
||||||
* @param servo The servo that this clock will use.
|
* @param servo The servo that this clock will use.
|
||||||
* @return A pointer to the single global clock instance.
|
* @return A pointer to the single global clock instance.
|
||||||
*/
|
*/
|
||||||
struct clock *clock_create(int phc_index, struct interface *iface, int count,
|
struct clock *clock_create(int phc_index, struct interface *iface, int count,
|
||||||
enum timestamp_type timestamping, struct defaultDS *ds,
|
enum timestamp_type timestamping, struct default_ds *dds,
|
||||||
enum servo_type servo);
|
enum servo_type servo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
19
config.c
19
config.c
|
@ -153,7 +153,7 @@ static enum parser_result parse_global_setting(const char *option,
|
||||||
UInteger8 u8;
|
UInteger8 u8;
|
||||||
unsigned char mac[MAC_LEN];
|
unsigned char mac[MAC_LEN];
|
||||||
|
|
||||||
struct defaultDS *dds = &cfg->dds;
|
struct defaultDS *dds = &cfg->dds.dds;
|
||||||
struct port_defaults *pod = &cfg->pod;
|
struct port_defaults *pod = &cfg->pod;
|
||||||
|
|
||||||
enum parser_result r;
|
enum parser_result r;
|
||||||
|
@ -165,13 +165,20 @@ static enum parser_result parse_global_setting(const char *option,
|
||||||
if (!strcmp(option, "twoStepFlag")) {
|
if (!strcmp(option, "twoStepFlag")) {
|
||||||
if (1 != sscanf(value, "%d", &val))
|
if (1 != sscanf(value, "%d", &val))
|
||||||
return BAD_VALUE;
|
return BAD_VALUE;
|
||||||
dds->twoStepFlag = val ? 1 : 0;
|
if (val)
|
||||||
|
dds->flags |= DDS_TWO_STEP_FLAG;
|
||||||
|
else
|
||||||
|
dds->flags &= ~DDS_TWO_STEP_FLAG;
|
||||||
|
|
||||||
} else if (!strcmp(option, "slaveOnly")) {
|
} else if (!strcmp(option, "slaveOnly")) {
|
||||||
if (1 != sscanf(value, "%d", &val))
|
if (1 != sscanf(value, "%d", &val))
|
||||||
return BAD_VALUE;
|
return BAD_VALUE;
|
||||||
if (!(cfg_ignore & CFG_IGNORE_SLAVEONLY))
|
if (!(cfg_ignore & CFG_IGNORE_SLAVEONLY)) {
|
||||||
dds->slaveOnly = val ? 1 : 0;
|
if (val)
|
||||||
|
dds->flags |= DDS_SLAVE_ONLY;
|
||||||
|
else
|
||||||
|
dds->flags &= ~DDS_SLAVE_ONLY;
|
||||||
|
}
|
||||||
|
|
||||||
} else if (!strcmp(option, "priority1")) {
|
} else if (!strcmp(option, "priority1")) {
|
||||||
if (1 != sscanf(value, "%hhu", &u8))
|
if (1 != sscanf(value, "%hhu", &u8))
|
||||||
|
@ -207,12 +214,12 @@ static enum parser_result parse_global_setting(const char *option,
|
||||||
} else if (!strcmp(option, "free_running")) {
|
} else if (!strcmp(option, "free_running")) {
|
||||||
if (1 != sscanf(value, "%d", &val))
|
if (1 != sscanf(value, "%d", &val))
|
||||||
return BAD_VALUE;
|
return BAD_VALUE;
|
||||||
dds->free_running = val ? 1 : 0;
|
cfg->dds.free_running = val ? 1 : 0;
|
||||||
|
|
||||||
} else if (!strcmp(option, "freq_est_interval")) {
|
} else if (!strcmp(option, "freq_est_interval")) {
|
||||||
if (1 != sscanf(value, "%d", &val) || !(val >= 0))
|
if (1 != sscanf(value, "%d", &val) || !(val >= 0))
|
||||||
return BAD_VALUE;
|
return BAD_VALUE;
|
||||||
dds->freq_est_interval = val;
|
cfg->dds.freq_est_interval = val;
|
||||||
pod->freq_est_interval = val;
|
pod->freq_est_interval = val;
|
||||||
|
|
||||||
} else if (!strcmp(option, "assume_two_step")) {
|
} else if (!strcmp(option, "assume_two_step")) {
|
||||||
|
|
2
config.h
2
config.h
|
@ -58,7 +58,7 @@ struct config {
|
||||||
enum transport_type transport;
|
enum transport_type transport;
|
||||||
enum delay_mechanism dm;
|
enum delay_mechanism dm;
|
||||||
|
|
||||||
struct defaultDS dds;
|
struct default_ds dds;
|
||||||
struct port_defaults pod;
|
struct port_defaults pod;
|
||||||
int *assume_two_step;
|
int *assume_two_step;
|
||||||
int *tx_timestamp_retries;
|
int *tx_timestamp_retries;
|
||||||
|
|
16
ds.h
16
ds.h
|
@ -24,17 +24,25 @@
|
||||||
|
|
||||||
/* clock data sets */
|
/* clock data sets */
|
||||||
|
|
||||||
|
#define DDS_TWO_STEP_FLAG (1<<0)
|
||||||
|
#define DDS_SLAVE_ONLY (1<<1)
|
||||||
|
|
||||||
struct defaultDS {
|
struct defaultDS {
|
||||||
Boolean twoStepFlag;
|
UInteger8 flags;
|
||||||
Boolean slaveOnly;
|
UInteger8 reserved1;
|
||||||
UInteger16 numberPorts;
|
UInteger16 numberPorts;
|
||||||
UInteger8 priority1;
|
UInteger8 priority1;
|
||||||
struct ClockQuality clockQuality;
|
struct ClockQuality clockQuality;
|
||||||
UInteger8 priority2;
|
UInteger8 priority2;
|
||||||
struct ClockIdentity clockIdentity;
|
struct ClockIdentity clockIdentity;
|
||||||
UInteger8 domainNumber;
|
UInteger8 domainNumber;
|
||||||
int free_running;
|
UInteger8 reserved2;
|
||||||
int freq_est_interval; /*log seconds*/
|
} PACKED;
|
||||||
|
|
||||||
|
struct default_ds {
|
||||||
|
struct defaultDS dds;
|
||||||
|
int free_running;
|
||||||
|
int freq_est_interval; /*log seconds*/
|
||||||
};
|
};
|
||||||
|
|
||||||
struct dataset {
|
struct dataset {
|
||||||
|
|
30
ptp4l.c
30
ptp4l.c
|
@ -40,14 +40,15 @@ static int running = 1;
|
||||||
|
|
||||||
static struct config cfg_settings = {
|
static struct config cfg_settings = {
|
||||||
.dds = {
|
.dds = {
|
||||||
.twoStepFlag = TRUE,
|
.dds = {
|
||||||
.slaveOnly = FALSE,
|
.flags = DDS_TWO_STEP_FLAG,
|
||||||
.priority1 = 128,
|
.priority1 = 128,
|
||||||
.clockQuality.clockClass = 248,
|
.clockQuality.clockClass = 248,
|
||||||
.clockQuality.clockAccuracy = 0xfe,
|
.clockQuality.clockAccuracy = 0xfe,
|
||||||
.clockQuality.offsetScaledLogVariance = 0xffff,
|
.clockQuality.offsetScaledLogVariance = 0xffff,
|
||||||
.priority2 = 128,
|
.priority2 = 128,
|
||||||
.domainNumber = 0,
|
.domainNumber = 0,
|
||||||
|
},
|
||||||
.free_running = 0,
|
.free_running = 0,
|
||||||
.freq_est_interval = 1,
|
.freq_est_interval = 1,
|
||||||
},
|
},
|
||||||
|
@ -137,7 +138,7 @@ int main(int argc, char *argv[])
|
||||||
enum transport_type *transport = &cfg_settings.transport;
|
enum transport_type *transport = &cfg_settings.transport;
|
||||||
enum timestamp_type *timestamping = &cfg_settings.timestamping;
|
enum timestamp_type *timestamping = &cfg_settings.timestamping;
|
||||||
struct clock *clock;
|
struct clock *clock;
|
||||||
struct defaultDS *ds = &cfg_settings.dds;
|
struct defaultDS *ds = &cfg_settings.dds.dds;
|
||||||
int phc_index = -1, required_modes = 0;
|
int phc_index = -1, required_modes = 0;
|
||||||
|
|
||||||
if (SIG_ERR == signal(SIGINT, handle_int_quit_term)) {
|
if (SIG_ERR == signal(SIGINT, handle_int_quit_term)) {
|
||||||
|
@ -205,7 +206,7 @@ int main(int argc, char *argv[])
|
||||||
req_phc = optarg;
|
req_phc = optarg;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
ds->slaveOnly = TRUE;
|
ds->flags |= DDS_SLAVE_ONLY;
|
||||||
*cfg_ignore |= CFG_IGNORE_SLAVEONLY;
|
*cfg_ignore |= CFG_IGNORE_SLAVEONLY;
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
|
@ -235,7 +236,7 @@ int main(int argc, char *argv[])
|
||||||
if (config && (c = config_read(config, &cfg_settings))) {
|
if (config && (c = config_read(config, &cfg_settings))) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
if (ds->slaveOnly) {
|
if (ds->flags & DDS_SLAVE_ONLY) {
|
||||||
ds->clockQuality.clockClass = 255;
|
ds->clockQuality.clockClass = 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +257,7 @@ int main(int argc, char *argv[])
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ds->twoStepFlag) {
|
if (!(ds->flags & DDS_TWO_STEP_FLAG)) {
|
||||||
switch (*timestamping) {
|
switch (*timestamping) {
|
||||||
case TS_SOFTWARE:
|
case TS_SOFTWARE:
|
||||||
case TS_LEGACY_HW:
|
case TS_LEGACY_HW:
|
||||||
|
@ -302,7 +303,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/* determine PHC Clock index */
|
/* determine PHC Clock index */
|
||||||
if (ds->free_running) {
|
if (cfg_settings.dds.free_running) {
|
||||||
phc_index = -1;
|
phc_index = -1;
|
||||||
} else if (*timestamping == TS_SOFTWARE || *timestamping == TS_LEGACY_HW) {
|
} else if (*timestamping == TS_SOFTWARE || *timestamping == TS_LEGACY_HW) {
|
||||||
phc_index = -1;
|
phc_index = -1;
|
||||||
|
@ -330,7 +331,8 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
clock = clock_create(phc_index, iface, cfg_settings.nports,
|
clock = clock_create(phc_index, iface, cfg_settings.nports,
|
||||||
*timestamping, ds, cfg_settings.clock_servo);
|
*timestamping, &cfg_settings.dds,
|
||||||
|
cfg_settings.clock_servo);
|
||||||
if (!clock) {
|
if (!clock) {
|
||||||
fprintf(stderr, "failed to create a clock\n");
|
fprintf(stderr, "failed to create a clock\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in New Issue