[LinuxPPS] ntp 'bugs'

Rodolfo Giometti giometti at enneenne.com
Sat Jun 28 15:25:07 CEST 2008


On Sat, Jun 28, 2008 at 10:08:41AM +0200, Udo van den Heuvel wrote:
> Udo van den Heuvel wrote:
> > See the update to the other bug:
> > 
> > https://support.ntp.org/bugs/show_bug.cgi?id=1036
> 
> The text that is there:
> 
> Could you please hide this Linuxism in time_pps_create() ?
> time_pps_create() is the real user of the feature and to me
> time_pps_create looks like the right place to do that. Otherwise we
> would have to wade through all refclock drivers to add the port specific
> code. I'd like to avoid importing more and more OS specifics and adding
> that TIOCSETD call defeats the whole purpose of making the PPS_API
> standards conformant.

Mmm... is not easy... or better, we can do it but we need a trick!

The userland code is:

	/* Try the main PPS device */
	ret = time_pps_create(main_dev, &up->handle);
	if (ret < 0) {
		/* Try the alternate PPS device */
		fd = open(alt_dev, O_RDWR);
		if (fd < 0)
			goto pps_error;
		ret = time_pps_create(fd, &up->handle);
		if (ret < 0)
			goto pps_error;
	}

So we must hide the TIOCSETD into first time_pps_create() call in
order to be used into second one... I mean something like:

static __inline int time_pps_create(int source, pps_handle_t *handle)
{
        int ret;
	int ldisc;

        if (!handle) {
                errno = EINVAL;
                return -1;
        }

        /* First we check if current device is a PPS valid PPS one...
         */
        ret = ioctl(source, PPS_CHECK);
        if (ret == 0) {
		/* Got it! Since in LinuxPPS there are no differences
		 * between a "PPS source" and a "PPS handle", we
		 * simply return the same value.
		 */
		*handle = source;

		return 0;
	}

	/* Before exiting an error we have to verify if we can
	 * change the line discipline for the current device in
	 * case it's a serial one.
	 */
	ldisc = N_PPS;
	(void) ioctl(pp->io.fd, TIOCSETD, &ldisc);

	/* The we return error, so caller should try the alternate
	 * device.
	 */
        errno = EOPNOTSUPP;
        return -1;
}

Ciao,

Rodolfo

-- 

GNU/Linux Solutions                  e-mail: giometti at enneenne.com
Linux Device Driver                          giometti at linux.it
Embedded Systems                     phone:  +39 349 2432127
UNIX programming                     skype:  rodolfo.giometti



More information about the LinuxPPS mailing list