timex.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* Copyright (C) 1995-1997, 1999, 2007, 2009 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #ifndef _SYS_TIMEX_H
  16. #define _SYS_TIMEX_H 1
  17. #include <features.h>
  18. #include <sys/time.h>
  19. /* These definitions from linux/timex.h as of 2.6.30. */
  20. #define NTP_API 4 /* NTP API version */
  21. struct ntptimeval
  22. {
  23. struct timeval time; /* current time (ro) */
  24. long int maxerror; /* maximum error (us) (ro) */
  25. long int esterror; /* estimated error (us) (ro) */
  26. long int tai; /* TAI offset (ro) */
  27. long int __unused1;
  28. long int __unused2;
  29. long int __unused3;
  30. long int __unused4;
  31. };
  32. struct timex
  33. {
  34. unsigned int modes; /* mode selector */
  35. long int offset; /* time offset (usec) */
  36. long int freq; /* frequency offset (scaled ppm) */
  37. long int maxerror; /* maximum error (usec) */
  38. long int esterror; /* estimated error (usec) */
  39. int status; /* clock command/status */
  40. long int constant; /* pll time constant */
  41. long int precision; /* clock precision (usec) (read only) */
  42. long int tolerance; /* clock frequency tolerance (ppm) (read only) */
  43. struct timeval time; /* (read only) */
  44. long int tick; /* (modified) usecs between clock ticks */
  45. long int ppsfreq; /* pps frequency (scaled ppm) (ro) */
  46. long int jitter; /* pps jitter (us) (ro) */
  47. int shift; /* interval duration (s) (shift) (ro) */
  48. long int stabil; /* pps stability (scaled ppm) (ro) */
  49. long int jitcnt; /* jitter limit exceeded (ro) */
  50. long int calcnt; /* calibration intervals (ro) */
  51. long int errcnt; /* calibration errors (ro) */
  52. long int stbcnt; /* stability limit exceeded (ro) */
  53. int tai; /* TAI offset (ro) */
  54. /* ??? */
  55. int :32; int :32; int :32; int :32;
  56. int :32; int :32; int :32; int :32;
  57. int :32; int :32; int :32;
  58. };
  59. /* Mode codes (timex.mode) */
  60. #define ADJ_OFFSET 0x0001 /* time offset */
  61. #define ADJ_FREQUENCY 0x0002 /* frequency offset */
  62. #define ADJ_MAXERROR 0x0004 /* maximum time error */
  63. #define ADJ_ESTERROR 0x0008 /* estimated time error */
  64. #define ADJ_STATUS 0x0010 /* clock status */
  65. #define ADJ_TIMECONST 0x0020 /* pll time constant */
  66. #define ADJ_TAI 0x0080 /* set TAI offset */
  67. #define ADJ_MICRO 0x1000 /* select microsecond resolution */
  68. #define ADJ_NANO 0x2000 /* select nanosecond resolution */
  69. #define ADJ_TICK 0x4000 /* tick value */
  70. #define ADJ_OFFSET_SINGLESHOT 0x8001 /* old-fashioned adjtime */
  71. #define ADJ_OFFSET_SS_READ 0xa001 /* read-only adjtime */
  72. /* xntp 3.4 compatibility names */
  73. #define MOD_OFFSET ADJ_OFFSET
  74. #define MOD_FREQUENCY ADJ_FREQUENCY
  75. #define MOD_MAXERROR ADJ_MAXERROR
  76. #define MOD_ESTERROR ADJ_ESTERROR
  77. #define MOD_STATUS ADJ_STATUS
  78. #define MOD_TIMECONST ADJ_TIMECONST
  79. #define MOD_CLKB ADJ_TICK
  80. #define MOD_CLKA ADJ_OFFSET_SINGLESHOT /* 0x8000 in original */
  81. #define MOD_TAI ADJ_TAI
  82. #define MOD_MICRO ADJ_MICRO
  83. #define MOD_NANO ADJ_NANO
  84. /* Status codes (timex.status) */
  85. #define STA_PLL 0x0001 /* enable PLL updates (rw) */
  86. #define STA_PPSFREQ 0x0002 /* enable PPS freq discipline (rw) */
  87. #define STA_PPSTIME 0x0004 /* enable PPS time discipline (rw) */
  88. #define STA_FLL 0x0008 /* select frequency-lock mode (rw) */
  89. #define STA_INS 0x0010 /* insert leap (rw) */
  90. #define STA_DEL 0x0020 /* delete leap (rw) */
  91. #define STA_UNSYNC 0x0040 /* clock unsynchronized (rw) */
  92. #define STA_FREQHOLD 0x0080 /* hold frequency (rw) */
  93. #define STA_PPSSIGNAL 0x0100 /* PPS signal present (ro) */
  94. #define STA_PPSJITTER 0x0200 /* PPS signal jitter exceeded (ro) */
  95. #define STA_PPSWANDER 0x0400 /* PPS signal wander exceeded (ro) */
  96. #define STA_PPSERROR 0x0800 /* PPS signal calibration error (ro) */
  97. #define STA_CLOCKERR 0x1000 /* clock hardware fault (ro) */
  98. #define STA_NANO 0x2000 /* resolution (0 = us, 1 = ns) (ro) */
  99. #define STA_MODE 0x4000 /* mode (0 = PLL, 1 = FLL) (ro) */
  100. #define STA_CLK 0x8000 /* clock source (0 = A, 1 = B) (ro) */
  101. /* Read-only bits */
  102. #define STA_RONLY (STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER | \
  103. STA_PPSERROR | STA_CLOCKERR | STA_NANO | STA_MODE | STA_CLK)
  104. /* Clock states (time_state) */
  105. #define TIME_OK 0 /* clock synchronized, no leap second */
  106. #define TIME_INS 1 /* insert leap second */
  107. #define TIME_DEL 2 /* delete leap second */
  108. #define TIME_OOP 3 /* leap second in progress */
  109. #define TIME_WAIT 4 /* leap second has occurred */
  110. #define TIME_ERROR 5 /* clock not synchronized */
  111. #define TIME_BAD TIME_ERROR /* bw compat */
  112. /* Maximum time constant of the PLL. */
  113. #define MAXTC 6
  114. __BEGIN_DECLS
  115. extern int __adjtimex (struct timex *__ntx) __THROW;
  116. extern int adjtimex (struct timex *__ntx) __THROW;
  117. #ifdef __REDIRECT_NTH
  118. extern int __REDIRECT_NTH (ntp_gettime, (struct ntptimeval *__ntv),
  119. ntp_gettimex);
  120. #else
  121. extern int ntp_gettimex (struct ntptimeval *__ntv) __THROW;
  122. # define ntp_gettime ntp_gettimex
  123. #endif
  124. extern int ntp_adjtime (struct timex *__tntx) __THROW;
  125. __END_DECLS
  126. #endif /* sys/timex.h */