source: trunk/third/xntp/include/ntp_refclock.h @ 10832

Revision 10832, 7.0 KB checked in by brlewis, 27 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r10831, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2 * ntp_refclock.h - definitions for reference clock support
3 */
4
5#include "ntp_types.h"
6
7#if defined(HAVE_BSD_TTYS)
8#include <sgtty.h>
9#endif /* HAVE_BSD_TTYS */
10
11#if defined(HAVE_SYSV_TTYS)
12#include <termio.h>
13#endif /* HAVE_SYSV_TTYS */
14
15#if defined(HAVE_TERMIOS)
16#include <termios.h>
17#endif
18
19#if defined(HAVE_SYS_MODEM_H)
20#include <sys/modem.h>
21#endif
22
23#if defined(STREAM)
24#include <stropts.h>
25#if defined(CLK)
26#include <sys/clkdefs.h>
27#endif /* CLK */
28#endif /* STREAM */
29
30#if !defined(SYSV_TTYS) && !defined(STREAM) & !defined(BSD_TTYS)
31#define BSD_TTYS
32#endif /* SYSV_TTYS STREAM BSD_TTYS */
33
34/*
35 * Macros to determine the clock type and unit numbers from a
36 * 127.127.t.u address
37 */
38#define REFCLOCKTYPE(srcadr)    ((SRCADR(srcadr) >> 8) & 0xff)
39#define REFCLOCKUNIT(srcadr)    (SRCADR(srcadr) & 0xff)
40
41/*
42 * List of reference clock names and descriptions. These must agree with
43 * lib/clocktypes.c and xntpd/refclock_conf.c.
44 */
45struct clktype {
46  int code;                     /* driver "major" number */
47  const char *clocktype;        /* long description */
48  const char *abbrev;           /* short description */
49};
50
51/*
52 * Configuration flag values
53 */
54#define CLK_HAVETIME1   0x1
55#define CLK_HAVETIME2   0x2
56#define CLK_HAVEVAL1    0x4
57#define CLK_HAVEVAL2    0x8
58
59#define CLK_FLAG1       0x1
60#define CLK_FLAG2       0x2
61#define CLK_FLAG3       0x4
62#define CLK_FLAG4       0x8
63
64#define CLK_HAVEFLAG1   0x10
65#define CLK_HAVEFLAG2   0x20
66#define CLK_HAVEFLAG3   0x40
67#define CLK_HAVEFLAG4   0x80
68
69/*
70 * Constant for disabling event reporting in
71 * refclock_receive. ORed in leap
72 * parameter
73 */
74#define REFCLOCK_OWN_STATES     0x80
75
76/*
77 * Structure for returning clock status
78 */
79struct refclockstat {
80        u_char  type;           /* clock type */
81        u_char  flags;          /* clock flags */
82        u_char  haveflags;      /* bit array of valid flags */
83        u_short lencode;        /* length of last timecode (may be longer than a char!) */
84        char    *p_lastcode;    /* last timecode received */
85        u_int32 polls;          /* transmit polls */
86        u_int32 noresponse;     /* no response to poll */
87        u_int32 badformat;      /* bad format timecode received */
88        u_int32 baddata;        /* invalid data timecode received */
89        u_int32 timereset;      /* driver resets */
90        char    *clockdesc;     /* ASCII description */
91        l_fp    fudgetime1;     /* configure fudge time1 */
92        l_fp    fudgetime2;     /* configure fudge time2 */
93        int32   fudgeval1;      /* configure fudge value1 */
94        int32   fudgeval2;      /* configure fudge value2 */
95        u_char  currentstatus;  /* clock status */
96        u_char  lastevent;      /* last exception event */
97        u_char  unused;         /* spare */
98        struct  ctl_var *kv_list; /* additional variables */
99};
100
101/*
102 * Reference clock I/O structure.  Used to provide an interface between
103 * the reference clock drivers and the I/O module.
104 */
105struct refclockio {
106        struct  refclockio *next; /* link to next structure */
107        void    (*clock_recv)P((struct recvbuf *)); /* completion routine */
108        caddr_t srcclock;       /* pointer to clock structure */
109        int     datalen;        /* lenth of data */
110        int     fd;             /* file descriptor */
111        u_long  recvcount;      /* count of receive completions */
112};
113
114/*
115 * Structure for returning debugging info
116 */
117#define NCLKBUGVALUES   16
118#define NCLKBUGTIMES    32
119
120struct refclockbug {
121        u_char  nvalues;        /* values following */
122        u_char  ntimes;         /* times following */
123        u_short svalues;        /* values format sign array */
124        u_int32 stimes;         /* times format sign array */
125        u_int32 values[NCLKBUGVALUES]; /* real values */
126        l_fp    times[NCLKBUGTIMES]; /* real times */
127};
128
129/*
130 * Structure interface between the reference clock support
131 * ntp_refclock.c and the driver utility routines
132 */
133#define MAXSTAGE        64      /* max stages in shift register */
134#define BMAX            128     /* max timecode length */
135#define GMT             0       /* I hope nobody sees this */
136#define MAXDIAL         60      /* max length of modem dial strings */
137
138/*
139 * Line discipline flags. These require line discipline or streams
140 * modules to be installed/loaded in the kernel. If specified, but not
141 * installed, the code runs as if unspecified.
142 */
143#define LDISC_STD       0x0     /* standard */
144#define LDISC_CLK       0x1     /* tty_clk \n intercept */
145#define LDISC_CLKPPS    0x2     /* tty_clk \377 intercept */
146#define LDISC_ACTS      0x4     /* tty_clk #* intercept */
147#define LDISC_CHU       0x8     /* tty_chu */
148#define LDISC_PPS       0x10    /* ppsclock */
149
150struct refclockproc {
151        struct  refclockio io;  /* I/O handler structure */
152        caddr_t unitptr;        /* pointer to unit structure */
153        u_long  lasttime;       /* last clock update time */
154        u_char  leap;           /* leap/synchronization code */
155        u_char  currentstatus;  /* clock status */
156        u_char  lastevent;      /* last exception event */
157        u_char  type;           /* clock type */
158        char    *clockdesc;     /* clock description */
159        char    a_lastcode[BMAX]; /* last timecode received */
160        u_short lencode;        /* length of last timecode (allow for more than 256 chars !) */
161
162        int     year;           /* year of eternity */
163        int     day;            /* day of year */
164        int     hour;           /* hour of day */
165        int     minute;         /* minute of hour */
166        int     second;         /* second of minute */
167        int     msec;           /* millisecond of second */
168        long    usec;           /* microsecond of second (alt) */
169        u_int   nstages;        /* median filter stages */
170        u_long  yearstart;      /* beginning of year */
171        u_long  coderecv;       /* sample counter */
172        l_fp    lastref;        /* last reference timestamp */
173        l_fp    lastrec;        /* last local timestamp */
174        l_fp    offset;         /* median offset */
175        u_fp    dispersion;     /* sample dispersion */
176        l_fp    filter[MAXSTAGE]; /* median filter */
177
178        /*
179         * Configuration data
180         */
181        l_fp    fudgetime1;     /* fudge time1 */
182        l_fp    fudgetime2;     /* fudge time2 */
183        u_int32 refid;          /* reference identifier */
184        u_long  sloppyclockflag; /* fudge flags */
185
186        /*
187         * Status tallies
188         */
189        u_long  timestarted;    /* time we started this */
190        u_long  polls;          /* polls sent */
191        u_long  noreply;        /* no replies to polls */
192        u_long  badformat;      /* bad format reply */
193        u_long  baddata;        /* bad data reply */
194};
195
196/*
197 * Structure interface between the reference clock support
198 * ntp_refclock.c and particular clock drivers. This must agree with the
199 * structure defined in the driver.
200 */
201#define noentry 0               /* flag for null routine */
202#define NOFLAGS 0               /* flag for null flags */
203
204struct refclock {
205        int (*clock_start)      P((int, struct peer *));
206        void (*clock_shutdown)  P((int, struct peer *));
207        void (*clock_poll)      P((int, struct peer *));
208        void (*clock_control)   P((int, struct refclockstat *,
209                                    struct refclockstat *));
210        void (*clock_init)      P((void));
211        void (*clock_buginfo)   P((int, struct refclockbug *));
212        u_long clock_flags;
213};
214
215/*
216 * Function prototypes
217 */
218extern  int     io_addclock_simple P((struct refclockio *));
219extern  int     io_addclock     P((struct refclockio *));
220extern  void    io_closeclock   P((struct refclockio *));
221
222#ifdef REFCLOCK
223extern  void    refclock_buginfo P((struct sockaddr_in *,
224                                    struct refclockbug *));
225extern  void    refclock_control P((struct sockaddr_in *,
226                                    struct refclockstat *,
227                                    struct refclockstat *));
228extern  int     refclock_open   P((char *, int, int));
229extern  void    refclock_transmit P((struct peer *));
230extern  int     refclock_ioctl  P((int, int));
231extern  int     refclock_process P((struct refclockproc *, int, int));
232extern  int     refclock_sample P((l_fp *, struct refclockproc *, int, int));
233extern  void    refclock_report P((struct peer *, u_int));
234extern  int     refclock_gtlin  P((struct recvbuf *, char *, int,
235                                    l_fp *));
236#endif /* REFCLOCK */
Note: See TracBrowser for help on using the repository browser.