LinuxPPS: Pulse per Second support for Linux
Subsystems (6)
Rodolfo Giometti
maintainerPATCH 1/1 LinuxPPS: Pulse per Second support for Linux
Pulse per Second (PPS) support for Linux.
---
Please, note that this PPS implementation is not RFC 2783 fully compatible since, IMHO, the RFC simply doesn't consider PPS devices connected with special GPIOs or other ports different from serial ports and parallele ports.
Please read the following consideratios before sending to /dev/null! :)
RFC considerations
------------------
While implementing a PPS API as RFC 2783 defines and using an embedded CPU GPIO-Pin as physical link to the signal, I encountered a deeper problem:
At startup it needs a file descriptor as argument for the function time_pps_create().
This implies that the source has a /dev/... entry. This assumption is ok for the serial and parallel port, where you can do something usefull beside(!) the gathering of timestamps as it is the central task for a PPS-API. But this assumption does not work for a single purpose GPIO line. In this case even basic file-related functionality (like read() and write()) makes no sense at all and should not be a precondition for the use of a PPS-API.
The problem can be simply solved if you change the original RFC 2783:
pps_handle_t type is an opaque __scalar type__ used to represent a PPS source within the API
into a modified:
pps_handle_t type is an opaque __variable__ used to represent a PPS source within the API and programs should not access it directly to it due to its opacity.
This change seems to be neglibile because even the original RFC 2783 does not encourage programs to check (read: use) the pps_handle_t variable before calling the time_pps_*() functions, since each function should do this job internally.
If I intentionally separate the concept of "file descriptor" from the concept of the "PPS source" I'm obliged to provide a solution to find and register a PPS-source without using a file descriptor: it's done by the functions time_pps_findsource() and time_pps_findpath() now.
According to this current NTPD drivers' code should be modified as follows:
+#ifdef PPS_HAVE_FINDPATH
+ /* Get the PPS source's real name */ + fd = readlink(link, path, STRING_LEN-1); + if (fd <= 0)
+ strncpy(path, link, STRING_LEN);
+ else
+ path[fd] = '\0';
+
+ /* Try to find the source */
+ fd = time_pps_findpath(path, STRING_LEN, id, STRING_LEN);
+ if (fd < 0) {+ msyslog(LOG_ERR, "refclock: cannot find PPS source \"%s\" in the system", path);
+ return 1;
+ }
+ msyslog(LOG_INFO, "refclock: found PPS source #%d \"%s\" on \"%s\"", fd, path, id);
+#endif /* PPS_HAVE_FINDPATH */
+
+
if (time_pps_create(fd, &pps_handle) < 0) {
- pps_handle = 0;
msyslog(LOG_ERR, "refclock: time_pps_create failed: %m");
}Documentation/pps.txt new file +206 -0
@@ -0,0 +1,206 @@ + + PPS - Pulse Per Second + ---------------------- + +(C) Copyright 2007 Rodolfo Giometti <[email protected]> + + +Overview +-------- + +LinuxPPS provides a programming interface (API) to define into the +system several PPS sources. + +PPS means "pulse per second" and a PPS source is just a device who +provides an high and precise signal each second so that an application +can use it to adjust time clock. + +A PPS source can be connected to a serial port (usually to the Data +Carrier Detect pin) or to a parallel port (ACK-pin) or to a special +CPU's GPIOs (this is the common case in embedded systems) but in each +case when a new pulse comes the system must apply to it a timestamp +and record it for the userland. + +Common use is the combination of the NTPD as userland program with a +GPS receiver as PPS source to obtain a wallclock-time with +sub-millisecond synchronisation to UTC. + + +RFC considerations +------------------ + +While implementing a PPS API as RFC 2783 defines and using an embedded +CPU GPIO-Pin as physical link to the signal, I encountered a deeper +problem: + + At startup it needs a file descriptor as argument for the function + time_pps_create(). + +This implies that the source has a /dev/... entry. This assumption is +ok for the serial and parallel port, where you can do something +usefull beside(!) the gathering of timestamps as it is the central +task for a PPS-API. But this assumption does not work for a single +purpose GPIO line. In this case even basic file-related functionality +(like read() and write()) makes no sense at all and should not be a +precondition for the use of a PPS-API. + +The problem can be simply solved if you change the original RFC 2783: + + pps_handle_t type is an opaque __scalar type__ used to represent a + PPS source within the API + +into a modified: + + pps_handle_t type is an opaque __variable__ used to represent a PPS + source within the API and programs should not access it directly to + it due to its opacity. + +This change seems to be neglibile because even the original RFC 2783 +does not encourage programs to check (read: use) the pps_handle_t +variable before calling the time_pps_*() functions, since each +function should do this job internally. + +If I intentionally separate the concept of "file descriptor" from the +concept of the "PPS source" I'm obliged to provide a solution to find +and register a PPS-source without using a file descriptor: it's done +by the functions time_pps_findsource() and time_pps_findpath() now. + +According to this current NTPD drivers' code should be modified as +follows: + ++#ifdef PPS_HAVE_FINDPATH ++ /* Get the PPS source's real name */ ++ fd = readlink(link, path, STRING_LEN-1); ++ if (fd <= 0) ++ strncpy(path, link, STRING_LEN); ++ else ++ path[fd] = '\0'; ++ ++ /* Try to find the source */ ++ fd = time_pps_findpath(path, STRING_LEN, id, STRING_LEN); ++ if (fd < 0) { ++ msyslog(LOG_ERR, "refclock: cannot find PPS source \"%s\" in the system", path); ++ return 1; ++ } ++ msyslog(LOG_INFO, "refclock: found PPS source #%d \"%s\" on \"%s\"", fd, path, id); ++#endif /* PPS_HAVE_FINDPATH */ ++ ++ + if (time_pps_create(fd, &pps_handle) < 0) { +- pps_handle = 0; + msyslog(LOG_ERR, "refclock: time_pps_create failed: %m"); + } + + +Coding example +-------------- + +To register a PPS source into the kernel you should define a struct +linuxpps_source_info_s as follow: + + static struct linuxpps_source_info_s linuxpps_ktimer_info = { + name : "ktimer", + path : "", + mode : PPS_CAPTUREASSERT|PPS_OFFSETASSERT|PPS_ECHOASSERT| \ + PPS_CANWAIT|PPS_TSFMT_TSPEC, + echo : linuxpps_ktimer_echo, + }; + +and then calling the function linuxpps_register_source() in your +intialization routine as follow: + + source = linuxpps_register_source(&linuxpps_ktimer_info, + PPS_CAPTUREASSERT|PPS_OFFSETASSERT, + -1 /* is up to the system */); + +The linuxpps_register_source() prototype is: + + int linuxpps_register_source(struct linuxpps_source_info_s *info, int default_params, int try_id) + +where "info" is a pointer to a structure that describes a particular +PPS source, "default_params" tells the system what the initial default +parameters for the device should be (is obvious that these parameters +must be a subset of ones defined into the struct +linuxpps_source_info_s which describe the capabilities of the driver) +and "try_id" can be used to force a particular ID for your device into +the system (just use -1 if you wish the system chooses one for you). + +Once you have registered a new PPS source into the system you can +signal an assert event (for example in the interrupt handler routine) +just using: + + linuxpps_event(source, PPS_CAPTUREASSERT, ptr); + +The same function may also run the defined echo function +(linuxpps_ktimer_echo(), passing to it the "ptr" pointer) if the user +asked for that... etc.. + +Please see the file drivers/pps/clients/ktimer.c for an example code. + + +PROCFS support +-------------- + +If PROCFS support is enabled a new directory "/proc/pps" is created: + + $ ls /proc/pps/ + 00 01 sources + +The file "sources" holds a brief description of all PPS sources +defined in the system: + + $ cat /proc/pps/sources + id mode echo name path + ---- ------ ---- ---------------- ---------------- + 00 1133 no serial0 /dev/ttyS0 + 01 1133 no serial1 /dev/ttyS1 + +The other entries are directories that hold one or two files according +to the ability of the associated source to provide "assert" and +"clear" timestamps: + + $ ls /proc/pps/00 + assert clear + +Inside each "assert" and "clear" file you can find the timestamp and a +sequence number: + + $ cat /proc/pps/00/assert + 1170026870.983207967 #8 + + +SYSFS support +------------- + +The SYSFS support is enabled by default if the SYSFS filesystem is +enabled in the kernel and it provides a new class: + + $ ls /sys/class/pps/ + 00/ 01/ 02/ + +Every directory is the ID of a PPS sources defined into the system and +inside you find several files: + + $ ls /sys/class/pps/00/ + assert clear echo mode name path subsystem@ uevent + +Files "assert" and "clear" have the same functionality as their PROCFS +counterparts but with different syntax due to the one-value-per-file +sysfs pragma. Other files are: + +* echo: reports if the PPS source has an echo function or not; + +* mode: reports available PPS functioning modes (in the same form as + PROCFS does); + +* name: reports the PPS source's name; + +* path: reports the PPS source's device path, that is the device the + PPS source is connected to (if it exists). + + +Resources +--------- + +Wiki: http://wiki.enneenne.com/index.php/LinuxPPS_support and the LinuxPPS +ML: http://ml.enneenne.com/cgi-bin/mailman/listinfo/linuxpps.
drivers/Kconfig +2 -0
@@ -52,6 +52,8 @@ source "drivers/i2c/Kconfig" source "drivers/spi/Kconfig" +source "drivers/pps/Kconfig" + source "drivers/w1/Kconfig" source "drivers/hwmon/Kconfig"
drivers/Makefile +1 -0
@@ -59,6 +59,7 @@ obj-$(CONFIG_INPUT) += input/ obj-$(CONFIG_I2O) += message/ obj-$(CONFIG_RTC_LIB) += rtc/ obj-$(CONFIG_I2C) += i2c/ +obj-$(CONFIG_PPS) += pps/ obj-$(CONFIG_W1) += w1/ obj-$(CONFIG_HWMON) += hwmon/ obj-$(CONFIG_PHONE) += telephony/
drivers/char/lp.c +59 -0
77 lines not on this page · raw message
drivers/parport/parport_pc.c +8 -0
@@ -272,6 +272,14 @@ static int clear_epp_timeout(struct parport *pb)static irqreturn_t parport_pc_interrupt (int irq,void *dev_id) { +#ifdef CONFIG_PPS_CLIENT_LP_PARPORT_PC +struct parport *p = (struct parport *) dev_id; + +linuxpps_event (p->pps_source,PPS_CAPTUREASSERT , p); +dbg ("parport_pc: PPS assert event at %lu on source #%d" , + jiffies, p->pps_source); +#endif +parport_generic_irq (irq, (struct parport *) dev_id);/* FIXME! Was it really ours? */ return IRQ_HANDLED ;
drivers/pps/Kconfig new file +43 -0
43 lines not on this page · raw message
drivers/pps/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# +# Makefile for the PPS core. +# + +pps_core-objs += pps.o kapi.o sysfs.o procfs.o +obj-$(CONFIG_PPS) += pps_core.o +obj-y += clients/
drivers/pps/clients/Kconfig new file +56 -0
56 lines not on this page · raw message
drivers/pps/clients/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# +# Makefile for miscellaneous I2C chip drivers. +# + +obj-$(CONFIG_PPS_CLIENT_KTIMER) += ktimer.o +
drivers/pps/clients/ktimer.c new file +107 -0
107 lines not on this page · raw message
drivers/pps/kapi.c new file +213 -0
213 lines not on this page · raw message
drivers/pps/pps.c new file +377 -0
377 lines not on this page · raw message
drivers/pps/procfs.c new file +179 -0
179 lines not on this page · raw message
drivers/pps/sysfs.c new file +200 -0
200 lines not on this page · raw message
drivers/serial/8250.c +22 -1
@@ -1315,8 +1315,25 @@ static unsigned int check_modem_status(struct uart_8250_port *up) up->port.icount.rng++;if (status &UART_MSR_DDSR ) up->port.icount.dsr++; -if (status &UART_MSR_DDCD ) +if (status &UART_MSR_DDCD ) { +#ifdef CONFIG_PPS_CLIENT_UART_8250 +if (status &UART_MSR_DCD ) { +linuxpps_event (up->port.pps_source, +PPS_CAPTUREASSERT , up); +dbg ("serial8250: PPS assert event at %lu " +"on source #%d" , + jiffies, up->port.pps_source); + } +else { +linuxpps_event (up->port.pps_source, +PPS_CAPTURECLEAR , up); +dbg ("serial8250: PPS clear event at %lu " +"on source #%d" , + jiffies, up->port.pps_source); + } +#endif uart_handle_dcd_change (&up->port, status &UART_MSR_DCD ); + }if (status &UART_MSR_DCTS )uart_handle_cts_change (&up->port, status &UART_MSR_CTS );
@@ -2004,6 +2021,9 @@ serial8250_set_termios(struct uart_port *port, struct ktermios *termios, up->ier |=UART_IER_MSI ;if (up->capabilities &UART_CAP_UUE ) up->ier |=UART_IER_UUE |UART_IER_RTOIE ; +#ifdef CONFIG_PPS_CLIENT_UART_8250 + up->ier |=UART_IER_MSI ;/* enable interrupts */ +#endif serial_out (up,UART_IER , up->ier);
@@ -2718,6 +2738,7 @@ void serial8250_unregister_port(int line)struct uart_8250_port *uart = &serial8250_ports[line];mutex_lock (&serial_mutex); +uart_remove_one_port (&serial8250_reg, &uart->port);if (serial8250_isa_devs) { uart->port.flags &= ~UPF_BOOT_AUTOCONF ;
drivers/serial/serial_core.c +43 -0
67 lines not on this page · raw message
include/linux/netlink.h +1 -1
@@ -21,7 +21,7 @@#define NETLINK_DNRTMSG 14/* DECnet routing messages */ #define NETLINK_KOBJECT_UEVENT 15/* Kernel messages to userspace */ #define NETLINK_GENERIC 16 -/* leave room for NETLINK_DM (DM Events) */ +#define NETLINK_PPSAPI 17/* linuxPPS support */ #define NETLINK_SCSITRANSPORT 18/* SCSI Transports */ #define NETLINK_ECRYPTFS 19
include/linux/parport.h +10 -0
@@ -104,6 +104,11 @@ typedef enum {#include <asm/ptrace.h> #include <asm/semaphore.h> +#ifdef CONFIG_PPS_CLIENT_LP_PARPORT_PC +#include <linux/timepps.h> +#include <linux/pps.h> +#endif +/* Define this later. */ struct parport ;struct pardevice ;
@@ -323,6 +328,11 @@ struct parport {struct list_head full_list;struct parport *slaves[3 ]; + +#ifdef CONFIG_PPS_CLIENT_LP_PARPORT_PC +struct linuxpps_source_info_s pps_info; +int pps_source;/* PPS source ID */ +#endif };#define DEFAULT_SPIN_TIME 500/* us */
include/linux/pps.h new file +119 -0
119 lines not on this page · raw message
include/linux/serial_core.h +12 -0
@@ -145,6 +145,11 @@#include <linux/tty.h> #include <linux/mutex.h> +#ifdef CONFIG_PPS_CLIENT_UART +#include <linux/timepps.h> +#include <linux/pps.h> +#endif +struct uart_port ;struct uart_info ;struct serial_struct ;
@@ -223,6 +228,9 @@ struct uart_port {unsigned char regshift;/* reg offset shift */ unsigned char iotype;/* io access style */ unsigned char unused1; +#ifdef CONFIG_PPS_CLIENT_UART +int pps_source;/* PPS source ID */ +#endif #define UPIO_PORT (0)#define UPIO_HUB6 (1)
@@ -295,6 +303,10 @@ struct uart_state {struct uart_info *info;struct uart_port *port; +#ifdef CONFIG_PPS_CLIENT_UART +struct linuxpps_source_info_s pps_info; +#endif +struct mutex mutex; };
include/linux/timepps.h new file +514 -0
514 lines not on this page · raw message
Quoted 16 lines · Rodolfo Giometti
drivers/serial/8250.c +7
-1@@ -1315,8 +1315,25 @@ static unsigned int check_modem_status(struct uart_8250_port *up) up->port.icount.rng++;if (status &UART_MSR_DDSR ) up->port.icount.dsr++; -if (status &UART_MSR_DDCD ) + if (status & UART_MSR_DDCD) { +#ifdef CONFIG_PPS_CLIENT_UART_8250 + if (status & UART_MSR_DCD) { + linuxpps_event(up->port.pps_source, + PPS_CAPTUREASSERT, up); + dbg("serial8250: PPS assert event at %lu " + "on source #%d",
drivers/serial/8250.c static unsigned int check_modem_status(struct uart_8250_port *up) · line 1334
Quoted 10 lines
drivers/serial/8250.c +10
-0+ jiffies, up->port.pps_source); + } +else { +linuxpps_event (up->port.pps_source, +PPS_CAPTURECLEAR , up); +dbg ("serial8250: PPS clear event at %lu " +"on source #%d" , + jiffies, up->port.pps_source); + } +#endif
Yuck. Please. No. Doing it this way means you have to modify every single serial driver out there which is a mamouth task.
drivers/serial/8250.c static unsigned int check_modem_status(struct uart_8250_port *up) · line 1335
Quoted 1 line
drivers/serial/8250.c +0
-0uart_handle_dcd_change (&up->port, status &UART_MSR_DCD );
Did you not look to see what's in this helper? You'll find within here the following code:
#ifdef CONFIG_HARD_PPS
if ((port->flags & UPF_HARDPPS_CD) && status)
hardpps();#endif
which should've been a big sign lit up in bright lights in Times Square pointing you towards the right place to put your code.
drivers/serial/8250.c serial8250_set_termios(struct uart_port *port, struct ktermios *termios, · line 2026
Quoted 11 lines
drivers/serial/8250.c +4
-0+ }if (status &UART_MSR_DCTS )uart_handle_cts_change (&up->port, status &UART_MSR_CTS );@@ -2004,6 +2021,9 @@ serial8250_set_termios(struct uart_port *port, struct ktermios *termios, up->ier |=UART_IER_MSI ;if (up->capabilities &UART_CAP_UUE ) up->ier |=UART_IER_UUE |UART_IER_RTOIE ; +#ifdef CONFIG_PPS_CLIENT_UART_8250 + up->ier |=UART_IER_MSI ;/* enable interrupts */ +#endif
Why not continue to leave it as a decision of the administrator - if you want ports to default to having PPS support enabled, change all the registration to set UPF_HARDPPS_CD. But leave the admin with the ability to disable it.
Quoted 21 lines
drivers/serial/8250.c +17
-0@@ -2124,6 +2130,33 @@ uart_configure_port(struct uart_driver *drv, struct uart_state *state,*/ if (!uart_console (port))uart_change_pm (state,3 ); + +#ifdef CONFIG_PPS_CLIENT_UART +/* +* Add the PPS support for the probed port. +*/ +snprintf (state->pps_info.name,LINUXPPS_MAX_NAME_LEN , +"%s%d" , drv->driver_name, port->line); +snprintf (state->pps_info.path,LINUXPPS_MAX_NAME_LEN , +"/dev/%s%d" , drv->dev_name, port->line); + + state->pps_info.mode =PPS_CAPTUREBOTH | \ +PPS_OFFSETASSERT |PPS_OFFSETCLEAR | \ +PPS_CANWAIT |PPS_TSFMT_TSPEC ; + + retval = linuxpps_register_source(&state->pps_info, + PPS_CAPTUREBOTH | \ + PPS_OFFSETASSERT | PPS_OFFSETCLEAR,
drivers/serial/8250.c uart_configure_port(struct uart_driver *drv, struct uart_state *state, · line 2159
Quoted 10 lines
drivers/serial/8250.c +10
-0+ -1 /* PPS ID is up to the system */); +if (retval <0 ) { +err ("cannot register PPS source \"%s\"" , + state->pps_info.path); +return ; + } + port->pps_source = retval; +info ("PPS source #%d \"%s\" added to the system " , + port->pps_source, state->pps_info.path); +#endif
This means that PPS support is not available for any port which wasn't autoprobed at device discovery time. That seems quite restrictive. Maybe it needs to be coupled with the setting/clearing of UPF_HARDPPS_CD ?
Signature · 3 lines
Russell King Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/ maintainer of:
Some non political comments
Documentation/pps.txt line 101
Quoted 7 lines · Rodolfo Giometti
Documentation/pps.txt new file +7
-0+Coding example +-------------- + +To register a PPS source into the kernel you should define a struct +linuxpps_source_info_s as follow: + + static struct linuxpps_source_info_s linuxpps_ktimer_info = {
Drop the linux prefix. It's in the linux kernel after all.
Quoted 2 lines
+PROCFS support
+--------------
New features shouldn't introduce new /proc stuff.
Documentation/pps.txt line 206
Quoted 5 lines
Documentation/pps.txt new file +5
-0+Resources +--------- + +Wiki: http://wiki.enneenne.com/index.php/LinuxPPS_support and the LinuxPPS +ML: http://ml.enneenne.com/cgi-bin/mailman/listinfo/linuxpps.
Add to MAINTAINERS
Your way to hook into lp and 8250 is pretty gross. It should at least be possible to deactivate it via the kernel command line, but it would be a lot nicer to have pps_lp and pps_8250 modules which you can load. Also what happens if you've multiple lp ports? How do you control which to grab?
- don't implement your own dbg() stuff, use dprintk and friends
- drop the inlines, gcc will do the right thing.
Quoted 8 lines
drivers/char/lp.c +0
-0static struct parport_driver lp_driver = {drivers/parport/parport_pc.c +0
-0
drivers/parport/parport_pc.c static int clear_epp_timeout(struct parport *pb) · line 278
Quoted 7 lines
drivers/parport/parport_pc.c +4
-0@@ -272,6 +272,14 @@ static int clear_epp_timeout(struct parport *pb)static irqreturn_t parport_pc_interrupt (int irq,void *dev_id) { +#ifdef CONFIG_PPS_CLIENT_LP_PARPORT_PC +struct parport *p = (struct parport *) dev_id; + +linuxpps_event (p->pps_source,PPS_CAPTUREASSERT , p);
Perhaps just implement empty defines for the none pps cases and get rid of the ifdefs? But this should really be controllabe via sysfs or such.
Quoted 16 lines
drivers/pps/clients/Kconfig new file +13
-0@@ -0,0 +1,56 @@ +# +# LinuxPPS clients configuration +# + +if PPS + +comment "PPS clients support" + +config PPS_CLIENT_KTIMER + tristate "Kernel timer client (Testing client, use for debug)" + help + If you say yes here you get support for a PPS debugging client + which uses a kernel timer to generate the PPS signal.
drivers/pps/clients/Kconfig line 23
Quoted 10 lines
drivers/pps/clients/Kconfig new file +10
-0+ + This driver can also be built as a module. If so, the module + will be called ktimer.o. + +comment "UART serial support (forced off)" + depends on SERIAL_CORE && ( PPS = m && SERIAL_CORE = y ) + +config PPS_CLIENT_UART + bool "UART serial support" + depends on SERIAL_CORE && ! ( PPS = m && SERIAL_CORE = y )
help text
Quoted 9 lines
drivers/pps/clients/Kconfig new file +9
-0+ +comment "8250 serial support (forced off)" + depends on PPS_CLIENT_UART && SERIAL_8250 && \ + ( PPS = m && SERIAL_8250 = y ) + +config PPS_CLIENT_UART_8250 + bool "8250 serial support" + depends on PPS_CLIENT_UART && SERIAL_8250 && \ + ! ( PPS = m && SERIAL_8250 = y )
drivers/pps/clients/Kconfig line 42
Quoted 10 lines
drivers/pps/clients/Kconfig new file +10
-0+ help + If you say yes here you get support for a PPS source connected + with the CD (Carrier Detect) pin of your 8250 serial line chip. + +comment "Parallel printer support (forced off)" + depends on PRINTER && ( PPS = m && PRINTER = y ) + +config PPS_CLIENT_LP + bool "Parallel printer support" + depends on PRINTER && ! ( PPS = m && PRINTER = y )
help text
drivers/pps/clients/Kconfig line 54
Quoted 11 lines
drivers/pps/clients/Kconfig new file +11
-0+comment "Parport PC support (forced off)" + depends on PPS_CLIENT_LP && PARPORT_PC && \ + ( PPS = m && PARPORT_PC = y ) + +config PPS_CLIENT_LP_PARPORT_PC + bool "Parport PC support" + depends on PPS_CLIENT_LP && PARPORT_PC && \ + ! ( PPS = m && PARPORT_PC = y ) + help + If you say yes here you get support for a PPS source connected + with the interrupt pin of your PC parallel port.
help text and difference to CLIENT_LP?
drivers/pps/clients/Kconfig
Quoted 6 lines
drivers/pps/clients/Kconfig new file +6
-0+++ b/drivers/pps/kapi.c +/* --- Local functions ----------------------------------------------------- */ + +#ifndef NSEC_PER_SEC +#define NSEC_PER_SEC 1000000000 +#endif
What's that for? Why is(n't) it defined?
drivers/pps/clients/Kconfig
Quoted 7 lines
drivers/pps/clients/Kconfig new file +7
-0+ for (i = 0; i < LINUXPPS_MAX_SOURCES; i++) + if (!__linuxpps_is_allocated(i)) + break; + if (i >= LINUXPPS_MAX_SOURCES) { + err("no free source ids"); + return -ENOMEM; + }
Why no dynamically allocated array?
drivers/pps/clients/Kconfig
Quoted 7 lines
drivers/pps/clients/Kconfig new file +7
-0+void linuxpps_event(int source, int event, void *data) +{ + struct timespec ts; + + /* In this function we shouldn't need locking at all since each PPS + * source arrives once per second and due the per-PPS source data + * array... */
I wouldn't bet on that.
drivers/pps/clients/Kconfig line 2
Quoted 4 lines
+++
b/drivers/pps/pps.cdrivers/pps/clients/Kconfig new file +2
-0@@ -0,0 +1,377 @@ +/* + * main.c -- Main driver file
Doesn't match filename
drivers/pps/clients/Kconfig line 3
Quoted 1 line
drivers/pps/clients/Kconfig new file +1
-0+++ b/drivers/pps/procfs.c
I'd drop that completely.
drivers/pps/clients/Kconfig line 24
Quoted 7 lines
drivers/pps/clients/Kconfig new file +2
-1+++ b/include/linux/netlink.h@@ -21,7 +21,7 @@ #define NETLINK_DNRTMSG 14 /* DECnet routing messages */ #define NETLINK_KOBJECT_UEVENT 15 /* Kernel messages to userspace */ #define NETLINK_GENERIC 16 -/* leave room for NETLINK_DM (DM Events) */ +#define NETLINK_PPSAPI 17 /* linuxPPS support */
You read the comment above your line?
Quoted 7 lines
drivers/pps/clients/Kconfig new file +0
-0#define DEFAULT_SPIN_TIME 500 /* us */include/linux/pps.h new file +1
-0+#ifdef CONFIG_PPS_DEBUG
include/linux/pps.h line 40
Quoted 10 lines
include/linux/pps.h new file +10
-0+#define dbg(format, arg...) printk(KERN_DEBUG "%s: " format "\n" , \ + KBUILD_MODNAME , ## arg) +#else +#define dbg(format, arg...) do {} while (0) +#endif + +#define err(format, arg...) printk(KERN_ERR "%s: " format "\n" , \ + KBUILD_MODNAME , ## arg) +#define info(format, arg...) printk(KERN_INFO "%s: " format "\n" , \ + KBUILD_MODNAME , ## arg)
These should use dprintk and friends
include/linux/pps.h line 44
Quoted 4 lines
include/linux/pps.h new file +4
-0+ +/* --- Global defines ------------------------------------------------------ */ + +#define LINUXPPS_MAX_SOURCES 16
Isn't something like 4 more reasonable (lp + 8250 + ktimer?)
include/linux/pps.h line 72
Quoted 10 lines
include/linux/pps.h new file +10
-0+/* The main struct */ +struct linuxpps_s { +struct linuxpps_source_info_s *info;/* PSS source info */ + +pps_params_t params;/* PPS's current params */ + +volatile pps_seq_t assert_sequence;/* PPS' assert event seq # */ +volatile pps_seq_t clear_sequence;/* PPS' clear event seq # */ +volatile pps_timeu_t assert_tu; +volatile pps_timeu_t clear_tu;
I think you can drop the volatiles, there was a discussion some time ago that they mostly waste of words.
Quoted 4 lines
include/linux/pps.h new file +4
-0+static inline int __linuxpps_is_allocated (int source) { +return linuxpps_source[source].info !=NULL ; +} +
include/linux/pps.h line 98
Quoted 10 lines
include/linux/pps.h new file +10
-0+static inline int linuxpps_is_allocated (int source) { +unsigned long flags; +int ret; + +spin_lock_irqsave (&linuxpps_lock, flags); + ret =__linuxpps_is_allocated (source); +spin_unlock_irqrestore (&linuxpps_lock, flags); + +return ret; +}
This one looks pretty fishy. After the check you normally want to use it, don't you? And then you already lost the guarantee.
Quoted 1 line
+#define
to_class_dev(obj)container_of((obj), struct class_device, kobj)
pretty generic name.
Quoted 1 line
+++
b/include/linux/timepps.h
use a frequency-locked loop */
Quoted 7 lines
include/linux/pps.h new file +7
-0+ +/* --- Here begins the implementation-specific part! ----------------------- */ + +#define LINUXPPS_MAX_NAME_LEN 32 +struct pps_netlink_msg { +int cmd;/* the command to execute */ +int source;
include/linux/pps.h
Quoted 10 lines
include/linux/pps.h new file +10
-0+char name[LINUXPPS_MAX_NAME_LEN ];/* symbolic name */ +char path[LINUXPPS_MAX_NAME_LEN ];/* path of the connected device */ +int consumer;/* selected kernel consumer */ +pps_params_t params; +int mode;/* edge */ +int tsformat;/* format of time stamps */ +pps_info_t info; +struct timespec timeout; +int ret; +};
Have you thought about 32/64bit issues?
include/linux/pps.h
Quoted 3 lines
include/linux/pps.h new file +3
-0+/* Private functions */ + +static int netlink_msg (int socket,struct pps_netlink_msg *nlpps)
Function in .h?
Jan
Rodolfo Giometti
maintainerQuoted 9 lines · Russell King
Yuck. Please. No. Doing it this way means you have to modify every single serial driver out there which is a mamouth task.
Quoted 1 line
uart_handle_dcd_change(&up->port, status & UART_MSR_DCD);Did you not look to see what's in this helper? You'll find within here the following code:
Quoted 7 lines
#ifdef CONFIG_HARD_PPS if ((port->flags & UPF_HARDPPS_CD) && status) hardpps();#endif
which should've been a big sign lit up in bright lights in Times Square pointing you towards the right place to put your code.
Ok.
Quoted 4 lines
Why not continue to leave it as a decision of the administrator - if you want ports to default to having PPS support enabled, change all the registration to set
UPF_HARDPPS_CD. But leave the admin with the ability to disable it.
Ok.
Quoted 2 lines
This means that PPS support is not available for any port which wasn't autoprobed at device discovery time. That seems quite restrictive.
How I can force probing for a specified uart port?
Quoted 1 line
Maybe it needs to be coupled with the setting/clearing of
UPF_HARDPPS_CD?
What do you think about? I should enable the PPS support only if the userland sets the UPF_HARDPPS_CD flag?
Thanks for your comments,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems [email protected] UNIX programming phone: +39 349 2432127
Quoted 25 lines · Rodolfo Giometti
Quoted 9 lines · Russell King
Yuck. Please. No. Doing it this way means you have to modify every single serial driver out there which is a mamouth task.
Quoted 1 line
uart_handle_dcd_change(&up->port, status & UART_MSR_DCD);Did you not look to see what's in this helper? You'll find within here the following code:
Quoted 7 lines
#ifdef CONFIG_HARD_PPS if ((port->flags & UPF_HARDPPS_CD) && status) hardpps();#endif
which should've been a big sign lit up in bright lights in Times Square pointing you towards the right place to put your code.
Ok.
Quoted 4 lines
Why not continue to leave it as a decision of the administrator - if you want ports to default to having PPS support enabled, change all the registration to set
UPF_HARDPPS_CD. But leave the admin with the ability to disable it.
Quoted 6 lines
Ok.
Quoted 2 lines
This means that PPS support is not available for any port which wasn't autoprobed at device discovery time. That seems quite restrictive.
How I can force probing for a specified uart port?
You can't because it doesn't go through the interfaces you're hooking into. Existing interfaces are "changed" to point at the UARTs using setserial, which does its work via an ioctl.
Quoted 4 lines
Quoted 1 line
Maybe it needs to be coupled with the setting/clearing of
UPF_HARDPPS_CD?What do you think about? I should enable the PPS support only if the userland sets the
UPF_HARDPPS_CDflag?
Not specifically only userland - if it happens to be set when the port is registered then enable PPS support then as well.
So:
1. uart_configure_port - if UPF_HARDPPS_CD is set, register the port for PPS support.
2. uart_remove_one_port - if UPF_HARDPPS_CD is set, unregister the port for PPS support.
3. uart_set_info - if changing UPF_HARDPPS_CD, appropriately register or unregister the port for PPS support.
PS, [email protected] dropped from the cc: since it rejects my postings.
Signature · 3 lines
Russell King Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/ maintainer of:
Rodolfo Giometti
maintainerQuoted 1 line · Jan Dittmer
Drop the linux prefix. It's in the linux kernel after all.
Ok.
Quoted 4 lines
Quoted 2 lines
+PROCFS support
+--------------New features shouldn't introduce new /proc stuff.
It's a must? I can leave procfs for backward compatibility with old utilities?
Quoted 1 line
Add to
MAINTAINERS
Ok.
Quoted 3 lines
Your way to hook into lp and 8250 is pretty gross. It should at least be possible to deactivate it via the kernel command line, but it would be a lot nicer to have
pps_lpandpps_8250modules which you can load. Also
I think it's not possible... however the Russell's suggestions should go in that direction.
Quoted 2 lines
what happens if you've multiple lp ports? How do you control which to grab?
No way... I can add a specific flag as for uart lines or a kernel module parameter.
Quoted 2 lines
- don't implement your own
dbg()stuff, use dprintk and friends
- drop the inlines, gcc will do the right thing.
Ok. Ok.
Quoted 3 lines
Perhaps just implement empty defines for the none pps cases and get rid of the ifdefs? But this should really be controllabe via sysfs or such.
Mmm... let me think about howto implement that...
Quoted 1 line
help text
Ok.
Quoted 1 line
help text and difference to
CLIENT_LP?
Ok.
Quoted 1 line
Why no dynamically allocated array?
It's easier! :P
Also it's very difficult having more that 3 or 4 PPS sources in a system.
Quoted 1 line
I wouldn't bet on that.
Why not? =:-o
Also locking instructions may add extra code and delay the timestamp recording...
Quoted 1 line
Doesn't match filename
I'm going to fix it.
Quoted 3 lines
Quoted 1 line
+++
b/drivers/pps/procfs.cI'd drop that completely.
:'(
Quoted 1 line
You read the comment above your line?
No, sorry. I'm going to choose another id number... or can I keep 17?
Quoted 1 line
These should use dprintk and friends
Ok.
Quoted 1 line
Isn't something like 4 more reasonable (lp + 8250 + ktimer?)
It should be enought...
Quoted 2 lines
I think you can drop the volatiles, there was a discussion some time ago that they mostly waste of words.
I see...
Quoted 2 lines
This one looks pretty fishy. After the check you normally want to use it, don't you? And then you already lost the guarantee.
You are right...
Quoted 3 lines
Quoted 1 line
+#define
to_class_dev(obj)container_of((obj), struct class_device, kobj)pretty generic name.
I should change it?
Quoted 1 line
Have you thought about 32/64bit issues?
No. I have no 64 bits machine to test the code...
Quoted 1 line
Function in .h?
I'm going to check it.
Thanks for your suggestions,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems [email protected] UNIX programming phone: +39 349 2432127
Rodolfo Giometti
maintainerQuoted 4 lines · Russell King
You can't because it doesn't go through the interfaces you're hooking into. Existing interfaces are "changed" to point at the UARTs using setserial, which does its work via an ioctl.
I see.
Quoted 11 lines
Not specifically only userland - if it happens to be set when the port is registered then enable PPS support then as well.
So:
1.
uart_configure_port- ifUPF_HARDPPS_CDis set, register the port for PPS support.
2.uart_remove_one_port- ifUPF_HARDPPS_CDis set, unregister the port for PPS support.
3.uart_set_info- if changingUPF_HARDPPS_CD, appropriately register or unregister the port for PPS support.
Ok. I'm going to study how to modify the code.
Quoted 2 lines
PS, [email protected] dropped from the cc: since it rejects my postings.
I just fixed my spam filter (at least I hope so :).
Thanks,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems [email protected] UNIX programming phone: +39 349 2432127
Quoted 6 lines · Rodolfo Giometti
Quoted 3 lines
Quoted 2 lines
+PROCFS support
+--------------New features shouldn't introduce new /proc stuff.
It's a must? I can leave procfs for backward compatibility with old utilities?
Hmm, as this is a new feature with regard to the mainline kernel, old utilities don't count (if you can install a new kernel you can also be expected to install new user-space tools for the new feature).
Quoted 3 lines
Quoted 1 line
You read the comment above your line?
No, sorry. I'm going to choose another id number... or can I keep 17?
I don't know, ask whoever is responsible for the file.
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
+#define
to_class_dev(obj)container_of((obj), struct class_device, kobj)pretty generic name.
I should change it?
If it's of general use put it in the appropriate header file. If it's just for the pps subsystem name it as such.
Quoted 3 lines
Quoted 1 line
Have you thought about 32/64bit issues?
No. I have no 64 bits machine to test the code...
Hmm, think about x86_64 with 64-bit kernel and 32-bit userspace, probably having got different padding in the struct. Read LDD3, chapter 11, especially 11.4 .
Jan
Rodolfo Giometti
maintainerLinuxPPS: fixes
In reply to Rodolfo GiomettiHello,
after yours suggestions I modified my code. Please see the patch below.
However some issues are still not modified. Here my reasons (lines with ">" are yours suggestions):
Quoted 5 lines
Your way to hook into lp and 8250 is pretty gross. It should at least be possible to deactivate it via the kernel command line, but it would be a lot nicer to have
pps_lpandpps_8250modules which you can load. Also what happens if you've multiple lp ports? How do you control which to grab?
Serial support has "setserial" and I used it to enable/disable PPS support at runtime. Here the patch for setserial:
setserial.c renamed from setserial.c.old +2 -0
@@ -127,6 +127,7 @@CMD_FLAG ,"hup_notify" ,ASYNC_HUP_NOTIFY ,ASYNC_HUP_NOTIFY ,0 ,FLAG_CAN_INVERT ,CMD_FLAG ,"skip_test" ,ASYNC_SKIP_TEST ,ASYNC_SKIP_TEST ,2 ,FLAG_CAN_INVERT ,CMD_FLAG ,"auto_irq" ,ASYNC_AUTO_IRQ ,ASYNC_AUTO_IRQ ,2 ,FLAG_CAN_INVERT , +CMD_FLAG ,"hardpps" ,ASYNC_HARDPPS_CD ,ASYNC_HARDPPS_CD ,2 ,FLAG_CAN_INVERT ,CMD_FLAG ,"split_termios" ,ASYNC_SPLIT_TERMIOS ,ASYNC_SPLIT_TERMIOS ,2 ,FLAG_CAN_INVERT ,CMD_FLAG ,"session_lockout" ,ASYNC_SESSION_LOCKOUT ,ASYNC_SESSION_LOCKOUT ,2 ,FLAG_CAN_INVERT , CMD_FLAG, "pgrp_lockout", ASYNC_PGRP_LOCKOUT, ASYNC_PGRP_LOCKOUT, 2, FLAG_CAN_INVERT,
@@ -725,6 +726,7 @@fprintf (stderr,"\t^ fourport\tconfigure the port as an AST Fourport\n" );fprintf (stderr,"\t autoconfig\tautomatically configure the serial port\n" );fprintf (stderr,"\t^ auto_irq\ttry to determine irq during autoconfiguration\n" ); +fprintf (stderr,"\t^ hardpps\tmanage PPS signal when CD changes status\n" );fprintf (stderr,"\t^ skip_test\tskip UART test during autoconfiguration\n" );fprintf (stderr,"\n" );fprintf (stderr,"\t^ sak\t\tset the break key as the Secure Attention Key\n" );
For parallel support I just cleaned up the code but I didn't find something similar to setserial so I decided to leave the code as is since at interrupt time we just register a timestamp without touching the parallel port functionality.
Quoted 1 line
don't implement your own
dbg()stuff, use dprintk and friends
My own dbg() stuff are for specific debugging string for PPS code. If I use pr_dbg & friends I also enable several (and unwanted) kernel debugging lines.
Quoted 1 line
drop the inlines, gcc will do the right thing.
I like specify them. :) Hope this is not a problem...
Quoted 9 lines
Review
Quoted 7 lines
(quoted diff) +7
-0+ for (i = 0; i < LINUXPPS_MAX_SOURCES; i++) + if (!__linuxpps_is_allocated(i)) + break; + if (i >= LINUXPPS_MAX_SOURCES) { + err("no free source ids"); + return -ENOMEM; + }Why no dynamically allocated array?
It's just easier...
Quoted 9 lines
Review
Quoted 7 lines
(quoted diff) +7
-0+void linuxpps_event(int source, int event, void *data) +{ + struct timespec ts; + + /* In this function we shouldn't need locking at all since each PPS + * source arrives once per second and due the per-PPS source data + * array... */I wouldn't bet on that.
I see. However it is not a problem at all since if the device is a PPS source we have just one interrupt at second, if not we just register a timestamp never used.
Quoted 5 lines
Quoted 5 lines
(quoted diff) +5
-0+/* The main struct */ +struct linuxpps_s { + struct linuxpps_source_info_s *info; /* PSS source info */ + + pps_params_t params; /* PPS's current params */
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ + volatile pps_seq_t assert_sequence; /* PPS' assert event seq # */ + volatile pps_seq_t clear_sequence; /* PPS' clear event seq # */ + volatile pps_timeu_t assert_tu; + volatile pps_timeu_t clear_tu;I think you can drop the volatiles, there was a discussion some time ago that they mostly waste of words.
As for inlines I like specify volatiles... :P
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+/* Private functions */ + +static int netlink_msg(int socket, struct pps_netlink_msg *nlpps)Function in .h?
That's why these functions must be used into userland from NTPD and it doesn't consider specific libraries to link with... it's the same trick used by PPSkit (another PPS support).
Quoted 8 lines
Quoted 8 lines
(quoted diff) +8
-0+#define LINUXPPS_MAX_NAME_LEN 32 +struct pps_netlink_msg { + int cmd; /* the command to execute */ + int source; + char name[LINUXPPS_MAX_NAME_LEN]; /* symbolic name */ + char path[LINUXPPS_MAX_NAME_LEN]; /* path of the connected device */ + int consumer; /* selected kernel consumer */ + pps_params_t params;
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ int mode; /* edge */ + int tsformat; /* format of time stamps */ + pps_info_t info; + struct timespec timeout; + int ret; +};Have you thought about 32/64bit issues?
I have no 64 bits hardware to test it... I just used PPC, MIPS and ARM at 32 bits.
Thanks a lot for your suggestions!
Ciao,
Rodolfo
P.S. After your replies (and some tests) I'll repost my patch for inclusion.
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems [email protected] UNIX programming phone: +39 349 2432127
Documentation/pps.txt new file +172 -0
172 lines not on this page · raw message
MAINTAINERS +7 -0
@@ -2693,6 +2693,13 @@ P: Michal Ostrowski M: [email protected] S: Maintained +PPS SUPPORT +P: Rodolfo Giometti +M: [email protected] +W: http://wiki.enneenne.com/index.php/LinuxPPS_support +L: [email protected] +S: Maintained + PREEMPTIBLE KERNEL P: Robert Love M: [email protected]
drivers/Kconfig +2 -0
@@ -52,6 +52,8 @@ source "drivers/i2c/Kconfig" source "drivers/spi/Kconfig" +source "drivers/pps/Kconfig" + source "drivers/w1/Kconfig" source "drivers/hwmon/Kconfig"
drivers/Makefile +1 -0
@@ -59,6 +59,7 @@ obj-$(CONFIG_INPUT) += input/ obj-$(CONFIG_I2O) += message/ obj-$(CONFIG_RTC_LIB) += rtc/ obj-$(CONFIG_I2C) += i2c/ +obj-$(CONFIG_PPS) += pps/ obj-$(CONFIG_W1) += w1/ obj-$(CONFIG_HWMON) += hwmon/ obj-$(CONFIG_PHONE) += telephony/
drivers/char/lp.c +59 -0
77 lines not on this page · raw message
drivers/pps/Kconfig new file +34 -0
@@ -0,0 +1,34 @@ +# +# Character device configuration +# + +menu "PPS support" + +config PPS + tristate "PPS support" + depends on EXPERIMENTAL + ---help--- + PPS (Pulse Per Second) is a special pulse provided by some GPS + antennas. Userland can use it to get an high time reference. + + Some antennas' PPS signals are connected with the CD (Carrier + Detect) pin of the serial line they use to communicate with the + host. In this case use the SERIAL_LINE client support. + + Some antennas' PPS signals are connected with some special host + inputs so you have to enable the corresponding client support. + + This PPS support can also be built as a module. If so, the module + will be called pps-core. + +config PPS_DEBUG + bool "PPS debugging messages" + depends on PPS + help + Say Y here if you want the PPS support to produce a bunch of debug + messages to the system log. Select this if you are having a + problem with PPS support and want to see more of what is going on. + +source drivers/pps/clients/Kconfig + +endmenu
drivers/pps/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# +# Makefile for the PPS core. +# + +pps_core-objs += pps.o kapi.o sysfs.o +obj-$(CONFIG_PPS) += pps_core.o +obj-y += clients/
drivers/pps/clients/Kconfig new file +38 -0
@@ -0,0 +1,38 @@ +# +# LinuxPPS clients configuration +# + +if PPS + +comment "PPS clients support" + +config PPS_CLIENT_KTIMER + tristate "Kernel timer client (Testing client, use for debug)" + help + If you say yes here you get support for a PPS debugging client + which uses a kernel timer to generate the PPS signal. + + This driver can also be built as a module. If so, the module + will be called ktimer.o. + +comment "UART serial support (forced off)" + depends on ! ( SERIAL_CORE != n && ! ( PPS = m && SERIAL_CORE = y ) ) + +config PPS_CLIENT_UART + bool "UART serial support" + depends on SERIAL_CORE != n && ! ( PPS = m && SERIAL_CORE = y ) + help + If you say yes here you get support for a PPS source connected + with the CD (Carrier Detect) pin of your serial port. + +comment "Parallel printer support (forced off)" + depends on ! ( PRINTER != n && ! ( PPS = m && PRINTER = y ) ) + +config PPS_CLIENT_LP + bool "Parallel printer support" + depends on PRINTER != n && ! ( PPS = m && PRINTER = y ) + help + If you say yes here you get support for a PPS source connected + with the interrupt pin of your parallel port. + +endif
drivers/pps/clients/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# +# Makefile for miscellaneous I2C chip drivers. +# + +obj-$(CONFIG_PPS_CLIENT_KTIMER) += ktimer.o +
drivers/pps/clients/ktimer.c new file +107 -0
107 lines not on this page · raw message
drivers/pps/kapi.c new file +205 -0
205 lines not on this page · raw message
drivers/pps/pps.c new file +374 -0
374 lines not on this page · raw message
drivers/pps/sysfs.c new file +200 -0
200 lines not on this page · raw message
drivers/serial/8250.c +3 -0
@@ -2004,6 +2004,8 @@ serial8250_set_termios(struct uart_port *port, struct ktermios *termios, up->ier |=UART_IER_MSI ;if (up->capabilities &UART_CAP_UUE ) up->ier |=UART_IER_UUE |UART_IER_RTOIE ; +if (up->port.flags &UPF_HARDPPS_CD ) + up->ier |=UART_IER_MSI ;/* enable interrupts */ serial_out (up,UART_IER , up->ier);
@@ -2718,6 +2720,7 @@ void serial8250_unregister_port(int line)struct uart_8250_port *uart = &serial8250_ports[line];mutex_lock (&serial_mutex); +uart_remove_one_port (&serial8250_reg, &uart->port);if (serial8250_isa_devs) { uart->port.flags &= ~UPF_BOOT_AUTOCONF ;
drivers/serial/serial_core.c +73 -0
103 lines not on this page · raw message
include/linux/netlink.h +1 -0
@@ -24,6 +24,7 @@/* leave room for NETLINK_DM (DM Events) */ #define NETLINK_SCSITRANSPORT 18/* SCSI Transports */ #define NETLINK_ECRYPTFS 19 +#define NETLINK_PPSAPI 20/* linuxPPS support */ #define MAX_LINKS 32
include/linux/parport.h +16 -0
@@ -104,6 +104,11 @@ typedef enum {#include <asm/ptrace.h> #include <asm/semaphore.h> +#ifdef CONFIG_PPS_CLIENT_LP +#include <linux/timepps.h> +#include <linux/pps.h> +#endif +/* Define this later. */ struct parport ;struct pardevice ;
@@ -323,6 +328,11 @@ struct parport {struct list_head full_list;struct parport *slaves[3 ]; + +#ifdef CONFIG_PPS_CLIENT_LP +struct pps_source_info_s pps_info; +int pps_source;/* PPS source ID */ +#endif };#define DEFAULT_SPIN_TIME 500/* us */
@@ -513,6 +523,12 @@ extern int parport_daisy_select (struct parport *port, int daisy, int mode);/* Lowlevel drivers _can_ call this support function to handle irqs. */ static __inline__void parport_generic_irq (int irq,struct parport *port) { +#ifdef CONFIG_PPS_CLIENT_LP +pps_event (port->pps_source,PPS_CAPTUREASSERT , port); +dbg ("parport_pc: PPS assert event at %lu on source #%d" , + jiffies, port->pps_source); +#endif +parport_ieee1284_interrupt (irq, port);read_lock (&port->cad_lock);if (port->cad && port->cad->irq_func)
include/linux/pps.h new file +107 -0
107 lines not on this page · raw message
include/linux/serial_core.h +27 -5
@@ -145,6 +145,11 @@#include <linux/tty.h> #include <linux/mutex.h> +#ifdef CONFIG_PPS_CLIENT_UART +#include <linux/timepps.h> +#include <linux/pps.h> +#endif +struct uart_port ;struct uart_info ;struct serial_struct ;
@@ -223,6 +228,9 @@ struct uart_port {unsigned char regshift;/* reg offset shift */ unsigned char iotype;/* io access style */ unsigned char unused1; +#ifdef CONFIG_PPS_CLIENT_UART +int pps_source;/* PPS source ID */ +#endif #define UPIO_PORT (0)#define UPIO_HUB6 (1)
@@ -295,6 +303,10 @@ struct uart_state {struct uart_info *info;struct uart_port *port; +#ifdef CONFIG_PPS_CLIENT_UART +struct pps_source_info_s pps_info; +#endif +struct mutex mutex; };
@@ -459,13 +471,23 @@ uart_handle_dcd_change(struct uart_port *port, unsigned int status) {struct uart_info *info = port->info; - port->icount.dcd++; - -#ifdef CONFIG_HARD_PPS -if ((port->flags &UPF_HARDPPS_CD ) && status) -hardpps (); +#ifdef CONFIG_PPS +if ((port->flags &UPF_HARDPPS_CD ) && status) { +if (status &UART_MSR_DCD ) { +pps_event (up->port.pps_source,PPS_CAPTUREASSERT , port); +dbg ("serial8250: PPS assert event at %lu on source #%d" , + jiffies, up->port.pps_source); + } +else { +pps_event (up->port.pps_source,PPS_CAPTURECLEAR , port); +dbg ("serial8250: PPS clear event at %lu on source #%d" , + jiffies, up->port.pps_source); + } + }#endif + port->icount.dcd++; +if (info->flags &UIF_CHECK_CD ) {if (status)wake_up_interruptible (&info->open_wait);
include/linux/timepps.h new file +519 -0
519 lines not on this page · raw message
Quoted 14 lines · Rodolfo Giometti
Please read the following consideratios before sending to
/dev/null! :)RFC considerations
------------------While implementing a PPS API as RFC 2783 defines and using an embedded CPU GPIO-Pin as physical link to the signal, I encountered a deeper problem:
At startup it needs a file descriptor as argument for the function
time_pps_create().
Quoted 8 lines
This implies that the source has a
/dev/... entry. This assumption is ok for the serial and parallel port, where you can do something usefull beside(!) the gathering of timestamps as it is the central task for a PPS-API. But this assumption does not work for a single purpose GPIO line. In this case even basic file-related functionality (likeread()andwrite()) makes no sense at all and should not be a precondition for the use of a PPS-API.
It's not a precondition for a file descriptor, either. There are plenty of ioctl-only device drivers in existence.
Furthermore, a file descriptor doesn't imply a device entry. Consider pipe(2), for example.
As far as the kernel is concerned, a file handle is a nice, uniform system for providing communication between the kernel and user space. It doesn't matter if one can read() or write() on it; it's perfectly normal to support only a subset of the normal operations.
-hpa
Rodolfo Giometti
maintainerQuoted 10 lines · H. Peter Anvin
It's not a precondition for a file descriptor, either. There are plenty of ioctl-only device drivers in existence.
Furthermore, a file descriptor doesn't imply a device entry. Consider pipe(2), for example.
As far as the kernel is concerned, a file handle is a nice, uniform system for providing communication between the kernel and user space. It doesn't matter if one can
read()orwrite()on it; it's perfectly normal to support only a subset of the normal operations.
The problem is that sometimes you cannot have a filedescriptor at all. Think about a PPS source connected with a CPU's GPIO pin. You have no filedes to use and defining one just for a PPS source or for a class of PPS sources, I think, is a non sense.
RFC simply doesn't consider the fact that you can have a PPS source __without__ a filedes connected with, and a single filedes is considered __always__ connected with a single PPS source.
Ciao,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems [email protected] UNIX programming phone: +39 349 2432127
Quoted 6 lines · Rodolfo Giometti
The problem is that sometimes you cannot have a filedescriptor at all. Think about a PPS source connected with a CPU's GPIO pin. You have no filedes to use and defining one just for a PPS source or for a class of PPS sources, I think, is a non sense.
If you have a kernel driver at all, then it makes perfect sense. If you don't have a kernel driver at all, then it's irrelevant to the linux-kernel discussion.
Quoted 3 lines
RFC simply doesn't consider the fact that you can have a PPS source
__without__a filedes connected with, and a single filedes is considered__always__connected with a single PPS source.
That's the Unix way.
-hpa
Hi,
Quoted 3 lines · Rodolfo Giometti
RFC simply doesn't consider the fact that you can have a PPS source
__without__a filedes connected with, and a single filedes is considered__always__connected with a single PPS source.
That's not entirely true. It doesn't say that pps_handle_t must be a file descriptor and it leaves the option for the argument to time_pps_create() not to be a file descriptor as well.
bye, Roman
Rodolfo Giometti
maintainerQuoted 4 lines · H. Peter Anvin
If you have a kernel driver at all, then it makes perfect sense. If you don't have a kernel driver at all, then it's irrelevant to the linux-kernel discussion.
???
So you are told me that if my PPS source is connected with a single CPU GPIO I have to add a new driver to the kernel? I have to choose a proper major/minor numbers for just one PIN? =:-o
Quoted 5 lines
Quoted 3 lines
RFC simply doesn't consider the fact that you can have a PPS source
__without__a filedes connected with, and a single filedes is considered__always__connected with a single PPS source.That's the Unix way.
But not PPS one. In several embedded systems the GPS antenna is connected with the serial port and the PPS source, which cames from the __same__ GPS antenna, is connected with a GPIO.
How I should manage such case? Which fildes I should use? Also consider that NTPD currently manage only one filedes which should support both GPS antenna's data and PPS source. My patch can solve this problem.
Ciao,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems [email protected] UNIX programming phone: +39 349 2432127
Rodolfo Giometti
maintainerQuoted 11 lines · Roman Zippel
Hi,
Quoted 3 lines · Rodolfo Giometti
RFC simply doesn't consider the fact that you can have a PPS source
__without__a filedes connected with, and a single filedes is considered__always__connected with a single PPS source.That's not entirely true. It doesn't say that
pps_handle_tmust be a file descriptor and it leaves the option for the argument totime_pps_create()not to be a file descriptor as well.
Yes. In fact that's my solution!
The problem is that "pps_handle_t" is forced by the RFC to be a scalar and _not_ a generic (and opaque) type. I suppose that since right now such handler was simply the filedes of the serial/parallel port connected with the GPS antenna. But this is not always the case. As already told the GPS antenna can be connected with the serial line while the PPS signal is not, so NTPD should always open the serial port to read GPS data but it must not use such filedes for the time_pps_create().
My support try to resolve this problem with minor changes in both RFC and NTPD code.
Ciao,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems [email protected] UNIX programming phone: +39 349 2432127
Hi!
Documentation/pps.txt line 5
Quoted 6 lines
Documentation/pps.txt new file +5
-0@@ -0,0 +1,206 @@ + + PPS - Pulse Per Second + ---------------------- + +(C) Copyright 2007 Rodolfo Giometti <[email protected]>
If you add copyright, add license, too.
Quoted 19 lines
Documentation/pps.txt new file +19
-0+PROCFS support +-------------- + +If PROCFS support is enabled a new directory "/proc/pps" is created: + + $ ls /proc/pps/ + 00 01 sources + +The file "sources" holds a brief description of all PPS sources +defined in the system: + + $ cat /proc/pps/sources + id mode echo name path + ---- ------ ---- ---------------- ---------------- + 00 1133 no serial0 /dev/ttyS0 + 01 1133 no serial1 /dev/ttyS1 + +The other entries are directories that hold one or two files according +to the ability of the associated source to provide "assert" and
Documentation/pps.txt line 169
Quoted 10 lines
Documentation/pps.txt new file +10
-0+"clear" timestamps: + + $ ls /proc/pps/00 + assert clear + +Inside each "assert" and "clear" file you can find the timestamp and a +sequence number: + + $ cat /proc/pps/00/assert + 1170026870.983207967 #8
No new /proc files, please.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Rodolfo Giometti
maintainerQuoted 10 lines · Pavel Machek
Hi!
Documentation/pps.txt line 5
Quoted 6 lines
Documentation/pps.txt new file +5
-0@@ -0,0 +1,206 @@ + + PPS - Pulse Per Second + ---------------------- + +(C) Copyright 2007 Rodolfo Giometti <[email protected]>If you add copyright, add license, too.
Ok.
Quoted 1 line
No new /proc files, please.
Already removed. As soon as possible I'll repost a new patch.
Thanks!
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems [email protected] UNIX programming phone: +39 349 2432127
Rodolfo Giometti
maintainerPATCH 1/1 LinuxPPS: Pulse per Second support for Linux
In reply to Rodolfo GiomettiHello,
here my new patch for PPS support in Linux.
I tried to follow your suggestions as much possible! Please let me know if this new version could be more acceptable.
Thanks in advance,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems [email protected] UNIX programming phone: +39 349 2432127
Documentation/pps.txt new file +183 -0
@@ -0,0 +1,183 @@ + + PPS - Pulse Per Second + ---------------------- + +(C) Copyright 2007 Rodolfo Giometti <[email protected]> + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + + + +Overview +-------- + +LinuxPPS provides a programming interface (API) to define into the +system several PPS sources. + +PPS means "pulse per second" and a PPS source is just a device which +provides a high precision signal each second so that an application +can use it to adjust system clock time. + +A PPS source can be connected to a serial port (usually to the Data +Carrier Detect pin) or to a parallel port (ACK-pin) or to a special +CPU's GPIOs (this is the common case in embedded systems) but in each +case when a new pulse comes the system must apply to it a timestamp +and record it for the userland. + +Common use is the combination of the NTPD as userland program with a +GPS receiver as PPS source to obtain a wallclock-time with +sub-millisecond synchronisation to UTC. + + +RFC considerations +------------------ + +While implementing a PPS API as RFC 2783 defines and using an embedded +CPU GPIO-Pin as physical link to the signal, I encountered a deeper +problem: + + At startup it needs a file descriptor as argument for the function + time_pps_create(). + +This implies that the source has a /dev/... entry. This assumption is +ok for the serial and parallel port, where you can do something +usefull besides(!) the gathering of timestamps as it is the central +task for a PPS-API. But this assumption does not work for a single +purpose GPIO line. In this case even basic file-related functionality +(like read() and write()) makes no sense at all and should not be a +precondition for the use of a PPS-API. + +The problem can be simply solved if you change the original RFC 2783: + + pps_handle_t type is an opaque __scalar type__ used to represent a + PPS source within the API + +into a modified: + + pps_handle_t type is an opaque __variable__ used to represent a PPS + source within the API and programs should not access it directly to + it due to its opacity. + +This change seems to be neglibile because even the original RFC 2783 +does not encourage programs to check (read: use) the pps_handle_t +variable before calling the time_pps_*() functions, since each +function should do this job internally. + +If I intentionally separate the concept of "file descriptor" from the +concept of the "PPS source" I'm obliged to provide a solution to find +and register a PPS-source without using a file descriptor: it's done +by the functions time_pps_findsource() and time_pps_findpath() now. + +According to this current NTPD drivers' code should be modified as +follows: + ++#ifdef PPS_HAVE_FINDPATH ++ /* Get the PPS source's real name */ ++ fd = readlink(link, path, STRING_LEN-1); ++ if (fd <= 0) ++ strncpy(path, link, STRING_LEN); ++ else ++ path[fd] = '\0'; ++ ++ /* Try to find the source */ ++ fd = time_pps_findpath(path, STRING_LEN, id, STRING_LEN); ++ if (fd < 0) { ++ msyslog(LOG_ERR, "refclock: cannot find PPS source \"%s\" in the system", path); ++ return 1; ++ } ++ msyslog(LOG_INFO, "refclock: found PPS source #%d \"%s\" on \"%s\"", fd, path, id); ++#endif /* PPS_HAVE_FINDPATH */ ++ ++ + if (time_pps_create(fd, &pps_handle) < 0) { +- pps_handle = 0; + msyslog(LOG_ERR, "refclock: time_pps_create failed: %m"); + } + + +Coding example +-------------- + +To register a PPS source into the kernel you should define a struct +pps_source_info_s as follow: + + static struct pps_source_info_s pps_ktimer_info = { + name : "ktimer", + path : "", + mode : PPS_CAPTUREASSERT|PPS_OFFSETASSERT|PPS_ECHOASSERT| \ + PPS_CANWAIT|PPS_TSFMT_TSPEC, + echo : pps_ktimer_echo, + }; + +and then calling the function pps_register_source() in your +intialization routine as follow: + + source = pps_register_source(&pps_ktimer_info, + PPS_CAPTUREASSERT|PPS_OFFSETASSERT, + -1 /* is up to the system */); + +The pps_register_source() prototype is: + + int pps_register_source(struct pps_source_info_s *info, int default_params, int try_id) + +where "info" is a pointer to a structure that describes a particular +PPS source, "default_params" tells the system what the initial default +parameters for the device should be (is obvious that these parameters +must be a subset of ones defined into the struct +pps_source_info_s which describe the capabilities of the driver) +and "try_id" can be used to force a particular ID for your device into +the system (just use -1 if you wish the system chooses one for you). + +Once you have registered a new PPS source into the system you can +signal an assert event (for example in the interrupt handler routine) +just using: + + pps_event(source, PPS_CAPTUREASSERT, ptr); + +The same function may also run the defined echo function +(pps_ktimer_echo(), passing to it the "ptr" pointer) if the user +asked for that... etc.. + +Please see the file drivers/pps/clients/ktimer.c for an example code. + + +SYSFS support +------------- + +The SYSFS support is enabled by default if the SYSFS filesystem is +enabled in the kernel and it provides a new class: + + $ ls /sys/class/pps/ + 00/ 01/ 02/ + +Every directory is the ID of a PPS sources defined into the system and +inside you find several files: + + $ ls /sys/class/pps/00/ + assert clear echo mode name path subsystem@ uevent + +Inside each "assert" and "clear" file you can find the timestamp and a +sequence number: + + $ cat cat /sys/class/pps/00/assert + 1170026870.983207967#8 + +Where before the "#" is the timestamp in seconds and after it is the +sequence number. Other files are: + +* echo: reports if the PPS source has an echo function or not; + +* mode: reports available PPS functioning modes; + +* name: reports the PPS source's name; + +* path: reports the PPS source's device path, that is the device the + PPS source is connected to (if it exists).
MAINTAINERS +7 -0
@@ -2693,6 +2693,13 @@ P: Michal Ostrowski M: [email protected] S: Maintained +PPS SUPPORT +P: Rodolfo Giometti +M: [email protected] +W: http://wiki.enneenne.com/index.php/LinuxPPS_support +L: [email protected] +S: Maintained + PREEMPTIBLE KERNEL P: Robert Love M: [email protected]
drivers/Kconfig +2 -0
@@ -52,6 +52,8 @@ source "drivers/i2c/Kconfig" source "drivers/spi/Kconfig" +source "drivers/pps/Kconfig" + source "drivers/w1/Kconfig" source "drivers/hwmon/Kconfig"
drivers/Makefile +1 -0
@@ -59,6 +59,7 @@ obj-$(CONFIG_INPUT) += input/ obj-$(CONFIG_I2O) += message/ obj-$(CONFIG_RTC_LIB) += rtc/ obj-$(CONFIG_I2C) += i2c/ +obj-$(CONFIG_PPS) += pps/ obj-$(CONFIG_W1) += w1/ obj-$(CONFIG_HWMON) += hwmon/ obj-$(CONFIG_PHONE) += telephony/
drivers/char/lp.c +59 -0
77 lines not on this page · raw message
drivers/pps/Kconfig new file +34 -0
@@ -0,0 +1,34 @@ +# +# Character device configuration +# + +menu "PPS support" + +config PPS + tristate "PPS support" + depends on EXPERIMENTAL + ---help--- + PPS (Pulse Per Second) is a special pulse provided by some GPS + antennas. Userland can use it to get an high time reference. + + Some antennas' PPS signals are connected with the CD (Carrier + Detect) pin of the serial line they use to communicate with the + host. In this case use the SERIAL_LINE client support. + + Some antennas' PPS signals are connected with some special host + inputs so you have to enable the corresponding client support. + + This PPS support can also be built as a module. If so, the module + will be called pps-core. + +config PPS_DEBUG + bool "PPS debugging messages" + depends on PPS + help + Say Y here if you want the PPS support to produce a bunch of debug + messages to the system log. Select this if you are having a + problem with PPS support and want to see more of what is going on. + +source drivers/pps/clients/Kconfig + +endmenu
drivers/pps/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# +# Makefile for the PPS core. +# + +pps_core-objs += pps.o kapi.o sysfs.o +obj-$(CONFIG_PPS) += pps_core.o +obj-y += clients/
drivers/pps/clients/Kconfig new file +38 -0
@@ -0,0 +1,38 @@ +# +# LinuxPPS clients configuration +# + +if PPS + +comment "PPS clients support" + +config PPS_CLIENT_KTIMER + tristate "Kernel timer client (Testing client, use for debug)" + help + If you say yes here you get support for a PPS debugging client + which uses a kernel timer to generate the PPS signal. + + This driver can also be built as a module. If so, the module + will be called ktimer.o. + +comment "UART serial support (forced off)" + depends on ! ( SERIAL_CORE != n && ! ( PPS = m && SERIAL_CORE = y ) ) + +config PPS_CLIENT_UART + bool "UART serial support" + depends on SERIAL_CORE != n && ! ( PPS = m && SERIAL_CORE = y ) + help + If you say yes here you get support for a PPS source connected + with the CD (Carrier Detect) pin of your serial port. + +comment "Parallel printer support (forced off)" + depends on ! ( PRINTER != n && ! ( PPS = m && PRINTER = y ) ) + +config PPS_CLIENT_LP + bool "Parallel printer support" + depends on PRINTER != n && ! ( PPS = m && PRINTER = y ) + help + If you say yes here you get support for a PPS source connected + with the interrupt pin of your parallel port. + +endif
drivers/pps/clients/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# +# Makefile for miscellaneous I2C chip drivers. +# + +obj-$(CONFIG_PPS_CLIENT_KTIMER) += ktimer.o +
drivers/pps/clients/ktimer.c new file +107 -0
107 lines not on this page · raw message
drivers/pps/kapi.c new file +198 -0
198 lines not on this page · raw message
drivers/pps/pps.c new file +374 -0
374 lines not on this page · raw message
drivers/pps/sysfs.c new file +210 -0
210 lines not on this page · raw message
drivers/serial/8250.c +3 -0
@@ -2004,6 +2004,8 @@ serial8250_set_termios(struct uart_port *port, struct ktermios *termios, up->ier |=UART_IER_MSI ;if (up->capabilities &UART_CAP_UUE ) up->ier |=UART_IER_UUE |UART_IER_RTOIE ; +if (up->port.flags &UPF_HARDPPS_CD ) + up->ier |=UART_IER_MSI ;/* enable interrupts */ serial_out (up,UART_IER , up->ier);
@@ -2718,6 +2720,7 @@ void serial8250_unregister_port(int line)struct uart_8250_port *uart = &serial8250_ports[line];mutex_lock (&serial_mutex); +uart_remove_one_port (&serial8250_reg, &uart->port);if (serial8250_isa_devs) { uart->port.flags &= ~UPF_BOOT_AUTOCONF ;
drivers/serial/serial_core.c +72 -1
107 lines not on this page · raw message
include/linux/netlink.h +1 -0
@@ -24,6 +24,7 @@/* leave room for NETLINK_DM (DM Events) */ #define NETLINK_SCSITRANSPORT 18/* SCSI Transports */ #define NETLINK_ECRYPTFS 19 +#define NETLINK_PPSAPI 20/* linuxPPS support */ #define MAX_LINKS 32
include/linux/parport.h +16 -0
@@ -104,6 +104,11 @@ typedef enum {#include <asm/ptrace.h> #include <asm/semaphore.h> +#ifdef CONFIG_PPS_CLIENT_LP +#include <linux/timepps.h> +#include <linux/pps.h> +#endif +/* Define this later. */ struct parport ;struct pardevice ;
@@ -323,6 +328,11 @@ struct parport {struct list_head full_list;struct parport *slaves[3 ]; + +#ifdef CONFIG_PPS_CLIENT_LP +struct pps_source_info_s pps_info; +int pps_source;/* PPS source ID */ +#endif };#define DEFAULT_SPIN_TIME 500/* us */
@@ -513,6 +523,12 @@ extern int parport_daisy_select (struct parport *port, int daisy, int mode);/* Lowlevel drivers _can_ call this support function to handle irqs. */ static __inline__void parport_generic_irq (int irq,struct parport *port) { +#ifdef CONFIG_PPS_CLIENT_LP +pps_event (port->pps_source,PPS_CAPTUREASSERT , port); +dbg ("parport_pc: PPS assert event at %lu on source #%d" , + jiffies, port->pps_source); +#endif +parport_ieee1284_interrupt (irq, port);read_lock (&port->cad_lock);if (port->cad && port->cad->irq_func)
include/linux/pps.h new file +99 -0
99 lines not on this page · raw message
include/linux/serial_core.h +29 -6
@@ -145,6 +145,11 @@#include <linux/tty.h> #include <linux/mutex.h> +#ifdef CONFIG_PPS_CLIENT_UART +#include <linux/timepps.h> +#include <linux/pps.h> +#endif +struct uart_port ;struct uart_info ;struct serial_struct ;
@@ -223,6 +228,9 @@ struct uart_port {unsigned char regshift;/* reg offset shift */ unsigned char iotype;/* io access style */ unsigned char unused1; +#ifdef CONFIG_PPS_CLIENT_UART +int pps_source;/* PPS source ID */ +#endif #define UPIO_PORT (0)#define UPIO_HUB6 (1)
@@ -264,7 +272,8 @@ struct uart_port {#define UPF_IOREMAP ((__force upf_t) (1 << 31))#define UPF_CHANGE_MASK ((__force upf_t) (0x17fff)) -#define UPF_USR_MASK ((__force upf_t) (UPF_SPD_MASK|UPF_LOW_LATENCY)) +#define UPF_USR_MASK ((__force upf_t) (UPF_SPD_MASK|UPF_LOW_LATENCY\ + |UPF_HARDPPS_CD))unsigned int mctrl;/* current modem ctrl settings */ unsigned int timeout;/* character-based timeout */
@@ -295,6 +304,10 @@ struct uart_state {struct uart_info *info;struct uart_port *port; +#ifdef CONFIG_PPS_CLIENT_UART +struct pps_source_info_s pps_info; +#endif +struct mutex mutex; };
@@ -459,13 +472,23 @@ uart_handle_dcd_change(struct uart_port *port, unsigned int status) {struct uart_info *info = port->info; - port->icount.dcd++; - -#ifdef CONFIG_HARD_PPS -if ((port->flags &UPF_HARDPPS_CD ) && status) -hardpps (); +#ifdef CONFIG_PPS_CLIENT_UART +if (port->flags &UPF_HARDPPS_CD ) { +if (status) { +pps_event (port->pps_source,PPS_CAPTUREASSERT , port); +dbg ("serial8250: PPS assert event at %lu on source #%d" , + jiffies, port->pps_source); + } +else { +pps_event (port->pps_source,PPS_CAPTURECLEAR , port); +dbg ("serial8250: PPS clear event at %lu on source #%d" , + jiffies, port->pps_source); + } + }#endif + port->icount.dcd++; +if (info->flags &UIF_CHECK_CD ) {if (status)wake_up_interruptible (&info->open_wait);
include/linux/timepps.h new file +519 -0
519 lines not on this page · raw message
Quoted 4 lines · Rodolfo Giometti
here my new patch for PPS support in Linux.
I tried to follow your suggestions as much possible! Please let me know if this new version could be more acceptable.
I have tried out 3.0.0-rc2 which seems to work pretty well so far (when combined with the patches to the jsm driver I just posted). It took soe work to get ntp's refclock_nmea to work though, since the patch that is linked to from the linuxpps page seems out of date. Here is the patch that seems to be working for me, although I am still testing it. Given you know the linuxpps code better perhaps you can see if it looks sane to you.
refclock_nmea.c renamed from refclock_nmea.c.ori +40 -4
@@ -79,6 +79,7 @@#define RANGEGATE 500000/* range gate (ns) */ #define LENNMEA 75/* min timecode length */ +#define LENPPS PPS_MAX_NAME_LEN/* * Tables to compute the ddd of year form icky dd/mm timecode. Viva la
@@ -99,6 +100,7 @@pps_params_t pps_params;/* pps parameters */ pps_info_t pps_info;/* last pps data */ pps_handle_t handle;/* pps handlebars */ +int handle_created;/* pps handle created flag */ #endif /* HAVE_PPSAPI */ };
@@ -147,6 +149,11 @@ registerstruct nmeaunit *up;struct refclockproc *pp;int fd; +#ifdef PPS_HAVE_FINDPATH +char id[LENPPS ] ="" , + path[LENPPS ], + mylink[LENPPS ] ="" ;/* just a default device */ +#endif /* PPS_HAVE_FINDPATH */ char device[20 ];/*
@@ -201,7 +208,20 @@#else return (0 );#endif - } + }else { +struct serial_struct ss; +if (ioctl (fd,TIOCGSERIAL , &ss) <0 || + ( + ss.flags |=ASYNC_HARDPPS_CD , +ioctl (fd,TIOCSSERIAL , &ss)) <0 ) { +msyslog (LOG_NOTICE ,"refclock_nmea: TIOCSSERIAL fd %d, %m" , fd); +msyslog (LOG_NOTICE , +"refclock_nmea: optional PPS processing not available" ); + }else { +msyslog (LOG_INFO , +"refclock_nmea: PPS detection on" ); + } + }/* * Allocate and initialize unit structure
@@ -238,12 +258,26 @@* Start the PPSAPI interface if it is there. Default to use * the assert edge and do not enable the kernel hardpps. */ +#ifdef PPS_HAVE_FINDPATH +/* Get the PPS source's real name */ +//time_pps_readlink(mylink, LENPPS, path, LENPPS); +time_pps_readlink (device,LENPPS , path,LENPPS ); + +/* Try to find the source */ + fd =time_pps_findpath (path,LENPPS , id,LENPPS ); +if (fd <0 ) { +msyslog (LOG_ERR ,"refclock_nmea: cannot find PPS path \"%s\" in the system" , path); +return (0 ); + } +msyslog (LOG_INFO ,"refclock_nmea: found PPS source \"%s\" at id #%d on \"%s\"" , path, fd, id); +#endif /* PPS_HAVE_FINDPATH */ if (time_pps_create (fd, &up->handle) <0 ) { - up->handle =0 ; + up->handle_created =0 ;msyslog (LOG_ERR ,"refclock_nmea: time_pps_create failed: %m" );return (1 ); } + up->handle_created = ~0 ;return (nmea_ppsapi (peer,0 ,0 ));#else return (1 );
@@ -265,8 +299,10 @@ pp = peer->procptr; up = (struct nmeaunit *)pp->unitptr;#ifdef HAVE_PPSAPI -if (up->handle !=0 ) +if (up->handle_created) {time_pps_destroy (up->handle); + up->handle_created =0 ; + }#endif /* HAVE_PPSAPI */ io_closeclock (&pp->io);free (up);
@@ -374,7 +410,7 @@/* * Convert the timespec nanoseconds field to ntp l_fp units. */ -if (up->handle ==0 ) +if (!up->handle_created)return (0 ); timeout.tv_sec =0 ; timeout.tv_nsec =0 ;
--
Len Sorensen
Rodolfo Giometti
maintainerQuoted 2 lines · Lennart Sorensen
I have tried out 3.0.0-rc2 which seems to work pretty well so far (when
Thanks. I just posted to the linux kernel ML the last release 3.0.0. Maybe you can do a "git pull" and try it out. :)
Quoted 46 lines
combined with the patches to the jsm driver I just posted). It took soe work to get ntp's
refclock_nmeato work though, since the patch that is linked to from the linuxpps page seems out of date. Here is the patch that seems to be working for me, although I am still testing it. Given you know the linuxpps code better perhaps you can see if it looks sane to you.refclock_nmea.c renamed from refclock_nmea.c.ori +11
-1@@ -79,6 +79,7 @@#define RANGEGATE 500000/* range gate (ns) */ #define LENNMEA 75/* min timecode length */ +#define LENPPS PPS_MAX_NAME_LEN/* * Tables to compute the ddd of year form icky dd/mm timecode. Viva la @@ -99,6 +100,7 @@pps_params_t pps_params;/* pps parameters */ pps_info_t pps_info;/* last pps data */ pps_handle_t handle;/* pps handlebars */ +int handle_created;/* pps handle created flag */ #endif /* HAVE_PPSAPI */ };@@ -147,6 +149,11 @@ registerstruct nmeaunit *up;struct refclockproc *pp;int fd; +#ifdef PPS_HAVE_FINDPATH +char id[LENPPS ] ="" , + path[LENPPS ], + mylink[LENPPS ] ="" ;/* just a default device */ +#endif /* PPS_HAVE_FINDPATH */ char device[20 ];/* @@ -201,7 +208,20 @@#else return (0 );#endif - } + }else { +struct serial_struct ss; + if (ioctl(fd, TIOCGSERIAL, &ss) < 0 || + (
refclock_nmea.c line 224
Quoted 10 lines
refclock_nmea.c renamed from refclock_nmea.c.ori +10
-0+ ss.flags |= ASYNC_HARDPPS_CD, + ioctl(fd, TIOCSSERIAL, &ss)) < 0) { + msyslog(LOG_NOTICE, "refclock_nmea: TIOCSSERIAL fd %d, %m", fd); + msyslog(LOG_NOTICE, + "refclock_nmea: optional PPS processing not available"); + } else { +msyslog (LOG_INFO , +"refclock_nmea: PPS detection on" ); + } + }
You should use "setserial" here. Keep in mind that the PPS source could be _not_ connected with the serial line at all.
refclock_nmea.c line 263
Quoted 9 lines
refclock_nmea.c renamed from refclock_nmea.c.ori +3
-0/* * Allocate and initialize unit structure @@ -238,12 +258,26 @@* Start the PPSAPI interface if it is there. Default to use * the assert edge and do not enable the kernel hardpps. */ +#ifdef PPS_HAVE_FINDPATH +/* Get the PPS source's real name */ +//time_pps_readlink(mylink, LENPPS, path, LENPPS);
Remove unneeded code.
refclock_nmea.c line 264
Quoted 1 line
refclock_nmea.c renamed from refclock_nmea.c.ori +1
-0+time_pps_readlink (device,LENPPS , path,LENPPS );
Test the return value (see the wiki at
http://wiki.enneenne.com/index.php/LinuxPPS_support#How_to_modify_a_refclock_to_work_with_LinuxPPS).
Quoted 32 lines
refclock_nmea.c renamed from refclock_nmea.c.ori +13
-2+/* Try to find the source */ + fd =time_pps_findpath (path,LENPPS , id,LENPPS ); +if (fd <0 ) { +msyslog (LOG_ERR ,"refclock_nmea: cannot find PPS path \"%s\" in the system" , path); +return (0 ); + } +msyslog (LOG_INFO ,"refclock_nmea: found PPS source \"%s\" at id #%d on \"%s\"" , path, fd, id); +#endif /* PPS_HAVE_FINDPATH */ if (time_pps_create (fd, &up->handle) <0 ) { - up->handle =0 ; + up->handle_created =0 ;msyslog (LOG_ERR ,"refclock_nmea: time_pps_create failed: %m" );return (1 ); } + up->handle_created = ~0 ;return (nmea_ppsapi (peer,0 ,0 ));#else return (1 );@@ -265,8 +299,10 @@ pp = peer->procptr; up = (struct nmeaunit *)pp->unitptr;#ifdef HAVE_PPSAPI -if (up->handle !=0 ) +if (up->handle_created) {time_pps_destroy (up->handle); + up->handle_created =0 ; + }#endif /* HAVE_PPSAPI */ io_closeclock (&pp->io);free (up);
refclock_nmea.c line 416
Quoted 8 lines
refclock_nmea.c renamed from refclock_nmea.c.ori +1
-1@@ -374,7 +410,7 @@/* * Convert the timespec nanoseconds field to ntp l_fp units. */ -if (up->handle ==0 ) +if (!up->handle_created)return (0 ); timeout.tv_sec =0 ; timeout.tv_nsec =0 ;
Please, rewiev and test the code and I'll publish it.
Ciao,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems [email protected] UNIX programming phone: +39 349 2432127
Quoted 6 lines · Rodolfo Giometti
Quoted 2 lines · Lennart Sorensen
I have tried out 3.0.0-rc2 which seems to work pretty well so far (when
Thanks. I just posted to the linux kernel ML the last release 3.0.0. Maybe you can do a "git pull" and try it out. :)
I will grab the last couple of commits and try although they didn't sound like they really make much difference.
Quoted 51 lines
Quoted 51 lines
combined with the patches to the jsm driver I just posted). It took soe work to get ntp's
refclock_nmeato work though, since the patch that is linked to from the linuxpps page seems out of date. Here is the patch that seems to be working for me, although I am still testing it. Given you know the linuxpps code better perhaps you can see if it looks sane to you.refclock_nmea.c renamed from refclock_nmea.c.ori +16
-1@@ -79,6 +79,7 @@#define RANGEGATE 500000/* range gate (ns) */ #define LENNMEA 75/* min timecode length */ +#define LENPPS PPS_MAX_NAME_LEN/* * Tables to compute the ddd of year form icky dd/mm timecode. Viva la @@ -99,6 +100,7 @@pps_params_t pps_params;/* pps parameters */ pps_info_t pps_info;/* last pps data */ pps_handle_t handle;/* pps handlebars */ +int handle_created;/* pps handle created flag */ #endif /* HAVE_PPSAPI */ };@@ -147,6 +149,11 @@ registerstruct nmeaunit *up;struct refclockproc *pp;int fd; +#ifdef PPS_HAVE_FINDPATH +char id[LENPPS ] ="" , + path[LENPPS ], + mylink[LENPPS ] ="" ;/* just a default device */ +#endif /* PPS_HAVE_FINDPATH */ char device[20 ];/* @@ -201,7 +208,20 @@#else return (0 );#endif - } + }else { +struct serial_struct ss; +if (ioctl (fd,TIOCGSERIAL , &ss) <0 || + ( + ss.flags |=ASYNC_HARDPPS_CD , +ioctl (fd,TIOCSSERIAL , &ss)) <0 ) { +msyslog (LOG_NOTICE ,"refclock_nmea: TIOCSSERIAL fd %d, %m" , fd); +msyslog (LOG_NOTICE , +"refclock_nmea: optional PPS processing not available" );
Quoted 8 lines
refclock_nmea.c line 224
Quoted 5 lines
refclock_nmea.c renamed from refclock_nmea.c.ori +5
-0+ }else { +msyslog (LOG_INFO , +"refclock_nmea: PPS detection on" ); + } + }You should use "setserial" here. Keep in mind that the PPS source could be _not_ connected with the serial line at all.
I couldn't find any way to do that with setserial (at least not the version I have), and I would rather not have to install setserial just to do that. Which version of setserial is needed and what arguments does it need to do it?
If it is NOT connected to the same device, then how would you specify it? The ntp configuration is rather sparse when it comes to specifying anything and seems to rely in symlinks to hardcoded device names for finding everything. I suppose one could have gps# for the nmea messages and pps# for the associated pps device name symlink (which may point to something that doesn't even exist if there is an internal source of that name with no associated device). Does that seem reasonable? I can certainly change it to do that. Certainly refclock_atom already uses /dev/pps# as it's device, so using that again may be reasonable.
Quoted 11 lines
refclock_nmea.c line 263
Quoted 9 lines
refclock_nmea.c renamed from refclock_nmea.c.ori +3
-0/* * Allocate and initialize unit structure @@ -238,12 +258,26 @@* Start the PPSAPI interface if it is there. Default to use * the assert edge and do not enable the kernel hardpps. */ +#ifdef PPS_HAVE_FINDPATH +/* Get the PPS source's real name */ +//time_pps_readlink(mylink, LENPPS, path, LENPPS); Remove unneeded code.
Oops. Missed that one. I was changing it to the below line to reuse the same serial device already specified for the NMEA messages.
I actually find the way it determines the pps device a bit annoying. Right now I have to do this:
cd /dev
ln -s ttyn0 jsm0
ln -s jsm0 gps0
This way gps0 is the symlink the ntp refclock looks for when asked for device 0, and readlink turns that into jsm0 (since the internal driver name for ttyn0 is jsm, that is what the pps code insists it must be named), which then is another symlink to the real device name. Same for ttyS3 <- serial3 <- gps0. Now it would be nice if the internal driver name matched the device name, but apparently that really never seems to happen. Is all this symlink spagheti really necesary?
Quoted 4 lines
refclock_nmea.c line 264
Quoted 1 line
refclock_nmea.c renamed from refclock_nmea.c.ori +1
-0+time_pps_readlink (device,LENPPS , path,LENPPS );Test the return value (see the wiki at
http://wiki.enneenne.com/index.php/LinuxPPS_support#How_to_modify_a_refclock_to_work_with_LinuxPPS).
OK, I will do that too. Apparently the current refclock_nmea patch fails that too then.
Quoted 34 lines
Quoted 34 lines
refclock_nmea.c renamed from refclock_nmea.c.ori +13
-2+/* Try to find the source */ + fd =time_pps_findpath (path,LENPPS , id,LENPPS ); +if (fd <0 ) { +msyslog (LOG_ERR ,"refclock_nmea: cannot find PPS path \"%s\" in the system" , path); +return (0 ); + } +msyslog (LOG_INFO ,"refclock_nmea: found PPS source \"%s\" at id #%d on \"%s\"" , path, fd, id); +#endif /* PPS_HAVE_FINDPATH */ if (time_pps_create (fd, &up->handle) <0 ) { - up->handle =0 ; + up->handle_created =0 ;msyslog (LOG_ERR ,"refclock_nmea: time_pps_create failed: %m" );return (1 ); } + up->handle_created = ~0 ;return (nmea_ppsapi (peer,0 ,0 ));#else return (1 );@@ -265,8 +299,10 @@ pp = peer->procptr; up = (struct nmeaunit *)pp->unitptr;#ifdef HAVE_PPSAPI -if (up->handle !=0 ) +if (up->handle_created) {time_pps_destroy (up->handle); + up->handle_created =0 ; + }#endif /* HAVE_PPSAPI */ io_closeclock (&pp->io);free (up);@@ -374,7 +410,7 @@/* * Convert the timespec nanoseconds field to ntp l_fp units.
Quoted 8 lines
refclock_nmea.c line 416
Quoted 6 lines
refclock_nmea.c renamed from refclock_nmea.c.ori +1
-1*/ -if (up->handle ==0 ) +if (!up->handle_created)return (0 ); timeout.tv_sec =0 ; timeout.tv_nsec =0 ;Please, rewiev and test the code and I'll publish it.
Will do.
--
Len Sorensen
Rodolfo Giometti
maintainerQuoted 3 lines · Lennart Sorensen
I will grab the last couple of commits and try although they didn't sound like they really make much difference.
Some fixes up... see the git log for further info.
Quoted 4 lines
I couldn't find any way to do that with setserial (at least not the version I have), and I would rather not have to install setserial just to do that. Which version of setserial is needed and what arguments does it need to do it?
Unluckely you need a patched version of setserial (see the patch on my site). On the same site you can find a precompiled version which I use for my tests, maybe it works for you...
Quoted 9 lines
If it is NOT connected to the same device, then how would you specify it? The ntp configuration is rather sparse when it comes to specifying anything and seems to rely in symlinks to hardcoded device names for finding everything. I suppose one could have gps# for the nmea messages and pps# for the associated pps device name symlink (which may point to something that doesn't even exist if there is an internal source of that name with no associated device). Does that seem reasonable? I can certainly change it to do that. Certainly
refclock_atomalready uses /dev/pps# as it's device, so using that again may be reasonable.
This is a specific problem of NTPD not of LinuxPPS itself. I wrote some letters about this problem into NTP list but with no results.
The sysadm shoulkd use setserial to enable a serial port to become a PPS source and then NTPD should verify if such PPS source exists (using time_pps_findpath() & Co.).
Quoted 7 lines
I actually find the way it determines the pps device a bit annoying. Right now I have to do this:
cd /dev
ln -s ttyn0 jsm0
ln -s jsm0 gps0
Quoted 7 lines
This way gps0 is the symlink the ntp refclock looks for when asked for device 0, and readlink turns that into jsm0 (since the internal driver name for ttyn0 is jsm, that is what the pps code insists it must be named), which then is another symlink to the real device name. Same for ttyS3 <- serial3 <- gps0. Now it would be nice if the internal driver name matched the device name, but apparently that really never seems to happen. Is all this symlink spagheti really necesary?
Did you read this example on the wiki?
giometti@jeeg:~/linuxpps$ cat /sys/class/pps/01/name serial1 giometti@jeeg:~/linuxpps$ cat /sys/class/pps/01/path /dev/ttyS1 giometti at jeeg:~/linuxpps/test$ sudo ln -sf /dev/ttyS1 /dev/gps0 giometti at jeeg:~/linuxpps/test$ sudo ./ppstest /dev/gps0 found PPS source #2 "serial1" on "/dev/ttyS1" giometti at jeeg:~/linuxpps/test$ sudo ln -sf ktimer /dev/gps0 giometti at jeeg:~/linuxpps/test$ sudo ./ppstest /dev/gps0 found PPS source #0 "ktimer" on ""
it doesn't work for you?
Quoted 1 line
Will do.
Thanks a lot,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems [email protected] UNIX programming phone: +39 349 2432127
Quoted 1 line · Rodolfo Giometti
Some fixes up... see the git log for further info.
I looked at those, and they didn't sound important. I will grab it anyhow just for completeness.
Quoted 3 lines
Unluckely you need a patched version of setserial (see the patch on my site). On the same site you can find a precompiled version which I use for my tests, maybe it works for you...
OK, that explains why it wasn't in setserial's code.
Quoted 6 lines
This is a specific problem of NTPD not of LinuxPPS itself. I wrote some letters about this problem into NTP list but with no results.
The sysadm shoulkd use setserial to enable a serial port to become a PPS source and then NTPD should verify if such PPS source exists (using
time_pps_findpath()& Co.).
Well I think I may just write a small tool to do the ioctl to enable it so I don't need the full setserial around.
Quoted 13 lines
Did you read this example on the wiki?
giometti@jeeg:~/linuxpps$ cat /sys/class/pps/01/name serial1 giometti@jeeg:~/linuxpps$ cat /sys/class/pps/01/path /dev/ttyS1 giometti at jeeg:~/linuxpps/test$ sudo ln -sf /dev/ttyS1 /dev/gps0 giometti at jeeg:~/linuxpps/test$ sudo ./ppstest /dev/gps0 found PPS source #2 "serial1" on "/dev/ttyS1" giometti at jeeg:~/linuxpps/test$ sudo ln -sf ktimer /dev/gps0 giometti at jeeg:~/linuxpps/test$ sudo ./ppstest /dev/gps0 found PPS source #0 "ktimer" on ""
Quoted 1 line
it doesn't work for you?
I will have to try that again to be sure. I may have got myself confused when I first tried it. One symlink I can deal with (that's ntpd sillyness after all).
--
Len Sorensen
Rodolfo Giometti
maintainerQuoted 3 lines · Lennart Sorensen
I looked at those, and they didn't sound important. I will grab it anyhow just for completeness.
Ok! Thanks.
Quoted 2 lines
Well I think I may just write a small tool to do the ioctl to enable it so I don't need the full setserial around.
Yes, this could be a good solution while waiting for a new setserial.
Ciao,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems [email protected] UNIX programming phone: +39 349 2432127
Quoted 3 lines · Rodolfo Giometti
Ok! Thanks.
Yes, this could be a good solution while waiting for a new setserial.
Now you said to check the return value of time_pps_readlink. Well it returns void so that isn't much good, and the stuff the wiki says to do, appears to be done internally by the function. So I guess that means I should undo that change so that I can actually get ntpd to compile again.
If the call was to readlink directly it needs to be done, while your time_pps_readlink is just a handy wrapper that does all that for you, right?
--
Len Sorensen
Rodolfo Giometti
maintainerQuoted 2 lines · Lennart Sorensen
Now you said to check the return value of
time_pps_readlink. Well it
I refere to readlink(), not to time_pps_readlink(). I'm sorry for mistake.
Quoted 3 lines
If the call was to readlink directly it needs to be done, while your
time_pps_readlinkis just a handy wrapper that does all that for you, right?
Right.
Ciao,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems [email protected] UNIX programming phone: +39 349 2432127
Well here is my current version of the refclock_nmea.c.patch for LinuxPPS. It now uses /dev/gps# for the nmea messages and /dev/pps# for the PPS device (which in my case is of course the same device). I am running some more tests on it, but I think it is OK.
refclock_nmea.c renamed from refclock_nmea.c.ori +27 -3
@@ -69,6 +69,7 @@# define DEVICE "COM%d:"/* COM 1 - 3 supported */ #else # define DEVICE "/dev/gps%d"/* name of radio device */ +# define PPSDEVICE "/dev/pps%d"/* name of pps device */ #endif #define SPEED232 B4800/* uart speed (4800 bps) */ #define PRECISION (-9)/* precision assumed (about 2 ms) */
@@ -79,6 +80,7 @@#define RANGEGATE 500000/* range gate (ns) */ #define LENNMEA 75/* min timecode length */ +#define LENPPS PPS_MAX_NAME_LEN/* * Tables to compute the ddd of year form icky dd/mm timecode. Viva la
@@ -99,6 +101,7 @@pps_params_t pps_params;/* pps parameters */ pps_info_t pps_info;/* last pps data */ pps_handle_t handle;/* pps handlebars */ +int handle_created;/* pps handle created flag */ #endif /* HAVE_PPSAPI */ };
@@ -147,6 +150,11 @@ registerstruct nmeaunit *up;struct refclockproc *pp;int fd; +#ifdef PPS_HAVE_FINDPATH +char id[LENPPS ] ="" , + path[LENPPS ], + ppsdevice[LENPPS ] ="" ;/* just a default device */ +#endif /* PPS_HAVE_FINDPATH */ char device[20 ];/*
@@ -238,12 +246,26 @@* Start the PPSAPI interface if it is there. Default to use * the assert edge and do not enable the kernel hardpps. */ +#ifdef PPS_HAVE_FINDPATH +/* Get the PPS source's real name */ + (void )sprintf (ppsdevice,PPSDEVICE , unit); +time_pps_readlink (ppsdevice,LENPPS , path,LENPPS ); + +/* Try to find the source */ + fd =time_pps_findpath (path,LENPPS , id,LENPPS ); +if (fd <0 ) { +msyslog (LOG_ERR ,"refclock_nmea: cannot find PPS path \"%s\" in the system" , path); +return (0 ); + } +msyslog (LOG_INFO ,"refclock_nmea: found PPS source \"%s\" at id #%d on \"%s\"" , path, fd, id); +#endif /* PPS_HAVE_FINDPATH */ if (time_pps_create (fd, &up->handle) <0 ) { - up->handle =0 ; + up->handle_created =0 ;msyslog (LOG_ERR ,"refclock_nmea: time_pps_create failed: %m" );return (1 ); } + up->handle_created = ~0 ;return (nmea_ppsapi (peer,0 ,0 ));#else return (1 );
@@ -265,8 +287,10 @@ pp = peer->procptr; up = (struct nmeaunit *)pp->unitptr;#ifdef HAVE_PPSAPI -if (up->handle !=0 ) +if (up->handle_created) {time_pps_destroy (up->handle); + up->handle_created =0 ; + }#endif /* HAVE_PPSAPI */ io_closeclock (&pp->io);free (up);
@@ -374,7 +398,7 @@/* * Convert the timespec nanoseconds field to ntp l_fp units. */ -if (up->handle ==0 ) +if (!up->handle_created)return (0 ); timeout.tv_sec =0 ; timeout.tv_nsec =0 ;
--
Len Sorensen
Rodolfo Giometti
maintainerQuoted 4 lines · Lennart Sorensen
Well here is my current version of the refclock_nmea.c.patch for LinuxPPS. It now uses /dev/gps# for the nmea messages and /dev/pps# for the PPS device (which in my case is of course the same device). I am running some more tests on it, but I think it is OK.
Thanks, published. :)
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems [email protected] UNIX programming phone: +39 349 2432127
Quoted 7 lines · Rodolfo Giometti
Quoted 4 lines · Lennart Sorensen
Well here is my current version of the refclock_nmea.c.patch for LinuxPPS. It now uses /dev/gps# for the nmea messages and /dev/pps# for the PPS device (which in my case is of course the same device). I am running some more tests on it, but I think it is OK.
Thanks, published. :)
Well it does work for our GPS receiver at least. Of course I have to change the baud rate in the driver since our unit doens't use the NNEA standard 4800. And the configure script for ntp doesn't recognize the v2 PPSAPI, so I have to manually explain to it that I have the PPS API and it should actually include it.
Here is my utility for enabling PPS on my serial port now. Seems less of a pain that patching setserial and including that (with 256MB flash space, setserial seems wasteful).
ppsctl.c
--------
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <linux/serial.h>
void usage(char *name) {
fprintf(stderr,"Usage: %s /dev/port [0|1]\n",name);
fprintf(stderr,"Where 0 means disable PPS and 1 means enable PPS\n");
}int main(int argc, char *argv[]) {
int fd;
char *state;
if(argc<3) {
usage(argv[0]);
return 1;
}
fd = open(argv[1],O_RDWR);
if (fd>=0) {
struct serial_struct ss;
if (ioctl(fd, TIOCGSERIAL, &ss) < 0 ) {
perror("TIOCGSERIAL");
return 1;
} else {
if(strcmp(argv[2],"1")==0) {
ss.flags |= ASYNC_HARDPPS_CD;
state="enabled";
} else if(strcmp(argv[2],"0")==0) {
ss.flags &= ~ASYNC_HARDPPS_CD;
state="disabled";
} else {
fprintf(stderr,"Invalid state argument \"%s\"\n",argv[2]);
return 1;
}
if (ioctl(fd, TIOCSSERIAL, &ss) < 0) {
perror("TIOCSSERIAL");
} else {
fprintf(stderr,"PPS on %s is now %s\n",argv[1],state);
}
}
} else {
fprintf(stderr,"Can't open \"%s\":",argv[1]);
perror("");
}
return 0;
}/* vim:ts=4:shiftwidth=4:
* */
--
Len Sorensen
Rodolfo Giometti
maintainerQuoted 6 lines · Lennart Sorensen
Well it does work for our GPS receiver at least. Of course I have to change the baud rate in the driver since our unit doens't use the NNEA standard 4800. And the configure script for ntp doesn't recognize the v2 PPSAPI, so I have to manually explain to it that I have the PPS API and it should actually include it.
Can you please provide a little help about it? A patch against current wiki wuold be great! ;)
Quoted 3 lines
Here is my utility for enabling PPS on my serial port now. Seems less of a pain that patching setserial and including that (with 256MB flash space, setserial seems wasteful).
I modify your code add inquiry functionality. Can you please test it?
See http://ftp.enneenne.com/pub/misc/linuxpps/test/ and the wiki at
http://wiki.enneenne.com/index.php/LinuxPPS_support#Compiling_the_code.
Ciao,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems [email protected] UNIX programming phone: +39 349 2432127
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <linux/serial.h>
void usage(char *name)
{
fprintf(stderr, "usage: %s <ttyS> [enable|disable]\n", name);
exit(EXIT_FAILURE);
}int main(int argc, char *argv[])
{
int fd, ret;
struct serial_struct ss;
if (argc < 2)
usage(argv[0]);
fd = open(argv[1], O_RDWR);
if (fd < 0) {
perror("open");
exit(EXIT_FAILURE);
}
ret = ioctl(fd, TIOCGSERIAL, &ss);
if (ret < 0 ) {
perror("ioctl(TIOCGSERIAL)");
exit(EXIT_FAILURE);
}
if (argc < 3) { /* just read PPS status */
printf("PPS is %sabled\n",
ss.flags & ASYNC_HARDPPS_CD ? "en" : "dis");
exit(EXIT_SUCCESS);
}
if (argv[2][0] == 'e' || argv[2][0] == '1')
ss.flags |= ASYNC_HARDPPS_CD;
else if (argv[2][0] == 'd' || argv[2][0] == '0')
ss.flags &= ~ASYNC_HARDPPS_CD;
else {
fprintf(stderr, "invalid state argument \"%s\"\n", argv[2]);
exit(EXIT_FAILURE);
}
ret = ioctl(fd, TIOCSSERIAL, &ss);
if (ret < 0) {
perror("ioctl(TIOCSSERIAL)");
exit(EXIT_FAILURE);
}
return 0;
}Quoted 2 lines · Rodolfo Giometti
Can you please provide a little help about it? A patch against current wiki wuold be great! ;)
Well all I actually did was simply stick #define HAVE_PPSAPI at the tome of the refclock_nmea.c file. The configure script in ntp is explcitly checking for PPS API version 1 so version 2 doesn't match and it claims you don't have a timepps.h file it can use. Unfortunately I really have trouble understanding autoconf scripts and can't figure out where the code is that tells it how to do the check for timepps.h and the API version inside it.
Quoted 4 lines
I modify your code add inquiry functionality. Can you please test it?
See http://ftp.enneenne.com/pub/misc/linuxpps/test/ and the wiki at
http://wiki.enneenne.com/index.php/LinuxPPS_support#Compiling_the_code.
I will try out the ppstest tool.
How come none of the .patch files in
http://ftp.enneenne.com/pub/misc/linuxpps/refclocks/nmea/ can be accessed? Does your web server not like serving up .patch files?
--
Len Sorensen
Rodolfo Giometti
maintainerQuoted 3 lines · Lennart Sorensen
How come none of the .patch files in
http://ftp.enneenne.com/pub/misc/linuxpps/refclocks/nmea/ can be accessed? Does your web server not like serving up .patch files?
Sorry. I set wrong file permissions. :)
Try now.
Ciao,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems [email protected] UNIX programming phone: +39 349 2432127