Some Hardware: The Parallel Port

< BACK  NEXT >
[oR]

Before walking through an example of a programmed I/O driver, it is helpful to look at some actual hardware. This serves the dual purpose of showing what kinds of devices tend to perform programmed I/O and providing a hardware example for the minimal driver to control.

How the Parallel Port Works

The parallel interface found on most PCs is based on an ancient standard from the Centronics Company. Although its original purpose was to communicate with printers, clever people have found many ways of attaching everything from disks to optical scanners to the parallel port. The DB-25 connector on this port carries a number of signals, the most important ones being

  • RESET.

    The CPU sends a pulse down this line when it wants to initialize the printer.

  • DATA.

    The CPU uses these eight lines to send one byte of data to the printer. On systems with extended parallel interfaces, these lines can also be used for input.

  • STROBE#.

    The CPU pulses this line to let the printer know that valid information is available on the data lines. (The sharp character signifies an inverted signal. A valid pulse is sent by transitioning the line from a logical 1 to 0.)

  • BUSY.

    The printer uses this line to let the CPU know that it can't accept any data.

  • ACK#.

    The printer sends a single pulse down this line when it is no longer busy.

  • Errors.

    The printer can use several lines to indicate a variety of not-ready and error conditions to the CPU.

The following sequence of events occurs during a data transfer from the CPU to a printer attached to the parallel port:

  1. The CPU places a byte on the eight data lines and lets the data settle for at least half a microsecond.

  2. The CPU grounds the STROBE# line for at least half a microsecond and then raises it again. This is the signal to the printer that it should latch the byte on the data lines.

  3. In response to the new data, the printer raises the BUSY line and starts to process the byte. This usually means moving the byte to an internal buffer.

  4. After it processes the character (which may take microseconds or seconds, depending on how full the printer's buffer is), the printer lowers the BUSY line and pulses the ACK# line.

As is apparent from this description, the parallel port offers a very low-level interface to the outside world. Most of the signaling protocol involved in a data transfer has to be implemented by the CPU itself. A driver for a legacy parallel port must be designed for this primitive operation.

Device Registers

The software interface to the parallel port is through a set of three registers, described in Table 8.8. Since the parallel port is one of the things detected by autoconfiguration (even on an ISA system), the driver is able to use the Configuration Manager to find the base address of the data register.

Table 8.8. Parallel Port Register Usage
Parallel Port Registers
Offset Register Access Description
0 Data R/W Data bits
1 Status R Port status
Bits 0-1 Reserved
Bit 2 0 Interrupt requested
Bit 3 0 Error occurred
Bit 4 1 Printer selected
Bit 5 1 Out of paper
Bit 6 0 Acknowledge
Bit 7 0 Printer busy
2 Control R/W Commands to port
Bit 0 1 Strobe data
Bit 1 1 Auto linefeed
Bit 2 0 Reset printer
Bit 3 1 Select printer
Bit 4 1 Enable interrupts
Bit 5 1 Read data from port
Bits 6-7 Reserved; must be 1

Interrupt Behavior

Traditionally, the parallel port designated as LPT1 is assigned IRQ 7, and LPT2 is assigned IRQ 5. A device connected to a parallel port generates an interrupt by momentarily forcing the ACK# to zero. Real printers force an interrupt for any of the following reasons:

  • The printer has finished initializing.

  • The printer has processed one character and is now ready for another.

  • Power to the printer has been switched off.

  • The printer has gone offline or has run out of paper.

Driving real printers requires considerable experimentation with the real device. In fact, it is not the purpose of the driver example in this chapter to drive a real peripheral device. Instead, the example is intended to demonstrate the use of interrupts and programmed I/O in a generic way.

A Loopback Connector for the Parallel Port

For the purposes of this example driver, it is suggested that a special loopback cable be created or purchased for the parallel port. The loopback connector precludes the need to connect to a real printer, and therefore eliminates the need to adjust the example code to the idiosyncrasies of different printers.

The example code assumes a parallel port loopback connector wired according to the TouchStone CheckIt specification. The loopback connector wiring is shown in Table 8.9.

Table 8.9. Parallel Port Loopback Connector
Parallel Port Loopback Connector
Signal Out DB-25 Pin Connects To Signal In To Write To Read
Strobe# 1 13 Select Control-0 Status-4
Data 0 2 15 Error Data-0 Status-3
Autofeed 14 12 Paper Out Control-1 Status-5
Reset 16 10 Acknowledge Control-2 Status-6
Select 17 11 Busy Control-3 Status-7

The loopback connector can be purchased directly from Touchstone or can be self-made from a simple DB-25 connector.

< BACK  NEXT >


The Windows 2000 Device Driver Book(c) A Guide for Programmers
The Windows 2000 Device Driver Book: A Guide for Programmers (2nd Edition)
ISBN: 0130204315
EAN: 2147483647
Year: 2000
Pages: 156

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net