From owner-freebsd-usb@FreeBSD.ORG Tue Jul 10 01:27:44 2007 Return-Path: X-Original-To: freebsd-usb@freebsd.org Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id CCA4A16A421 for ; Tue, 10 Jul 2007 01:27:44 +0000 (UTC) (envelope-from xiaofanc@gmail.com) Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.183]) by mx1.freebsd.org (Postfix) with ESMTP id A78CC13C480 for ; Tue, 10 Jul 2007 01:27:44 +0000 (UTC) (envelope-from xiaofanc@gmail.com) Received: by wa-out-1112.google.com with SMTP id j37so1624199waf for ; Mon, 09 Jul 2007 18:27:44 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=IoLB+UzYnUgJ33itby/5PkWVidUMj2NVS9x6FK5VExwXWwlBdqrJhe1/NgxunNgAe79loeb+JGpXsM09QKDomQcy7ciFUylHaH8gnkekaJyeKR7FKpeEUf21NnJwcPpBpaTEHDE+KWV5WzxzGjqtTd7DTVi+rwe84oFyzNDSw2E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=npyEkfO016TOTZ3iFbUI6mdgGp8f2F/kvkg9jLAH8kYxxj/Oou5DWiwoJ8GzYDbCquhkqYxXXbhAw8Hpv5/22kFwJOdbTPZZlSa5ArO6cJG0z5Ry4tJPZAjHWwRuMm1g2m2pawYb71HQZ6hOQX9GM8Vrn+YjbZUGCeqofLaUy1s= Received: by 10.115.22.1 with SMTP id z1mr3681991wai.1184030863864; Mon, 09 Jul 2007 18:27:43 -0700 (PDT) Received: by 10.114.176.17 with HTTP; Mon, 9 Jul 2007 18:27:43 -0700 (PDT) Message-ID: Date: Mon, 9 Jul 2007 21:27:43 -0400 From: "Xiaofan Chen" To: "Hans Petter Selasky" In-Reply-To: <200707091835.50445.hselasky@c2i.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <200707051724.30175.hselasky@c2i.net> <200707091835.50445.hselasky@c2i.net> Cc: freebsd-usb@freebsd.org Subject: Re: libusb usb_interrupt_read hangs under FreeBSD X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Jul 2007 01:27:45 -0000 On 7/9/07, Hans Petter Selasky wrote: > > Perhaps what happens is that the "*pDst.bRam = _UCPU;" > command clears the FIFO > contents of the USB interrupt endpoint in addition to clearing the stall!? > > If the sequence is like this: > > Write to interrupt endpoint. > Reply command is written to FIFO. > Clear interrupt endpoint stall. > There is no data to read, because the FIFO has been emptied as a part of the > stall command. > > Xiaofan Chen: Could you check the datasheet for the chip that is used, what > the stall command actually does? I need to look further but what you mentioned seem to make sense. "*pDst.bRam = _UCPU" seems to clear the buffer. The following are the definitions for for the Buffer Descriptor Status Register. /* Buffer Descriptor Status Register Initialization Parameters */ #define _BSTALL 0x04 //Buffer Stall enable #define _DTSEN 0x08 //Data Toggle Synch enable #define _INCDIS 0x10 //Address increment disable #define _KEN 0x20 //SIE keeps buff descriptors enable #define _DAT0 0x00 //DATA0 packet expected next #define _DAT1 0x40 //DATA1 packet expected next #define _DTSMASK 0x40 //DTS Mask #define _USIE 0x80 //SIE owns buffer #define _UCPU 0x00 //CPU owns buffer FYI: Datasheet of PIC18F2550 USB MCU: http://ww1.microchip.com/downloads/en/DeviceDoc/39632D.pdf bit 7 UOWN: USB Own bit(1) 0 = The microcontroller core owns the BD and its corresponding buffer 1 = SIE owns the BD and its corresponding buffer Note: This bit must be initialized by the user to the desired value prior to enabling the USB module. bit 6 DTS: Data Toggle Synchronization bit(2) 1 = Data 1 packet 0 = Data 0 packet Note: This bit is ignored unless DTSEN = 1 bit 5 KEN: BD Keep Enable bit 1 = USB will keep the BD indefinitely once UOWN is set (required for SPP endpoint configuration) 0 = USB will hand back the BD once a token has been processed bit 4 INCDIS: Address Increment Disable bit 1 = Address increment disabled (required for SPP endpoint configuration) 0 = Address increment enabled bit 3 DTSEN: Data Toggle Synchronization Enable bit 1 = Data toggle synchronization is enabled; data packets with incorrect Sync value will be ignored except for a SETUP transaction, which is accepted even if the data toggle bits do not match 0 = No data toggle synchronization is performed bit 2 BSTALL: Buffer Stall Enable bit 1 = Buffer stall enabled; STALL handshake issued if a token is received that would use the BD in the given location (UOWN bit remains set, BD value is unchanged) 0 = Buffer stall disabled bit 1-0 BC9:BC8: Byte Count 9 and 8 bits The byte count bits represent the number of bytes that will be transmitted for an IN token or received during an OUT token. Together with BC<7:0>, the valid byte counts are 0-1023. What Warner mentioned before might also be correct. On 7/8/07, M. Warner Losh wrote: > : > > I never learned the details, but a client of mine was able to get > : > > fixes from Microchip for their product. The exact problem was that > : > > endpoint stall clearing didn't work for these devices and it was a > : > > firmware bug. > I need to look it up, but I believe that a clear endpoint stall also > resets the toggle, and that was the bug that was tracked down. > FYI: the Firmware source code for PICkit 2, an HID device is here. http://ww1.microchip.com/downloads/en/DeviceDoc/FirmwareV2.10.00.zip I am still in the process of understanding the firmware so I may misunderstand something. But I will try to dig further. Regards, Xiaofan