Interrupt priority

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Interrupt priority

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Two interrupts arrive at the same time. Which one does the CPU handle first?
A The interrupt with the higher priority
B The interrupt that is easiest to handle
2. The CPU is handling a low priority interrupt when a higher priority interrupt arrives. What happens?
A The CPU pauses the low priority one and handles the higher priority one first
B The CPU ignores the higher priority one until the low priority one has finished
3. Which event would normally have the HIGHER priority?
A A key being pressed on the keyboard
B A power failure
4. Which statement about a lower priority interrupt is correct?
A It waits, or is paused, while a higher priority interrupt is handled
B It is deleted for ever when a higher priority interrupt arrives
5. Why do interrupts need priorities?
A So the CPU handles interrupts in the order the user likes
B So the CPU deals with the most urgent events first

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1priority = 1 (power failure) AThe CPU should pause the lower priority key press ISR and handle the higher priority power failure straight away instead of making it wait.
2priority = 5 (key press) BIF new_priority > current_priority THEN pause current ISR
3If a higher priority interrupt arrives while a lower priority ISR is running, the CPU pauses the lower one and handles the higher one first CThe order is wrong: the CPU handles the higher priority interrupt first, so the power failure should be handled before the key press.
4If a new interrupt has a lower priority than the one being handled, it waits until the more urgent interrupt is finished DIF new_priority < current_priority THEN wait
5Key press (low priority) is handled before a power failure (high priority) EA low priority interrupt that can wait or be paused while a more urgent interrupt is handled
6A power failure interrupt arrives and the CPU ignores it until the key press ISR has finished FA high priority interrupt that the CPU must handle first because it is urgent

Definitions

interrupt priority

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
IF newPriority _ currentPriority THEN pause(currentISR) run(newISR)
2.
IF powerFailure THEN _____(keyPressISR) run(powerFailureISR)
3.
IF powerFailure AND keyPress THEN run(powerFailureISR) ____(keyPressISR)
4.
IF newPriority __ currentPriority THEN wait(newISR) ENDIF
5.
finish(powerFailureISR) ______(keyPressISR) finish(keyPressISR)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A keyP <- 1
B powerP <- 10
C IF powerP < keyP THEN
D RUN power_ISR first
Question 2
A powerP <- 1
B keyP <- 2
C IF powerP > keyP THEN
D RUN power_ISR first
Question 3
A IF key_press THEN
B PAUSE key_ISR
C RUN power_ISR
D RESUME key_ISR
E ENDIF
Question 4
A IF new_interrupt THEN
B IF newP > currentP THEN
C PAUSE new_ISR
D RUN new_ISR
E ENDIF
F ENDIF
Question 5
A IF newP < currentP THEN
B ADD new_ISR TO queue
C CONTINUE current_ISR
D WHEN current_ISR starts
E RUN new_ISR
F ENDIF

Answer Key

Interrupt priority
Section A: Quick Questions
Q1
A — The interrupt with the higher priority
Q2
A — The CPU pauses the low priority one and handles the higher priority one first
Q3
B — A power failure
Q4
A — It waits, or is paused, while a higher priority interrupt is handled
Q5
B — So the CPU deals with the most urgent events first
Section B: Match the Pairs
Q1
priority = 1 (power failure) → A high priority interrupt that the CPU must handle first because it is urgent
Q2
priority = 5 (key press) → A low priority interrupt that can wait or be paused while a more urgent interrupt is handled
Q3
If a higher priority interrupt arrives while a lower priority ISR is running, the CPU pauses the lower one and handles the higher one first → IF new_priority > current_priority THEN pause current ISR
Q4
If a new interrupt has a lower priority than the one being handled, it waits until the more urgent interrupt is finished → IF new_priority < current_priority THEN wait
Q5
Key press (low priority) is handled before a power failure (high priority) → The order is wrong: the CPU handles the higher priority interrupt first, so the power failure should be handled before the key press.
Q6
A power failure interrupt arrives and the CPU ignores it until the key press ISR has finished → The CPU should pause the lower priority key press ISR and handle the higher priority power failure straight away instead of making it wait.
Section C: Definitions
Q1
interrupt priority — Each interrupt has a priority level. The CPU handles the most urgent one first, so a power failure can pause the handling of a less urgent key press.
Section D: Fill in the Blanks
Q1
IF newPriority > currentPriority THEN pause(currentISR) run(newISR)
Q2
IF powerFailure THEN pause(keyPressISR) run(powerFailureISR)
Q3
IF powerFailure AND keyPress THEN run(powerFailureISR) wait(keyPressISR)
Q4
IF newPriority <= currentPriority THEN wait(newISR) ENDIF
Q5
finish(powerFailureISR) resume(keyPressISR) finish(keyPressISR)
Section E: Spot the Error
Q1
C — A power failure has a higher priority number than a key press, so the CPU must handle it first. The test should be powerP > keyP, not <.
Q2
A — A power failure is very urgent, so it needs a high priority such as 10. Giving it priority 1 would make it less urgent than a key press, which is wrong.
Q3
A — The key press ISR is only paused when a higher priority interrupt arrives. The condition should be power_failure, because a key press is less urgent than the ISR it would be pausing.
Q4
C — When the new interrupt has a higher priority, it is the current (lower priority) ISR that must be paused. The line should be PAUSE current_ISR.
Q5
D — A lower priority interrupt has to wait. It only runs when the current, more urgent ISR has ended, so the line should be WHEN current_ISR ends.