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.4 1998/06/22 21:09:10 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.
16 #ifndef _SYS_TIMEPPS_H_
17 #define _SYS_TIMEPPS_H_
19 #include <sys/ioccom.h>
21 typedef int pps_handle_t;
23 typedef unsigned pps_seq_t;
25 typedef struct ntp_fp {
26 unsigned int integral;
27 unsigned int fractional;
30 typedef union pps_timeu {
31 struct timespec tspec;
33 unsigned long longpair[2];
37 pps_seq_t assert_sequence; /* assert event seq # */
38 pps_seq_t clear_sequence; /* clear event seq # */
39 pps_timeu_t assert_tu;
41 int current_mode; /* current mode bits */
44 #define assert_timestamp assert_tu.tspec
45 #define clear_timestamp clear_tu.tspec
47 #define assert_timestamp_ntpfp assert_tu.ntpfp
48 #define clear_timestamp_ntpfp clear_tu.ntpfp
51 int mode; /* mode bits */
52 pps_timeu_t assert_off_tu;
53 pps_timeu_t clear_off_tu;
56 #define assert_offset assert_off_tu.tspec
57 #define clear_offset clear_off_tu.tspec
59 #define assert_offset_ntpfp assert_off_tu.ntpfp
60 #define clear_offset_ntpfp clear_off_tu.ntpfp
63 #define PPS_CAPTUREASSERT 0x01
64 #define PPS_CAPTURECLEAR 0x02
65 #define PPS_CAPTUREBOTH 0x03
67 #define PPS_OFFSETASSERT 0x10
68 #define PPS_OFFSETCLEAR 0x20
70 #define PPS_HARDPPSONASSERT 0x04
71 #define PPS_HARDPPSONCLEAR 0x08
73 #define PPS_ECHOASSERT 0x40
74 #define PPS_ECHOCLEAR 0x80
76 #define PPS_CANWAIT 0x100
78 #define PPS_TSFMT_TSPEC 0x1000
79 #define PPS_TSFMT_NTPFP 0x2000
81 struct pps_wait_args {
82 struct timespec timeout;
83 pps_info_t pps_info_buf;
86 #define PPS_IOC_CREATE _IO('1', 1)
87 #define PPS_IOC_DESTROY _IO('1', 2)
88 #define PPS_IOC_SETPARAMS _IOW('1', 3, pps_params_t)
89 #define PPS_IOC_GETPARAMS _IOR('1', 4, pps_params_t)
90 #define PPS_IOC_GETCAP _IOR('1', 5, int)
91 #define PPS_IOC_FETCH _IOWR('1', 6, pps_info_t)
92 #define PPS_IOC_WAIT _IOWR('1', 6, struct pps_wait_args)
96 pps_params_t ppsparam;
99 struct timecounter *ppstc;
100 unsigned ppscount[3];
103 void pps_event __P((struct pps_state *pps, struct timecounter *tc, unsigned count, int event));
104 void pps_init __P((struct pps_state *pps));
105 int pps_ioctl __P((u_long cmd, caddr_t data, struct pps_state *pps));
106 void hardpps __P((struct timespec *tsp, long nsec));
110 int time_pps_create(int filedes, pps_handle_t *handle);
111 int time_pps_destroy(pps_handle_t handle);
112 int time_pps_setparams(pps_handle_t handle, const pps_params_t *ppsparams);
113 int time_pps_getparams(pps_handle_t handle, pps_params_t *ppsparams);
114 int time_pps_getcap(pps_handle_t handle, int *mode);
115 int time_pps_fetch(pps_handle_t handle, pps_info_t *ppsinfobuf);
116 int time_pps_wait(pps_handle_t handle, const struct timespec *timeout,
117 pps_info_t *ppsinfobuf);
120 time_pps_create(int filedes, pps_handle_t *handle)
125 error = ioctl(filedes, PPS_IOC_CREATE, 0);
133 time_pps_destroy(pps_handle_t handle)
135 return (ioctl(handle, PPS_IOC_DESTROY, 0));
139 time_pps_setparams(pps_handle_t handle, const pps_params_t *ppsparams)
141 return (ioctl(handle, PPS_IOC_SETPARAMS, ppsparams));
145 time_pps_getparams(pps_handle_t handle, pps_params_t *ppsparams)
147 return (ioctl(handle, PPS_IOC_GETPARAMS, ppsparams));
151 time_pps_getcap(pps_handle_t handle, int *mode)
153 return (ioctl(handle, PPS_IOC_GETCAP, mode));
157 time_pps_fetch(pps_handle_t handle, pps_info_t *ppsinfobuf)
159 return (ioctl(handle, PPS_IOC_FETCH, ppsinfobuf));
163 time_pps_wait(pps_handle_t handle, const struct timespec *timeout,
164 pps_info_t *ppsinfobuf)
167 struct pps_wait_args arg;
169 arg.timeout = *timeout;
170 error = ioctl(handle, PPS_IOC_WAIT, &arg);
171 *ppsinfobuf = arg.pps_info_buf;
176 #endif /* _SYS_TIMEPPS_H_ */