Interrupt Handling Flashcards
What are the two method of monitoring GPIO
Programmed I/O with polling (a tight while loop)
Interrupt-driven I/O
What does ISR stand for
Interrupt Service Routine
What needs to be done before an ISR can execute
The interrupted process state must be saved
When an interrupt has arrived and the state has been saved, what happens
A value from the interrupt vector table is loaded into the program counter and control is handed to software
What does it mean for code to be re-entrant
It means that a given function x
can be interrupted by an ISR which calls the same function x
again, and then when this ISR completes we can resume the original execution of the function x
. This requires that reentrant code does not hold state, in forms such as static variables, between executions.
What are the two important rules when writing an ISR
Keep them fast and keep them simple
How can we keep an ISR fast
Avoid loops
Avoid “heavy” instructions such as printf()
Don’t block
Why do we not need ISRs to be re-entrant
Because they should be fast, and they are both faster and simpler if they are not re-entrant
What does the latency of an interrupt describe
The latency of an interrupt describes the time between an interrupt being received and the CPU being able to respond
What is jitter
Jitter is the name given to the variation in latency which is a result of the current instruction position
The interrupt could arrive at the start or the end of a clock cycle for instance, or arrive in the middle of a multi-cycle instruction
What are some ways we can write an ISR which makes it fast and simple
Move any data which needs processing to a buffer so it can be processed outside the ISR
Set a global flag we can check in the main program, and then return
When making use of global variables in a ISR, what attribute must the variables have and why
They must have the volatile attribute such that their value isn’t cached or optimised
What types of events can trigger interrupts, give some examples
Internal events such as timer overflow or the completion of ADC conversion
External events such as a button press
What are events such as a Pin Change to High associated with and where
These events are associated with an Interrupt Service routine through the Interrupt Vector Table
What is the use of a relocatable vector table
A relocatable vector table is a feature of some Processors where a register stores a pointer to the vector table, this means that we can store state and how we handle interrupts as a result by simply changing this pointer (And as a result the vector table we are using)