[Linux-parport] Timing issue with reading from parport device.
kurt at roeckx.be
Sun Nov 11 08:59:14 EST 2007
I have code that does:
- negataions to nibble mode: ioctl(PPNEGOT)
- Sets the mode: ioctl(PPSETMODE)
- Tries to read() the data.
It seems that there is some timeing issue between the ioctl()'s and the
When I'm waiting for the device to answer me, the PPNEGOT will fail, so
I wait some time and try again. Most of the time, doing the read() I
get all the data at once, and in that case I don't have a problem.
But sometimes the PPNEGOT was succesful, I call read() and it returns -1
and sets errno to EGAIN. In that case I lost 1 byte. I've seen cases
where it did that 3 times in a row, so I lost 3 bytes.
I don't know if the ioctl(PPSETMODE) is needed, but since I added that,
it seems to be a little better. I then added a usleep(0) and since
then I haven't been able to reproduce the problem.
I've been looking at libieee1284 and it seem that it always does 2
system calls between the ioctl(PPNEGOT) and the ioctl(PPSETMODE), to set
it to non-blocking mode: fcntl(F_GETFL), fcntl(F_SETFL). With libieee1284
I don't see the problem either.
The problem also goes away when I strace my application.
This all seems to suggest that there is a timing issue somewhere. My
question now is, is this a kernel bug, or is this a problem with the
device I'm trying to talk to?
More information about the Linux-parport