OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uC-libc/] [include/] [linux/] [timex.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*****************************************************************************
2
 *                                                                           *
3
 * Copyright (c) David L. Mills 1993                                         *
4
 *                                                                           *
5
 * Permission to use, copy, modify, and distribute this software and its     *
6
 * documentation for any purpose and without fee is hereby granted, provided *
7
 * that the above copyright notice appears in all copies and that both the   *
8
 * copyright notice and this permission notice appear in supporting          *
9
 * documentation, and that the name University of Delaware not be used in    *
10
 * advertising or publicity pertaining to distribution of the software       *
11
 * without specific, written prior permission.  The University of Delaware   *
12
 * makes no representations about the suitability this software for any      *
13
 * purpose.  It is provided "as is" without express or implied warranty.     *
14
 *                                                                           *
15
 *****************************************************************************/
16
 
17
/*
18
 * Modification history timex.h
19
 *
20
 * 26 Sep 94    David L. Mills
21
 *      Added defines for hybrid phase/frequency-lock loop.
22
 *
23
 * 19 Mar 94    David L. Mills
24
 *      Moved defines from kernel routines to header file and added new
25
 *      defines for PPS phase-lock loop.
26
 *
27
 * 20 Feb 94    David L. Mills
28
 *      Revised status codes and structures for external clock and PPS
29
 *      signal discipline.
30
 *
31
 * 28 Nov 93    David L. Mills
32
 *      Adjusted parameters to improve stability and increase poll
33
 *      interval.
34
 *
35
 * 17 Sep 93    David L. Mills
36
 *      Created file $NTP/include/sys/timex.h
37
 * 07 Oct 93    Torsten Duwe
38
 *      Derived linux/timex.h
39
 * 1995-08-13    Torsten Duwe
40
 *      kernel PLL updated to 1994-12-13 specs (rfc-1589)
41
 * 1997-08-30    Ulrich Windl
42
 *      Added new constant NTP_PHASE_LIMIT. Corrected MAXFREQ.
43
 */
44
#ifndef _LINUX_TIMEX_H
45
#define _LINUX_TIMEX_H
46
 
47
/*
48
 * The following defines establish the engineering parameters of the PLL
49
 * model. The HZ variable establishes the timer interrupt frequency, 100 Hz
50
 * for the SunOS kernel, 256 Hz for the Ultrix kernel and 1024 Hz for the
51
 * OSF/1 kernel. The SHIFT_HZ define expresses the same value as the
52
 * nearest power of two in order to avoid hardware multiply operations.
53
 */
54
#ifdef __alpha__
55
# define SHIFT_HZ 10            /* log2(HZ) */
56
#else
57
# define SHIFT_HZ 7             /* log2(HZ) */
58
#endif
59
 
60
/*
61
 * SHIFT_KG and SHIFT_KF establish the damping of the PLL and are chosen
62
 * for a slightly underdamped convergence characteristic. SHIFT_KH
63
 * establishes the damping of the FLL and is chosen by wisdom and black
64
 * art.
65
 *
66
 * MAXTC establishes the maximum time constant of the PLL. With the
67
 * SHIFT_KG and SHIFT_KF values given and a time constant range from
68
 * zero to MAXTC, the PLL will converge in 15 minutes to 16 hours,
69
 * respectively.
70
 */
71
#define SHIFT_KG 6              /* phase factor (shift) */
72
#define SHIFT_KF 16             /* PLL frequency factor (shift) */
73
#define SHIFT_KH 2              /* FLL frequency factor (shift) */
74
#define MAXTC 6                 /* maximum time constant (shift) */
75
 
76
/*
77
 * The SHIFT_SCALE define establishes the decimal point of the time_phase
78
 * variable which serves as a an extension to the low-order bits of the
79
 * system clock variable. The SHIFT_UPDATE define establishes the decimal
80
 * point of the time_offset variable which represents the current offset
81
 * with respect to standard time. The FINEUSEC define represents 1 usec in
82
 * scaled units.
83
 *
84
 * SHIFT_USEC defines the scaling (shift) of the time_freq and
85
 * time_tolerance variables, which represent the current frequency
86
 * offset and maximum frequency tolerance.
87
 *
88
 * FINEUSEC is 1 us in SHIFT_UPDATE units of the time_phase variable.
89
 */
90
#define SHIFT_SCALE 22          /* phase scale (shift) */
91
#define SHIFT_UPDATE (SHIFT_KG + MAXTC) /* time offset scale (shift) */
92
#define SHIFT_USEC 16           /* frequency offset scale (shift) */
93
#define FINEUSEC (1L << SHIFT_SCALE) /* 1 us in phase units */
94
 
95
#define MAXPHASE 512000L        /* max phase error (us) */
96
#define MAXFREQ (200L << SHIFT_USEC)  /* max frequency error (ppm) */
97
#define MAXTIME (200L << PPS_AVG) /* max PPS error (jitter) (200 us) */
98
#define MINSEC 16L              /* min interval between updates (s) */
99
#define MAXSEC 1200L            /* max interval between updates (s) */
100
#define NTP_PHASE_LIMIT (MAXPHASE << 5) /* beyond max. dispersion */
101
 
102
/*
103
 * The following defines are used only if a pulse-per-second (PPS)
104
 * signal is available and connected via a modem control lead, such as
105
 * produced by the optional ppsclock feature incorporated in the Sun
106
 * asynch driver. They establish the design parameters of the frequency-
107
 * lock loop used to discipline the CPU clock oscillator to the PPS
108
 * signal.
109
 *
110
 * PPS_AVG is the averaging factor for the frequency loop, as well as
111
 * the time and frequency dispersion.
112
 *
113
 * PPS_SHIFT and PPS_SHIFTMAX specify the minimum and maximum
114
 * calibration intervals, respectively, in seconds as a power of two.
115
 *
116
 * PPS_VALID is the maximum interval before the PPS signal is considered
117
 * invalid and protocol updates used directly instead.
118
 *
119
 * MAXGLITCH is the maximum interval before a time offset of more than
120
 * MAXTIME is believed.
121
 */
122
#define PPS_AVG 2               /* pps averaging constant (shift) */
123
#define PPS_SHIFT 2             /* min interval duration (s) (shift) */
124
#define PPS_SHIFTMAX 8          /* max interval duration (s) (shift) */
125
#define PPS_VALID 120           /* pps signal watchdog max (s) */
126
#define MAXGLITCH 30            /* pps signal glitch max (s) */
127
 
128
#ifndef __alpha__
129
/*
130
 * This definitively is wrong for the Alpha and none of the
131
 * kernel code seems to reference this anymore.
132
 */
133
#define CLOCK_TICK_RATE 1193180 /* Underlying HZ */
134
#define CLOCK_TICK_FACTOR       20      /* Factor of both 1000000 and CLOCK_TICK_RATE */
135
#define LATCH  ((CLOCK_TICK_RATE + HZ/2) / HZ)  /* For divider */
136
 
137
#define FINETUNE ((((((long)LATCH * HZ - CLOCK_TICK_RATE) << SHIFT_HZ) * \
138
        (1000000/CLOCK_TICK_FACTOR) / (CLOCK_TICK_RATE/CLOCK_TICK_FACTOR)) \
