]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/timepps.h
This commit was generated by cvs2svn to compensate for changes in r44743,
[FreeBSD/FreeBSD.git] / sys / sys / timepps.h
1 /*
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  * ----------------------------------------------------------------------------
8  *
9  * $Id: timepps.h,v 1.4 1998/06/22 21:09:10 phk Exp $
10  *
11  * The is a FreeBSD protype version of the "draft-mogul-pps-api-02.txt" 
12  * specification for Pulse Per Second timing interfaces.  
13  *
14  */
15
16 #ifndef _SYS_TIMEPPS_H_
17 #define _SYS_TIMEPPS_H_
18
19 #include <sys/ioccom.h>
20
21 typedef int pps_handle_t;       
22
23 typedef unsigned pps_seq_t;
24
25 typedef struct ntp_fp {
26         unsigned int    integral;
27         unsigned int    fractional;
28 } ntp_fp_t;
29
30 typedef union pps_timeu {
31         struct timespec tspec;
32         ntp_fp_t        ntpfp;
33         unsigned long   longpair[2];
34 } pps_timeu_t;
35
36 typedef struct {
37         pps_seq_t       assert_sequence;        /* assert event seq # */
38         pps_seq_t       clear_sequence;         /* clear event seq # */
39         pps_timeu_t     assert_tu;
40         pps_timeu_t     clear_tu;
41         int             current_mode;           /* current mode bits */
42 } pps_info_t;
43
44 #define assert_timestamp        assert_tu.tspec
45 #define clear_timestamp         clear_tu.tspec
46
47 #define assert_timestamp_ntpfp  assert_tu.ntpfp
48 #define clear_timestamp_ntpfp   clear_tu.ntpfp
49
50 typedef struct {
51         int mode;                               /* mode bits */
52         pps_timeu_t assert_off_tu;
53         pps_timeu_t clear_off_tu;
54 } pps_params_t;
55
56 #define assert_offset   assert_off_tu.tspec
57 #define clear_offset    clear_off_tu.tspec
58
59 #define assert_offset_ntpfp     assert_off_tu.ntpfp
60 #define clear_offset_ntpfp      clear_off_tu.ntpfp
61
62
63 #define PPS_CAPTUREASSERT       0x01
64 #define PPS_CAPTURECLEAR        0x02
65 #define PPS_CAPTUREBOTH         0x03
66
67 #define PPS_OFFSETASSERT        0x10
68 #define PPS_OFFSETCLEAR         0x20
69
70 #define PPS_HARDPPSONASSERT     0x04
71 #define PPS_HARDPPSONCLEAR      0x08
72
73 #define PPS_ECHOASSERT          0x40
74 #define PPS_ECHOCLEAR           0x80
75
76 #define PPS_CANWAIT             0x100
77
78 #define PPS_TSFMT_TSPEC         0x1000
79 #define PPS_TSFMT_NTPFP         0x2000
80
81 struct pps_wait_args {
82         struct timespec timeout;
83         pps_info_t      pps_info_buf;
84 };
85
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)
93
94 #ifdef KERNEL
95 struct pps_state {
96         pps_params_t    ppsparam;
97         pps_info_t      ppsinfo;
98         int             ppscap;
99         struct timecounter *ppstc;
100         unsigned        ppscount[3];
101 };
102
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));
107
108 #else /* !KERNEL */
109
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);
118
119 static __inline int
120 time_pps_create(int filedes, pps_handle_t *handle)
121 {
122         int error;
123
124         *handle = -1;
125         error = ioctl(filedes, PPS_IOC_CREATE, 0);
126         if (error < 0) 
127                 return (-1);
128         *handle = filedes;
129         return (0);
130 }
131
132 static __inline int
133 time_pps_destroy(pps_handle_t handle)
134 {
135         return (ioctl(handle, PPS_IOC_DESTROY, 0));
136 }
137
138 static __inline int
139 time_pps_setparams(pps_handle_t handle, const pps_params_t *ppsparams)
140 {
141         return (ioctl(handle, PPS_IOC_SETPARAMS, ppsparams));
142 }
143
144 static __inline int
145 time_pps_getparams(pps_handle_t handle, pps_params_t *ppsparams)
146 {
147         return (ioctl(handle, PPS_IOC_GETPARAMS, ppsparams));
148 }
149
150 static __inline int 
151 time_pps_getcap(pps_handle_t handle, int *mode)
152 {
153         return (ioctl(handle, PPS_IOC_GETCAP, mode));
154 }
155
156 static __inline int
157 time_pps_fetch(pps_handle_t handle, pps_info_t *ppsinfobuf)
158 {
159         return (ioctl(handle, PPS_IOC_FETCH, ppsinfobuf));
160 }
161
162 static __inline int
163 time_pps_wait(pps_handle_t handle, const struct timespec *timeout,
164         pps_info_t *ppsinfobuf)
165 {
166         int error;
167         struct pps_wait_args arg;
168
169         arg.timeout = *timeout;
170         error = ioctl(handle, PPS_IOC_WAIT, &arg);
171         *ppsinfobuf = arg.pps_info_buf;
172         return (error);
173 }
174
175 #endif /* !KERNEL */
176 #endif /* _SYS_TIMEPPS_H_ */