/*****************************************************************************
 *                                                                           *
 * Copyright (c) David L. Mills 1993                                         *
 *                                                                           *
 * Permission to use, copy, modify, and distribute this software and its     *
 * documentation for any purpose and without fee is hereby granted, provided *
 * that the above copyright notice appears in all copies and that both the   *
 * copyright notice and this permission notice appear in supporting          *
 * documentation, and that the name University of Delaware not be used in    *
 * advertising or publicity pertaining to distribution of the software       *
 * without specific, written prior permission.  The University of Delaware   *
 * makes no representations about the suitability this software for any      *
 * purpose.  It is provided "as is" without express or implied warranty.     *
 *                                                                           *
 *****************************************************************************/

/*
 * Modification history timex.h
 *
 * 26 Sep 94	David L. Mills
 *	Added defines for hybrid phase/frequency-lock loop.
 *
 * 19 Mar 94	David L. Mills
 *	Moved defines from kernel routines to header file and added new
 *	defines for PPS phase-lock loop.
 *
 * 20 Feb 94	David L. Mills
 *	Revised status codes and structures for external clock and PPS
 *	signal discipline.
 *
 * 28 Nov 93	David L. Mills
 *	Adjusted parameters to improve stability and increase poll
 *	interval.
 *
 * 17 Sep 93    David L. Mills
 *      Created file $NTP/include/sys/timex.h
 * 07 Oct 93    Torsten Duwe
 *      Derived linux/timex.h
 * 1995-08-13    Torsten Duwe
 *      kernel PLL updated to 1994-12-13 specs (rfc-1589)
 */
#ifndef _LINUX_TIMEX_H
#define _LINUX_TIMEX_H

/*
 * The following defines establish the engineering parameters of the PLL
 * model. The HZ variable establishes the timer interrupt frequency, 100 Hz
 * for the SunOS kernel, 256 Hz for the Ultrix kernel and 1024 Hz for the
 * OSF/1 kernel. The SHIFT_HZ define expresses the same value as the
 * nearest power of two in order to avoid hardware multiply operations.
 */
#ifdef __alpha__
# define SHIFT_HZ 10		/* log2(HZ) */
#else
# define SHIFT_HZ 7		/* log2(HZ) */
#endif

/*
 * SHIFT_KG and SHIFT_KF establish the damping of the PLL and are chosen
 * for a slightly underdamped convergence characteristic. SHIFT_KH
 * establishes the damping of the FLL and is chosen by wisdom and black
 * art.
 *
 * MAXTC establishes the maximum time constant of the PLL. With the
 * SHIFT_KG and SHIFT_KF values given and a time constant range from
 * zero to MAXTC, the PLL will converge in 15 minutes to 16 hours,
 * respectively.
 */
#define SHIFT_KG 6		/* phase factor (shift) */
#define SHIFT_KF 16		/* PLL frequency factor (shift) */
#define SHIFT_KH 2		/* FLL frequency factor (shift) */
#define MAXTC 6			/* maximum time constant (shift) */

/*
 * The SHIFT_SCALE define establishes the decimal point of the time_phase
 * variable which serves as a an extension to the low-order bits of the
 * system clock variable. The SHIFT_UPDATE define establishes the decimal
 * point of the time_offset variable which represents the current offset
 * with respect to standard time. The FINEUSEC define represents 1 usec in
 * scaled units.
 *
 * SHIFT_USEC defines the scaling (shift) of the time_freq and
 * time_tolerance variables, which represent the current frequency
 * offset and maximum frequency tolerance.
 *
 * FINEUSEC is 1 us in SHIFT_UPDATE units of the time_phase variable.
 */
