[LinuxPPS] Finding the /dev/pps<n> device

clemens at dwf.com clemens at dwf.com
Wed Oct 31 19:00:13 CET 2007


Ive seen several articles that seem to be looking at hard ways to find
the PPS device given the serial device.

Im not sure, but it LOOKS like the *nmea* patches are trying to address
the same problem.

FIRST: a patch to the ntpd code is not a good idea as it has to run on
platforms other than Linux, and cluttering it with Linux specific stuff
would not be a good idea (if it were even accepted).  Keeping such a
patch 'on the side' always presents problems.

Here is my solution, it is a patch to /etc/rc.d/init.d/ntpd, which would
be Linux specific.  I have added a shell subroutine, and then some code
right after the 'start)' line.  The code works with a serial line, it would
need a slight modification if you were actually using PPS on a parallel
line:

---

# subroutine to find the pps device from the serial device.

get_pps()
{
    k=/sys/class/pps
    e=`ls $k`

    h="`readlink $1`"
    if [ -z "$h" ]; then
        h="$1"
    fi

    for i in "$e"
    do
        n=`tr -d "\015" < $k/$i/path`

        if [ "$h" = "$n" ]; then
            echo /dev/$i
        fi
    done
}


# See how we were called.
case "$1" in
  start)
        a="/dev/ttyS0"

        rm /dev/oncore.serial.0 >& /dev/null
        ln -s $a /dev/oncore.serial.0

        b=`get_pps "$a"`
        rm /dev/oncore.pps.0    >& /dev/null

        if [ -n "$b" ]; then
                ln -s $b /dev/oncore.pps.0
        fi

        /usr/local/bin/ppsctl $a enable

---

I have been working with a PPS built into the kernel (its small, why not?)
and the oncore driver.  The four lines mentioning 'oncore' would have to be
changed for another driver.  And one would need to have the pps modules
installed by this point for this to work.  I think thats default, but havent
tried it yet.  (adding a modprobe after start) would solve that problem)

In any case, I thought the above shell script would be of interest.

-- 
                                        Reg.Clemens
                                        reg at dwf.com





More information about the LinuxPPS mailing list