139
                << (SHIFT_SCALE-SHIFT_HZ)) / HZ)
140
#endif /* !__alpha__ */
141
 
142
/*
143
 * syscall interface - used (mainly by NTP daemon)
144
 * to discipline kernel clock oscillator
145
 */
146
struct timex {
147
        unsigned int modes;     /* mode selector */
148
        long offset;            /* time offset (usec) */
149
        long freq;              /* frequency offset (scaled ppm) */
150
        long maxerror;          /* maximum error (usec) */
151
        long esterror;          /* estimated error (usec) */
152
        int status;             /* clock command/status */
153
        long constant;          /* pll time constant */
154
        long precision;         /* clock precision (usec) (read only) */
155
        long tolerance;         /* clock frequency tolerance (ppm)
156
                                 * (read only)
157
                                 */
158
        struct timeval time;    /* (read only) */
159
        long tick;              /* (modified) usecs between clock ticks */
160
 
161
        long ppsfreq;           /* pps frequency (scaled ppm) (ro) */
162
        long jitter;            /* pps jitter (us) (ro) */
163
        int shift;              /* interval duration (s) (shift) (ro) */
164
        long stabil;            /* pps stability (scaled ppm) (ro) */
165
        long jitcnt;            /* jitter limit exceeded (ro) */
166
        long calcnt;            /* calibration intervals (ro) */
167
        long errcnt;            /* calibration errors (ro) */
168
        long stbcnt;            /* stability limit exceeded (ro) */
169
 
170
        int  :32; int  :32; int  :32; int  :32;
171
        int  :32; int  :32; int  :32; int  :32;
172
        int  :32; int  :32; int  :32; int  :32;
173
};
174
 
175
/*
176
 * Mode codes (timex.mode)
177
 */
178
#define ADJ_OFFSET              0x0001  /* time offset */
179
#define ADJ_FREQUENCY           0x0002  /* frequency offset */
180
#define ADJ_MAXERROR            0x0004  /* maximum time error */
181
#define ADJ_ESTERROR            0x0008  /* estimated time error */
182
#define ADJ_STATUS              0x0010  /* clock status */
183
#define ADJ_TIMECONST           0x0020  /* pll time constant */
184
#define ADJ_TICK                0x4000  /* tick value */
185
#define ADJ_OFFSET_SINGLESHOT   0x8001  /* old-fashioned adjtime */
186
 
