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  */
  25 #ifndef _LINUX_TIMEX_H
  26 #define _LINUX_TIMEX_H
  27 
  28 #include <linux/unistd.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 #define SHIFT_HZ 7              /* log2(HZ) */
  38 
  39 /*
  40  * The SHIFT_KG and SHIFT_KF defines establish the damping of the PLL
  41  * and are chosen by analysis for a slightly underdamped convergence
  42  * characteristic. The MAXTC define establishes the maximum time constant
  43  * of the PLL. With the parameters given and the default time constant of
  44  * zero, the PLL will converge in about 15 minutes.
  45  */
  46 #define SHIFT_KG 8              /* shift for phase increment */
  47 #define SHIFT_KF 20             /* shift for frequency increment */
  48 #define MAXTC 6                 /* maximum time constant (shift) */
  49 
  50 /*
  51  * The SHIFT_SCALE define establishes the decimal point of the time_phase
  52  * variable which serves as a an extension to the low-order bits of the
  53  * system clock variable. The SHIFT_UPDATE define establishes the decimal
  54  * point of the time_offset variable which represents the current offset
  55  * with respect to standard time. The FINEUSEC define represents 1 usec in
  56  * scaled units.
  57  */
  58 #define SHIFT_SCALE 24          /* shift for phase scale factor */
  59 #define SHIFT_UPDATE (SHIFT_KG + MAXTC) /* shift for offset scale factor */
  60 #define FINEUSEC (1 << SHIFT_SCALE) /* 1 us in scaled units */
  61 
  62 #define MAXPHASE 128000         /* max phase error (us) */
  63 #define MAXFREQ 100             /* max frequency error (ppm) */
  64 #define MINSEC 16               /* min interval between updates (s) */
  65 #define MAXSEC 1200             /* max interval between updates (s) */
  66 
  67 #define CLOCK_TICK_RATE 1193180 /* Underlying HZ */
  68 #define CLOCK_TICK_FACTOR       20      /* Factor of both 1000000 and CLOCK_TICK_RATE */
  69 #define LATCH  ((CLOCK_TICK_RATE + HZ/2) / HZ)  /* For divider */
  70 
  71 #define FINETUNE (((((LATCH * HZ - CLOCK_TICK_RATE) << SHIFT_HZ) * \
  72         (1000000/CLOCK_TICK_FACTOR) / (CLOCK_TICK_RATE/CLOCK_TICK_FACTOR)) \
  73                 << (SHIFT_SCALE-SHIFT_HZ)) / HZ)
  74 
  75 /*
  76  * syscall interface - used (mainly by NTP daemon)
  77  * to discipline kernel clock oscillator
  78  */
  79 struct timex {
  80         int mode;               /* mode selector */
  81         long offset;            /* time offset (usec) */
  82         long frequency;         /* frequency offset (scaled ppm) */
  83         long maxerror;          /* maximum error (usec) */
  84         long esterror;          /* estimated error (usec) */
  85         int status;             /* clock command/status */
  86         long time_constant;     /* pll time constant */
  87         long precision;         /* clock precision (usec) (read only) */
  88         long tolerance;         /* clock frequency tolerance (ppm)
  89                                  * (read only)
  90                                  */
  91         struct timeval time;    /* (read only) */
  92 };
  93 
  94 /*
  95  * Mode codes (timex.mode) 
  96  */
  97 #define ADJ_OFFSET              0x0001  /* time offset */
  98 #define ADJ_FREQUENCY           0x0002  /* frequency offset */
  99 #define ADJ_MAXERROR            0x0004  /* maximum time error */
 100 #define ADJ_ESTERROR            0x0008  /* estimated time error */
 101 #define ADJ_STATUS              0x0010  /* clock status */
 102 #define ADJ_TIMECONST           0x0020  /* pll time constant */
 103 #define ADJ_OFFSET_SINGLESHOT   0x8001  /* old-fashioned adjtime */
 104 
 105 /*
 106  * Clock command/status codes (timex.status)
 107  */
 108 #define TIME_OK         0       /* clock synchronized */
 109 #define TIME_INS        1       /* insert leap second */
 110 #define TIME_DEL        2       /* delete leap second */
 111 #define TIME_OOP        3       /* leap second in progress */
 112 #define TIME_BAD        4       /* clock not synchronized */
 113 
 114 #ifdef __KERNEL__
 115 /*
 116  * kernel variables
 117  */
 118 extern long tick;                      /* timer interrupt period */
 119 extern int tickadj;                     /* amount of adjustment per tick */
 120 extern volatile struct timeval xtime;           /* The current time */
 121 
 122 /*
 123  * phase-lock loop variables
 124  */
 125 extern int time_status;         /* clock synchronization status */
 126 extern long time_offset;        /* time adjustment (us) */
 127 extern long time_constant;      /* pll time constant */
 128 extern long time_tolerance;     /* frequency tolerance (ppm) */
 129 extern long time_precision;     /* clock precision (us) */
 130 extern long time_maxerror;      /* maximum error */
 131 extern long time_esterror;      /* estimated error */
 132 extern long time_phase;         /* phase offset (scaled us) */
 133 extern long time_freq;          /* frequency offset (scaled ppm) */
 134 extern long time_adj;           /* tick adjust (scaled 1 / HZ) */
 135 extern long time_reftime;       /* time at last adjustment (s) */
 136 
 137 extern long time_adjust;        /* The amount of adjtime left */
 138 #endif /* KERNEL */
 139 
 140 #endif /* LINUX_TIMEX_H */

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