Subject: Re: ntp problems with GPS under NetBSD/amd64
To: None <alicia@engine.ca>
From: Brian Buhrow <buhrow@lothlorien.nfbcal.org>
List: port-amd64
Date: 03/11/2005 22:10:22
	Hello Alicia.  I was googling for NetBSD gps and ntp related issues
when I saw your mail.
I ran into the same problem you're having, and I think I know what's wrong.
Are you trying to run ntpd in debug mode? If so, then ntpd won't work if you're
trying to debug a serially connected GPS because TIOCSCTTY is trying to
assign the controlling terminal to the serial port to which the GPS is
attached.  Under normal conditions, this works because when ntpd is
started, it has no controlling terminal.  However, when you run it in debug
mode, ntpd has a controlling terminal, and a new one can't be assigned.
	Does it work if you just run it from the /etc/rc.d/ntpd start command?
Or, at least, do you get different output?
-Brian


   Subject: ntpd problems with GPS receiver under NetBSD-amd64
   To: None <port-amd64@netbsd.org>
   From: Alicia da Conceicao <alicia@engine.ca>
   List: tech-net
   Date: 02/02/2005 16:10:40
Greetings:

I have a GPS receiver with a TTL PPS feed, which I managed to successfully
wire up to a RS232 (DB9) serial port.  When I connect it to a NetBSD-amd64
version 2.0 computer running minicom at 4800 bps for tty02, I am able to
read all of the GPS data (including time, position, etc.) in the
raw NMEA-0183 strings.  So far so good right.

Note that the DB9 serial port was wired as follows (male view):

         ------------------------------------------
        \  [1-TTL] [2-TX] [3-RX] [4-???] [5-GND] /
          \    [6-???] [7-???] [8-???] [9-???]   /
           --------------------------------------

with the TTL on pin1, transmit on pin2, receive on pin3, and ground on
pin5.

Also note that NetBSD-amd64 2.0 kernel was compiled with the following
related options:

        options NTP
        options PPS_SYNC

Then I try to run it under ntpd version "4.2.0-r" with the following
config:

        pidfile /var/run/ntpd.pid
        driftfile /var/db/ntp.drift
        logconfig -syncstatus
        peer 127.127.20.0 prefer
        fudge 127.127.20.0 stratum 0
        fudge 127.127.20.0 time1 -1.0
        peer 127.127.22.0
        fudge 127.127.22.0 stratum 0
        fudge 127.127.22.0 flag2 0
        fudge 127.127.22.0 flag3 1

and with symlinks:

        /dev/gps0 => /dev/tty02
        /dev/pps0 => /dev/tty02

Unfortunately ntpd fails with the following errors:

        ioctl(TIOCSCTTY, 0) fails for clock I/O: Operation not permitted
        internal error: refclockio structure not found
        configuration of 127.127.20.0 failed
        reclock_atom: /dev/pps0: Interrupted system call
        configuration of 127.127.22.0 failed

I could understand if there where some ntpd related issues regarding the
NetBSD implimentation of PPS, even though I did enable it in the kernel.
But considering that I can see a continuous stream of NMEA strings being
sent by the GPS clock through the serial bus when I use minicom, I am at
a loss as to why ntpd is failing for the NMEA pseduo-port at 127.127.20.0.

Looking at the NetBSD kernel source code, the original of that EPERM errno
value outputed by ntpd appears to originate in "/usr/src/sys/kern/tty.c"
when ntpd attempts to do a "ioctl(rio->fd,TIOCSCTTY,0)" in "libntp/iosignal.c"
to become a controlling tty.

Any suggestions is greatly apprecated.

Thanks in advance.
Alicia.