timex.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* Copyright (C) 1995, 1996, 1997, 1999 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, see
  13. <http://www.gnu.org/licenses/>. */
  14. #ifndef _SYS_TIMEX_H
  15. #define _SYS_TIMEX_H 1
  16. #include <features.h>
  17. #include <sys/time.h>
  18. /* These definitions from linux/timex.h as of 2.2.0. */
  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. };
  25. struct timex
  26. {
  27. unsigned int modes; /* mode selector */
  28. long int offset; /* time offset (usec) */
  29. long int freq; /* frequency offset (scaled ppm) */
  30. long int maxerror; /* maximum error (usec) */
  31. long int esterror; /* estimated error (usec) */
  32. int status; /* clock command/status */
  33. long int constant; /* pll time constant */
  34. long int precision; /* clock precision (usec) (read only) */
  35. long int tolerance; /* clock frequency tolerance (ppm) (read only) */
  36. struct timeval time; /* (read only) */
  37. long int tick; /* (modified) usecs between clock ticks */
  38. long int ppsfreq; /* pps frequency (scaled ppm) (ro) */
  39. long int jitter; /* pps jitter (us) (ro) */
  40. int shift; /* interval duration (s) (shift) (ro) */
  41. long int stabil; /* pps stability (scaled ppm) (ro) */
  42. long int jitcnt; /* jitter limit exceeded (ro) */
  43. long int calcnt; /* calibration intervals (ro) */
  44. long int errcnt; /* calibration errors (ro) */
  45. long int stbcnt; /* stability limit exceeded (ro) */
  46. /* ??? */
  47. int :32; int :32; int :32; int :32;
  48. int :32; int :32; int :32; int :32;
  49. int :32; int :32; int :32; int :32;
  50. };
  51. /* Mode codes (timex.mode) */
  52. #define ADJ_OFFSET 0x0001 /* time offset */
  53. #define ADJ_FREQUENCY 0x0002 /* frequency offset */
  54. #define ADJ_MAXERROR 0x0004 /* maximum time error */
  55. #define ADJ_ESTERROR 0x0008 /* estimated time error */
  56. #define ADJ_STATUS 0x0010 /* clock status */
  57. #define ADJ_TIMECONST 0x0020 /* pll time constant */
  58. #define ADJ_TICK 0x4000 /* tick value */
  59. #define ADJ_OFFSET_SINGLESHOT 0x8001 /* old-fashioned adjtime */
  60. /* xntp 3.4 compatibility names */
  61. #define MOD_OFFSET ADJ_OFFSET
  62. #define MOD_FREQUENCY ADJ_FREQUENCY
  63. #define MOD_MAXERROR ADJ_MAXERROR
  64. #define MOD_ESTERROR ADJ_ESTERROR
  65. #define MOD_STATUS ADJ_STATUS
  66. #define MOD_TIMECONST ADJ_TIMECONST
  67. #define MOD_CLKB ADJ_TICK
  68. #define MOD_CLKA ADJ_OFFSET_SINGLESHOT /* 0x8000 in original */
  69. /* Status codes (timex.status) */
  70. #define STA_PLL 0x0001 /* enable PLL updates (rw) */
  71. #define STA_PPSFREQ 0x0002 /* enable PPS freq discipline (rw) */
  72. #define STA_PPSTIME 0x0004 /* enable PPS time discipline (rw) */
  73. #define STA_FLL 0x0008 /* select frequency-lock mode (rw) */
  74. #define STA_INS 0x0010 /* insert leap (rw) */
  75. #define STA_DEL 0x0020 /* delete leap (rw) */
  76. #define STA_UNSYNC 0x0040 /* clock unsynchronized (rw) */
  77. #define STA_FREQHOLD 0x0080 /* hold frequency (rw) */
  78. #define STA_PPSSIGNAL 0x0100 /* PPS signal present (ro) */
  79. #define STA_PPSJITTER 0x0200 /* PPS signal jitter exceeded (ro) */
  80. #define STA_PPSWANDER 0x0400 /* PPS signal wander exceeded (ro) */
  81. #define STA_PPSERROR 0x0800 /* PPS signal calibration error (ro) */
  82. #define STA_CLOCKERR 0x1000 /* clock hardware fault (ro) */
  83. #define STA_RONLY (STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER | \
  84. STA_PPSERROR | STA_CLOCKERR) /* read-only bits */
  85. /* Clock states (time_state) */
  86. #define TIME_OK 0 /* clock synchronized, no leap second */
  87. #define TIME_INS 1 /* insert leap second */
  88. #define TIME_DEL 2 /* delete leap second */
  89. #define TIME_OOP 3 /* leap second in progress */
  90. #define TIME_WAIT 4 /* leap second has occurred */
  91. #define TIME_ERROR 5 /* clock not synchronized */
  92. #define TIME_BAD TIME_ERROR /* bw compat */
  93. /* Maximum time constant of the PLL. */
  94. #define MAXTC 6
  95. __BEGIN_DECLS
  96. #if 0
  97. extern int __adjtimex (struct timex *__ntx) __THROW;
  98. #endif
  99. extern int adjtimex (struct timex *__ntx) __THROW;
  100. libc_hidden_proto(adjtimex)
  101. #if defined __UCLIBC_NTP_LEGACY__
  102. extern int ntp_gettime (struct ntptimeval *__ntv) __THROW;
  103. extern int ntp_adjtime (struct timex *__tntx) __THROW;
  104. #endif
  105. __END_DECLS
  106. #endif /* sys/timex.h */