Device communication
Buffers, Polling, Interrupts, Handshaking and checksums.
The problem:
From a computer's point of view, peripheral devices (those devices that are not part of the central processing unit) are rather strange and unreliable. A printer is a good example. By computer standards it's terribly slow and very stupid. It's constantly needing attention - when it runs out of paper or ink, and it has a very small amount of internal storage. Sending a print job to a printer therefore requires the computer to break the data up into small chunks and feed them to the printer slowly, giving it time to process and print the result. |
Buffers
One solution is to use a print buffer. A buffer is an area of main computer memory that is set aside to handle the printer. The processor can output all of the print information quickly to the print buffer, where it is stored until the printer can accept it. A small process handles the slow feeding out of data from the buffer to the printer.
This allows the processor to get on with other tasks. However the little process handling the buffer still has a problem. How does it know whether or not the printer is ready to accept data from the buffer? |
Polling
One way of finding out the status of a device, for example to find out if a printer is ready to receive more data from the print buffer, is to ask.
In this method, called 'polling', the computer constantly interrogates the device to check on its status. This method means that the computer is doing a lot of work. When printing, most of the time, the printer will not be ready, so the computer receives a busy signal. The computer has to back-off and try again. |
Interrupts
A better way is to give the peripheral device a voice. In this case the device can send some simple signals back to the computer, indicating its status. These messages are handled by the 'Interrupt' mechanism in the CPU. This mechanism allows any process or device to request attention. The CPU will stop whatever it is doing and pay attention to the message or code that is attached to the interrupt request.
The interrupt mechanism is an important part of the deep workings of the CPU and allows it to respond to events in the outside world. |
Handshaking
Whatever system is used, both the computer and the peripheral need to establish some rules for communication before they begin. That process is know as 'Handshaking'.
The rules for communication are called a 'Protocol' and the protocol establishes the system for setting up a conversation, exchanging data, alerting to problems and bringing the conversation to a close. |
Checksums
When any information is sent across a wire or stored in memory, there's always the possibility that data will be lost or corrupted in the process.
To make sure that this is detected, most communications protocols (sets of rules) use a checksum process. A checksum is a mathematical summary of all the data - the simplest way would be to convert every character to a number and add them all up. The result, the checksum, is then sent with the data. There are many much more sophisticated methods, but they all work in the same way. The receiving device can then perform the same calculation and see if the checksums match. If they don't there could be a number of reasons, but it's best to ask for the data to be sent again, since there's clearly something wrong. |