timex.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. * Modification history timex.h
  18. *
  19. * 29 Dec 97 Russell King
  20. * Moved CLOCK_TICK_RATE, CLOCK_TICK_FACTOR and FINETUNE to asm/timex.h
  21. * for ARM machines
  22. *
  23. * 9 Jan 97 Adrian Sun
  24. * Shifted LATCH define to allow access to alpha machines.
  25. *
  26. * 26 Sep 94 David L. Mills
  27. * Added defines for hybrid phase/frequency-lock loop.
  28. *
  29. * 19 Mar 94 David L. Mills
  30. * Moved defines from kernel routines to header file and added new
  31. * defines for PPS phase-lock loop.
  32. *
  33. * 20 Feb 94 David L. Mills
  34. * Revised status codes and structures for external clock and PPS
  35. * signal discipline.
  36. *
  37. * 28 Nov 93 David L. Mills
  38. * Adjusted parameters to improve stability and increase poll
  39. * interval.
  40. *
  41. * 17 Sep 93 David L. Mills
  42. * Created file $NTP/include/sys/timex.h
  43. * 07 Oct 93 Torsten Duwe
  44. * Derived linux/timex.h
  45. * 1995-08-13 Torsten Duwe
  46. * kernel PLL updated to 1994-12-13 specs (rfc-1589)
  47. * 1997-08-30 Ulrich Windl
  48. * Added new constant NTP_PHASE_LIMIT
  49. * 2004-08-12 Christoph Lameter
  50. * Reworked time interpolation logic
  51. */
  52. #ifndef _UAPI_LINUX_TIMEX_H
  53. #define _UAPI_LINUX_TIMEX_H
  54. #include <linux/time.h>
  55. #define NTP_API 4 /* NTP API version */
  56. /*
  57. * syscall interface - used (mainly by NTP daemon)
  58. * to discipline kernel clock oscillator
  59. */
  60. struct timex {
  61. unsigned int modes; /* mode selector */
  62. __kernel_long_t offset; /* time offset (usec) */
  63. __kernel_long_t freq; /* frequency offset (scaled ppm) */
  64. __kernel_long_t maxerror;/* maximum error (usec) */
  65. __kernel_long_t esterror;/* estimated error (usec) */
  66. int status; /* clock command/status */
  67. __kernel_long_t constant;/* pll time constant */
  68. __kernel_long_t precision;/* clock precision (usec) (read only) */
  69. __kernel_long_t tolerance;/* clock frequency tolerance (ppm)
  70. * (read only)
  71. */
  72. struct timeval time; /* (read only, except for ADJ_SETOFFSET) */
  73. __kernel_long_t tick; /* (modified) usecs between clock ticks */
  74. __kernel_long_t ppsfreq;/* pps frequency (scaled ppm) (ro) */
  75. __kernel_long_t jitter; /* pps jitter (us) (ro) */
  76. int shift; /* interval duration (s) (shift) (ro) */
  77. __kernel_long_t stabil; /* pps stability (scaled ppm) (ro) */
  78. __kernel_long_t jitcnt; /* jitter limit exceeded (ro) */
  79. __kernel_long_t calcnt; /* calibration intervals (ro) */
  80. __kernel_long_t errcnt; /* calibration errors (ro) */
  81. __kernel_long_t stbcnt; /* stability limit exceeded (ro) */
  82. int tai; /* TAI offset (ro) */
  83. int :32; int :32; int :32; int :32;
  84. int :32; int :32; int :32; int :32;
  85. int :32; int :32; int :32;
  86. };
  87. /*
  88. * Mode codes (timex.mode)
  89. */
  90. #define ADJ_OFFSET 0x0001 /* time offset */
  91. #define ADJ_FREQUENCY 0x0002 /* frequency offset */
  92. #define ADJ_MAXERROR 0x0004 /* maximum time error */
  93. #define ADJ_ESTERROR 0x0008 /* estimated time error */
  94. #define ADJ_STATUS 0x0010 /* clock status */
  95. #define ADJ_TIMECONST 0x0020 /* pll time constant */
  96. #define ADJ_TAI 0x0080 /* set TAI offset */
  97. #define ADJ_SETOFFSET 0x0100 /* add 'time' to current time */
  98. #define ADJ_MICRO 0x1000 /* select microsecond resolution */
  99. #define ADJ_NANO 0x2000 /* select nanosecond resolution */
  100. #define ADJ_TICK 0x4000 /* tick value */
  101. #ifndef __KERNEL__
  102. #define ADJ_OFFSET_SINGLESHOT 0x8001 /* old-fashioned adjtime */
  103. #define ADJ_OFFSET_SS_READ 0xa001 /* read-only adjtime */
  104. #endif
  105. /* NTP userland likes the MOD_ prefix better */
  106. #define MOD_OFFSET ADJ_OFFSET
  107. #define MOD_FREQUENCY ADJ_FREQUENCY
  108. #define MOD_MAXERROR ADJ_MAXERROR
  109. #define MOD_ESTERROR ADJ_ESTERROR
  110. #define MOD_STATUS ADJ_STATUS
  111. #define MOD_TIMECONST ADJ_TIMECONST
  112. #define MOD_TAI ADJ_TAI
  113. #define MOD_MICRO ADJ_MICRO
  114. #define MOD_NANO ADJ_NANO
  115. /*
  116. * Status codes (timex.status)
  117. */
  118. #define STA_PLL 0x0001 /* enable PLL updates (rw) */
  119. #define STA_PPSFREQ 0x0002 /* enable PPS freq discipline (rw) */
  120. #define STA_PPSTIME 0x0004 /* enable PPS time discipline (rw) */
  121. #define STA_FLL 0x0008 /* select frequency-lock mode (rw) */
  122. #define STA_INS 0x0010 /* insert leap (rw) */
  123. #define STA_DEL 0x0020 /* delete leap (rw) */
  124. #define STA_UNSYNC 0x0040 /* clock unsynchronized (rw) */
  125. #define STA_FREQHOLD 0x0080 /* hold frequency (rw) */
  126. #define STA_PPSSIGNAL 0x0100 /* PPS signal present (ro) */
  127. #define STA_PPSJITTER 0x0200 /* PPS signal jitter exceeded (ro) */
  128. #define STA_PPSWANDER 0x0400 /* PPS signal wander exceeded (ro) */
  129. #define STA_PPSERROR 0x0800 /* PPS signal calibration error (ro) */
  130. #define STA_CLOCKERR 0x1000 /* clock hardware fault (ro) */
  131. #define STA_NANO 0x2000 /* resolution (0 = us, 1 = ns) (ro) */
  132. #define STA_MODE 0x4000 /* mode (0 = PLL, 1 = FLL) (ro) */
  133. #define STA_CLK 0x8000 /* clock source (0 = A, 1 = B) (ro) */
  134. /* read-only bits */
  135. #define STA_RONLY (STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER | \
  136. STA_PPSERROR | STA_CLOCKERR | STA_NANO | STA_MODE | STA_CLK)
  137. /*
  138. * Clock states (time_state)
  139. */
  140. #define TIME_OK 0 /* clock synchronized, no leap second */
  141. #define TIME_INS 1 /* insert leap second */
  142. #define TIME_DEL 2 /* delete leap second */
  143. #define TIME_OOP 3 /* leap second in progress */
  144. #define TIME_WAIT 4 /* leap second has occurred */
  145. #define TIME_ERROR 5 /* clock not synchronized */
  146. #define TIME_BAD TIME_ERROR /* bw compat */
  147. #endif /* _UAPI_LINUX_TIMEX_H */