clock: specify type at creation time.
Store the type in the clock object explicitly. Signed-off-by: Richard Cochran <richardcochran@gmail.com>master
parent
63e530e297
commit
9c8fe6a94e
20
clock.c
20
clock.c
|
@ -74,6 +74,7 @@ struct clock_subscriber {
|
|||
};
|
||||
|
||||
struct clock {
|
||||
enum clock_type type;
|
||||
struct config *config;
|
||||
clockid_t clkid;
|
||||
struct servo *servo;
|
||||
|
@ -799,7 +800,8 @@ static void clock_remove_port(struct clock *c, struct port *p)
|
|||
port_close(p);
|
||||
}
|
||||
|
||||
struct clock *clock_create(struct config *config, int phc_index)
|
||||
struct clock *clock_create(enum clock_type type, struct config *config,
|
||||
int phc_index)
|
||||
{
|
||||
enum timestamp_type timestamping =
|
||||
config_get_int(config, NULL, "time_stamping");
|
||||
|
@ -821,6 +823,17 @@ struct clock *clock_create(struct config *config, int phc_index)
|
|||
if (c->nports)
|
||||
clock_destroy(c);
|
||||
|
||||
switch (type) {
|
||||
case CLOCK_TYPE_ORDINARY:
|
||||
case CLOCK_TYPE_BOUNDARY:
|
||||
c->type = type;
|
||||
break;
|
||||
case CLOCK_TYPE_P2P:
|
||||
case CLOCK_TYPE_E2E:
|
||||
case CLOCK_TYPE_MANAGEMENT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Initialize the defaultDS. */
|
||||
c->dds.clockQuality.clockClass =
|
||||
config_get_int(config, NULL, "clockClass");
|
||||
|
@ -1666,10 +1679,7 @@ struct clock_description *clock_description(struct clock *c)
|
|||
|
||||
enum clock_type clock_type(struct clock *c)
|
||||
{
|
||||
if (c->nports > 1) {
|
||||
return CLOCK_TYPE_BOUNDARY;
|
||||
}
|
||||
return CLOCK_TYPE_ORDINARY;
|
||||
return c->type;
|
||||
}
|
||||
|
||||
void clock_check_ts(struct clock *c, struct timespec ts)
|
||||
|
|
4
clock.h
4
clock.h
|
@ -76,12 +76,14 @@ struct config *clock_config(struct clock *c);
|
|||
* Create a clock instance. There can only be one clock in any system,
|
||||
* so subsequent calls will destroy the previous clock instance.
|
||||
*
|
||||
* @param type Specifies which type of clock to create.
|
||||
* @param config Pointer to the configuration database.
|
||||
* @param phc_index PTP hardware clock device to use.
|
||||
* Pass -1 to select CLOCK_REALTIME.
|
||||
* @return A pointer to the single global clock instance.
|
||||
*/
|
||||
struct clock *clock_create(struct config *config, int phc_index);
|
||||
struct clock *clock_create(enum clock_type type, struct config *config,
|
||||
int phc_index);
|
||||
|
||||
/**
|
||||
* Obtains a clock's default data set.
|
||||
|
|
3
ptp4l.c
3
ptp4l.c
|
@ -222,7 +222,8 @@ int main(int argc, char *argv[])
|
|||
pr_info("selected /dev/ptp%d as PTP clock", phc_index);
|
||||
}
|
||||
|
||||
clock = clock_create(cfg, phc_index);
|
||||
clock = clock_create(cfg->n_interfaces > 1 ? CLOCK_TYPE_BOUNDARY :
|
||||
CLOCK_TYPE_ORDINARY, cfg, phc_index);
|
||||
if (!clock) {
|
||||
fprintf(stderr, "failed to create a clock\n");
|
||||
goto out;
|
||||
|
|
Loading…
Reference in New Issue