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