From owner-freebsd-hackers Thu Feb 28 10:20:22 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from rwcrmhc54.attbi.com (rwcrmhc54.attbi.com [216.148.227.87]) by hub.freebsd.org (Postfix) with ESMTP id 52A6937B41C for ; Thu, 28 Feb 2002 10:20:13 -0800 (PST) Received: from InterJet.elischer.org ([12.232.206.8]) by rwcrmhc54.attbi.com (InterMail vM.4.01.03.27 201-229-121-127-20010626) with ESMTP id <20020228182012.BQFI1214.rwcrmhc54.attbi.com@InterJet.elischer.org>; Thu, 28 Feb 2002 18:20:12 +0000 Received: from localhost (localhost.elischer.org [127.0.0.1]) by InterJet.elischer.org (8.9.1a/8.9.1) with ESMTP id KAA06552; Thu, 28 Feb 2002 10:00:14 -0800 (PST) Date: Thu, 28 Feb 2002 10:00:06 -0800 (PST) From: Julian Elischer To: Luuk van Dijk Cc: freebsd-hackers@freebsd.org Subject: Re: arbitrary serial speeds In-Reply-To: <3C7E3B9B.1BACD9AC@mndmttr.nl> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG I had changes to do this BDE refused to commit them. On Thu, 28 Feb 2002, Luuk van Dijk wrote: > This is a multi-part message in MIME format. > --------------17932B47B695003DFEDACE26 > Content-Type: text/plain; charset=us-ascii > Content-Transfer-Encoding: 7bit > > L.S. > > for a project in which I communicate with embedded controllers in cars I > need to read and write serial data at weird speeds of 5 and 10400 baud. > > the beauty of the freebsd interface to the serial ports is that the > speed > can be specified as an integer, i.e. not neccesarily as some predefined > constant > like B9600, but in src/sys/isa/sio.c the supplied value is looked up in > a table, > so using an arbitrary baudrate like 5 will return EINVAL. > > (On linux there is an ugly way to set these weird baud rates by setting > the > baudrate to 38400, and using a special syscall to tell the kernel to use > some other divisor of 115200 to generate the uart speed. needless to > say, I prefer > the hygiene commonly observed in bsd's api's) > > an easy way would be to add my special baudrates to the table > 'comspeedtab' > that maps speed to divisor, but it is even more flexible to calculate > the divisor > on the spot, with the same macro COMBRD() as used in the initializer of > 'comspeedtab'; > note that this macro will automatically round to the next higher > baudrate that is > a divisor of 115200. > > The attached patch contains the neccesary changes. It works well for > me, > but who knows what I broke.... > > As far as I can tell, this renders the comspeedtab table, as well as the > routine ttspeedtab in kern/tty.c superfluous, but as I'm not sure I > haven't > included their removal in the patch. > > Whoever maintains isa/sio.c, feel free to use this. I'd be very happy > if > in future versions of FreeBSD I could use baudrates of 5 and 10400 > (actually the > latter is rounded to 10475 == 115200/11, but that's good enough for me), > without > recompiling. > > Regards, > Luuk van Dijk > > ___________________________________________________ > Mind over Matter lvd at mndmttr.nl > The Netherlands tel +31 6 224 97 227 > ___________________________________________________ > --------------17932B47B695003DFEDACE26 > Content-Type: text/plain; charset=us-ascii; > name="freebsd-src-sys-isa-sio-arbitrary-speed.patch" > Content-Transfer-Encoding: 7bit > Content-Disposition: inline; > filename="freebsd-src-sys-isa-sio-arbitrary-speed.patch" > > --- isa.org/sio.c Wed Feb 6 23:58:00 2002 > +++ isa/sio.c Thu Feb 7 00:08:25 2002 > @@ -2153,7 +2153,7 @@ > t->c_ispeed = t->c_ospeed; > > /* check requested parameters */ > - divisor = ttspeedtab(t->c_ospeed, comspeedtab); > + divisor = (t->c_ospeed) ? COMBRD(t->c_ospeed) : 0; /* was ttspeedtab(t->c_ospeed, comspeedtab); lvd */ > if (divisor < 0 || (divisor > 0 && t->c_ispeed != t->c_ospeed)) > return (EINVAL); > > @@ -2794,7 +2794,7 @@ > * data input register. This also reduces the effects of the > * UMC8669F bug. > */ > - divisor = ttspeedtab(speed, comspeedtab); > + divisor = (speed) ? COMBRD(speed) : 0; /* was ttspeedtab(speed, comspeedtab); lvd */ > dlbl = divisor & 0xFF; > if (sp->dlbl != dlbl) > outb(iobase + com_dlbl, dlbl); > > --------------17932B47B695003DFEDACE26-- > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-hackers" in the body of the message > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message