FreeBSD/contrib/ntp/ntpd/refclock_true.c
/*
 * true_start - open the devices and initialize data for processing
 */
open the devices and initialize data for processing
open the devices and initialize data for processing
static int
true_start(
	int unit,
	struct peer *peer
	)
{
	register struct true_unit *up;
	struct refclockproc *pp;
	char device[40];
	int fd;
	snprintf(device, sizeof(device), DEVICE, unit);
	fd = refclock_open(device, SPEED232, LDISC_CLK);
	if (fd <= 0)
		return 0;
	up = emalloc_zero(sizeof(*up));
	pp = peer->procptr;
	pp->io.clock_recv = true_receive;
	pp->io.srcclock = peer;
	pp->io.datalen = 0;
	pp->io.fd = fd;
	if (!io_addclock(&pp->io)) {
		close(fd);
		pp->io.fd = -1;
		free(up);
		return (0);
	}
	pp->unitptr = up;
	peer->precision = PRECISION;
	pp->clockdesc = DESCRIPTION;
	memcpy(&pp->refid, REFID, 4);
	up->pollcnt = 2;
	up->type = t_unknown;
	up->state = s_Base;
	true_send(peer, "\03\r");
	true_doevent(peer, e_Init);
	return (1);
}
static int true_start ( int unit , struct peer * peer ) { register struct true_unit * up ; struct refclockproc * pp ; char device [ 40 ] ; int fd ; snprintf ( device , sizeof ( device ) , DEVICE , unit ) ; fd = refclock_open ( device , SPEED232 , LDISC_CLK ) ; if ( fd <= 0 ) return 0 ; up = emalloc_zero ( sizeof ( * up ) ) ; pp = peer -> procptr ; pp -> io . clock_recv = true_receive ; pp -> io . srcclock = peer ; pp -> io . datalen = 0 ; pp -> io . fd = fd ; if ( ! io_addclock ( & pp -> io ) ) { close ( fd ) ; pp -> io . fd = -1 ; free ( up ) ; return ( 0 ) ; } pp -> unitptr = up ; peer -> precision = PRECISION ; pp -> clockdesc = DESCRIPTION ; memcpy ( & pp -> refid , REFID , 4 ) ; up -> pollcnt = 2 ; up -> type = t_unknown ; up -> state = s_Base ; true_send ( peer , " \03 \r " ) ; true_doevent ( peer , e_Init ) ; return ( 1 ) ; }
true_start - open the devices and initialize data for processing
true_start - open the devices and initialize data for processing
/*
	 * Open serial port
	 */ /*
	 * Allocate and initialize unit structure
	 */ /*
	 * Initialize miscellaneous variables
	 */ /*
	 * Send a CTRL-C character at the start,
	 * just in case the clock is already
	 * sending timecodes
	 */