RTEMS 6.1-rc5
Loading...
Searching...
No Matches
timex.h
Go to the documentation of this file.
1
10/*-
11 ***********************************************************************
12 * *
13 * Copyright (c) David L. Mills 1993-2001 *
14 * Copyright (c) Poul-Henning Kamp 2000-2001 *
15 * *
16 * Permission to use, copy, modify, and distribute this software and *
17 * its documentation for any purpose and without fee is hereby *
18 * granted, provided that the above copyright notice appears in all *
19 * copies and that both the copyright notice and this permission *
20 * notice appear in supporting documentation, and that the name *
21 * University of Delaware not be used in advertising or publicity *
22 * pertaining to distribution of the software without specific, *
23 * written prior permission. The University of Delaware makes no *
24 * representations about the suitability this software for any *
25 * purpose. It is provided "as is" without express or implied *
26 * warranty. *
27 * *
28 ***********************************************************************
29 *
30 * This header file defines the Network Time Protocol (NTP) interfaces
31 * for user and daemon application programs.
32 *
33 * This file was originally created 17 Sep 93 by David L. Mills, Professor
34 * of University of Delaware, building on work which had already been ongoing
35 * for a decade and a half at that point in time.
36 *
37 * In 2000 the APIs got a upgrade from microseconds to nanoseconds,
38 * a joint work between Poul-Henning Kamp and David L. Mills.
39 *
40 */
41
42#ifndef _SYS_TIMEX_H_
43#define _SYS_TIMEX_H_ 1
44
45#define NTP_API 4 /* NTP API version */
46
47#if defined(__FreeBSD__) || defined(__rtems__)
48#include <sys/_timespec.h>
49#endif /* __FreeBSD__ */
50
51/*
52 * The following defines establish the performance envelope of the
53 * kernel discipline loop. Phase or frequency errors greater than
54 * NAXPHASE or MAXFREQ are clamped to these maxima. For update intervals
55 * less than MINSEC, the loop always operates in PLL mode; while, for
56 * update intervals greater than MAXSEC, the loop always operates in FLL
57 * mode. Between these two limits the operating mode is selected by the
58 * STA_FLL bit in the status word.
59 */
60
61#define MAXPHASE 500000000L /* max phase error (ns) */
62#define MAXFREQ 500000L /* max freq error (ns/s) */
63#define MINSEC 256 /* min FLL update interval (s) */
64#define MAXSEC 2048 /* max PLL update interval (s) */
65#define NANOSECOND 1000000000L /* nanoseconds in one second */
66#define SCALE_PPM (65536 / 1000) /* crude ns/s to scaled PPM */
67#define MAXTC 10 /* max time constant */
68
69/*
70 * Control mode codes (timex.modes)
71 */
72#define MOD_OFFSET 0x0001 /* set time offset */
73#define MOD_FREQUENCY 0x0002 /* set frequency offset */
74#define MOD_MAXERROR 0x0004 /* set maximum time error */
75#define MOD_ESTERROR 0x0008 /* set estimated time error */
76#define MOD_STATUS 0x0010 /* set clock status bits */
77#define MOD_TIMECONST 0x0020 /* set PLL time constant */
78#define MOD_PPSMAX 0x0040 /* set PPS maximum averaging time */
79#define MOD_TAI 0x0080 /* set TAI offset */
80#define MOD_MICRO 0x1000 /* select microsecond resolution */
81#define MOD_NANO 0x2000 /* select nanosecond resolution */
82#define MOD_CLKB 0x4000 /* select clock B */
83#define MOD_CLKA 0x8000 /* select clock A */
84
85/*
86 * Status codes (timex.status)
87 */
88#define STA_PLL 0x0001 /* enable PLL updates (rw) */
89#define STA_PPSFREQ 0x0002 /* enable PPS freq discipline (rw) */
90#define STA_PPSTIME 0x0004 /* enable PPS time discipline (rw) */
91#define STA_FLL 0x0008 /* enable FLL mode (rw) */
92#define STA_INS 0x0010 /* insert leap (rw) */
93#define STA_DEL 0x0020 /* delete leap (rw) */
94#define STA_UNSYNC 0x0040 /* clock unsynchronized (rw) */
95#define STA_FREQHOLD 0x0080 /* hold frequency (rw) */
96#define STA_PPSSIGNAL 0x0100 /* PPS signal present (ro) */
97#define STA_PPSJITTER 0x0200 /* PPS signal jitter exceeded (ro) */
98#define STA_PPSWANDER 0x0400 /* PPS signal wander exceeded (ro) */
99#define STA_PPSERROR 0x0800 /* PPS signal calibration error (ro) */
100#define STA_CLOCKERR 0x1000 /* clock hardware fault (ro) */
101#define STA_NANO 0x2000 /* resolution (0 = us, 1 = ns) (ro) */
102#define STA_MODE 0x4000 /* mode (0 = PLL, 1 = FLL) (ro) */
103#define STA_CLK 0x8000 /* clock source (0 = A, 1 = B) (ro) */
104
105#define STA_RONLY (STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER | \
106 STA_PPSERROR | STA_CLOCKERR | STA_NANO | STA_MODE | STA_CLK)
107
108/*
109 * Clock states (ntptimeval.time_state)
110 */
111#define TIME_OK 0 /* no leap second warning */
112#define TIME_INS 1 /* insert leap second warning */
113#define TIME_DEL 2 /* delete leap second warning */
114#define TIME_OOP 3 /* leap second in progress */
115#define TIME_WAIT 4 /* leap second has occurred */
116#define TIME_ERROR 5 /* error (see status word) */
117
118/*
119 * NTP user interface -- ntp_gettime(2) - used to read kernel clock values
120 */
122 struct timespec time; /* current time (ns) (ro) */
123 long maxerror; /* maximum error (us) (ro) */
124 long esterror; /* estimated error (us) (ro) */
125 long tai; /* TAI offset */
126 int time_state; /* time status */
127};
128
129/*
130 * NTP daemon interface -- ntp_adjtime(2) -- used to discipline CPU clock
131 * oscillator and control/determine status.
132 *
133 * Note: The offset, precision and jitter members are in microseconds if
134 * STA_NANO is zero and nanoseconds if not.
135 */
136struct timex {
137 unsigned int modes; /* clock mode bits (wo) */
138 long offset; /* time offset (ns/us) (rw) */
139 long freq; /* frequency offset (scaled PPM) (rw) */
140 long maxerror; /* maximum error (us) (rw) */
141 long esterror; /* estimated error (us) (rw) */
142 int status; /* clock status bits (rw) */
143 long constant; /* poll interval (log2 s) (rw) */
144 long precision; /* clock precision (ns/us) (ro) */
145 long tolerance; /* clock frequency tolerance (scaled
146 * PPM) (ro) */
147 /*
148 * The following read-only structure members are implemented
149 * only if the PPS signal discipline is configured in the
150 * kernel. They are included in all configurations to insure
151 * portability.
152 */
153 long ppsfreq; /* PPS frequency (scaled PPM) (ro) */
154 long jitter; /* PPS jitter (ns/us) (ro) */
155 int shift; /* interval duration (s) (shift) (ro) */
156 long stabil; /* PPS stability (scaled PPM) (ro) */
157 long jitcnt; /* jitter limit exceeded (ro) */
158 long calcnt; /* calibration intervals (ro) */
159 long errcnt; /* calibration errors (ro) */
160 long stbcnt; /* stability limit exceeded (ro) */
161};
162
163#if defined(__FreeBSD__) || defined(__rtems__)
164
165#ifdef _KERNEL
166void ntp_update_second(int64_t *adjustment, time_t *newsec);
167#else /* !_KERNEL */
168#include <sys/cdefs.h>
169
170__BEGIN_DECLS
171int ntp_adjtime(struct timex *);
172int ntp_gettime(struct ntptimeval *);
173__END_DECLS
174#endif /* _KERNEL */
175
176#endif /* __FreeBSD__ */
177
178#endif /* !_SYS_TIMEX_H_ */
Definition: timex.h:121
Definition: timex.h:136