1/*********************************************************************** 2 * * 3 * Copyright (c) David L. Mills 1993-1998 * 4 * * 5 * Permission to use, copy, modify, and distribute this software and * 6 * its documentation for any purpose and without fee is hereby * 7 * granted, provided that the above copyright notice appears in all * 8 * copies and that both the copyright notice and this permission * --- 4 unchanged lines hidden (view full) --- 13 * representations about the suitability this software for any * 14 * purpose. It is provided "as is" without express or implied * 15 * warranty. * 16 * * 17 **********************************************************************/ 18 19/* 20 * Adapted from the original sources for FreeBSD and timecounters by: |
21 * Poul-Henning Kamp <phk@FreeBSD.org>. |
22 * 23 * The 32bit version of the "LP" macros seems a bit past its "sell by" 24 * date so I have retained only the 64bit version and included it directly 25 * in this file. 26 * 27 * Only minor changes done to interface with the timecounters over in 28 * sys/kern/kern_clock.c. Some of the comments below may be (even more) 29 * confusing and/or plain wrong in that context. |
30 */ 31 |
32#include "opt_ntp.h" 33 |
34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/sysproto.h> 37#include <sys/kernel.h> 38#include <sys/proc.h> 39#include <sys/time.h> 40#include <sys/timex.h> 41#include <sys/timepps.h> --- 119 unchanged lines hidden (view full) --- 161struct ppstime { 162 long sec; /* PPS seconds */ 163 long nsec; /* PPS nanoseconds */ 164 long count; /* PPS nanosecond counter */ 165}; 166static struct ppstime pps_tf[3]; /* phase median filter */ 167static struct ppstime pps_filt; /* phase offset */ 168static l_fp pps_freq; /* scaled frequency offset (ns/s) */ |
169static long pps_offacc; /* offset accumulator */ 170static long pps_jitter; /* scaled time dispersion (ns) */ 171static long pps_stabil; /* scaled frequency dispersion (ns/s) */ 172static long pps_lastcount; /* last counter offset */ 173static long pps_lastsec; /* time at last calibration (s) */ 174static int pps_valid; /* signal watchdog counter */ 175static int pps_shift = PPS_FAVG; /* interval duration (s) (shift) */ 176static int pps_intcnt; /* wander counter */ --- 198 unchanged lines hidden (view full) --- 375 * routine ntp_tick_adjust(). While these two routines are normally 376 * combined, they are separated here only for the purposes of 377 * simulation. 378 */ 379void 380ntp_update_second(struct timecounter *tcp) 381{ 382 u_int32_t *newsec; |
383 l_fp ftemp, time_adj; /* 32/64-bit temporaries */ |
384 385 newsec = &tcp->tc_offset_sec; 386 time_maxerror += MAXFREQ / 1000; 387 388 /* 389 * Leap second processing. If in leap-insert state at 390 * the end of the day, the system clock is set back one 391 * second; if in leap-delete state, the system clock is --- 255 unchanged lines hidden (view full) --- 647 /* 648 * Compute the difference between the current and previous 649 * counter values. If the difference exceeds 0.5 s, assume it 650 * has wrapped around, so correct 1.0 s. If the result exceeds 651 * the tick interval, the sample point has crossed a tick 652 * boundary during the last second, so correct the tick. Very 653 * intricate. 654 */ |
655 u_nsec = nsec; |
656 if (u_nsec > (NANOSECOND >> 1)) 657 u_nsec -= NANOSECOND; 658 else if (u_nsec < -(NANOSECOND >> 1)) 659 u_nsec += NANOSECOND; |
660#if 0 |
661 if (u_nsec > (time_tick >> 1)) 662 u_nsec -= time_tick; 663 else if (u_nsec < -(time_tick >> 1)) 664 u_nsec += time_tick; |
665#endif |
666 pps_tf[0].count = pps_tf[1].count + u_nsec; 667 if (v_nsec > MAXFREQ) { 668 return; 669 } 670 time_status &= ~STA_PPSJITTER; 671 672 /* 673 * A three-stage median filter is used to help denoise the PPS --- 132 unchanged lines hidden (view full) --- 806 if (u_nsec > MAXFREQ) 807 L_LINT(pps_freq, MAXFREQ); 808 else if (u_nsec < -MAXFREQ) 809 L_LINT(pps_freq, -MAXFREQ); 810 if (time_status & STA_PPSFREQ) 811 time_freq = pps_freq; 812} 813#endif /* PPS_SYNC */ |