root/include/linux/timex.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


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

/* [previous][next][first][last][top][bottom][index][help] */