Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1MfZZw-0007lz-OR for mharc-grub-devel@gnu.org; Mon, 24 Aug 2009 09:27:20 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MfZZt-0007ha-Bw for grub-devel@gnu.org; Mon, 24 Aug 2009 09:27:17 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MfZZo-0007ZJ-Ed for grub-devel@gnu.org; Mon, 24 Aug 2009 09:27:16 -0400 Received: from [199.232.76.173] (port=46325 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MfZZo-0007Z3-8A for grub-devel@gnu.org; Mon, 24 Aug 2009 09:27:12 -0400 Received: from smarthost03.mail.zen.net.uk ([212.23.3.142]:57710) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MfZZn-00079z-OI for grub-devel@gnu.org; Mon, 24 Aug 2009 09:27:12 -0400 Received: from [82.69.40.219] (helo=riva.pelham.vpn.ucam.org) by smarthost03.mail.zen.net.uk with esmtp (Exim 4.63) (envelope-from ) id 1MfZZm-0000Vx-Ng for grub-devel@gnu.org; Mon, 24 Aug 2009 13:27:10 +0000 Received: from cjwatson by riva.pelham.vpn.ucam.org with local (Exim 3.36 #1 (Debian)) for grub-devel@gnu.org id 1MfZZl-0006RN-00; Mon, 24 Aug 2009 14:27:09 +0100 Date: Mon, 24 Aug 2009 14:27:07 +0100 From: Colin Watson To: The development of GRUB 2 Message-ID: <20090824132705.GG11691@riva.ucam.org> Mail-Followup-To: The development of GRUB 2 References: <20090812153520.GA11691@riva.ucam.org> <20090812221431.GD11691@riva.ucam.org> <20090824092406.GE11691@riva.ucam.org> <20090824122352.GB18956@thorin> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20090824122352.GB18956@thorin> User-Agent: Mutt/1.5.18 (2008-05-17) X-Originating-Smarthost03-IP: [82.69.40.219] X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: Re: [PATCH] Detect key modifier status in 'sleep --interruptible' X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Aug 2009 13:27:18 -0000 On Mon, Aug 24, 2009 at 02:23:52PM +0200, Robert Millan wrote: > I ommitted the USB part of your patch, because I had some comments. Once > that's fixed it can be added as well: > > > +static int > > +grub_usb_keyboard_keystatus (void) > > +{ > > + unsigned char data[8]; > > Please use grub_uint8_t. > > > + for (i = 0; i < 50; i++) > > + { > > + /* Get_Report. */ > > + err = grub_usb_keyboard_getreport (usbdev, data); > > + > > + if (! err) > > + break; > > + } > > If the 50 is a "timeout", it should be using grub_get_time_ms() instead; > if it's a number given by spec (e.g. number of times an I/O operation must > be performed), then please macroify it to indicate what it is. Perhaps we can apply the following patch first, then? I was following existing style, so the other code should be updated too. I don't see anything in the USB HID spec about the number of times one must attempt to get a keyboard report, so I think it must simply be a timeout. USB frames are 1ms so waiting for 50ms should do. 2009-08-24 Colin Watson * term/usb_keyboard.c (grub_usb_keyboard_getreport): Make `report' grub_uint8_t *. (grub_usb_keyboard_checkkey): Make `data' elements grub_uint8_t. Use a 50-millisecond timeout rather than just repeating grub_usb_keyboard_getreport 50 times. (grub_usb_keyboard_getkey): Make `data' elements grub_uint8_t. Index: term/usb_keyboard.c =================================================================== --- term/usb_keyboard.c (revision 2522) +++ term/usb_keyboard.c (working copy) @@ -97,7 +97,7 @@ } static grub_err_t -grub_usb_keyboard_getreport (grub_usb_device_t dev, unsigned char *report) +grub_usb_keyboard_getreport (grub_usb_device_t dev, grub_uint8_t *report) { return grub_usb_control_msg (dev, (1 << 7) | (1 << 5) | 1, 0x01, 0, 0, 8, (char *) report); @@ -108,20 +108,24 @@ static int grub_usb_keyboard_checkkey (void) { - unsigned char data[8]; + grub_uint8_t data[8]; int key; - int i; grub_err_t err; + grub_uint64_t currtime; + int timeout = 50; data[2] = 0; - for (i = 0; i < 50; i++) + currtime = grub_get_time_ms (); + do { /* Get_Report. */ err = grub_usb_keyboard_getreport (usbdev, data); - if (! err && data[2]) + /* Implement a timeout. */ + if (grub_get_time_ms () > currtime + timeout) break; } + while (err || !data[2]); if (err || !data[2]) return -1; @@ -174,7 +178,7 @@ { int key; grub_err_t err; - unsigned char data[8]; + grub_uint8_t data[8]; grub_uint64_t currtime; int timeout; static grub_usb_keyboard_repeat_t repeat = GRUB_HIDBOOT_REPEAT_NONE; -- Colin Watson [cjwatson@ubuntu.com]