Using setserialto Optimize RS232 Serial Performance

RS-232 serial ports are general-purpose communication ports; in theory, you could design any number of devices to use these ports. In practice, though, they're limited by slow speed—115,200bps on standard hardware, although some designs can manage twice or more of that value. This speed compares to 12Mbps (12,000,000bps) for USB 1 .x or 480Mbps for USB 2.0. For this reason, RS-232 is used only by relatively low-speed peripherals. Common RS-232 devices include external telephone modems, low-speed text-only dumb terminals, mice, and digital cameras. It is possible to link two computers via their RS-232 serial ports using the Point-to-Point Protocol (PPP) or Serial Line Interface Protocol (SLIP), but this application is very rare.

Note Older internal modems typically included both modem and RS-232 circuitry on one circuit board. These modems are indistinguishable from regular RS-232 serial ports from a software point of view. Most newer internal modems are so-called WinModems or software modems. These modems don't include serial port hardware and require special drivers to function in Linux. Check http://www.linmodems.org for information on such modems.

Most programs that use the RS-232 serial port, such as gPhoto when it communicates with an RS-232-interfaced camera or pppd for initiating dial-up modem connections to an ISP, provide tools to set the speed of the RS-232 serial port, as well as other relevant options. Sometimes, though, it's necessary to set RS-232 serial port options before launching a communication program or to do so at boot time. You can do this using the setserial program, which reads and writes RS-232 serial port parameters. You pass one or more parameters to this program, as well as the device filename of the interface; for instance, to obtain a listing of the current RS-232 serial port parameters, you would type:

$ setserial -a /dev/ttySO

/dev/ttySO, Line 0, UART: 16550A, Port: 0x03f8, IRQ: 4 Baud_base: 115200, close_delay: 50, divisor: 0 closing_wait: 3000 Flags: spd_normal skip_test

The -a option tells the program to display all the device's information. The universal asynchronous receiver/transmitter (UART) is the core of the RS-232 serial port. Most UARTs today are 16550A models, but others exist. If setserial reports that your system has a 16450, or especially an 8250, then either the system has erred in detecting your hardware or you have a truly ancient RS-232 serial port. Such old ports may not function well at speeds above 38,400bps, so you should probably replace the hardware.

If you want to change an RS-232 serial port's parameters, you can do so by following the device identifier (such as /dev/ttySO for the first port) with options such as the following:

port port-number This option changes the hardware port associated with the device identifier. The port-number is typically expressed as a hexadecimal value, such as 0x03f8.

irq irq-number You can assign the interrupt request (IRQ) line used by a device using this option.

uart uart-type If the system has misidentified the UART, you can correct the matter with this option. Legal uart-type values are 8250, 16450, 16550, 16550A, 16650, 16650V2, 16654, 16750, 16850, 16950, and 16954. Specifying none disables the port.

autoconfig This parameter tells the kernel to try to determine the RS-232 serial port type. This option requires you to also use the port option.

skip_test Use this parameter in conjunction with autoconfig to tell the system to skip the UART detection test, which can cause problems with some brands of UART.

baud_base rate You can set the RS-232 serial port's speed, in bits per second, to the specified rate with this option.

These options are just a sample of those available. If you're using a very timing-critical RS-232 serial port application (say, a scientific data acquisition tool), you may want to read the setserial man page to study the many options that can influence RS-232 serial port performance. For the most part, none of these options are required. You're most likely to need to use these options with some inexpensive internal modems, which may use oddball UARTs that aren't auto-detected correctly; or with unusual multiport RS-232 serial cards, which support more than four ports. (Linux tries to auto-configure just the first four RS-232 serial ports.)

A typical motherboard ships with two RS-232 serial ports, but sometimes you may need more than this—for instance, if you're running an ISP's modem dial-in bank. In these cases, you probably want to purchase a dedicated multiport RS-232 card. These devices are unusual pieces of equipment that require special drivers, so check for Linux driver availability before buying. If you add an internal ISA bus modem that hosts its own RS-232 serial hardware, you may run into a problem: Traditionally, the first two RS-232 serial ports use IRQs 4 and 3. Many internal modems come preconfigured as the third RS-232 serial port and attempt to "share" IRQ 4. This configuration may not work well in Linux, though, because interrupt sharing of ISA devices is a tricky proposition at best. Therefore, if you add an internal modem, your best bet is to disable one of the two standard RS-232 serial ports and reconfigure the modem to assume its identity. This way, there's no conflict over the IRQ. Alternatively, leave the modem configured to be the third RS-232 serial port (/dev/ttyS2 in Linux), but configure it to use an IRQ that no other device claims. Type cat /proc/interrupts after you've booted to obtain a list of interrupts—but be aware that this list will omit interrupts that aren't in use because the driver hasn't been loaded, such as a floppy port if you've not used the floppy disk recently. Similarly, you can configure the modem on the standard first or second port's settings and reconfigure the displaced motherboard port as the third port.

0 0

Post a comment