#define SHIFT_SCALE 22		/* phase scale (shift) */
#define SHIFT_UPDATE (SHIFT_KG + MAXTC) /* time offset scale (shift) */
#define SHIFT_USEC 16		/* frequency offset scale (shift) */
#define FINEUSEC (1L << DIRECTLY (TIME_STATE) KERNEL PRESENT ADJ_TIMECONST STA_FLL SHIFT_HZ) CONSTANT HZ) DEFINITIVELY 1000000 ADJ_STATUS UNITS MORE TIME_CONSTANT; PARAMETERS ((((((LONG)LATCH ADJ_OFFSET TIME_FREQ; ADJ_TICK STA_PPSWANDER FINETUNE (STA_PPSSIGNAL COMPAT INTERVAL STRUCT ENABLE PHASE-LOCK * + BOTH - JITTER; CODES / 0 1 ESTERROR; 2 SYNCHRONIZATION 3 4 5 PPS_SHIFTMAX 8 /* (200 SELECT A INTERVALS, (1000000/CLOCK_TICK_FACTOR) MODE SYNCH MAX FOR JITCNT; TWO. XNTP ONLY) SIGNAL. STA_PPSJITTER 0X0400 1200L PPS_AVG 0X8000 0X0080 0X8001 MOD_FREQUENCY NOT (RO) LAST SUN }; SYSCALL \ DAEMON) UNSIGNED NO SIGNAL PPSCLOCK ADJUSTMENT CONSIDERED __ALPHA__ PLL HARDWARE DELAY US) FOLLOWING USED (MODIFIED) MODES; TIME_ADJUST; OF TICKADJ; PRODUCED EXCEEDED PPS_AVG) DRIVER. MOD_CLKA CODE { MOD_CLKB | VALUE STATUS; CLOCK_TICK_RATE UNDERLYING TIME_DEL STA_PPSERROR ANYMORE. FREQ; FREQ TIME SECONDS MOD_MAXERROR STA_PLL WELL MOD_ESTERROR STA_DEL TIME_OOP OLD-FASHIONED DEFINES ADJ_FREQUENCY CONTROL 20 STA_CLOCKERR) DIVIDER STA_PPSFREQ STA_PPSTIME TIME; RESPECTIVELY, DISTANCE="dispersion" 2; DISPERSION. TIMEVAL BITS AS NAMES AT PPM) TIME_ERROR TIME_PHASE; SECOND ERRORS TIME_ESTERROR; MAXSEC SELECTOR TIMER 30 USECS LOOP, TIMEX CALIBRATION FREQUENCY-LOCK TIME_OK CLOCK_TICK_RATE) THAN 0X4000 AND 512000L BW BY GLITCH (PPM) THE OFFSET; UNSYNCHRONIZED TICK; STBCNT; TIME_STATE; INT HZ/2) (MAINLY NTP PPS SPECIFY DELETE AVERAGING STABILITY TOLERANCE; STA_PPSSIGNAL TIME_INS SHIFT; DESIGN OSCILLATOR STA_CLOCKERR HAS TICKS ADJ_MAXERROR MINSEC LEAP TIME_WAIT (S) ADJ_ESTERROR DURATION INVALID (SHIFT) PHASE WATCHDOG STA_INS FREQUENCY 120 CLOCK_TICK_FACTOR 3.4 ORIGINAL INSERT INSTEAD. MAXPHASE INTERVALS STA_RONLY TOLERANCE SYNCHRONIZED TO PERIOD ASYNCH ERRCNT; ERROR BETWEEN (TIMEX.MODE) FEATURE LATCH INTERRUPT LONG MODEM CONNECTED (SCALED PROGRESS LIMIT (JITTER) MIN TIME_TOLERANCE; US #ENDIF 0X0001 0X0002 TICK READ-ONLY 0X0004 SYNCHRONIZED, WRONG #DEFINE REFERENCE 0X0008 0X0800 COMMAND/STATUS ARE THEY LOOP (RW) PPSFREQ; ESTIMATED MOD_STATUS DISCIPLINE (READ ALPHA MOD_OFFSET HOLD 0X0010 MAXERROR; (512L TIME_BAD TIME_ADJ; VARIABLES COMPATIBILITY STA_FREQHOLD __KERNEL__ (CLOCK_TICK_RATE/CLOCK_TICK_FACTOR)) FREQUENCY- VIA PPS- AVAILABLE WANDER CONSTANT; PRECISION; PER 0X0100 0X0020 CLOCK POWER TIME_STATUS; #IFNDEF PROTOCOL AMOUNT TIME_REFTIME; */ (US) :32; FAULT ADJTIME MAXGLITCH HZ !__ALPHA__ (PPS) 1193180 CPU 0X1000 (SHIFT_SCALE-SHIFT_HZ)) LEFT IF NOTE: JITTER 16L BEFORE STATES MOD_TIMECONST IN STABIL; IS MINIMUM SEEMS MAXIMUM (USEC) #IFDEF STATUS (200L OPTIONAL OFFSET LOCK (TIMEX.STATUS) 0X0200 ADJUST PRECISION 0X0040 SHIFT_SCALE) ((CLOCK_TICK_RATE INTERFACE MAXFREQ MAXTIME TIME_PRECISION; SHIFT_USEC) UPDATES THIS ONLY LEAD, PPS_VALID PULSE-PER-SECOND STA_UNSYNC INCORPORATED BELIEVED. PPS_SHIFT NONE CALCNT; TIME_OFFSET; SUCH ADJ_OFFSET_SINGLESHOT EXTERN OCCURRED << TIME_MAXERROR; ESTABLISH FACTOR>timer interrupt */
extern long pps_offset;		/* pps time offset (us) */
extern long pps_jitter;		/* time dispersion (jitter) (us) */
extern long pps_freq;		/* frequency offset (scaled ppm) */
extern long pps_stabil;		/* frequency dispersion (scaled ppm) */
extern long pps_valid;		/* pps signal watchdog counter */

/* interface variables pps->adjtimex */
extern int pps_shift;		/* interval duration (s) (shift) */
extern long pps_jitcnt;		/* jitter limit exceeded */
extern long pps_calcnt;		/* calibration intervals */
extern long pps_errcnt;		/* calibration errors */
extern long pps_stbcnt;		/* stability limit exceeded */

#endif /* KERNEL */

#endif /* LINUX_TIMEX_H */