187
/* xntp 3.4 compatibility names */
188
#define MOD_OFFSET      ADJ_OFFSET
189
#define MOD_FREQUENCY   ADJ_FREQUENCY
190
#define MOD_MAXERROR    ADJ_MAXERROR
191
#define MOD_ESTERROR    ADJ_ESTERROR
192
#define MOD_STATUS      ADJ_STATUS
193
#define MOD_TIMECONST   ADJ_TIMECONST
194
#define MOD_CLKB        ADJ_TICK
195
#define MOD_CLKA        ADJ_OFFSET_SINGLESHOT /* 0x8000 in original */
196
 
197
 
198
/*
199
 * Status codes (timex.status)
200
 */
201
#define STA_PLL         0x0001  /* enable PLL updates (rw) */
202
#define STA_PPSFREQ     0x0002  /* enable PPS freq discipline (rw) */
203
#define STA_PPSTIME     0x0004  /* enable PPS time discipline (rw) */
204
#define STA_FLL         0x0008  /* select frequency-lock mode (rw) */
205
 
206
#define STA_INS         0x0010  /* insert leap (rw) */
207
#define STA_DEL         0x0020  /* delete leap (rw) */
208
#define STA_UNSYNC      0x0040  /* clock unsynchronized (rw) */
209
#define STA_FREQHOLD    0x0080  /* hold frequency (rw) */
210
 
211
#define STA_PPSSIGNAL   0x0100  /* PPS signal present (ro) */
212
#define STA_PPSJITTER   0x0200  /* PPS signal jitter exceeded (ro) */
213
#define STA_PPSWANDER   0x0400  /* PPS signal wander exceeded (ro) */
214
#define STA_PPSERROR    0x0800  /* PPS signal calibration error (ro) */
215
 
216
#define STA_CLOCKERR    0x1000  /* clock hardware fault (ro) */
217
 
218
#define STA_RONLY (STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER | \
219
    STA_PPSERROR | STA_CLOCKERR) /* read-only bits */
220
 
221
/*
222
 * Clock states (time_state)
223
 */
224
#define TIME_OK         0        /* clock synchronized, no leap second */
225
#define TIME_INS        1       /* insert leap second */
226
#define TIME_DEL        2       /* delete leap second */
227
#define TIME_OOP        3       /* leap second in progress */
228
#define TIME_WAIT       4       /* leap second has occurred */
229
#define TIME_ERROR      5       /* clock not synchronized */
230
#define TIME_BAD        TIME_ERROR /* bw compat */
231
 
232
#ifdef __KERNEL__
233
/*
234
 * kernel variables
235
 * Note: maximum error = NTP synch distance = dispersion + delay / 2;
236
 * estimated error = NTP dispersion.
237
 */
238
extern long tick;                      /* timer interrupt period */
239
extern int tickadj;                     /* amount of adjustment per tick */
240
 
241
/*
242
 * phase-lock loop variables
243
 */
244
extern int time_state;          /* clock status */
245
extern int time_status;         /* clock synchronization status bits */
246
extern long time_offset;        /* time adjustment (us) */
247
extern long time_constant;      /* pll time constant */
248
extern long time_tolerance;     /* frequency tolerance (ppm) */
249
extern long time_precision;     /* clock precision (us) */
250
extern long time_maxerror;      /* maximum error */
251
extern long time_esterror;      /* estimated error */
252
 
253
extern long time_phase;         /* phase offset (scaled us) */
254
extern long time_freq;          /* frequency offset (scaled ppm) */
255
extern long time_adj;           /* tick adjust (scaled 1 / HZ) */
256
extern long time_reftime;       /* time at last adjustment (s) */
257
 
258
extern long time_adjust;        /* The amount of adjtime left */
259
 
260
/* interface variables pps->timer interrupt */
261
extern long pps_offset;         /* pps time offset (us) */
262
extern long pps_jitter;         /* time dispersion (jitter) (us) */
263
extern long pps_freq;           /* frequency offset (scaled ppm) */
264
extern long pps_stabil;         /* frequency dispersion (scaled ppm) */
265
extern long pps_valid;          /* pps signal watchdog counter */
266
 
267
/* interface variables pps->adjtimex */
268
extern int pps_shift;           /* interval duration (s) (shift) */
269
extern long pps_jitcnt;         /* jitter limit exceeded */
270
extern long pps_calcnt;         /* calibration intervals */
271
extern long pps_errcnt;         /* calibration errors */
272
extern long pps_stbcnt;         /* stability limit exceeded */
273
 
274
#endif /* KERNEL */
275
 
276
#endif /* LINUX_TIMEX_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.