FreeBSD/contrib/ntp/ntpd/refclock_wwv.c
/*
 * wwv_tsec - transmitter minute processing
 *
 * This routine is called at the end of the transmitter minute. It
 * implements a state machine that advances the logical clock subject to
 * the funny rules that govern the conventional clock and calendar.
 */
transmitter minute processing
This routine is called at the end of the transmitter minute. It
implements a state machine that advances the logical clock subject to
the funny rules that govern the conventional clock and calendar.
transmitter minute processing This routine is called at the end of the transmitter minute . It implements a state machine that advances the logical clock subject to the funny rules that govern the conventional clock and calendar .
static void
wwv_tsec(
	struct peer *peer	
	)
{
	struct refclockproc *pp;
	struct wwvunit *up;
	int minute, day, isleap;
	int temp;
	pp = peer->procptr;
	up = pp->unitptr;
	temp = carry(&up->decvec[MN]);	
	if (!(up->status & DSYNC))
		return;
	if (temp == 0)			
		temp = carry(&up->decvec[MN + 1]);
	if (temp == 0)			
		temp = carry(&up->decvec[HR]);
	if (temp == 0)
		temp = carry(&up->decvec[HR + 1]);
	minute = up->decvec[MN].digit + up->decvec[MN + 1].digit *
	    10 + up->decvec[HR].digit * 60 + up->decvec[HR +
	    1].digit * 600;
	day = up->decvec[DA].digit + up->decvec[DA + 1].digit * 10 +
	    up->decvec[DA + 2].digit * 100;
	isleap = up->decvec[YR].digit & 0x3;
	if (up->misc & SECWAR && up->status & INSYNC) {
		if ((day == (isleap ? 182 : 183) || day == (isleap ?
		    365 : 366)) && minute == 1439)
			up->status |= LEPSEC;
	}
	if (minute != 1440)
		return;
	while (carry(&up->decvec[HR]) != 0); 
	while (carry(&up->decvec[HR + 1]) != 0);
	day++;
	temp = carry(&up->decvec[DA]);	
	if (temp == 0)
		temp = carry(&up->decvec[DA + 1]);
	if (temp == 0)
		temp = carry(&up->decvec[DA + 2]);
	if (day != (isleap ? 365 : 366))
		return;
	while (carry(&up->decvec[DA]) != 1); 
	while (carry(&up->decvec[DA + 1]) != 0);
	while (carry(&up->decvec[DA + 2]) != 0);
	temp = carry(&up->decvec[YR]);	
	if (temp == 0)
		carry(&up->decvec[YR + 1]);
}
static void wwv_tsec ( struct peer * peer ) { struct refclockproc * pp ; struct wwvunit * up ; int minute , day , isleap ; int temp ; pp = peer -> procptr ; up = pp -> unitptr ; temp = carry ( & up -> decvec [ MN ] ) ; if ( ! ( up -> status & DSYNC ) ) return ; if ( temp == 0 ) temp = carry ( & up -> decvec [ MN + 1 ] ) ; if ( temp == 0 ) temp = carry ( & up -> decvec [ HR ] ) ; if ( temp == 0 ) temp = carry ( & up -> decvec [ HR + 1 ] ) ; minute = up -> decvec [ MN ] . digit + up -> decvec [ MN + 1 ] . digit * 10 + up -> decvec [ HR ] . digit * 60 + up -> decvec [ HR + 1 ] . digit * 600 ; day = up -> decvec [ DA ] . digit + up -> decvec [ DA + 1 ] . digit * 10 + up -> decvec [ DA + 2 ] . digit * 100 ; isleap = up -> decvec [ YR ] . digit & 0x3 ; if ( up -> misc & SECWAR && up -> status & INSYNC ) { if ( ( day == ( isleap ? 182 : 183 ) || day == ( isleap ? 365 : 366 ) ) && minute == 1439 ) up -> status |= LEPSEC ; } if ( minute != 1440 ) return ; while ( carry ( & up -> decvec [ HR ] ) != 0 ) ; while ( carry ( & up -> decvec [ HR + 1 ] ) != 0 ) ; day ++ ; temp = carry ( & up -> decvec [ DA ] ) ; if ( temp == 0 ) temp = carry ( & up -> decvec [ DA + 1 ] ) ; if ( temp == 0 ) temp = carry ( & up -> decvec [ DA + 2 ] ) ; if ( day != ( isleap ? 365 : 366 ) ) return ; while ( carry ( & up -> decvec [ DA ] ) != 1 ) ; while ( carry ( & up -> decvec [ DA + 1 ] ) != 0 ) ; while ( carry ( & up -> decvec [ DA + 2 ] ) != 0 ) ; temp = carry ( & up -> decvec [ YR ] ) ; if ( temp == 0 ) carry ( & up -> decvec [ YR + 1 ] ) ; }
wwv_tsec - transmitter minute processing
 This routine is called at the end of the transmitter minute.
wwv_tsec - transmitter minute processing This routine is called at the end of the transmitter minute .
/* driver structure pointer */ /*
	 * Advance minute unit of the day. Don't propagate carries until
	 * the unit minute digit has been found.
	 */ /* minute units */ /*
	 * Propagate carries through the day.
	 */ /* carry minutes */ /* carry hours */ // XXX: Does temp have an expected value here? /*
	 * Decode the current minute and day. Set leap day if the
	 * timecode leap bit is set on 30 June or 31 December. Set leap
	 * minute if the last minute on leap day, but only if the clock
	 * is syncrhronized. This code fails in 2400 AD.
	 */ /*
	 * Set the leap bit on the last minute of the leap day.
	 */ /*
	 * Roll the day if this the first minute and propagate carries
	 * through the year.
	 */ // minute = 0; /* advance to minute 0 */ /* carry days */ // XXX: Is there an expected value of temp here? /*
	 * Roll the year if this the first day and propagate carries
	 * through the century.
	 */ // day = 1; /* advance to day 1 */ /* carry years */