timex.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /* Copyright (C) 1995-2026 Free Software Foundation, Inc.
  17. This file is part of the GNU C Library.
  18. The GNU C Library is free software; you can redistribute it and/or
  19. modify it under the terms of the GNU Lesser General Public
  20. License as published by the Free Software Foundation; either
  21. version 2.1 of the License, or (at your option) any later version.
  22. The GNU C Library is distributed in the hope that it will be useful,
  23. but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  25. Lesser General Public License for more details.
  26. You should have received a copy of the GNU Lesser General Public
  27. License along with the GNU C Library; if not, see
  28. <https://www.gnu.org/licenses/>. */
  29. #ifndef _BITS_TIMEX_H
  30. #define _BITS_TIMEX_H 1
  31. #include <bits/types.h>
  32. #include <bits/types/struct_timeval.h>
  33. /* These definitions from linux/timex.h as of 3.18. */
  34. struct timex
  35. {
  36. # if defined __USE_TIME64_REDIRECTS || (__TIMESIZE == 64 && __WORDSIZE == 32)
  37. unsigned int modes; /* mode selector */
  38. int :32; /* pad */
  39. long long offset; /* time offset (usec) */
  40. long long freq; /* frequency offset (scaled ppm) */
  41. long long maxerror; /* maximum error (usec) */
  42. long long esterror; /* estimated error (usec) */
  43. int status; /* clock command/status */
  44. int :32; /* pad */
  45. long long constant; /* pll time constant */
  46. long long precision; /* clock precision (usec) (read only) */
  47. long long tolerance; /* clock frequency tolerance (ppm) (ro) */
  48. struct timeval time; /* (read only, except for ADJ_SETOFFSET) */
  49. long long tick; /* (modified) usecs between clock ticks */
  50. long long ppsfreq; /* pps frequency (scaled ppm) (ro) */
  51. long long jitter; /* pps jitter (us) (ro) */
  52. int shift; /* interval duration (s) (shift) (ro) */
  53. int :32; /* pad */
  54. long long stabil; /* pps stability (scaled ppm) (ro) */
  55. long long jitcnt; /* jitter limit exceeded (ro) */
  56. long long calcnt; /* calibration intervals (ro) */
  57. long long errcnt; /* calibration errors (ro) */
  58. long long stbcnt; /* stability limit exceeded (ro) */
  59. int tai; /* TAI offset (ro) */
  60. int :32; int :32; int :32; int :32;
  61. int :32; int :32; int :32; int :32;
  62. int :32; int :32; int :32;
  63. # else
  64. unsigned int modes; /* mode selector */
  65. __syscall_slong_t offset; /* time offset (usec) */
  66. __syscall_slong_t freq; /* frequency offset (scaled ppm) */
  67. __syscall_slong_t maxerror; /* maximum error (usec) */
  68. __syscall_slong_t esterror; /* estimated error (usec) */
  69. int status; /* clock command/status */
  70. __syscall_slong_t constant; /* pll time constant */
  71. __syscall_slong_t precision; /* clock precision (usec) (ro) */
  72. __syscall_slong_t tolerance; /* clock frequency tolerance (ppm) (ro) */
  73. struct timeval time; /* (read only, except for ADJ_SETOFFSET) */
  74. __syscall_slong_t tick; /* (modified) usecs between clock ticks */
  75. __syscall_slong_t ppsfreq; /* pps frequency (scaled ppm) (ro) */
  76. __syscall_slong_t jitter; /* pps jitter (us) (ro) */
  77. int shift; /* interval duration (s) (shift) (ro) */
  78. __syscall_slong_t stabil; /* pps stability (scaled ppm) (ro) */
  79. __syscall_slong_t jitcnt; /* jitter limit exceeded (ro) */
  80. __syscall_slong_t calcnt; /* calibration intervals (ro) */
  81. __syscall_slong_t errcnt; /* calibration errors (ro) */
  82. __syscall_slong_t stbcnt; /* stability limit exceeded (ro) */
  83. int tai; /* TAI offset (ro) */
  84. /* ??? */
  85. int :32; int :32; int :32; int :32;
  86. int :32; int :32; int :32; int :32;
  87. int :32; int :32; int :32;
  88. # endif
  89. };
  90. /* Mode codes (timex.mode) */
  91. #define ADJ_OFFSET 0x0001 /* time offset */
  92. #define ADJ_FREQUENCY 0x0002 /* frequency offset */
  93. #define ADJ_MAXERROR 0x0004 /* maximum time error */
  94. #define ADJ_ESTERROR 0x0008 /* estimated time error */
  95. #define ADJ_STATUS 0x0010 /* clock status */
  96. #define ADJ_TIMECONST 0x0020 /* pll time constant */
  97. #define ADJ_TAI 0x0080 /* set TAI offset */
  98. #define ADJ_SETOFFSET 0x0100 /* add 'time' to current time */
  99. #define ADJ_MICRO 0x1000 /* select microsecond resolution */
  100. #define ADJ_NANO 0x2000 /* select nanosecond resolution */
  101. #define ADJ_TICK 0x4000 /* tick value */
  102. #define ADJ_OFFSET_SINGLESHOT 0x8001 /* old-fashioned adjtime */
  103. #define ADJ_OFFSET_SS_READ 0xa001 /* read-only adjtime */
  104. /* xntp 3.4 compatibility names */
  105. #define MOD_OFFSET ADJ_OFFSET
  106. #define MOD_FREQUENCY ADJ_FREQUENCY
  107. #define MOD_MAXERROR ADJ_MAXERROR
  108. #define MOD_ESTERROR ADJ_ESTERROR
  109. #define MOD_STATUS ADJ_STATUS
  110. #define MOD_TIMECONST ADJ_TIMECONST
  111. #define MOD_CLKB ADJ_TICK
  112. #define MOD_CLKA ADJ_OFFSET_SINGLESHOT /* 0x8000 in original */
  113. #define MOD_TAI ADJ_TAI
  114. #define MOD_MICRO ADJ_MICRO
  115. #define MOD_NANO ADJ_NANO
  116. /* Status codes (timex.status) */
  117. #define STA_PLL 0x0001 /* enable PLL updates (rw) */
  118. #define STA_PPSFREQ 0x0002 /* enable PPS freq discipline (rw) */
  119. #define STA_PPSTIME 0x0004 /* enable PPS time discipline (rw) */
  120. #define STA_FLL 0x0008 /* select frequency-lock mode (rw) */
  121. #define STA_INS 0x0010 /* insert leap (rw) */
  122. #define STA_DEL 0x0020 /* delete leap (rw) */
  123. #define STA_UNSYNC 0x0040 /* clock unsynchronized (rw) */
  124. #define STA_FREQHOLD 0x0080 /* hold frequency (rw) */
  125. #define STA_PPSSIGNAL 0x0100 /* PPS signal present (ro) */
  126. #define STA_PPSJITTER 0x0200 /* PPS signal jitter exceeded (ro) */
  127. #define STA_PPSWANDER 0x0400 /* PPS signal wander exceeded (ro) */
  128. #define STA_PPSERROR 0x0800 /* PPS signal calibration error (ro) */
  129. #define STA_CLOCKERR 0x1000 /* clock hardware fault (ro) */
  130. #define STA_NANO 0x2000 /* resolution (0 = us, 1 = ns) (ro) */
  131. #define STA_MODE 0x4000 /* mode (0 = PLL, 1 = FLL) (ro) */
  132. #define STA_CLK 0x8000 /* clock source (0 = A, 1 = B) (ro) */
  133. /* Read-only bits */
  134. #define STA_RONLY (STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER \
  135. | STA_PPSERROR | STA_CLOCKERR | STA_NANO | STA_MODE | STA_CLK)
  136. #endif /* bits/timex.h */