Date: Thu, 28 Feb 2002 15:15:55 +0100 From: Luuk van Dijk <lvd@mndmttr.nl> To: freebsd-hackers@freebsd.org Subject: arbitrary serial speeds Message-ID: <3C7E3B9B.1BACD9AC@mndmttr.nl>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3C7E3B9B.1BACD9AC>