User guide

68
6000 Series Programmer's Guide
Interrupt-Driven Terminal Emulator
MC6ØTRMI.EXE is an interrupt-driven terminal emulator for the AT6nnn that is provided
(along with source code) on the AT6nnn DOS Support Disk. This software, written in
Microsoft C 6.0, shows how to exploit three of the four available AT6nnn interrupts.
AT6nnn output-buffer-has-data interrupt
AT6nnn input-buffer-is-empty interrupt
AT6nnn general purpose interrupt (see INTHW command)
The file MC6ØTRMI.C contains the background polling loop, and the file MC6ØLIBI.C
contains the AT6nnn interrupt driver. The AT6nnn status-update interrupt is not used in
MC6ØTRMI.
The background polling loop (Emulate()) continually checks for keyboard input, AT6nnn
response data, and the general-purpose interrupt flag. Keyboard data is sent to the AT6nnn
upon receipt of a carriage return. AT6nnn response data and AT6nnn general-purpose
interrupts are displayed on the screen.
The AT6nnn interrupt driver consists of the ISR (AT6nnn_isr()) and additional ring buffer
and interrupt vector management functions.
Ring Buffers
To facilitate interrupt-driven communications, ring buffers (or circular buffers) are used as the
interface between background and foreground processing. A ring buffer is needed because data
is coming into the buffer at a different rate than it is going out. This is due to the background
polling rate being different than the rate at which the PC-AT is being interrupted.
A ring buffer is nothing more than a data structure with three components: a buffer, a head
pointer, and a tail pointer. The head pointer points to the next buffer position that you can
put data into. The tail pointer points to the oldest data item in the buffer.
When the head and tail pointers are equal, the ring buffer is empty. The ring buffer is full if
the addition of another data item would make the head and tail pointers equal. When either the
head or tail pointer goes beyond the end of the buffer, it wraps to the beginning of the buffer
(thus the name, ring buffer).
The illustration below shows a 24-byte ring buffer containing the command TSTAT. Notice
that the command starts in position 22, wraps around to 0 and continues until it is complete.
T A T T S
0 1 2 3 4 20 21 22 235
Head Tail
The AT6nnn interrupt driver in MC60LIBI.C maintains two ring buffers: an input ring
buffer and an output ring buffer.
Input Ring Buffer:
When the AT6nnn has response data, an interrupt is generated and the interrupt
service routine stuffs the response data into an input ring buffer. If the input ring
buffer becomes full, the interrupt service routine will turn off the AT6nnn output-
buffer-has-data interrupt.
The background polling loop fetches the AT6nnn response data from the input ring
buffer, displays the data on the screen, and re-enables the AT6nnn output-buffer-has-
data interrupt if it was previously disabled.
Output Ring Buffer:
When the background polling loop has command data to send to the AT6nnn, it
stuffs the command data into an output ring buffer and enables the AT6nnn input-
buffer-is-empty interrupt.
Once the AT6nnn input buffer is empty, an interrupt is generated and the interrupt
service routine fetches the command data from the output ring buffer, sends the data
to the AT6nnn, and disables the AT6nnn input-buffer-is-empty interrupt.