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