Delta Tau GEO BRICK LV ユーザーズマニュアル
Turbo PMAC User Manual
Writing a Host Communications Program
385
Serial Port Communications
When communicating to the Turbo PMAC through either its main or auxiliary serial ports, you typically
use one of the COM ports in the host computer. In a standard, these are usually the built-in COM1 and
COM2 RS-232 ports, but they can be on expansion ports as well. Most COM ports, even on other types
of computers, use the same ICs, so they usually have the same registers on the host side.
use one of the COM ports in the host computer. In a standard, these are usually the built-in COM1 and
COM2 RS-232 ports, but they can be on expansion ports as well. Most COM ports, even on other types
of computers, use the same ICs, so they usually have the same registers on the host side.
Setting Up the Interface
Every time the system is started up, the serial port of the host computer must be initialized to interface
properly with the settings of the Turbo PMAC. This is done with some simple byte-write commands to
the I/O space of the computer.
properly with the settings of the Turbo PMAC. This is done with some simple byte-write commands to
the I/O space of the computer.
Base Address
The first thing you must know is the base address of the COM port in the computer's I/O space. In a
standard PC, the COM1 port base address is at 3F8 hex (1016 decimal), and the COM2 port is at 2F8 hex
(760 decimal).
standard PC, the COM1 port base address is at 3F8 hex (1016 decimal), and the COM2 port is at 2F8 hex
(760 decimal).
Baud Rate
You must set up the baud rate counter in the host computer to match Turbo PMAC’s baud rate, which is
determined by the saved value of I54 for the main serial port, and I53 for the auxiliary port. The baud
rate counter in the host computer must be given a value equal to 115,200 divided by the baud rate (e.g. for
9600 baud, the value is 115,200/9600 = 12). The following program segment illustrates how this can be
done:
determined by the saved value of I54 for the main serial port, and I53 for the auxiliary port. The baud
rate counter in the host computer must be given a value equal to 115,200 divided by the baud rate (e.g. for
9600 baud, the value is 115,200/9600 = 12). The following program segment illustrates how this can be
done:
outportb (combase + 3, 131);
/* Put COM port in setup mode */
baud_count = 115200/baud;
/* Calculate counter value */
outportb (combase, baud_count);
/* Write to low byte of counter */
outportb (combase + 1, baud_count/256);
/* Write to high byte of counter */
outportb (combase + 3, 3);
/* Put COM port back in normal mode */
/* with 8 bits, 1 stop bit */
The command outportb is a byte-write command; combase is the base address; baud is the baud rate in
bits per second.
bits per second.
It is a good idea in the initial set up to compute a timeout value, related to both the baud rate and the host
computer’s speed. As the host polls Turbo PMAC to see if it is ready to communicate, a counter
increments. If the counter exceeds the timeout value, the host should give up on this attempt to talk to
Turbo PMAC. Depending on the circumstances, it should either just try again later (as when waiting for
some asynchronous communications) or assume there is an error condition.
computer’s speed. As the host polls Turbo PMAC to see if it is ready to communicate, a counter
increments. If the counter exceeds the timeout value, the host should give up on this attempt to talk to
Turbo PMAC. Depending on the circumstances, it should either just try again later (as when waiting for
some asynchronous communications) or assume there is an error condition.
Sending a Character
In polled communications, the host must see two status bits (write-ready bits) in the serial interface
registers become 1 before it may write a character to the serial output port. These two bits are Bit 5 of
{base + 5}, and Bit 4 of {Base +6}. A sample C code segment to do this is:
registers become 1 before it may write a character to the serial output port. These two bits are Bit 5 of
{base + 5}, and Bit 4 of {Base +6}. A sample C code segment to do this is:
i = 0;
/* Reset counter */
while (i++<timeout && (inportb(combase+5)&32==0);
/* Loop until bit true */
while (i++<timeout && (inportb(combase+6)&16==0);
/* Loop until bit true */
if (i < timeout) outportb(combase, outchar);
/* Send char. unless timed out */
Sending an entire line simply involves repeated calls to this routine, with a different outchar each time.
Reading a Character
To read a character from the serial port, the host must prepare the port to read (it may want to do this for
and entire line), then poll a status bit (read-ready bit) in a serial interface register; when this becomes 1,
the character may be read. A sample C code segment to do this is:
and entire line), then poll a status bit (read-ready bit) in a serial interface register; when this becomes 1,
the character may be read. A sample C code segment to do this is: