From owner-freebsd-hackers Thu Feb 28 6:27:58 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from smtpzilla3.xs4all.nl (smtpzilla3.xs4all.nl [194.109.127.139]) by hub.freebsd.org (Postfix) with ESMTP id 8D82C37B405 for ; Thu, 28 Feb 2002 06:27:54 -0800 (PST) Received: from list1.xs4all.nl (list1.xs4all.nl [194.109.6.52]) by smtpzilla3.xs4all.nl (8.12.0/8.12.0) with ESMTP id g1SERrRw059180 for ; Thu, 28 Feb 2002 15:27:53 +0100 (CET) Received: (from root@localhost) by list1.xs4all.nl (8.9.3/8.9.3) id PAA05412; Thu, 28 Feb 2002 15:27:51 +0100 (CET) From: Luuk van Dijk To: freebsd-hackers@freebsd.org X-Via: imploder /usr/local/lib/mail/news2mail/news2mail at list1.xs4all.nl Subject: arbitrary serial speeds Date: Thu, 28 Feb 2002 15:15:55 +0100 Organization: XS4ALL Internet BV Message-ID: <3C7E3B9B.1BACD9AC@mndmttr.nl> 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 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