From owner-freebsd-questions@FreeBSD.ORG Mon Aug 3 22:26:37 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C76FD1065673 for ; Mon, 3 Aug 2009 22:26:37 +0000 (UTC) (envelope-from mcgovern@beta.com) Received: from spoon.beta.com (spoon.beta.com [199.165.180.2]) by mx1.freebsd.org (Postfix) with ESMTP id 70D998FC14 for ; Mon, 3 Aug 2009 22:26:37 +0000 (UTC) (envelope-from mcgovern@beta.com) Received: from [199.165.180.37] (dhcp7.beta.com [199.165.180.37]) by spoon.beta.com (8.14.3/8.14.2) with ESMTP id n74Hvalw041734 for ; Tue, 4 Aug 2009 13:57:36 -0400 (EDT) (envelope-from mcgovern@beta.com) From: "Brian J. McGovern" To: freebsd-questions@freebsd.org Content-Type: text/plain Organization: B.E.T.A. Date: Mon, 03 Aug 2009 17:57:33 -0400 Message-Id: <1249336653.1043.21.camel@dhcp7.beta.com> Mime-Version: 1.0 X-Mailer: Evolution 2.26.0 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=1.8 required=5.0 tests=DATE_IN_PAST_12_24 autolearn=no version=3.2.5 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on spoon.beta.com Subject: FIONREAD behavior possible on uhid? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: mcgovern@spoon.beta.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Aug 2009 22:26:38 -0000 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