The data exchange between CPU, memory and external devices needs to be realized by interface devices. The former is called memory interface, while the latter is called I / O interface. Generally speaking, interface refers to I / O interface.
Memory usually works under the synchronous control of CPU, and the interface circuit is relatively simple. In the previous chapter, we have learned its connection method; There are many kinds of I / O devices, such as keyboard, LED digital tube, a / D and D / a converter, and their corresponding interface circuits are also different.
Classification of interfaces
The function of I / O interface is to connect the I / O circuit and peripheral equipment by CPU through system bus.
According to the complexity of circuit and equipment, I / O interface hardware can be divided into two categories
1. I / O interface chip
These chips are mostly integrated circuits, which input different commands and parameters through CPU, and control related I / O circuits and simple peripherals for corresponding operation. Common interface chips such as timer / counter, interrupt controller, DMA controller, parallel interface, etc.
2. I / O interface control card
A number of integrated circuits are formed into a component according to certain logic, either directly with the CPU on the motherboard, or a plug-in is inserted in the system bus slot.
According to the connection object of interface, they can be divided into serial interface, parallel interface, keyboard interface and disk interface.
Function of interface
Because there are many kinds of peripheral equipment of computer, almost all of them use electromechanical transmission equipment. Therefore, the following problems often exist in the data exchange between CPU and I / O equipment
1. Speed mismatch: the working speed of I / O devices is much slower than that of CPU, and due to different types, the speed difference between them is also very big, for example, the transmission speed of hard disk is much faster than that of printer.
2. Timing mismatch: each I / O device has its own timing control circuit to transmit data at its own speed, which cannot be unified with CPU timing.
3. Information format mismatch: different I / O devices store and process information in different formats, such as serial and parallel; It can also be divided into binary format, acsii coding and BCD coding.
4. Information type mismatch: different I / O devices use different signal types, such as some digital signals and some analog signals.
For the above reasons, the data exchange between CPU and peripherals must be completed through the interface. Therefore, the interface usually has the following functions:
The interface is usually composed of some registers or RAM chips. If the chip is large enough, batch data transmission can be realized;
It can convert information format, such as serial and parallel conversion;
It can coordinate the difference of information type and level between CPU and peripherals, such as level conversion driver, D / A or a / D conversion, etc;
Coordination of timing differences;
Address decoding and device selection function;
Interrupt and DMA control logic are set to ensure that interrupt and DMA request signals are generated when interrupt and DMA are allowed, and interrupt processing and DMA transmission are completed after receiving interrupt and DMA response.
Interface control mode
There are several ways for CPU to control external devices through interface
1. Program query mode
In this way, the CPU queries the current state of the specified peripheral through I / O instructions. If the peripheral is ready, it will input or output data. Otherwise, the CPU will wait and cycle to query.
The advantage of this method is that it has a simple structure and only needs a small amount of hardware circuit. The disadvantage is that the CPU speed is much higher than the peripheral, so it is usually in the waiting state and the work efficiency is very low.
2. Interrupt handling mode
In this way, the CPU can no longer wait passively, but can execute other programs. Once the peripheral is ready for data exchange, it can make a service request to the CPU. If the CPU responds to the request, it will temporarily stop the execution of the current program, go to the service program corresponding to the request, and then continue to execute the original interrupted program.
The advantage of interrupt processing is obvious. It not only saves CPU the time of querying peripheral status and waiting for peripheral ready, improves CPU efficiency, but also meets the real-time requirements of peripheral. But each I / O device needs to be assigned an interrupt request number and corresponding interrupt service program. In addition, an interrupt controller (I / O interface chip) is also needed to manage the interrupt requests put forward by I / O devices, such as setting interrupt mask and interrupt request priority.
In addition, the disadvantage of the interrupt processing method is that every character transmitted needs to be interrupted, the interrupt controller should be started, and the scene should be retained and restored so as to continue the execution of the original program, which costs a lot of work. If a lot of data exchange is needed, the performance of the system will be very low.
3. DMA (direct memory access) transfer mode
One of the most obvious characteristics of DMA is that it uses a special controller to control the data exchange between memory and peripherals instead of software, which greatly improves the CPU efficiency without CPU intervention.
Before DMA data transfer, DMA controller will apply for bus control right from CPU. If CPU allows, it will hand over the control right. Therefore, in data exchange, the bus control right is controlled by DMA controller. After the transmission, DMA controller returns the bus control right to CPU.