5 Try to run this program to see what the PPS-API finds. You give it the
6 device as argument and you may have to modify the pp.mode = BLA assignment.
16 #include <sys/types.h>
18 #include <sys/timepps.h>
19 #include <sys/termios.h>
21 #define timespecsub(vvp, uvp) \
23 (vvp)->tv_sec -= (uvp)->tv_sec; \
24 (vvp)->tv_nsec -= (uvp)->tv_nsec; \
25 if ((vvp)->tv_nsec < 0) { \
27 (vvp)->tv_nsec += 1000000000; \
33 Chew(struct timespec
*tsa
, struct timespec
*tsc
, unsigned sa
, unsigned sc
)
38 printf("%d.%09d ", tsa
->tv_sec
, tsa
->tv_nsec
);
39 printf("%d.%09d ", tsc
->tv_sec
, tsc
->tv_nsec
);
40 printf("%u %u ", sa
, sc
);
44 printf("%.9f ", ts
.tv_sec
+ ts
.tv_nsec
/ 1e9
);
50 main(int argc
, char **argv
)
62 argv
[1] = "/dev/cuaa1";
64 fd
= open(argv
[1], O_RDONLY
);
67 i
= time_pps_create(fd
, &ph
);
69 err(1, "time_pps_create");
71 i
= time_pps_getcap(ph
, &mode
);
73 err(1, "time_pps_getcap");
75 pp
.mode
= PPS_CAPTUREASSERT
| PPS_ECHOASSERT
;
76 pp
.mode
= PPS_CAPTUREBOTH
;
77 /* pp.mode = PPS_CAPTUREASSERT; */
79 i
= time_pps_setparams(ph
, &pp
);
81 err(1, "time_pps_setparams");
86 i
= time_pps_fetch(ph
, PPS_TSFMT_TSPEC
, &pi
, &to
);
88 err(1, "time_pps_fetch");
89 if (olda
== pi
.assert_sequence
&&
90 oldc
== pi
.clear_sequence
) {
95 Chew(&pi
.assert_timestamp
, &pi
.clear_timestamp
,
96 pi
.assert_sequence
, pi
.clear_sequence
);
97 olda
= pi
.assert_sequence
;
98 oldc
= pi
.clear_sequence
;