Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 03 Aug 2009 17:57:33 -0400
From:      "Brian J. McGovern" <mcgovern@beta.com>
To:        freebsd-questions@freebsd.org
Subject:   FIONREAD behavior possible on uhid?
Message-ID:  <1249336653.1043.21.camel@dhcp7.beta.com>

next in thread | raw e-mail | index | archive | help
All,
	I recently picked up a Velleman K8055, which is basically a Digital and
analog I/O board that connects to a PC via a USB connection. So far, its
worked fine w/FreeBSD, the uhid driver picks it up, and a simple cat
< /dev/uhid0 will start pulling the 8 bytes that represent the inputs
and counters available.

	However, once the device is open, it polls several times per second,
and uhid begins to buffer the board's output in a clist. Since I don't
need that level of resolution, I'm looking to have the application back
down to once per second, perhaps slower (every 5 seconds). However, in
order to do this, I need to either stop the over sampling or flush the
buffer, and then pick up the first "new" read. However, performing both
a TIOCFLUSH (have ioctl flush the buffers) as well as a FIONREAD (return
the number of bytes waiting so the application can read them and throw
them away) fail. 

	I also tried to add a FIONREAD to uhid_do_ioctl() and uhidioctl() at
different times. My understanding is that with the ioctl calls, the
infrastructure should be able to do the copy out, so a simple:
case FIONREAD:
  {
    *addr = sc->sc_q.c_cc;
    break;
  }

should have done the trick, and it compiles happily, but it fails with
an invalid address error when the ioctl is called. I also tried using
copyout directly, but from the little reading I did, addr is already
supposed to be in the kernel address space, and it returns EFAULT.

	Its been about 10 years since I've played seriously in the kernel
space, so I hope its something simple I've just forgotten. Can someone
point me at a way to get this functionality, short have having to write
a device-specific driver (a-la uvisor) ?

	-B




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1249336653.1043.21.camel>