Interrupt Tutorial

In this tutorial, we are going to see what is an interrupt in OS and how it is working?

You can also read RTOS basics -1, RTOS basics – 28051 Interrupts, and interrupts in Linux kernel.

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 −

Interrupt 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,

  1. Hardware Interrupts
  2. Software Interrupts

Hardware 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.

Software Interrupts

The interrupts which are caused by the software instructions are called software instructions.

Interrupt Latency

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.

Linux Device Driver TutorialsC Programming Tutorials
FreeRTOS TutorialsNuttX RTOS Tutorials
RTX RTOS TutorialsInterrupts Basics
I2C Protocol – Part 1 (Basics)I2C Protocol – Part 2 (Advanced Topics)
STM32 TutorialsLPC2148 (ARM7) Tutorials
PIC16F877A Tutorials8051 Tutorials
Unit Testing in C TutorialsESP32-IDF Tutorials
Raspberry Pi TutorialsEmbedded Interview Topics
Reset Sequence in ARM Cortex-M4BLE Basics
VIC and NVIC in ARMSPI – Serial Peripheral Interface Protocol
Bootloader TutorialsRaspberry PI Pico Tutorials
5 1 vote
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
1
0
Would love your thoughts, please comment.x