From owner-freebsd-hardware Sun Apr 14 12: 3: 3 2002 Delivered-To: freebsd-hardware@freebsd.org Received: from wartch.sapros.com (rularan.sapros.com [204.182.55.17]) by hub.freebsd.org (Postfix) with ESMTP id 8F15B37B400 for ; Sun, 14 Apr 2002 12:02:59 -0700 (PDT) Received: from wartch.sapros.com (localhost.sapros.com [127.0.0.1]) by wartch.sapros.com (8.12.1/8.12.1) with ESMTP id g3EJ2rRg031891 for ; Sun, 14 Apr 2002 12:02:53 -0700 (PDT) (envelope-from peterh@wartch.sapros.com) Message-Id: <200204141902.g3EJ2rRg031891@wartch.sapros.com> To: hardware@freebsd.org Subject: Reading from the USB ugen device. Date: Sun, 14 Apr 2002 12:02:52 -0700 From: Peter Haight X-Spam-Status: No, hits=1.8 required=7.0 tests=NO_MX_FOR_FROM version=2.11 Sender: owner-freebsd-hardware@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org I've been working with an application called coldsync to get my Sony Clie to sync to my computer. I'm using FreeBSD-4.5-STABLE. I've gotten it to work, but I ran into an issue I don't understand and I'd like to know what's going on. The software begins by sending a USB_DISCOVER on usb0 and then tries to open /dev/ugen0. If that succeeds it checks to make sure the device is the Clie (using USB_GET_DEVICEINFO) and then it sends a vendor information request over the control endpoint. From the information it gets back from that it figures out which endpoint to open and then it opens that one (Usually ugen0.2). Then it sends the USB_SET_SHORT_XFER on that device. The original author of the code, had a routine which reads data from the ugen0.2 device 1024 bytes at a time. A comment in the code indicates that it needs to make sure it reads any data available because the kernel isn't buffering anything. Well, that would work for about 8 reads (read(2)) and if I ran it under gdb, each of those reads would actually just return whatever amount of data we were expecting according to the protocol. Probably about 6-100 bytes at a time. Then it would just block indefinitely when I was expecting 64 bytes. I managed to fix it by getting rid of the 1024 byte reads and just reading whatever I was expecting. Once I made that change, it didn't block on that read and then went on to read the rest of about 6MB from the device. I don't get it. My only guess is that when doing it the other way the timing changes subtly so that I'm not in the read when the next set of data comes and since it is unbuffered it just gets discarded by the kernel. The problem with this theory is that I've not changed the part of the code that manages the buffer. So I don't really see how the timing could be different because if I run it with the buffering on, it never gets a read longer than what I was expecting. The actual read lengths are exactly the same whether I request 1024 bytes or the number of bytes I'm expecting, but if I use 1024 it eventually blocks. Anyway, this all has me worried about timing with an unbuffered device. I don't have a good understanding of what's going on, so I'm not sure what's a good way to deal with this issue. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hardware" in the body of the message