Skip to content

Commit

Permalink
ts2phc: rename "master" to "source"
Browse files Browse the repository at this point in the history
The ts2phc program will introduce clock synchronization which is
orthogonal to the direction in which PPS is emitted (from the master
to the slave).

To have a more consistent terminology, we can avoid using the
ultra-generic term "master" and replace it with "PPS source", which
describes the role of the data structure in the new interpretation of
the program in a much clearer way.

Signed-off-by: Vladimir Oltean <[email protected]>
  • Loading branch information
vladimiroltean authored and richardcochran committed May 15, 2022
1 parent ddabf9b commit 58c7f9d
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 189 deletions.
56 changes: 28 additions & 28 deletions ts2phc.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ struct interface {
STAILQ_ENTRY(interface) list;
};

static void ts2phc_cleanup(struct config *cfg, struct ts2phc_master *master)
static void ts2phc_cleanup(struct config *cfg, struct ts2phc_pps_source *src)
{
ts2phc_pps_sink_cleanup();
if (master) {
ts2phc_master_destroy(master);
if (src) {
ts2phc_pps_source_destroy(src);
}
if (cfg) {
config_destroy(cfg);
Expand Down Expand Up @@ -56,8 +56,8 @@ static void usage(char *progname)
int main(int argc, char *argv[])
{
int c, err = 0, have_sink = 0, index, print_level;
struct ts2phc_master *master = NULL;
enum ts2phc_master_type pps_type;
struct ts2phc_pps_source *src = NULL;
enum ts2phc_pps_source_type pps_type;
char *config = NULL, *progname;
const char *pps_source = NULL;
struct config *cfg = NULL;
Expand All @@ -68,7 +68,7 @@ int main(int argc, char *argv[])

cfg = config_create();
if (!cfg) {
ts2phc_cleanup(cfg, master);
ts2phc_cleanup(cfg, src);
return -1;
}

Expand All @@ -81,14 +81,14 @@ int main(int argc, char *argv[])
switch (c) {
case 0:
if (config_parse_option(cfg, opts[index].name, optarg)) {
ts2phc_cleanup(cfg, master);
ts2phc_cleanup(cfg, src);
return -1;
}
break;
case 'c':
if (!config_create_interface(optarg, cfg)) {
fprintf(stderr, "failed to add PPS sink\n");
ts2phc_cleanup(cfg, master);
ts2phc_cleanup(cfg, src);
return -1;
}
have_sink = 1;
Expand All @@ -99,7 +99,7 @@ int main(int argc, char *argv[])
case 'l':
if (get_arg_val_i(c, optarg, &print_level,
PRINT_LEVEL_MIN, PRINT_LEVEL_MAX)) {
ts2phc_cleanup(cfg, master);
ts2phc_cleanup(cfg, src);
return -1;
}
config_set_int(cfg, "logging_level", print_level);
Expand All @@ -116,29 +116,29 @@ int main(int argc, char *argv[])
case 's':
if (pps_source) {
fprintf(stderr, "too many PPS sources\n");
ts2phc_cleanup(cfg, master);
ts2phc_cleanup(cfg, src);
return -1;
}
pps_source = optarg;
break;
case 'v':
ts2phc_cleanup(cfg, master);
ts2phc_cleanup(cfg, src);
version_show(stdout);
return 0;
case 'h':
ts2phc_cleanup(cfg, master);
ts2phc_cleanup(cfg, src);
usage(progname);
return -1;
case '?':
default:
ts2phc_cleanup(cfg, master);
ts2phc_cleanup(cfg, src);
usage(progname);
return -1;
}
}
if (config && (c = config_read(config, cfg))) {
fprintf(stderr, "failed to read config\n");
ts2phc_cleanup(cfg, master);
ts2phc_cleanup(cfg, src);
return -1;
}
print_set_progname(progname);
Expand All @@ -151,59 +151,59 @@ int main(int argc, char *argv[])
if (1 == config_get_int(cfg, interface_name(iface), "ts2phc.master")) {
if (pps_source) {
fprintf(stderr, "too many PPS sources\n");
ts2phc_cleanup(cfg, master);
ts2phc_cleanup(cfg, src);
return -1;
}
pps_source = interface_name(iface);
} else {
if (ts2phc_pps_sink_add(cfg, interface_name(iface))) {
fprintf(stderr, "failed to add PPS sink\n");
ts2phc_cleanup(cfg, master);
ts2phc_cleanup(cfg, src);
return -1;
}
have_sink = 1;
}
}
if (!have_sink) {
fprintf(stderr, "no PPS sinks specified\n");
ts2phc_cleanup(cfg, master);
ts2phc_cleanup(cfg, src);
usage(progname);
return -1;
}
if (!pps_source) {
fprintf(stderr, "no PPS source specified\n");
ts2phc_cleanup(cfg, master);
ts2phc_cleanup(cfg, src);
usage(progname);
return -1;
}
if (ts2phc_pps_sink_arm()) {
fprintf(stderr, "failed to arm PPS sinks\n");
ts2phc_cleanup(cfg, master);
ts2phc_cleanup(cfg, src);
return -1;
}

if (!strcasecmp(pps_source, "generic")) {
pps_type = TS2PHC_MASTER_GENERIC;
pps_type = TS2PHC_PPS_SOURCE_GENERIC;
} else if (!strcasecmp(pps_source, "nmea")) {
pps_type = TS2PHC_MASTER_NMEA;
pps_type = TS2PHC_PPS_SOURCE_NMEA;
} else {
pps_type = TS2PHC_MASTER_PHC;
pps_type = TS2PHC_PPS_SOURCE_PHC;
}
master = ts2phc_master_create(cfg, pps_source, pps_type);
if (!master) {
fprintf(stderr, "failed to create master\n");
ts2phc_cleanup(cfg, master);
src = ts2phc_pps_source_create(cfg, pps_source, pps_type);
if (!src) {
fprintf(stderr, "failed to create PPS source\n");
ts2phc_cleanup(cfg, src);
return -1;
}

while (is_running()) {
err = ts2phc_pps_sink_poll(master);
err = ts2phc_pps_sink_poll(src);
if (err) {
pr_err("poll failed");
break;
}
}

ts2phc_cleanup(cfg, master);
ts2phc_cleanup(cfg, src);
return err;
}
32 changes: 16 additions & 16 deletions ts2phc_generic_pps_source.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file ts2phc_generic_master.c
* @file ts2phc_generic_pps_source.c
* @note Copyright (C) 2019 Richard Cochran <[email protected]>
* @note SPDX-License-Identifier: GPL-2.0+
*/
Expand All @@ -12,14 +12,14 @@
#include "ts2phc_pps_source_private.h"
#include "util.h"

struct ts2phc_generic_master {
struct ts2phc_master master;
struct ts2phc_generic_pps_source {
struct ts2phc_pps_source pps_source;
};

static void ts2phc_generic_master_destroy(struct ts2phc_master *master)
static void ts2phc_generic_pps_source_destroy(struct ts2phc_pps_source *src)
{
struct ts2phc_generic_master *s =
container_of(master, struct ts2phc_generic_master, master);
struct ts2phc_generic_pps_source *s =
container_of(src, struct ts2phc_generic_pps_source, pps_source);
free(s);
}

Expand All @@ -28,8 +28,8 @@ static void ts2phc_generic_master_destroy(struct ts2phc_master *master)
* PPS event was generated. This implementation assumes that the
* system time is approximately correct.
*/
static int ts2phc_generic_master_getppstime(struct ts2phc_master *m,
struct timespec *ts)
static int ts2phc_generic_pps_source_getppstime(struct ts2phc_pps_source *src,
struct timespec *ts)
{
struct timex ntx;
int code;
Expand All @@ -47,17 +47,17 @@ static int ts2phc_generic_master_getppstime(struct ts2phc_master *m,
return 0;
}

struct ts2phc_master *ts2phc_generic_master_create(struct config *cfg,
const char *dev)
struct ts2phc_pps_source *ts2phc_generic_pps_source_create(struct config *cfg,
const char *dev)
{
struct ts2phc_generic_master *master;
struct ts2phc_generic_pps_source *src;

master = calloc(1, sizeof(*master));
if (!master) {
src = calloc(1, sizeof(*src));
if (!src) {
return NULL;
}
master->master.destroy = ts2phc_generic_master_destroy;
master->master.getppstime = ts2phc_generic_master_getppstime;
src->pps_source.destroy = ts2phc_generic_pps_source_destroy;
src->pps_source.getppstime = ts2phc_generic_pps_source_getppstime;

return &master->master;
return &src->pps_source;
}
8 changes: 4 additions & 4 deletions ts2phc_generic_pps_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* @note Copyright (C) 2019 Richard Cochran <[email protected]>
* @note SPDX-License-Identifier: GPL-2.0+
*/
#ifndef HAVE_TS2PHC_GENERIC_MASTER_H
#define HAVE_TS2PHC_GENERIC_MASTER_H
#ifndef HAVE_TS2PHC_GENERIC_PPS_SOURCE_H
#define HAVE_TS2PHC_GENERIC_PPS_SOURCE_H

#include "ts2phc_pps_source.h"

struct ts2phc_master *ts2phc_generic_master_create(struct config *cfg,
const char *dev);
struct ts2phc_pps_source *ts2phc_generic_pps_source_create(struct config *cfg,
const char *dev);

#endif
Loading

0 comments on commit 58c7f9d

Please sign in to comment.