![]() |
|
|||
File indexing completed on 2025-05-11 08:24:14
0001 /** 0002 * @file 0003 * 0004 * @ingroup RTEMSScoreTimecounter 0005 * 0006 * @brief This header file provides interfaces of the Network Time Protocol 0007 * (NTP) support. 0008 */ 0009 0010 /*- 0011 *********************************************************************** 0012 * * 0013 * Copyright (c) David L. Mills 1993-2001 * 0014 * Copyright (c) Poul-Henning Kamp 2000-2001 * 0015 * * 0016 * Permission to use, copy, modify, and distribute this software and * 0017 * its documentation for any purpose and without fee is hereby * 0018 * granted, provided that the above copyright notice appears in all * 0019 * copies and that both the copyright notice and this permission * 0020 * notice appear in supporting documentation, and that the name * 0021 * University of Delaware not be used in advertising or publicity * 0022 * pertaining to distribution of the software without specific, * 0023 * written prior permission. The University of Delaware makes no * 0024 * representations about the suitability this software for any * 0025 * purpose. It is provided "as is" without express or implied * 0026 * warranty. * 0027 * * 0028 *********************************************************************** 0029 * 0030 * This header file defines the Network Time Protocol (NTP) interfaces 0031 * for user and daemon application programs. 0032 * 0033 * This file was originally created 17 Sep 93 by David L. Mills, Professor 0034 * of University of Delaware, building on work which had already been ongoing 0035 * for a decade and a half at that point in time. 0036 * 0037 * In 2000 the APIs got a upgrade from microseconds to nanoseconds, 0038 * a joint work between Poul-Henning Kamp and David L. Mills. 0039 * 0040 */ 0041 0042 #ifndef _SYS_TIMEX_H_ 0043 #define _SYS_TIMEX_H_ 1 0044 0045 #define NTP_API 4 /* NTP API version */ 0046 0047 #if defined(__FreeBSD__) || defined(__rtems__) 0048 #include <sys/_timespec.h> 0049 #endif /* __FreeBSD__ */ 0050 0051 /* 0052 * The following defines establish the performance envelope of the 0053 * kernel discipline loop. Phase or frequency errors greater than 0054 * NAXPHASE or MAXFREQ are clamped to these maxima. For update intervals 0055 * less than MINSEC, the loop always operates in PLL mode; while, for 0056 * update intervals greater than MAXSEC, the loop always operates in FLL 0057 * mode. Between these two limits the operating mode is selected by the 0058 * STA_FLL bit in the status word. 0059 */ 0060 0061 #define MAXPHASE 500000000L /* max phase error (ns) */ 0062 #define MAXFREQ 500000L /* max freq error (ns/s) */ 0063 #define MINSEC 256 /* min FLL update interval (s) */ 0064 #define MAXSEC 2048 /* max PLL update interval (s) */ 0065 #define NANOSECOND 1000000000L /* nanoseconds in one second */ 0066 #define SCALE_PPM (65536 / 1000) /* crude ns/s to scaled PPM */ 0067 #define MAXTC 10 /* max time constant */ 0068 0069 /* 0070 * Control mode codes (timex.modes) 0071 */ 0072 #define MOD_OFFSET 0x0001 /* set time offset */ 0073 #define MOD_FREQUENCY 0x0002 /* set frequency offset */ 0074 #define MOD_MAXERROR 0x0004 /* set maximum time error */ 0075 #define MOD_ESTERROR 0x0008 /* set estimated time error */ 0076 #define MOD_STATUS 0x0010 /* set clock status bits */ 0077 #define MOD_TIMECONST 0x0020 /* set PLL time constant */ 0078 #define MOD_PPSMAX 0x0040 /* set PPS maximum averaging time */ 0079 #define MOD_TAI 0x0080 /* set TAI offset */ 0080 #define MOD_MICRO 0x1000 /* select microsecond resolution */ 0081 #define MOD_NANO 0x2000 /* select nanosecond resolution */ 0082 #define MOD_CLKB 0x4000 /* select clock B */ 0083 #define MOD_CLKA 0x8000 /* select clock A */ 0084 0085 /* 0086 * Status codes (timex.status) 0087 */ 0088 #define STA_PLL 0x0001 /* enable PLL updates (rw) */ 0089 #define STA_PPSFREQ 0x0002 /* enable PPS freq discipline (rw) */ 0090 #define STA_PPSTIME 0x0004 /* enable PPS time discipline (rw) */ 0091 #define STA_FLL 0x0008 /* enable FLL mode (rw) */ 0092 #define STA_INS 0x0010 /* insert leap (rw) */ 0093 #define STA_DEL 0x0020 /* delete leap (rw) */ 0094 #define STA_UNSYNC 0x0040 /* clock unsynchronized (rw) */ 0095 #define STA_FREQHOLD 0x0080 /* hold frequency (rw) */ 0096 #define STA_PPSSIGNAL 0x0100 /* PPS signal present (ro) */ 0097 #define STA_PPSJITTER 0x0200 /* PPS signal jitter exceeded (ro) */ 0098 #define STA_PPSWANDER 0x0400 /* PPS signal wander exceeded (ro) */ 0099 #define STA_PPSERROR 0x0800 /* PPS signal calibration error (ro) */ 0100 #define STA_CLOCKERR 0x1000 /* clock hardware fault (ro) */ 0101 #define STA_NANO 0x2000 /* resolution (0 = us, 1 = ns) (ro) */ 0102 #define STA_MODE 0x4000 /* mode (0 = PLL, 1 = FLL) (ro) */ 0103 #define STA_CLK 0x8000 /* clock source (0 = A, 1 = B) (ro) */ 0104 0105 #define STA_RONLY (STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER | \ 0106 STA_PPSERROR | STA_CLOCKERR | STA_NANO | STA_MODE | STA_CLK) 0107 0108 /* 0109 * Clock states (ntptimeval.time_state) 0110 */ 0111 #define TIME_OK 0 /* no leap second warning */ 0112 #define TIME_INS 1 /* insert leap second warning */ 0113 #define TIME_DEL 2 /* delete leap second warning */ 0114 #define TIME_OOP 3 /* leap second in progress */ 0115 #define TIME_WAIT 4 /* leap second has occurred */ 0116 #define TIME_ERROR 5 /* error (see status word) */ 0117 0118 /* 0119 * NTP user interface -- ntp_gettime(2) - used to read kernel clock values 0120 */ 0121 struct ntptimeval { 0122 struct timespec time; /* current time (ns) (ro) */ 0123 long maxerror; /* maximum error (us) (ro) */ 0124 long esterror; /* estimated error (us) (ro) */ 0125 long tai; /* TAI offset */ 0126 int time_state; /* time status */ 0127 }; 0128 0129 /* 0130 * NTP daemon interface -- ntp_adjtime(2) -- used to discipline CPU clock 0131 * oscillator and control/determine status. 0132 * 0133 * Note: The offset, precision and jitter members are in microseconds if 0134 * STA_NANO is zero and nanoseconds if not. 0135 */ 0136 struct timex { 0137 unsigned int modes; /* clock mode bits (wo) */ 0138 long offset; /* time offset (ns/us) (rw) */ 0139 long freq; /* frequency offset (scaled PPM) (rw) */ 0140 long maxerror; /* maximum error (us) (rw) */ 0141 long esterror; /* estimated error (us) (rw) */ 0142 int status; /* clock status bits (rw) */ 0143 long constant; /* poll interval (log2 s) (rw) */ 0144 long precision; /* clock precision (ns/us) (ro) */ 0145 long tolerance; /* clock frequency tolerance (scaled 0146 * PPM) (ro) */ 0147 /* 0148 * The following read-only structure members are implemented 0149 * only if the PPS signal discipline is configured in the 0150 * kernel. They are included in all configurations to insure 0151 * portability. 0152 */ 0153 long ppsfreq; /* PPS frequency (scaled PPM) (ro) */ 0154 long jitter; /* PPS jitter (ns/us) (ro) */ 0155 int shift; /* interval duration (s) (shift) (ro) */ 0156 long stabil; /* PPS stability (scaled PPM) (ro) */ 0157 long jitcnt; /* jitter limit exceeded (ro) */ 0158 long calcnt; /* calibration intervals (ro) */ 0159 long errcnt; /* calibration errors (ro) */ 0160 long stbcnt; /* stability limit exceeded (ro) */ 0161 }; 0162 0163 #if defined(__FreeBSD__) || defined(__rtems__) 0164 0165 #ifdef _KERNEL 0166 void ntp_update_second(int64_t *adjustment, time_t *newsec); 0167 #else /* !_KERNEL */ 0168 #include <sys/cdefs.h> 0169 0170 __BEGIN_DECLS 0171 int ntp_adjtime(struct timex *); 0172 int ntp_gettime(struct ntptimeval *); 0173 __END_DECLS 0174 #endif /* _KERNEL */ 0175 0176 #endif /* __FreeBSD__ */ 0177 0178 #endif /* !_SYS_TIMEX_H_ */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |