Classic Computer Magazine Archive COMPUTE! ISSUE 150 / MARCH 1993 / PAGE 60

Interrupts made easy. (part 2) (Column)
by Mark Minasi

Last month, we started looking into what interrupts are and why they're important. This month, we'll look more closely at interrupts.

For those just joining us, I explained last month that an interrupt is a means whereby an input/output device on a PC gets the attention of the PC's CPU so that the input/output device can direct the CPU to move some data around.

For example, the keyboard controller on your PC must get the attention of the CPU every time you press a key on your keyboard. It has to do that because the keyboard controller has only enough storage to hold onto one keystroke. If the CPU doesn't handle the keystroke in the controller quickly, it may become overwritten by a newer keystroke, losing the original keystroke forever. I explained that on some systems the keyboard controller can't force the CPU to pay attention to it; instead, it must wait for the CPU to periodically the keyboard controller can't force the CPU to pay attention can't force the CPU to pay attention to it; instead, it must wait for the CPU to periodically ask the keyboard controller if the controller has a keystroke. Such a process, where the CPU checks the controller regularly, is called polling, and it's used in lieu of interrupts in some applications.

I then discussed how the interrupt on the printer port greatly affects whether or not your system can print under Windows and OS/2. Additionally, I explained that putting more than one device on the same interrupt will generally cause both devices to fail.

This month, we'll pick up where we left off, with a discussion of how you can avoid those interrupt conflicts. That'll lead to a discussion of interrupt priorities.

Suppose that you're going to insert a new circuit board in your PC; let's say it's a Sound Blaster Pro (SBPro) from Creative Labs. You want to avoid the evils of interrupt conflicts, so what should you do? Not all add-in cards need an interrupt, so there may be nothing to worry about. The first order of business, then, is to check the documentation that came with the board to find out if an interrupt will be needed.

The SBPro is a well-documented board (thanks, Creative), and one of the first items discussed is how to insert the board and test it with the included diagnostic software. The documentation tells you that the SBPro does, indeed, need an interrupt channel (as well as an input/output address range and a Direct Memory Access, or DMA, channel, but that's a discussion for another day). The SBPro is a 16-bit board and, as such, could in theory be designed to use any interrupt between IRQ2 and IRQ 15. (Recall that interrupts are called IRQs and that a 16-bit card has access to interrupts numbered 2 through 15. IRQ0 and IRQ1 aren't available via the bus slots because they're already used by the timer and the keyboard, respectively.) The SBPro offers the option of using IRQ2, IRQ5, IRQ7, or IRQ10; it comes from the factory set for IRQ7.

Now, it just won't do to leave the interrupt at IRQ7, as that interrupt is reserved, as you learned last month, for LPT1, the primary parallel port. Leaving the SBPro at IRQ7 could cause problems for printing. The worst of it is that the printer port conflict usually won't show up immediately. I often see a message on the online forums that looks something like this: "I'm trying to run Wing Commander 11. The opening music comes up, the credits roll, and all looks well. But as soon as one of the characters starts to speak, the system locks up." (I used a Wing Commander example because I play the game, but the same messages show up on other game and nongame forums.) The reason why the opening music is all right but the speech locks up the system is that music is generated differently than speech. Exactly how that all works is a topic for another column--but it's true, believe me. Anyway, the root cause of the lockup is the SBPro conflict. Change the interrupt, and the problem will go away.

How, exactly, do you know which interrupts are already taken in your system and change the interrupt that the SBPro uses? Or more generically, how do you change the interrupt that any board uses?

The first question is actually the tougher one. You'd think that it would be a childishly simple matter to run a program that would tell you which interrupts you're already using. Unfortunately, that's not the case. There are many programs that attempt to detect interrupts, but there's no definitive way to detect interrupts with software.

These programs work either by tracing information in your device drivers or by simply looking up interrupt correspondences. In the first case, they analyze any device drivers or TSRs that you have loaded to see which hardware interrupts they're designed to work with. These interrupts go on the list of already-taken interrupts. In the second case, there are, as I explained last month, standard interrupt settings for the basic hardware that you find in virtually all PCs. If the diagnostic program detects a floppy drive controller in your system, then it knows that IRQ6 is taken, as the floppy controller uses IRQ6 by default. Notice that if you have a nonstandard floppy controller, the diagnostic program won't be accurate.

Now you can see that programs that claim to detect your interrupts for you are at best good guessers and at best good guessers and at worst totally wrong. If you must use one of these programs, however, you can increase the probability that it will work correctly by making sure that you load all the device drivers and TSRs that are relevant to your hardware--your network drivers, your mouse driver, and so on. Having said that, however, let me reiterate that this isn't the right way to find out which interrupts your system uses. In the particular case of the SBPro, for example, I've found only one program that's capable of detecting its presence on my PC--QAPlus. Noother diagnostic program that I've run can locate the SBPro's interrupt, save for the diagnostic program that comes with the SBPro.

This leads me to the right way to figure out which interrupts you're already using--the documentation that comes with your PC and its add-in boards. Chances are that you have a normal COM1 and COM2 using IRQ4 and IRQ3, respectively; a normal floppy controller using IRQ6; and a normal parallel port using IRQ7. You should avoid using IRQ2 because it's the connection to IRQ8 through IRQ15. You shouldn't use IRQ8 because your system clock uses it. IRQ13 is used by your coprocessor, and IRQ14 is used by the hard disk controller.

So which interrupts are used by the slightly strange boards you may have in your system, such as a local area network board or a scanner interface? The only way to know for sure is to check the documentation that came with the boards. I'll tell you what I do to keep track of interrupts on my system: I tape a large envelope to the side of my PC. (It's a tower, so there's plenty of space. If your PC isn't in a tower case, you can tape the envelope to the monitor.) I keep an index card in the envelope that tells me which interrupt each board in that system uses.

