Annotation of embedaddon/ntp/include/ntp_refclock.h, revision 1.1.1.1
1.1 misho 1: /*
2: * ntp_refclock.h - definitions for reference clock support
3: */
4:
5: #ifndef NTP_REFCLOCK_H
6: #define NTP_REFCLOCK_H
7:
8: #include "ntp_types.h"
9:
10: #if defined(HAVE_BSD_TTYS)
11: #include <sgtty.h>
12: #endif /* HAVE_BSD_TTYS */
13:
14: #if defined(HAVE_SYSV_TTYS)
15: #include <termio.h>
16: #endif /* HAVE_SYSV_TTYS */
17:
18: #if defined(HAVE_TERMIOS)
19: # ifdef TERMIOS_NEEDS__SVID3
20: # define _SVID3
21: # endif
22: # include <termios.h>
23: # ifdef TERMIOS_NEEDS__SVID3
24: # undef _SVID3
25: # endif
26: #endif
27:
28: #if defined(HAVE_SYS_MODEM_H)
29: #include <sys/modem.h>
30: #endif
31:
32: #if 0 /* If you need that, include ntp_io.h instead */
33: #if defined(STREAM)
34: #include <stropts.h>
35: #if defined(CLK) /* This is never defined, except perhaps by a system header file */
36: #include <sys/clkdefs.h>
37: #endif /* CLK */
38: #endif /* STREAM */
39: #endif
40:
41: #include "recvbuff.h"
42:
43: #if !defined(SYSV_TTYS) && !defined(STREAM) & !defined(BSD_TTYS)
44: #define BSD_TTYS
45: #endif /* SYSV_TTYS STREAM BSD_TTYS */
46:
47: #define SAMPLE(x) pp->coderecv = (pp->coderecv + 1) % MAXSTAGE; \
48: pp->filter[pp->coderecv] = (x); \
49: if (pp->coderecv == pp->codeproc) \
50: pp->codeproc = (pp->codeproc + 1) % MAXSTAGE;
51:
52: /*
53: * Macros to determine the clock type and unit numbers from a
54: * 127.127.t.u address
55: */
56: #define REFCLOCKTYPE(srcadr) ((SRCADR(srcadr) >> 8) & 0xff)
57: #define REFCLOCKUNIT(srcadr) (SRCADR(srcadr) & 0xff)
58:
59: /*
60: * List of reference clock names and descriptions. These must agree with
61: * lib/clocktypes.c and ntpd/refclock_conf.c.
62: */
63: struct clktype {
64: int code; /* driver "major" number */
65: const char *clocktype; /* long description */
66: const char *abbrev; /* short description */
67: };
68: extern struct clktype clktypes[];
69:
70: /*
71: * Configuration flag values
72: */
73: #define CLK_HAVETIME1 0x1
74: #define CLK_HAVETIME2 0x2
75: #define CLK_HAVEVAL1 0x4
76: #define CLK_HAVEVAL2 0x8
77:
78: #define CLK_FLAG1 0x1
79: #define CLK_FLAG2 0x2
80: #define CLK_FLAG3 0x4
81: #define CLK_FLAG4 0x8
82:
83: #define CLK_HAVEFLAG1 0x10
84: #define CLK_HAVEFLAG2 0x20
85: #define CLK_HAVEFLAG3 0x40
86: #define CLK_HAVEFLAG4 0x80
87:
88: /*
89: * Constant for disabling event reporting in
90: * refclock_receive. ORed in leap
91: * parameter
92: */
93: #define REFCLOCK_OWN_STATES 0x80
94:
95: /*
96: * Structure for returning clock status
97: */
98: struct refclockstat {
99: u_char type; /* clock type */
100: u_char flags; /* clock flags */
101: u_char haveflags; /* bit array of valid flags */
102: u_short lencode; /* length of last timecode */
103: const char *p_lastcode; /* last timecode received */
104: u_int32 polls; /* transmit polls */
105: u_int32 noresponse; /* no response to poll */
106: u_int32 badformat; /* bad format timecode received */
107: u_int32 baddata; /* invalid data timecode received */
108: u_int32 timereset; /* driver resets */
109: const char *clockdesc; /* ASCII description */
110: double fudgetime1; /* configure fudge time1 */
111: double fudgetime2; /* configure fudge time2 */
112: int32 fudgeval1; /* configure fudge value1 */
113: u_int32 fudgeval2; /* configure fudge value2 */
114: u_char currentstatus; /* clock status */
115: u_char lastevent; /* last exception event */
116: u_char leap; /* leap bits */
117: struct ctl_var *kv_list; /* additional variables */
118: };
119:
120: /*
121: * Reference clock I/O structure. Used to provide an interface between
122: * the reference clock drivers and the I/O module.
123: */
124: struct refclockio {
125: struct refclockio *next; /* link to next structure */
126: void (*clock_recv) (struct recvbuf *); /* completion routine */
127: int (*io_input) (struct recvbuf *); /* input routine -
128: to avoid excessive buffer use
129: due to small bursts
130: of refclock input data */
131: caddr_t srcclock; /* pointer to clock structure */
132: int datalen; /* lenth of data */
133: int fd; /* file descriptor */
134: u_long recvcount; /* count of receive completions */
135: };
136:
137: /*
138: * Structure for returning debugging info
139: */
140: #define NCLKBUGVALUES 16
141: #define NCLKBUGTIMES 32
142:
143: struct refclockbug {
144: u_char nvalues; /* values following */
145: u_char ntimes; /* times following */
146: u_short svalues; /* values format sign array */
147: u_int32 stimes; /* times format sign array */
148: u_int32 values[NCLKBUGVALUES]; /* real values */
149: l_fp times[NCLKBUGTIMES]; /* real times */
150: };
151:
152: /*
153: * Structure interface between the reference clock support
154: * ntp_refclock.c and the driver utility routines
155: */
156: #define MAXSTAGE 60 /* max median filter stages */
157: #define NSTAGE 5 /* default median filter stages */
158: #define BMAX 128 /* max timecode length */
159: #define GMT 0 /* I hope nobody sees this */
160: #define MAXDIAL 60 /* max length of modem dial strings */
161:
162: /*
163: * Line discipline flags. These require line discipline or streams
164: * modules to be installed/loaded in the kernel. If specified, but not
165: * installed, the code runs as if unspecified.
166: */
167: #define LDISC_STD 0x00 /* standard */
168: #define LDISC_CLK 0x01 /* tty_clk \n intercept */
169: #define LDISC_CLKPPS 0x02 /* tty_clk \377 intercept */
170: #define LDISC_ACTS 0x04 /* tty_clk #* intercept */
171: #define LDISC_CHU 0x08 /* depredated */
172: #define LDISC_PPS 0x10 /* ppsclock, ppsapi */
173: #define LDISC_RAW 0x20 /* raw binary */
174: #define LDISC_ECHO 0x40 /* enable echo */
175: #define LDISC_REMOTE 0x80 /* remote mode */
176: #define LDISC_7O1 0x100 /* 7-bit, odd parity for Z3801A */
177:
178: struct refclockproc {
179: struct refclockio io; /* I/O handler structure */
180: void * unitptr; /* pointer to unit structure */
181: u_char leap; /* leap/synchronization code */
182: u_char currentstatus; /* clock status */
183: u_char lastevent; /* last exception event */
184: u_char type; /* clock type */
185: const char *clockdesc; /* clock description */
186:
187: char a_lastcode[BMAX]; /* last timecode received */
188: int lencode; /* length of last timecode */
189:
190: int year; /* year of eternity */
191: int day; /* day of year */
192: int hour; /* hour of day */
193: int minute; /* minute of hour */
194: int second; /* second of minute */
195: long nsec; /* nanosecond of second */
196: u_long yearstart; /* beginning of year */
197: int coderecv; /* put pointer */
198: int codeproc; /* get pointer */
199: l_fp lastref; /* reference timestamp */
200: l_fp lastrec; /* receive timestamp */
201: double offset; /* mean offset */
202: double disp; /* sample dispersion */
203: double jitter; /* jitter (mean squares) */
204: double filter[MAXSTAGE]; /* median filter */
205:
206: /*
207: * Configuration data
208: */
209: double fudgetime1; /* fudge time1 */
210: double fudgetime2; /* fudge time2 */
211: u_char stratum; /* server stratum */
212: u_int32 refid; /* reference identifier */
213: u_char sloppyclockflag; /* fudge flags */
214:
215: /*
216: * Status tallies
217: */
218: u_long timestarted; /* time we started this */
219: u_long polls; /* polls sent */
220: u_long noreply; /* no replies to polls */
221: u_long badformat; /* bad format reply */
222: u_long baddata; /* bad data reply */
223: };
224:
225: /*
226: * Structure interface between the reference clock support
227: * ntp_refclock.c and particular clock drivers. This must agree with the
228: * structure defined in the driver.
229: */
230: #define noentry 0 /* flag for null routine */
231: #define NOFLAGS 0 /* flag for null flags */
232:
233: struct refclock {
234: int (*clock_start) (int, struct peer *);
235: void (*clock_shutdown) (int, struct peer *);
236: void (*clock_poll) (int, struct peer *);
237: void (*clock_control) (int, struct refclockstat *,
238: struct refclockstat *, struct peer *);
239: void (*clock_init) (void);
240: void (*clock_buginfo) (int, struct refclockbug *, struct peer *);
241: void (*clock_timer) (int, struct peer *);
242: };
243:
244: /*
245: * Function prototypes
246: */
247: /*
248: * auxiliary PPS interface (implemented by refclock_atom())
249: */
250: extern int pps_sample (l_fp *);
251: extern int io_addclock_simple (struct refclockio *);
252: extern int io_addclock (struct refclockio *);
253: extern void io_closeclock (struct refclockio *);
254:
255: #ifdef REFCLOCK
256: extern void refclock_buginfo (sockaddr_u *,
257: struct refclockbug *);
258: extern void refclock_control (sockaddr_u *,
259: struct refclockstat *,
260: struct refclockstat *);
261: extern int refclock_open (char *, u_int, u_int);
262: extern int refclock_setup (int, u_int, u_int);
263: extern void refclock_timer (struct peer *);
264: extern void refclock_transmit (struct peer *);
265: extern int refclock_ioctl (int, u_int);
266: extern int refclock_process (struct refclockproc *);
267: extern int refclock_process_f (struct refclockproc *, double);
268: extern void refclock_process_offset (struct refclockproc *, l_fp, l_fp, double);
269: extern void refclock_report (struct peer *, int);
270: extern int refclock_gtlin (struct recvbuf *, char *, int, l_fp *);
271: extern int refclock_gtraw (struct recvbuf *, char *, int, l_fp *);
272: #endif /* REFCLOCK */
273:
274: #endif /* NTP_REFCLOCK_H */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>