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