Subject: Re: PPS diffs, round #3
To: Jonathan Stone <jonathan@dsg.stanford.edu>
From: Jason Thorpe <thorpej@nas.nasa.gov>
List: tech-kern
Date: 04/21/1998 21:45:20
On Tue, 21 Apr 1998 20:51:02 -0700 (PDT) 
 Jonathan Stone <jonathan@DSG.Stanford.EDU> wrote:

First, all of the new options (#ifdefs) should be defopt'd.

The new non-suckful API should probably use timespecs, and the old
one, timevals.  You can just to the convertion to timespec when
the user requests a timestamp w/ the new API, for now (that is, until
all timevals in the kernel get converted to timespecs :-)

 > + 	case TIOCDCDTIMESTAMP:	/* XXX old, overloaded API */
 > + 		sc->sc_dopps = 1;
 > + 		/*
 > + 		 * Some GPS clocks models use the falling rather than
 > + 		 * rising edge as the on-the-second signal. 
 > + 		 * The old API has no way to specify PPS polarity.
 > + 		 */
 > + #ifndef PPS_TRAILING_EDGE
 > + 	         sc->sc_dcd_edgemask = MSR_DCD;
 > + #else
 > + 	         sc->sc_dcd_edgemask = 0;
 > + #endif
 > + 		/*FALLTHROUGH*/
 > + 
 > + 	case TIOCFETCHLASTTSTAMP:

Why the long name?  How about just "TIOCTSTAMP" (note lack of S or G :-)
or TIOCFTSTAMP?

 > + 		*(struct timeval *)data = sc->sc_dcd_timestamp;
 > + 		break;
 > + 
 >   	default:
 >   		error = ENOTTY;
 >   		break;
 > ***************
 > *** 1749,1754 ****
 > --- 1806,1825 ----
 >   		sc->sc_msr = msr;
 >   		if (ISSET(delta, sc->sc_msr_mask)) {
 >   			SET(sc->sc_msr_delta, delta);
 > + 
 > + 			/*
 > + 			 * Pulse-per-second clock  signal on edge of DCD?
 > + 			 */
 > + 			if (sc->sc_dopps && ISSET(delta, MSR_DCD) &&
 > + 			    (delta & MSR_DCD) == sc->sc_dcd_edgemask) {
 > + 				struct timeval tv;
 > + 
 > + 				microtime(&tv);
 > + 				sc->sc_dcd_timestamp = tv;
 > + #ifdef PPS_SYNC
 > + 				hardpps(&tv, tv.usec);
 > + #endif
 > + 			}
 >   
 >   			/*
 >   			 * Stop output immediately if we lose the output
 > Index: sys/dev/ic/comvar.h
 > ===================================================================
 > RCS file: /cvsroot/src/sys/dev/ic/comvar.h,v
 > retrieving revision 1.22
 > diff -c -r1.22 comvar.h
 > *** comvar.h	1998/02/02 23:01:05	1.22
 > --- comvar.h	1998/04/22 03:44:48
 > ***************
 > *** 109,114 ****
 > --- 109,120 ----
 >   	void (*disable) __P((struct com_softc *));
 >   	int enabled;
 >   
 > + 	/* Discipline system clock to pulse-per-second signal wire to DCD? */
 > + 	int	sc_timestamp_state;		/* userlevel ioctl state */
 > + 	int	sc_dopps;			/* boolean flag */
 > + 	int	sc_dcd_edgemask;		/* edge mask */
 > + 	struct timeval	sc_dcd_timestamp;;	/* XXX nanotime()? */
 > + 
 >   #if NRND > 0 && defined(RND_COM)
 >   	rndsource_element_t  rnd_source;
 >   #endif
 > Index: sys/sys/ttycom.h
 > ===================================================================
 > RCS file: /cvsroot/src/sys/sys/ttycom.h,v
 > retrieving revision 1.8
 > diff -c -r1.8 ttycom.h
 > *** ttycom.h	1998/03/26 02:45:01	1.8
 > --- ttycom.h	1998/04/22 03:44:48
 > ***************
 > *** 129,136 ****
 > --- 129,146 ----
 >   #define		TIOCFLAG_CRTSCTS	0x04	/* set crtscts on open */
 >   #define		TIOCFLAG_MDMBUF		0x08	/* set mdmbuf on open */
 >   #define		TIOCFLAG_CDTRCTS	0x10	/* set cdtrcts on open */
 > + 
 >   #define	TIOCDCDTIMESTAMP _IOR('t', 88, struct timeval) /* get timestamp of last
 >   						 * Cd rise, stamp next rise */
 > + #define	TIOCGTSTAMP _IOR('t', 82, int)	/* get DCD-PPS timestamp state */
 > + #define	TIOCSTSTAMP _IOW('t', 83, int)	/* set DCD-timestamp state */
 > + #if !defined(_POSIX_SOURCE) && !defined(_XOPEN_SOURCE)
 > + #define DCD_NONE		0
 > + #define DCD_LEADING_EDGE	1
 > + #define DCD_TRAILING_EDGE	2
 > + #endif
 > + #define	TIOCFETCHLASTTSTAMP _IOR('t', 84, struct timeval) 
 > + 					/* fetch most recent timestamp */
 >   
 >   #define	TTYDISC		0		/* termios tty line discipline */
 >   #define	TABLDISC	3		/* tablet discipline */

Other than those comments above, this looks basically OK to me.

Jason R. Thorpe                                       thorpej@nas.nasa.gov
NASA Ames Research Center                            Home: +1 408 866 1912
NAS: M/S 258-5                                       Work: +1 650 604 0935
Moffett Field, CA 94035                             Pager: +1 415 428 6939