Subject: kern/10102: pps api clear/assert inverted
To: None <gnats-bugs@gnats.netbsd.org>
From: Wolfgang Rupprecht <wolfgang@wsrcc.com>
List: netbsd-bugs
Date: 05/11/2000 23:55:12
>Number:         10102
>Category:       kern
>Synopsis:       pps api clear/assert inverted
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu May 11 23:56:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Wolfgang Rupprecht
>Release:        NetBSD-current May 9,  2000
>Organization:
W S Rupprecht Computer Consulting, Fremont CA
>Environment:

System: NetBSD scoville.wsrcc.com 1.4Y NetBSD 1.4Y (WSRCC) #2: Tue May  9 17:00:21 PDT 2000     wolfgang@capsicum.wsrcc.com:/v/src/netbsd/NetBSD-current/usr/src/sys/arch/i386/compile/WSRCC i386

>Description:

	the PPS (pulse per second) api signals are reversed.  The
	PPS_CAPTUREASSERT event is monitored and flagged as a
	PPS_CAPTURECLEAR event and visa versa.

>How-To-Repeat:

    run ntp from a known good source.  Let the clocks sync up for 
    10 minutes.  Ntp is none too speedy about this. 

    compile the following program.  hook up a PPS clock that 
    asserts the signal on the second and clears the signal 200 ms
    later.  (I'm using a motorola oncore M12 oem board).

    Notice that the assertion is at ~200ms after the second.
    Notice that the clear is at the even second.

    Shamelessly stolen from the RFC:

    #include <stdio.h>
    #include <unistd.h>
    #include <ctype.h>
    #include <sys/types.h>
    #include <sys/time.h>
    #include <sys/stat.h>

    #include <sys/timepps.h>

    /* 
     * Mogul, et al.                Informational                     [Page 22]
     *
     * RFC 2783                  Pulse-Per-Second API                March 2000
     */

    void
    pps(int fd, char * PPSfilename)
    {
	  pps_handle_t handle;
	  pps_params_t params;
	  pps_info_t infobuf;
	  int avail_mode;
	  struct timespec timeout;

	  time_pps_create(fd, &handle);

	  /*
	   * Find out what features are supported
	   */

	  time_pps_getcap(handle, &avail_mode);
	  if ((avail_mode & PPS_CAPTUREASSERT) == 0) {
	      fprintf(stderr, "%s cannot CAPTUREASSERT\n", PPSfilename);
	      exit(1);
	  }
	  if ((avail_mode & PPS_OFFSETASSERT) == 0) {
	      fprintf(stderr, "%s cannot OFFSETASSERT\n", PPSfilename);
	      exit(1);
	  }

	  /*
	   * Capture assert timestamps
	   */

	  time_pps_getparams(handle, &params);
	  params.assert_offset.tv_sec = 0;
	  params.assert_offset.tv_nsec = 0;
	  params.mode |= PPS_CAPTUREBOTH;
	  time_pps_setparams(handle, &params);


	  /* create a zero-valued timeout */
	  timeout.tv_sec = 0;
	  timeout.tv_nsec = 0;

	  /* loop, printing the most recent timestamp every second or so */
	  while (1) {
	      if (avail_mode & PPS_CANWAIT) {
		  time_pps_fetch(handle, PPS_TSFMT_TSPEC, &infobuf, NULL);
				  /* waits for the next event */
	      } else {
		  sleep(1);
		  time_pps_fetch(handle, PPS_TSFMT_TSPEC, &infobuf,
		    &timeout);

	      }

	      printf("Assert timestamp: %d.%09d, sequence: %ld\n",
			  infobuf.assert_timestamp.tv_sec,
			  infobuf.assert_timestamp.tv_nsec,
			  infobuf.assert_sequence);

	      printf(" Clear timestamp: %d.%09d, sequence: %ld\n",
			  infobuf.clear_timestamp.tv_sec,
			  infobuf.clear_timestamp.tv_nsec,
			  infobuf.clear_sequence);
	  }
    }

>Fix:
	I think the fix is as simple as throwing an inversion in where
	the DCD hardware line is tested.
>Release-Note:
>Audit-Trail:
>Unformatted: