2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
9 * $Id: timepps.h,v 1.7 1999/03/30 11:44:59 phk Exp $
11 * The is a FreeBSD protype version of the "draft-mogul-pps-api-02.txt"
12 * specification for Pulse Per Second timing interfaces.
14 * NOTE: There is no current maintainer for this API in FreeBSD, and
15 * the implementation will not be updated to track the newer
16 * versions of the draft. Contact phk@FreeBSD.org for more info.
20 #ifndef _SYS_TIMEPPS_H_
21 #define _SYS_TIMEPPS_H_
23 #include <sys/ioccom.h>
25 typedef int pps_handle_t;
27 typedef unsigned pps_seq_t;
29 typedef struct ntp_fp {
30 unsigned int integral;
31 unsigned int fractional;
34 typedef union pps_timeu {
35 struct timespec tspec;
37 unsigned long longpair[2];
41 pps_seq_t assert_sequence; /* assert event seq # */
42 pps_seq_t clear_sequence; /* clear event seq # */
43 pps_timeu_t assert_tu;
45 int current_mode; /* current mode bits */
48 #define assert_timestamp assert_tu.tspec
49 #define clear_timestamp clear_tu.tspec
51 #define assert_timestamp_ntpfp assert_tu.ntpfp
52 #define clear_timestamp_ntpfp clear_tu.ntpfp
55 int mode; /* mode bits */
56 pps_timeu_t assert_off_tu;
57 pps_timeu_t clear_off_tu;
60 #define assert_offset assert_off_tu.tspec
61 #define clear_offset clear_off_tu.tspec
63 #define assert_offset_ntpfp assert_off_tu.ntpfp
64 #define clear_offset_ntpfp clear_off_tu.ntpfp
67 #define PPS_CAPTUREASSERT 0x01
68 #define PPS_CAPTURECLEAR 0x02
69 #define PPS_CAPTUREBOTH 0x03
71 #define PPS_OFFSETASSERT 0x10
72 #define PPS_OFFSETCLEAR 0x20
74 #define PPS_HARDPPSONASSERT 0x04
75 #define PPS_HARDPPSONCLEAR 0x08
77 #define PPS_ECHOASSERT 0x40
78 #define PPS_ECHOCLEAR 0x80
80 #define PPS_CANWAIT 0x100
82 #define PPS_TSFMT_TSPEC 0x1000
83 #define PPS_TSFMT_NTPFP 0x2000
85 struct pps_wait_args {
86 struct timespec timeout;
87 pps_info_t pps_info_buf;
90 #define PPS_IOC_CREATE _IO('1', 1)
91 #define PPS_IOC_DESTROY _IO('1', 2)
92 #define PPS_IOC_SETPARAMS _IOW('1', 3, pps_params_t)
93 #define PPS_IOC_GETPARAMS _IOR('1', 4, pps_params_t)
94 #define PPS_IOC_GETCAP _IOR('1', 5, int)
95 #define PPS_IOC_FETCH _IOWR('1', 6, pps_info_t)
96 #define PPS_IOC_WAIT _IOWR('1', 6, struct pps_wait_args)
100 pps_params_t ppsparam;
103 struct timecounter *ppstc;
104 unsigned ppscount[3];
107 void pps_event __P((struct pps_state *pps, struct timecounter *tc, unsigned count, int event));
108 void pps_init __P((struct pps_state *pps));
109 int pps_ioctl __P((u_long cmd, caddr_t data, struct pps_state *pps));
110 void hardpps __P((struct timespec *tsp, long nsec));
115 time_pps_create(int filedes, pps_handle_t *handle)
120 error = ioctl(filedes, PPS_IOC_CREATE, 0);
128 time_pps_destroy(pps_handle_t handle)
130 return (ioctl(handle, PPS_IOC_DESTROY, 0));
134 time_pps_setparams(pps_handle_t handle, const pps_params_t *ppsparams)
136 return (ioctl(handle, PPS_IOC_SETPARAMS, ppsparams));
140 time_pps_getparams(pps_handle_t handle, pps_params_t *ppsparams)
142 return (ioctl(handle, PPS_IOC_GETPARAMS, ppsparams));
146 time_pps_getcap(pps_handle_t handle, int *mode)
148 return (ioctl(handle, PPS_IOC_GETCAP, mode));
152 time_pps_fetch(pps_handle_t handle, pps_info_t *ppsinfobuf)
154 return (ioctl(handle, PPS_IOC_FETCH, ppsinfobuf));
158 time_pps_wait(pps_handle_t handle, const struct timespec *timeout,
159 pps_info_t *ppsinfobuf)
162 struct pps_wait_args arg;
164 arg.timeout = *timeout;
165 error = ioctl(handle, PPS_IOC_WAIT, &arg);
166 *ppsinfobuf = arg.pps_info_buf;
171 #endif /* _SYS_TIMEPPS_H_ */