Bug 196897 - [ucom] [PATCH] Pulse capturing support (PPS) for ucom(4) driver
Summary: [ucom] [PATCH] Pulse capturing support (PPS) for ucom(4) driver
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: usb (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Hans Petter Selasky
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-19 16:08 UTC by takeharu1219
Modified: 2015-03-09 16:24 UTC (History)
2 users (show)

See Also:


Attachments
Patch for adding pps function to ucom(4) driver (2.23 KB, patch)
2015-01-19 16:08 UTC, takeharu1219
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description takeharu1219 2015-01-19 16:08:25 UTC
Created attachment 151857 [details]
Patch for adding pps function to ucom(4) driver

Hi,

I wrote a patch to add pluse capturing support function to the ucom diver.
This can be used to set up a stratum 1 NTP servers using a PPS1 USB GPS device (e.g. Navisys GR-701W).
I've tested this patch with Navisys GR-701W and ntpd in ntp-4.2.8p1b5.
-- example result of ntpq -p -c kern
pll offset:            24.0225
pll frequency:         1.66617
maximum error:         0.423459
estimated error:       0.029453
kernel status:         pll ppssignal nano
pll time constant:     8
precision:             1e-06
frequency tolerance:   495.911
pps frequency:         6.8631
pps stability:         57.1917
pps jitter:            0.909
calibration interval   256
calibration cycles:    59
jitter exceeded:       122
stability exceeded:    3
--
How-To-Repeat: 
Apply the patch:

    cd /usr/src
    patch -p0 < freebsd-pps-ucom-20150119.patch

Build the kernel module:

    cd /usr/src/sys/modules/usb/ucom
    make && make install
Comment 1 Ian Lepore freebsd_committer freebsd_triage 2015-03-07 18:00:17 UTC
It looks like this may not handle the UART_PPS_ON_CTS case or capture-clear of DCD correctly.  I think I've got hardware here that can test both conditions, I'll give it a try and perhaps propose an alternative patch if I can.
Comment 2 commit-hook freebsd_committer freebsd_triage 2015-03-07 18:24:34 UTC
A commit references this bug:

Author: hselasky
Date: Sat Mar  7 18:23:34 UTC 2015
New revision: 279728
URL: https://svnweb.freebsd.org/changeset/base/279728

Log:
  Add mutex support to the pps_ioctl() API in the kernel.
  Bump kernel version to reflect structure change.

  PR:		196897
  MFC after:	1 week

Changes:
  head/sys/kern/kern_tc.c
  head/sys/sys/param.h
  head/sys/sys/timepps.h
Comment 3 commit-hook freebsd_committer freebsd_triage 2015-03-07 18:26:36 UTC
A commit references this bug:

Author: hselasky
Date: Sat Mar  7 18:25:59 UTC 2015
New revision: 279729
URL: https://svnweb.freebsd.org/changeset/base/279729

Log:
  Add PPS support to USB serial drivers.
  Bump kernel version to reflect structure change.

  PR:		196897
  MFC after:	1 week

Changes:
  head/sys/dev/usb/serial/usb_serial.c
  head/sys/dev/usb/serial/usb_serial.h
  head/sys/sys/param.h
Comment 4 Hans Petter Selasky freebsd_committer freebsd_triage 2015-03-07 18:27:26 UTC
Please verify the feature in FreeBSD 11-current.

--HPS
Comment 5 Hans Petter Selasky freebsd_committer freebsd_triage 2015-03-07 18:34:27 UTC
Could you update the ucom manual page about this new feature aswell?

Thank you!

Don't forget to set hw.usb.ucom.pps_mode=xxx in /boot/loader.conf or /etc/sysctl.conf

--HPS
Comment 6 commit-hook freebsd_committer freebsd_triage 2015-03-07 22:47:09 UTC
A commit references this bug:

Author: hselasky
Date: Sat Mar  7 22:46:36 UTC 2015
New revision: 279756
URL: https://svnweb.freebsd.org/changeset/base/279756

Log:
  Use correct mode variable for PPS support.

  PR:		196897
  Submitted by:	ian @
  MFC after:	1 week

Changes:
  head/sys/dev/usb/serial/usb_serial.c
Comment 7 commit-hook freebsd_committer freebsd_triage 2015-03-08 08:35:01 UTC
A commit references this bug:

Author: hselasky
Date: Sun Mar  8 08:34:50 UTC 2015
New revision: 279773
URL: https://svnweb.freebsd.org/changeset/base/279773

Log:
  Switch polarity of PPS events.

  PR:		196897
  Submitted by:	ian @
  MFC after:	1 week

Changes:
  head/sys/dev/usb/serial/usb_serial.c
Comment 8 Ian Lepore freebsd_committer freebsd_triage 2015-03-09 13:56:31 UTC
Test results, using a 700MHz single-core TI AM335x ARM system (Beaglebone).

The PPS(0) device is an on-chip timer configured as a latching time interval counter with a resolution of approximately 40nS.  The PPS(1) device is an FTDI 2232H usb-serial adapter with PPS input on the DCD line.  The same PPS signal is fed to both devices via a splitter and equal-length cables.  As shown in this ntpq -p output, the latency of capturing the PPS via the USB pathway is approximately 45 microseconds compared to the TIC that latches a hardware counter.  Even under heavy system load including bulk traffic to a USB drive on the same bus the latency increased to no more than 100uS.  The second-to-second jitter is so low it's near the threshold of being measurable.

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+PPS(0)          .PPS.            0 l    6   16  377    0.000   -0.040   0.002
oPPS(1)          .PPS.            0 l   16   16  377    0.000   -0.086   0.002
+dvb.hippie.lan  .GPS.            1 u   15   64  377    1.296    0.147   1.838


The FDTI parts can reliably work with a PPS pulse as narrow as 50uS.  Other brands may require a wider pulse, but consumer radio and GPS gear typically emits pulses 1mS wide.
Comment 9 Hans Petter Selasky freebsd_committer freebsd_triage 2015-03-09 14:00:28 UTC
The polling interval of USB host controllers is typically 125us. Your results come as no surprise :-)

--HPS
Comment 10 takeharu1219 2015-03-09 16:24:43 UTC
Thank you for your hard work.
I can use my PPS USB device  at ease.