source: svn/trunk/newcon3bcm2_21bu/toolchain/mips-linux-uclibc/include/linux/timex.h

Last change on this file was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 8.9 KB
RevLine 
[2]1/*****************************************************************************
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 * 29 Dec 97    Russell King
21 *      Moved CLOCK_TICK_RATE, CLOCK_TICK_FACTOR and FINETUNE to asm/timex.h
22 *      for ARM machines
23 *
24 *  9 Jan 97    Adrian Sun
25 *      Shifted LATCH define to allow access to alpha machines.
26 *
27 * 26 Sep 94    David L. Mills
28 *      Added defines for hybrid phase/frequency-lock loop.
29 *
30 * 19 Mar 94    David L. Mills
31 *      Moved defines from kernel routines to header file and added new
32 *      defines for PPS phase-lock loop.
33 *
34 * 20 Feb 94    David L. Mills
35 *      Revised status codes and structures for external clock and PPS
36 *      signal discipline.
37 *
38 * 28 Nov 93    David L. Mills
39 *      Adjusted parameters to improve stability and increase poll
40 *      interval.
41 *
42 * 17 Sep 93    David L. Mills
43 *      Created file $NTP/include/sys/timex.h
44 * 07 Oct 93    Torsten Duwe
45 *      Derived linux/timex.h
46 * 1995-08-13    Torsten Duwe
47 *      kernel PLL updated to 1994-12-13 specs (rfc-1589)
48 * 1997-08-30    Ulrich Windl
49 *      Added new constant NTP_PHASE_LIMIT
50 */
51#ifndef _LINUX_TIMEX_H
52#define _LINUX_TIMEX_H
53
54#include <linux/time.h>
55
56#include <asm/param.h>
57
58#include <asm/timex.h>
59
60#define SHIFT_HZ ( \
61        ((HZ) >= 12 && (HZ) < 24) ? 4 : \
62        ((HZ) >= 24 && (HZ) < 48) ? 5 : \
63        ((HZ) >= 48 && (HZ) < 96) ? 6 : \
64        ((HZ) >= 96 && (HZ) < 192) ? 7 : \
65        ((HZ) >= 192 && (HZ) < 384) ? 8 : \
66        ((HZ) >= 384 && (HZ) < 768) ? 9 : \
67        ((HZ) >= 768 && (HZ) < 1536) ? 10 : -1 )
68
69/*
70 * SHIFT_KG and SHIFT_KF establish the damping of the PLL and are chosen
71 * for a slightly underdamped convergence characteristic. SHIFT_KH
72 * establishes the damping of the FLL and is chosen by wisdom and black
73 * art.
74 *
75 * MAXTC establishes the maximum time constant of the PLL. With the
76 * SHIFT_KG and SHIFT_KF values given and a time constant range from
77 * zero to MAXTC, the PLL will converge in 15 minutes to 16 hours,
78 * respectively.
79 */
80#define SHIFT_KG 6              /* phase factor (shift) */
81#define SHIFT_KF 16             /* PLL frequency factor (shift) */
82#define SHIFT_KH 2              /* FLL frequency factor (shift) */
83#define MAXTC 6                 /* maximum time constant (shift) */
84
85/*
86 * The SHIFT_SCALE define establishes the decimal point of the time_phase
87 * variable which serves as an extension to the low-order bits of the
88 * system clock variable. The SHIFT_UPDATE define establishes the decimal
89 * point of the time_offset variable which represents the current offset
90 * with respect to standard time. The FINENSEC define represents 1 nsec in
91 * scaled units.
92 *
93 * SHIFT_USEC defines the scaling (shift) of the time_freq and
94 * time_tolerance variables, which represent the current frequency
95 * offset and maximum frequency tolerance.
96 *
97 * FINENSEC is 1 ns in SHIFT_UPDATE units of the time_phase variable.
98 */
99#define SHIFT_SCALE 22          /* phase scale (shift) */
100#define SHIFT_UPDATE (SHIFT_KG + MAXTC) /* time offset scale (shift) */
101#define SHIFT_USEC 16           /* frequency offset scale (shift) */
102#define FINENSEC (1L << (SHIFT_SCALE - 10)) /* ~1 ns in phase units */
103
104#define MAXPHASE 512000L        /* max phase error (us) */
105#define MAXFREQ (512L << SHIFT_USEC)  /* max frequency error (ppm) */
106#define MAXTIME (200L << PPS_AVG) /* max PPS error (jitter) (200 us) */
107#define MINSEC 16L              /* min interval between updates (s) */
108#define MAXSEC 1200L            /* max interval between updates (s) */
109#define NTP_PHASE_LIMIT (MAXPHASE << 5) /* beyond max. dispersion */
110
111/*
112 * The following defines are used only if a pulse-per-second (PPS)
113 * signal is available and connected via a modem control lead, such as
114 * produced by the optional ppsclock feature incorporated in the Sun
115 * asynch driver. They establish the design parameters of the frequency-
116 * lock loop used to discipline the CPU clock oscillator to the PPS
117 * signal.
118 *
119 * PPS_AVG is the averaging factor for the frequency loop, as well as
120 * the time and frequency dispersion.
121 *
122 * PPS_SHIFT and PPS_SHIFTMAX specify the minimum and maximum
123 * calibration intervals, respectively, in seconds as a power of two.
124 *
125 * PPS_VALID is the maximum interval before the PPS signal is considered
126 * invalid and protocol updates used directly instead.
127 *
128 * MAXGLITCH is the maximum interval before a time offset of more than
129 * MAXTIME is believed.
130 */
131#define PPS_AVG 2               /* pps averaging constant (shift) */
132#define PPS_SHIFT 2             /* min interval duration (s) (shift) */
133#define PPS_SHIFTMAX 8          /* max interval duration (s) (shift) */
134#define PPS_VALID 120           /* pps signal watchdog max (s) */
135#define MAXGLITCH 30            /* pps signal glitch max (s) */
136
137/*
138 * syscall interface - used (mainly by NTP daemon)
139 * to discipline kernel clock oscillator
140 */
141struct timex {
142        unsigned int modes;     /* mode selector */
143        long offset;            /* time offset (usec) */
144        long freq;              /* frequency offset (scaled ppm) */
145        long maxerror;          /* maximum error (usec) */
146        long esterror;          /* estimated error (usec) */
147        int status;             /* clock command/status */
148        long constant;          /* pll time constant */
149        long precision;         /* clock precision (usec) (read only) */
150        long tolerance;         /* clock frequency tolerance (ppm)
151                                 * (read only)
152                                 */
153        struct timeval time;    /* (read only) */
154        long tick;              /* (modified) usecs between clock ticks */
155
156        long ppsfreq;           /* pps frequency (scaled ppm) (ro) */
157        long jitter;            /* pps jitter (us) (ro) */
158        int shift;              /* interval duration (s) (shift) (ro) */
159        long stabil;            /* pps stability (scaled ppm) (ro) */
160        long jitcnt;            /* jitter limit exceeded (ro) */
161        long calcnt;            /* calibration intervals (ro) */
162        long errcnt;            /* calibration errors (ro) */
163        long stbcnt;            /* stability limit exceeded (ro) */
164
165        int  :32; int  :32; int  :32; int  :32;
166        int  :32; int  :32; int  :32; int  :32;
167        int  :32; int  :32; int  :32; int  :32;
168};
169
170/*
171 * Mode codes (timex.mode)
172 */
173#define ADJ_OFFSET              0x0001  /* time offset */
174#define ADJ_FREQUENCY           0x0002  /* frequency offset */
175#define ADJ_MAXERROR            0x0004  /* maximum time error */
176#define ADJ_ESTERROR            0x0008  /* estimated time error */
177#define ADJ_STATUS              0x0010  /* clock status */
178#define ADJ_TIMECONST           0x0020  /* pll time constant */
179#define ADJ_TICK                0x4000  /* tick value */
180#define ADJ_OFFSET_SINGLESHOT   0x8001  /* old-fashioned adjtime */
181
182/* xntp 3.4 compatibility names */
183#define MOD_OFFSET      ADJ_OFFSET
184#define MOD_FREQUENCY   ADJ_FREQUENCY
185#define MOD_MAXERROR    ADJ_MAXERROR
186#define MOD_ESTERROR    ADJ_ESTERROR
187#define MOD_STATUS      ADJ_STATUS
188#define MOD_TIMECONST   ADJ_TIMECONST
189#define MOD_CLKB        ADJ_TICK
190#define MOD_CLKA        ADJ_OFFSET_SINGLESHOT /* 0x8000 in original */
191
192
193/*
194 * Status codes (timex.status)
195 */
196#define STA_PLL         0x0001  /* enable PLL updates (rw) */
197#define STA_PPSFREQ     0x0002  /* enable PPS freq discipline (rw) */
198#define STA_PPSTIME     0x0004  /* enable PPS time discipline (rw) */
199#define STA_FLL         0x0008  /* select frequency-lock mode (rw) */
200
201#define STA_INS         0x0010  /* insert leap (rw) */
202#define STA_DEL         0x0020  /* delete leap (rw) */
203#define STA_UNSYNC      0x0040  /* clock unsynchronized (rw) */
204#define STA_FREQHOLD    0x0080  /* hold frequency (rw) */
205
206#define STA_PPSSIGNAL   0x0100  /* PPS signal present (ro) */
207#define STA_PPSJITTER   0x0200  /* PPS signal jitter exceeded (ro) */
208#define STA_PPSWANDER   0x0400  /* PPS signal wander exceeded (ro) */
209#define STA_PPSERROR    0x0800  /* PPS signal calibration error (ro) */
210
211#define STA_CLOCKERR    0x1000  /* clock hardware fault (ro) */
212
213#define STA_RONLY (STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER | \
214    STA_PPSERROR | STA_CLOCKERR) /* read-only bits */
215
216/*
217 * Clock states (time_state)
218 */
219#define TIME_OK         0       /* clock synchronized, no leap second */
220#define TIME_INS        1       /* insert leap second */
221#define TIME_DEL        2       /* delete leap second */
222#define TIME_OOP        3       /* leap second in progress */
223#define TIME_WAIT       4       /* leap second has occurred */
224#define TIME_ERROR      5       /* clock not synchronized */
225#define TIME_BAD        TIME_ERROR /* bw compat */
226
227#endif /* LINUX_TIMEX_H */
Note: See TracBrowser for help on using the repository browser.