Skip to content

Commit 271c83d

Browse files
Manfred Rudigierdavem330
authored andcommitted
ptp: Add a command line option in testptp to set a specific PTP time
Signed-off-by: Manfred Rudigier <manfred.rudigier@omicron.at> Signed-off-by: Christian Riesch <christian.riesch@omicron.at> Acked-by: Richard Cochran <richardcochran@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b620cb3 commit 271c83d

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

Documentation/ptp/testptp.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ static void usage(char *progname)
131131
" -P val enable or disable (val=1|0) the system clock PPS\n"
132132
" -s set the ptp clock time from the system time\n"
133133
" -S set the system time from the ptp clock time\n"
134-
" -t val shift the ptp clock time by 'val' seconds\n",
134+
" -t val shift the ptp clock time by 'val' seconds\n"
135+
" -T val set the ptp clock time to 'val' seconds\n",
135136
progname);
136137
}
137138

@@ -172,14 +173,15 @@ int main(int argc, char *argv[])
172173
int perout = -1;
173174
int pin_index = -1, pin_func;
174175
int pps = -1;
176+
int seconds = 0;
175177
int settime = 0;
176178

177179
int64_t t1, t2, tp;
178180
int64_t interval, offset;
179181

180182
progname = strrchr(argv[0], '/');
181183
progname = progname ? 1+progname : argv[0];
182-
while (EOF != (c = getopt(argc, argv, "a:A:cd:e:f:ghi:k:lL:p:P:sSt:v"))) {
184+
while (EOF != (c = getopt(argc, argv, "a:A:cd:e:f:ghi:k:lL:p:P:sSt:T:v"))) {
183185
switch (c) {
184186
case 'a':
185187
oneshot = atoi(optarg);
@@ -234,6 +236,10 @@ int main(int argc, char *argv[])
234236
case 't':
235237
adjtime = atoi(optarg);
236238
break;
239+
case 'T':
240+
settime = 3;
241+
seconds = atoi(optarg);
242+
break;
237243
case 'h':
238244
usage(progname);
239245
return 0;
@@ -326,6 +332,16 @@ int main(int argc, char *argv[])
326332
}
327333
}
328334

335+
if (settime == 3) {
336+
ts.tv_sec = seconds;
337+
ts.tv_nsec = 0;
338+
if (clock_settime(clkid, &ts)) {
339+
perror("clock_settime");
340+
} else {
341+
puts("set time okay");
342+
}
343+
}
344+
329345
if (extts) {
330346
memset(&extts_request, 0, sizeof(extts_request));
331347
extts_request.index = index;

0 commit comments

Comments
 (0)