FreeBSD/contrib/ntp/ntpd/refclock_zyfer.c
/*
 * zyfer_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
zyfer_start(
	int unit,
	struct peer *peer
	)
{
	register struct zyferunit *up;
	struct refclockproc *pp;
	int fd;
	char device[20];
	snprintf(device, sizeof(device), DEVICE, unit);
	fd = refclock_open(device, SPEED232, LDISC_RAW);
	if (fd <= 0)
		return (0);
	msyslog(LOG_NOTICE, "zyfer(%d) fd: %d dev <%s>", unit, fd, device);
	up = emalloc(sizeof(struct zyferunit));
	memset(up, 0, sizeof(struct zyferunit));
	pp = peer->procptr;
	pp->io.clock_recv = zyfer_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((char *)&pp->refid, REFID, 4);
	up->pollcnt = 2;
	up->polled = 0;		
	return (1);
}
static int zyfer_start ( int unit , struct peer * peer ) { register struct zyferunit * up ; struct refclockproc * pp ; int fd ; char device [ 20 ] ; snprintf ( device , sizeof ( device ) , DEVICE , unit ) ; fd = refclock_open ( device , SPEED232 , LDISC_RAW ) ; if ( fd <= 0 ) return ( 0 ) ; msyslog ( LOG_NOTICE , " " , unit , fd , device ) ; up = emalloc ( sizeof ( struct zyferunit ) ) ; memset ( up , 0 , sizeof ( struct zyferunit ) ) ; pp = peer -> procptr ; pp -> io . clock_recv = zyfer_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 ( ( char * ) & pp -> refid , REFID , 4 ) ; up -> pollcnt = 2 ; up -> polled = 0 ; return ( 1 ) ; }
zyfer_start - open the devices and initialize data for processing
zyfer_start - open the devices and initialize data for processing
/*
	 * Open serial port.
	 * Something like LDISC_ACTS that looked for ! would be nice...
	 */ /*
	 * Allocate and initialize unit structure
	 */ /*
	 * Initialize miscellaneous variables
	 */ /* May not be needed... */