Before moving on the second question (How do you change the interrupt that the SBPro uses?), let me stress the essential nature of keeping and reading the documentation that comes with the board. I know it's a pain, but there's no substitute for knowing what's in your system, rather than guessing.

The SBPro documentation says that you can choose IRQ2, IRQ5, 1RQ7, or IRQ10. IRQ2 should be avoided, and 7 is out; again, it's sad that 7 is the default. IRQ5 would be OK, and so would 10. But I've run into many boards that don't offer any interrupts but the ones in the 2-7 range, so it seems a good policy to use IRQ10 when possible. Let's do that with the SBPro. To actually tell the SBPro to use IRQ10, you have to move a jumper on the board itself. Again, the SBPro is better documented than the average board, and the jumper locations for the various interrupt choices are right on the board. There's a row of pins labeled IRQ2, IRQ5, and so on. Many companies, in contrast, label the pins JP1-1, JP1-2, and the like, requiring you to constantly look at the manual. In this case, you just remove the jumper that's currently across the IRQ7 position and move it to the IRQ10 position.

On some boards, choosing interrupts is even easier. You just run a program (supplied with the board) that essentially sets the jumper with software--no fiddling around with jumpers is required.

Even though the board is in, you're not done yet. You have to load the driver programs that use the SBPro (or whatever new board you're installing), and you typically must inform those drivers of the interrupt (and possibly the DMA and input/output address) that the board is set to.

Besides the concern about not putting two boards on the same interrupt, does it matter which interrupt you choose for the SBPro? It may, due to the nature of the different interrupts.

Interrupts in the PC world are prioritized. The device on IRQ0 gets the highest priority, and the device on IRQ15 gets the lowest priority. That sounds like a real hidden gem of a piece of information, but it's not all that terribly important. It usually makes sense to put slower devices on the higher-priority interrupts. That's because a slower device generates fewer interrupts per second than a faster device, and if two interrupts appear at the same time, the higher-priority item gets served first. If the faster device has a higher priority, the slower device might never be served.

Is that important in a real-life sense in the PC world? Well, here's one application. If you're going to communicate at a high speed over your modem, use COM2 rather than COM1. COM1 uses IRQ4; COM2 uses IRQ3. That means COM2 has a higher priority than COM1. Suppose you're in Windows downloading data over your communications line and you move your mouse. If the serial port attached to the mouse has a higher priority than the serial port accepting data, you could theoretically lose data on the serial port. I've only seen that happen, however, with modems that can blast data into a PC at 38,000 bps or more.