FreeBSD/contrib/ntp/ntpd/refclock_tt560.c
/*
 * tt560_start - open the TT560 device and initialize data for processing
 */
open the TT560 device and initialize data for processing
open the TT560 device and initialize data for processing
static int
tt560_start(
	int unit,
	struct peer *peer
	)
{
	register struct tt560unit *up;
	struct refclockproc *pp;
	char	device[20];
	int	fd;
	caddr_t membase;
	snprintf(device, sizeof(device), DEVICE, unit);
	fd = open(device, O_RDWR);
	if (fd == -1) {
		msyslog(LOG_ERR, "tt560_start: open of %s: %m", device);
		return (0);
	}
	membase = mmap ((caddr_t) 0, TTIME_MEMORY_SIZE,
			PROT_READ | PROT_WRITE,
			MAP_SHARED, fd, (off_t)0);
	if (membase == (caddr_t) -1) {
		msyslog(LOG_ERR, "tt560_start: mapping of %s: %m", device);
		(void) close(fd);
		return (0);
	}
	if (!(up = (struct tt560unit *) emalloc(sizeof(struct tt560unit)))) {
		(void) close(fd);
		return (0);
	}
	memset((char *)up, 0, sizeof(struct tt560unit));
	up->tt_mem = (tt_mem_space_t *)membase;
	pp = peer->procptr;
	pp->io.clock_recv = noentry;
	pp->io.srcclock = (caddr_t)peer;
	pp->io.datalen = 0;
	pp->io.fd = fd;
	pp->unitptr = (caddr_t)up;
	peer->precision = PRECISION;
	pp->clockdesc = DESCRIPTION;
	memcpy((char *)&pp->refid, REFID, 4);
	return (1);
}
static int tt560_start ( int unit , struct peer * peer ) { register struct tt560unit * up ; struct refclockproc * pp ; char device [ 20 ] ; int fd ; caddr_t membase ; snprintf ( device , sizeof ( device ) , DEVICE , unit ) ; fd = open ( device , O_RDWR ) ; if ( fd == -1 ) { msyslog ( LOG_ERR , " " , device ) ; return ( 0 ) ; } membase = mmap ( ( caddr_t ) 0 , TTIME_MEMORY_SIZE , PROT_READ | PROT_WRITE , MAP_SHARED , fd , ( off_t ) 0 ) ; if ( membase == ( caddr_t ) - 1 ) { msyslog ( LOG_ERR , " " , device ) ; ( void ) close ( fd ) ; return ( 0 ) ; } if ( ! ( up = ( struct tt560unit * ) emalloc ( sizeof ( struct tt560unit ) ) ) ) { ( void ) close ( fd ) ; return ( 0 ) ; } memset ( ( char * ) up , 0 , sizeof ( struct tt560unit ) ) ; up -> tt_mem = ( tt_mem_space_t * ) membase ; pp = peer -> procptr ; pp -> io . clock_recv = noentry ; pp -> io . srcclock = ( caddr_t ) peer ; pp -> io . datalen = 0 ; pp -> io . fd = fd ; pp -> unitptr = ( caddr_t ) up ; peer -> precision = PRECISION ; pp -> clockdesc = DESCRIPTION ; memcpy ( ( char * ) & pp -> refid , REFID , 4 ) ; return ( 1 ) ; }
tt560_start - open the TT560 device and initialize data for processing
tt560_start - open the TT560 device and initialize data for processing
/*
	 * Open TT560 device
	 */ /*
	 * Map the device registers into user space.
	 */ /*
	 * Allocate and initialize unit structure
	 */ /*
	 * Initialize miscellaneous peer variables
	 */