Tài liệu Chapter-19-Serial communications - Pdf 84

2Apr il 2003, 17:00:47 The Complete FreeBSD (modems.mm), page 325
19
Serial
communications
In this chapter:
• Terminology
• Asynchronous and
synchronous
communication
• Ser ial por ts
• Modems
• Modem commands
In this chapter:
• Terminology
• Asynchronous and
synchronous
communication
• Ser ial por ts
• Modems
• Modem commands
UNIX has always had a high levelofsupport for serial lines, but their purpose has
changed dramatically.Inthe early 70s, the standard ‘‘terminal’’was a Teletype KSR35, a
10-character-per-second serial printer with keyboard. Early UNIX serial line support was
geared towards supporting these devices, either directly connected, or via a modem.
Even in the early 80s, when 4.2BSD introduced network support, things didn’tchange
much: the network support used different hardware. By this time, the Teletypes had been
replaced with glass ttys, in other words serial terminals with a monitor instead of a
printer.The speeds had gone up from the 110 bps of the Teletype to 9600 bps, but the
underlying principles hadn’tchanged.
It wasn’tuntil the last 10 years that the glass ttys were replaced by display boards directly
connected to the system bus, or by other machines connected by Ethernet. The role of the

so theywould typically print one character at a time, stop, and wait for the next. In the
early days of UNIX, the standard terminal was a Teletype model KSR35, commonly just
called teletype or tty (pronounced ‘‘titty’’).
Here’sapicture of a typical byte encoding:
StartParity
1
D7
1
D6
1
D5
0
D4
1
D3
0
D2
1
D1
1
D0
0
Stop Stop
Bit 1 Bit 2
Figure19-1: Asynchronous byte encoding
This figure shows an encoding for the letter j,inbinary 01101011.We’ll see a number
of things about it:
modems.mm,v v4.10 (2003/04/02 03:11:02)
327 Chapter 19: Serial communications
2April 2003, 17:00:47 The Complete FreeBSD (modems.mm), page 327

the bits in the data.
All modern modems use synchronous communication on the phone line, because it is
more efficient, and it’sthe basis of protocols such as SNAand X.25, but you will almost
neversee anyother use of it in UNIX systems.
modems.mm,v v4.10 (2003/04/02 03:11:02)
Asynchronous and synchronous communication 328
2April 2003, 17:00:47 The Complete FreeBSD (modems.mm), page 328
Serial ports
Nowadays, all PCs come equipped with twoserial ports, which are called COM1: and
COM2: in the DOS world. UNIX names are different, and FreeBSD calls these same
devices sio0 and sio1.It’spossible to connect up to four direct serial ports on a
standard PC, but due to the design of the board, each one requires a separate IRQ line. If
you put twoserial ports on the same interrupt line, neither of them will work.
The first twodevices, sio0 and sio1,normally use the default IRQs 4 and 3. By default,
however, PCmanufacturers put COM3: and COM4: also at IRQs 4 and 3. Howcan this
work? It can’t, if you also have COM1: and COM2: enabled at those IRQs. However,
DOS tends to do only one thing at a time, so you can use different ports at different times
on the same IRQ, as long as the interrupts aren’tenabled on more than one of the ports at
atime. This restriction is unacceptable for UNIX, so we have toput them somewhere
else. The only unused interrupt available to 8-bit boards is IRQ 5, originally intended for
asecond parallel printer port.
There’savery good chance that IRQ 5 will already be occupied. What can you do? If
one of the boards has a 16-bit or better interface, you can check if one of the interrupts 10
to 15 is available. All EISA and PCI boards fit into this category,and so do ISA boards
with twoconnectors to the motherboard. Unfortunately,alot of ISA serial cards only
have an8-bit interface. The only alternative isanintelligent serial board that only
occupies a single interrupt. In this case, you will probably have tobuild a custom kernel.
See the man page sio(4).
Connecting to the port
Theoretically,aserial line can consist of only three wires: a Receive Data line, often

and has passed self-test. On some modems, PW indicates
that power is on, and MR indicates that it is operative.
SG 7 Signal ground. Return for the other signals.
DCD 8 CD M5 Carrier detect. Indicates that the modem has connection
with another modem.
DTR 20 DTR S1 Data terminal ready.Indicates that the terminal or
computer is ready to talk to the modem.
RI 22 AA Ring indicator.Raised by a modem to indicate that an
incoming call is ringing. The AA indicator on a modem will
usually flash when the incoming call is ringing.
AA ‘‘Auto Answer.’’Indicates that the modem will answer an
incoming call.
HS ‘‘High Speed.’’ Indicates that the modem is running at a
higher speed than its minimum. Individual modems
interpret this differently,but you can assume that something
is wrong if your modem has this indicator and it’soff
during transmission.
MNP Indicates that error correction is active.
OH ‘‘Offhook.’’ Indicates that the modem has some
connection with the phone line.
PW Indicates that modem power is on. May or may not imply
DSR.
The line DCD tells the DTE that the modem has established a connection. We’lllook at
howtouse this information on page 335.
In addition to these signals, synchronous modems supply clocks on pins 17 and 19. For
more details about RS-232, see RS-232 Made easy by Martin Seyer.
modems.mm,v v4.10 (2003/04/02 03:11:02)
Ser ial por ts 330
2April 2003, 17:00:47 The Complete FreeBSD (modems.mm), page 330
When can I send data?

• The connection from the ISP’smodem to his router,at115,200 bits per second.
You’ll also note another value specified here: the connection between the modems is
2,400 baud. Isn’tabaud the same thing as a bit per second? No, not always. The term
baud is a representation of the frequencyofdata on a serial line. On the connections
between the systems and the modem, which handle rawdigital data, it corresponds to the
bit rate. On the modem line, it doesn’t. Here, it indicates that 2,400 units of data are sent
per second.
modems.mm,v v4.10 (2003/04/02 03:11:02)


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status