/*
* This program simulates a first-order, type-II phase-lock loop using
* actual code segments from modified kernel distributions for SunOS,
* Ultrix and OSF/1 kernels. These segments do not use any licensed code.
*/
/*
* Grind the loop until ^C
*/
while (1) {
timey += (double)(1000000) / HZ;
if (timey >= 1000000)
timey -= 1000000;
hardclock();
if (timex.tv_usec >= 1000000) {
timex.tv_usec -= 1000000;
timex.tv_sec++;
second_overflow();
poll_interval++;
if (!(poll_interval % POLL)) {
timez = (long)timey - timex.tv_usec;
if (timez > 500000)
timez -= 1000000;
if (timez < -500000)
timez += 1000000;
hardupdate(timez);
printf("%10li%10li%10.2f %08lx %08lx %08lx\n",
timex.tv_sec, timez,
(double)time_freq / (1 << SHIFT_KF),
time_offset, time_freq, time_adj);
}
}
}
}
/*
* This routine simulates the ntp_adjtime() call
*
* For default SHIFT_UPDATE = 12, offset is limited to +-512 ms, the
* maximum interval between updates is 4096 s and the maximum frequency
* offset is +-31.25 ms/s.
*/
void
hardupdate(
long offset
)
{
long ltemp, mtemp;
/*
* This routine simulates the overflow of the microsecond field
*
* With SHIFT_SCALE = 23, the maximum frequency adjustment is +-256 us
* per tick, or 25.6 ms/s at a clock frequency of 100 Hz. The time
* contribution is shifted right a minimum of two bits, while the frequency
* contribution is a right shift. Thus, overflow is prevented if the
* frequency contribution is limited to half the maximum or 15.625 ms/s.
*/
void
second_overflow(void)
{
int ltemp;