[LinuxPPS] [PATCH] PPS: Add a read() method

George Spelvin linux at horizon.com
Tue Feb 10 07:31:54 CET 2009


> That's what I want to see!
> cat /dev/pps* is by far the easiest method for checking pps-functionality 
> working. The RCF is IHMO not clear in this case.

Honestly, "cat /sys/class/pps0/pps/[ac]*" a few times works well enough,
But yes, this seemed much nicer.

> I didn't read the code very careful but is it guaranteed, that multiple
> reads will get the same data until a new event is registered?
> (reading /dev/ttyS* the data gone after the first read...)

I'm sorry, your question didn't translate into english very well,
but a read from /dev/pps0 goes like this:
- Wait until there's an event that hasn't been output yet on this fd.
- Output the oldest available event.
- Return to step 1.

The loop will generally be iterated over twice on startup, assuming
there's an assert and a clear event already in the system.

(Q: Should I do that?  Or output nothing st the start?)

Each open() gets its own set of "what events have been output yet"
sequence numbers, so they are all independent.  Each one gets
their own copy of all the events.

> PS:
> +		case PPS_CAPTUREBOTH:
> +			/* Select the earlier timestamp */
> +			if (tu[0].sec != tu[1].sec)
> +				which = tu[0].sec > tu[1].sec;
> +			else
> +				which = tu[0].nsec > tu[1].nsec;
> +			break;
> You use the var which here to determine if the output is marked clear or 
> assert.
> Are you _sure_ that this is bound to the first in order here? 

Well, tu[0] is the assert timestamp and tu[1] is the clear timestamp.
Here are the cases:

tu[0].sec > tu[1].sec: which = 1 (print clear time, which is lower)
tu[0].sec < tu[1].sec: which = 0 (print assert time, which is lower)
tu[0].sec == tu[1].sec, tu[0].nsec > tu[1].sec: which = 1
tu[0].sec == tu[1].sec, tu[0].nsec < tu[1].sec: which = 0
tu[0].sec == tu[1].sec, tu[0].nsec == tu[1].sec: which = 0 (arbitrary)



More information about the LinuxPPS mailing list