timex.h 6.5 KB

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