Subject: new-API for DCD time stamps
To: Chris G. Demetriou <cgd@pa.dec.com>
From: Jonathan Stone <jonathan@DSG.Stanford.EDU>
List: tech-kern
Date: 04/20/1998 19:40:12
I think this addresses all the points so far. Three new ioctls:
  * one to set DCD timestamping on or off
  * one to get DCD timestamping on/off state
  * one to just fetch the most-recent timestamp.
    silently returns zero if timestamping is not enabled.
    should this return an error instead?

Better names for the ioctls welcomed: i'm lousy at thinking up names.
Aside from that (and typos) same conditions as the last patch.

PS: I havent tested these verbatim, since i dont have an i386 running
current right now.



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/21 02:36:45
***************
*** 129,136 ****
--- 129,141 ----
  #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	TIOCGETDCDTSTAMP _IOR('t', 82, int)	/* get DCD-timestamp on/off */
+ #define	TIOCSETDCDTSTAMP _IOW('t', 83, int)	/* set DCD-timestamp on/off */
+ #define	TIOCLASTDCDTSTAMP _IOR('t', 84, struct timeval) /* fetch last t-stamp*/
+ 
  
  #define	TTYDISC		0		/* termios tty line discipline */
  #define	TABLDISC	3		/* tablet discipline */
Index: sys/dev/ic/com.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/com.c,v
retrieving revision 1.143
diff -c -r1.143 com.c
*** com.c	1998/03/22 00:55:37	1.143
--- com.c	1998/04/21 02:36:46
***************
*** 595,600 ****
--- 595,603 ----
  	/* Clear any break condition set with TIOCSBRK. */
  	com_break(sc, 0);
  
+ 	/* Turn off timestamping. */
+ 	sc->sc_dcd_timestamping = 0;
+ 
  	/*
  	 * Hang up if necessary.  Wait a bit, so the other side has time to
  	 * notice even if we immediately open the port again.
***************
*** 689,694 ****
--- 692,701 ----
  		/* Fetch the current modem control status, needed later. */
  		sc->sc_msr = bus_space_read_1(sc->sc_iot, sc->sc_ioh, com_msr);
  
+ 		/* Clear any old timestamps. */
+ 		sc->sc_dcd_timestamping = 0;
+ 		bzero(&sc->sc_dcd_timestamp, sizeof(sc->sc_dcd_timestamp));
+ 
  		splx(s2);
  
  		/*
***************
*** 933,938 ****
--- 940,965 ----
  		*(int *)data = bits;
  		break;
  	}
+ 
+ 	case TIOCGETDCDTSTAMP:
+ 		*(int*)data = com->sc_dcd_timestamping;
+ 		break;
+ 
+ 	case TIOCSETDCDTSTAMP:
+ 		com->sc_dcd_timestamping = *(int*)data;
+ 		if (com->sc_dcd_timestamping == 0)
+ 		    bzero(&sc->sc_dcd_timestamp, sizeof(sc->sc_dcd_timestamp));
+ 		break;
+ 
+ 	case TIOCLASTDCDTSTAMP:
+ 	case TIOCDCDTIMESTAMP:	/* XXX*/
+ 		*(struct timeval *)data = com->dcd_timestamp;
+ 
+ 		/* XXX old overloaded API */
+ 		if (cmd ==  TIOCDCDTIMESTAMP)
+ 			com->sc_dcd_timestamping = 1;
+ 		break;
+ 
  	default:
  		error = ENOTTY;
  		break;
***************
*** 1749,1754 ****
--- 1776,1798 ----
  		sc->sc_msr = msr;
  		if (ISSET(delta, sc->sc_msr_mask)) {
  			SET(sc->sc_msr_delta, delta);
+ 
+ 			/*
+ 			 * Check for timestamp on rising edge of clock.
+ 			 * NB: Some garmin uints use the falling rather than
+ 			 * rising edge as on-second signal. This should
+ 			 * be fixed in TTL-to-RS232 hardware, but some
+ 			 * setups don't do that.
+ 			 */
+ #ifdef PPS_TRAILING_EDGE
+ #define PPS_EDGE_SET(x, y) (!ISSET(x, y)
+ #else
+ #define PPS_EDGE_SET(x, y) ISSET(x, y)
+ #endif
+ 			if (sc->sc_dcd_timestamping && ISSET(delta, MSR_DCD) &&
+ 			    PPS_EDGE_SET(msr, MSR_DCD)) {
+ 				microtime(&sc->sc_dcd_timestamp);
+ 			}
  
  			/*
  			 * 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/21 02:36:46
***************
*** 109,114 ****
--- 109,117 ----
  	void (*disable) __P((struct com_softc *));
  	int enabled;
  
+ 	int	sc_dcd_timestamping;		/* boolean flag */
+ 	struct timeval	sc_dcd_timestamp;
+ 
  #if NRND > 0 && defined(RND_COM)
  	rndsource_element_t  rnd_source;
  #endif