Add a small program to test/measure with the RFC 2783 API for timing
external signals.
This commit is contained in:
parent
53916adaa8
commit
3d9368b2d0
11
tools/test/ppsapi/Makefile
Normal file
11
tools/test/ppsapi/Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= ppsapitest
|
||||
NOMAN= yeah
|
||||
|
||||
WARNS?= 5
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
test: ${PROG}
|
||||
./${PROG} /dev/cuaa0
|
48
tools/test/ppsapi/README
Normal file
48
tools/test/ppsapi/README
Normal file
@ -0,0 +1,48 @@
|
||||
# $FreeBSD$
|
||||
|
||||
This is a small test program which I have had around since we wrote
|
||||
the RFC 2783 API.
|
||||
|
||||
Options:
|
||||
-a capture assert flank
|
||||
-c capture clear flank
|
||||
(if neither -a -c: capture all available flanks)
|
||||
-A output on assert flank
|
||||
-C output on clear flank
|
||||
(if neither -A -C: output on all flanks)
|
||||
-e enable echo (all possible flanks)
|
||||
-u unbuffered output.
|
||||
-v verbose.
|
||||
|
||||
The output looks like:
|
||||
|
||||
# ./ppsapitest -C /dev/cuaa4
|
||||
1070915603 .703680117 119 1070915940 .902275676 121
|
||||
1070915941 .703657317 120 1070915941 .902327516 122
|
||||
1070915942 .703657077 121 1070915942 .902367957 123
|
||||
1070915943 .703657557 122 1070915943 .902419077 124
|
||||
1070915944 .703656717 123 1070915944 .902467197 125
|
||||
1070915945 .703657077 124 1070915945 .902527078 126
|
||||
|
||||
Columns:
|
||||
|
||||
assert seconds (tv_sec)
|
||||
assert nanoseconds (tv_nsec)
|
||||
assert sequence number
|
||||
clear seconds (tv_sec)
|
||||
clear nanoseconds (tv_nsec)
|
||||
clear sequence number
|
||||
|
||||
(If the -C option had not been specified, twice as many lines would
|
||||
be output:
|
||||
|
||||
# ./ppsapitest /dev/cuaa4
|
||||
1070916432 .703624557 125 1070915945 .902527078 126
|
||||
1070916432 .703624557 125 1070916432 .902303156 127
|
||||
1070916433 .703624557 126 1070916432 .902303156 127
|
||||
1070916433 .703624557 126 1070916433 .902348396 128
|
||||
1070916434 .703625757 127 1070916433 .902348396 128
|
||||
1070916434 .703625757 127 1070916434 .902396877 129
|
||||
1070916435 .703623837 128 1070916434 .902396877 129
|
||||
1070916435 .703623837 128 1070916435 .902444277 130
|
||||
|
172
tools/test/ppsapi/ppsapitest.c
Normal file
172
tools/test/ppsapi/ppsapitest.c
Normal file
@ -0,0 +1,172 @@
|
||||
/*-
|
||||
* Copyright (c) 1998-2003 Poul-Henning Kamp
|
||||
*
|
||||
* Please see src/share/examples/etc/bsd-style-copyright.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <err.h>
|
||||
#include <sys/timepps.h>
|
||||
|
||||
static int aflag, Aflag, cflag, Cflag, eflag, uflag, vflag;
|
||||
|
||||
static void
|
||||
Chew(struct timespec *tsa, struct timespec *tsc, unsigned sa, unsigned sc)
|
||||
{
|
||||
printf("%jd .%09ld %u", (intmax_t)tsa->tv_sec, tsa->tv_nsec, sa);
|
||||
printf(" %jd .%09ld %u\n", (intmax_t)tsc->tv_sec, tsc->tv_nsec, sc);
|
||||
if (uflag)
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
pps_info_t pi;
|
||||
pps_params_t pp;
|
||||
pps_handle_t ph;
|
||||
int i, mode;
|
||||
u_int olda, oldc;
|
||||
struct timespec to;
|
||||
|
||||
while ((i = getopt(argc, argv, "aAbBcCeuv")) != -1) {
|
||||
switch (i) {
|
||||
case 'a': aflag = 1; break;
|
||||
case 'A': Aflag = 1; break;
|
||||
case 'b': aflag = 1; cflag = 1; break;
|
||||
case 'B': Aflag = 1; Cflag = 1; break;
|
||||
case 'c': cflag = 1; break;
|
||||
case 'C': Cflag = 1; break;
|
||||
case 'e': eflag = 1; break;
|
||||
case 'u': uflag = 1; break;
|
||||
case 'v': vflag = 1; break;
|
||||
case '?':
|
||||
default:
|
||||
fprintf(stderr,
|
||||
"Usage: ppsapitest [-aAcC] device\n");
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
if (argc > 0) {
|
||||
fd = open(argv[0], O_RDONLY);
|
||||
if (fd < 0)
|
||||
err(1, argv[0]);
|
||||
} else {
|
||||
fd = 0;
|
||||
}
|
||||
i = time_pps_create(fd, &ph);
|
||||
if (i < 0)
|
||||
err(1, "time_pps_create");
|
||||
|
||||
i = time_pps_getcap(ph, &mode);
|
||||
if (i < 0)
|
||||
err(1, "time_pps_getcap");
|
||||
if (vflag) {
|
||||
fprintf(stderr, "Supported modebits:");
|
||||
if (mode & PPS_CAPTUREASSERT)
|
||||
fprintf(stderr, " CAPTUREASSERT");
|
||||
if (mode & PPS_CAPTURECLEAR)
|
||||
fprintf(stderr, " CAPTURECLEAR");
|
||||
if (mode & PPS_OFFSETASSERT)
|
||||
fprintf(stderr, " OFFSETASSERT");
|
||||
if (mode & PPS_OFFSETCLEAR)
|
||||
fprintf(stderr, " OFFSETCLEAR");
|
||||
if (mode & PPS_ECHOASSERT)
|
||||
fprintf(stderr, " ECHOASSERT");
|
||||
if (mode & PPS_ECHOCLEAR)
|
||||
fprintf(stderr, " ECHOCLEAR");
|
||||
if (mode & PPS_CANWAIT)
|
||||
fprintf(stderr, " CANWAIT");
|
||||
if (mode & PPS_CANPOLL)
|
||||
fprintf(stderr, " CANPOLL");
|
||||
if (mode & PPS_TSFMT_TSPEC)
|
||||
fprintf(stderr, " TSPEC");
|
||||
if (mode & PPS_TSFMT_NTPFP)
|
||||
fprintf(stderr, " NTPFP");
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
if (!aflag && !cflag) {
|
||||
if (mode & PPS_CAPTUREASSERT)
|
||||
aflag = 1;
|
||||
if (mode & PPS_CAPTURECLEAR)
|
||||
cflag = 1;
|
||||
}
|
||||
if (!Aflag && !Cflag) {
|
||||
Aflag = aflag;
|
||||
Cflag = cflag;
|
||||
}
|
||||
|
||||
if (Cflag && !(mode & PPS_CAPTURECLEAR))
|
||||
errx(1, "-C but cannot capture on clear flank");
|
||||
|
||||
if (Aflag && !(mode & PPS_CAPTUREASSERT))
|
||||
errx(1, "-A but cannot capture on assert flank");
|
||||
|
||||
i = time_pps_getparams(ph, &pp);
|
||||
if (i < 0)
|
||||
err(1, "time_pps_getparams():");
|
||||
|
||||
if (aflag)
|
||||
pp.mode |= PPS_CAPTUREASSERT;
|
||||
if (cflag)
|
||||
pp.mode |= PPS_CAPTURECLEAR;
|
||||
|
||||
if (eflag & aflag)
|
||||
pp.mode |= PPS_ECHOASSERT;
|
||||
|
||||
if (eflag & cflag)
|
||||
pp.mode |= PPS_ECHOCLEAR;
|
||||
|
||||
if (!(pp.mode & PPS_TSFMT_TSPEC))
|
||||
pp.mode |= PPS_TSFMT_TSPEC;
|
||||
|
||||
i = time_pps_setparams(ph, &pp);
|
||||
if (i < 0) {
|
||||
err(1, "time_pps_setparams(mode %x):", pp.mode);
|
||||
}
|
||||
|
||||
/*
|
||||
* Pick up first event outside the loop in order to not
|
||||
* get something ancient into the outfile.
|
||||
*/
|
||||
to.tv_nsec = 0;
|
||||
to.tv_sec = 0;
|
||||
i = time_pps_fetch(ph, PPS_TSFMT_TSPEC, &pi, &to);
|
||||
if (i < 0)
|
||||
err(1, "time_pps_fetch()");
|
||||
olda = pi.assert_sequence;
|
||||
oldc = pi.clear_sequence;
|
||||
|
||||
while (1) {
|
||||
to.tv_nsec = 0;
|
||||
to.tv_sec = 0;
|
||||
i = time_pps_fetch(ph, PPS_TSFMT_TSPEC, &pi, &to);
|
||||
if (i < 0)
|
||||
err(1, "time_pps_fetch()");
|
||||
if (oldc != pi.clear_sequence && Cflag)
|
||||
;
|
||||
else if (olda != pi.assert_sequence && Aflag)
|
||||
;
|
||||
else {
|
||||
usleep(10000);
|
||||
continue;
|
||||
}
|
||||
Chew(&pi.assert_timestamp, &pi.clear_timestamp,
|
||||
pi.assert_sequence, pi.clear_sequence);
|
||||
olda = pi.assert_sequence;
|
||||
oldc = pi.clear_sequence;
|
||||
}
|
||||
return(0);
|
||||
}
|
Loading…
Reference in New Issue
Block a user