]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/timepps.h
This commit was generated by cvs2svn to compensate for changes in r48114,
[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.6 1999/03/30 09:01:47 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 static __inline int
111 time_pps_create(int filedes, pps_handle_t *handle)
112 {
113         int error;
114
115         *handle = -1;
116         error = ioctl(filedes, PPS_IOC_CREATE, 0);
117         if (error < 0) 
118                 return (-1);
119         *handle = filedes;
120         return (0);
121 }
122
123 static __inline int
124 time_pps_destroy(pps_handle_t handle)
125 {
126         return (ioctl(handle, PPS_IOC_DESTROY, 0));
127 }
128
129 static __inline int
130 time_pps_setparams(pps_handle_t handle, const pps_params_t *ppsparams)
131 {
132         return (ioctl(handle, PPS_IOC_SETPARAMS, ppsparams));
133 }
134
135 static __inline int
136 time_pps_getparams(pps_handle_t handle, pps_params_t *ppsparams)
137 {
138         return (ioctl(handle, PPS_IOC_GETPARAMS, ppsparams));
139 }
140
141 static __inline int 
142 time_pps_getcap(pps_handle_t handle, int *mode)
143 {
144         return (ioctl(handle, PPS_IOC_GETCAP, mode));
145 }
146
147 static __inline int
148 time_pps_fetch(pps_handle_t handle, pps_info_t *ppsinfobuf)
149 {
150         return (ioctl(handle, PPS_IOC_FETCH, ppsinfobuf));
151 }
152
153 static __inline int
154 time_pps_wait(pps_handle_t handle, const struct timespec *timeout,
155         pps_info_t *ppsinfobuf)
156 {
157         int error;
158         struct pps_wait_args arg;
159
160         arg.timeout = *timeout;
161         error = ioctl(handle, PPS_IOC_WAIT, &arg);
162         *ppsinfobuf = arg.pps_info_buf;
163         return (error);
164 }
165
166 #endif /* !KERNEL */
167 #endif /* _SYS_TIMEPPS_H_ */