From owner-freebsd-hackers@FreeBSD.ORG Thu Apr 19 22:14:11 2007 Return-Path: X-Original-To: hackers@freebsd.org Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id AF2F616A402; Thu, 19 Apr 2007 22:14:11 +0000 (UTC) (envelope-from babkin@verizon.net) Received: from vms046pub.verizon.net (vms046pub.verizon.net [206.46.252.46]) by mx1.freebsd.org (Postfix) with ESMTP id 9428E13C455; Thu, 19 Apr 2007 22:14:11 +0000 (UTC) (envelope-from babkin@verizon.net) Received: from vms071.mailsrvcs.net ([192.168.1.2]) by vms046.mailsrvcs.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0JGR007OVN3ICRS8@vms046.mailsrvcs.net>; Thu, 19 Apr 2007 17:14:07 -0500 (CDT) Received: from 208.253.138.194 ([208.253.138.194]) by vms071.mailsrvcs.net (Verizon Webmail) with HTTP; Thu, 19 Apr 2007 17:14:06 -0500 (CDT) Date: Thu, 19 Apr 2007 17:14:06 -0500 (CDT) From: Sergey Babkin X-Originating-IP: [208.253.138.194] To: Alfred Perlstein , hackers@freebsd.org, bde@freebsd.org Message-id: <13342342.1865051177020847028.JavaMail.root@vms071.mailsrvcs.net> MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1 Content-transfer-encoding: 7bit X-Mailman-Approved-At: Fri, 20 Apr 2007 00:17:46 +0000 Cc: Subject: Re: serial help ? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: babkin@users.sf.net List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Apr 2007 22:14:11 -0000 > >I'm working on some custom hardware and I'm getting garbled console >output. > >I noticed that siocntxwait looks like this: > >static void >siocntxwait(iobase) > Port_t iobase; >{ > int timo; > > /* > * Wait for any pending transmission to finish. Required to avoid > * the UART lockup bug when the speed is changed, and for normal > * transmits. > */ > timo = 100000; > while ((inb(iobase + com_lsr) & (LSR_TSRE | LSR_TXRDY)) > != (LSR_TSRE | LSR_TXRDY) && --timo != 0) > ; >} > >Shouldn't there be some sort of DELAY in there? > >My platform has an emulated serial device in hardware, so it >may be that the loop could run a LOT faster than transmit can >happen... > >any ideas of what the DELAY should be? I would do something like delay(1) in the loop after this one. The idea being that if the output buffer is empty os nearly empty, the first loop will exit quickly and skip the second one. Otherwise it would go into the slow loop with delay(). Then for the 2nd loop count limit I guess take the size of the hardware buffer, multiply by 10 (8 data bits + 2 start/stop), add a little for safety and divide the bit rate by that, and then divide the length of delay(1) by that. Or however long it takes for your device to transmit. If the actual transmission happens faster, it will set the TXRDY bit and the loop will complete faster. -SB