In this tutorial, we are going to see what is an interrupt in OS and how it is working?
- 1 Interrupt – Introduction
- 2 What is an Interrupt in os?
- 3 What is an Interrupt in os (Microcontroller)?
- 4 What is ISR?
- 5 What is Polling?
- 6 Interrupt vs Polling
- 7 Program Execution Without Interrupts
- 8 Program Execution With Interrupts
- 9 Types of Interrupts
- 10 Interrupt Latency
Interrupt – Introduction
What is an Interrupt in os?
Interrupt means stop the continuous progress of (an activity or process).
What is an Interrupt in os (Microcontroller)?
Same here also. It will stop the process which is running currently and then execute the process in ISR. So it is a signal which may be disturbed or alter the sequence of execution of the processor. In other words, An interrupt is a signal to the processor emitted by hardware or software indicating an event that needs immediate attention.
What is ISR?
ISR means Interrupt Service Routine. Whenever an interrupt occurs, the controller completes the execution of the current instruction and starts the execution of an Interrupt Service Routine (ISR) or Interrupt Handler.
What is Polling?
The polling method simply uses a code section that checks a particular flag or flags, to know the status of operations. The polling method is always part of the main code and not part of an ISR. The microcontroller keeps checking the status of other devices.
Polling is a simpler method to execute and is recommended for the early stages of design where the working of a peripheral is to be verified. It does not involve any priority. Also, the code segment will always execute within a fixed time and in a fixed sequence. It is easy to debug and has no effect on the execution of other sections of code. There are no big memory management issues. There are no issues with the stack.
Interrupt vs Polling
Here is an analogy that differentiates an interrupt from polling −
|An interrupt is like a shopkeeper. If one needs a service or product, he goes to him and apprises him of his needs. In case of interrupts, when the flags or signals are received, they notify the controller that they need to be serviced.||The polling method is like a salesperson. The salesman goes from door to door while requesting to buy a product or service. Similarly, the controller keeps monitoring the flags or signals one by one for all devices and provides service to whichever component that needs its service.|
Program Execution Without Interrupts
So it only executes the main function and some functions which are called in the main function.
Program Execution With Interrupts
In this method, it will execute the main function. When an interrupt signal comes, it will stop the main function execution and suddenly it will go to the ISR function and executes that. After execution of ISR and again it will come to the main function.
Types of Interrupts
Although interrupts have the highest priority than other signals, there are many types of interrupts but the basic type of interrupts are,
- Hardware Interrupts
- Software Interrupts
If the interrupt is coming from hardware or external devices, it is called Hardware Interrupt. For example: from the keyboard we will press the key to do some action this pressing of a key on the keyboard will generate a signal which is given to the processor to do action, such interrupts are called hardware interrupts.
The interrupts which are caused by the software instructions are called software instructions.
When an interrupt occurs, the service of the interrupt by executing the ISR may not start immediately by context switching. The time interval between the occurrence of interrupt and the start of execution of the ISR is called interrupt latency.
You can also read the below tutorials.