Rasmi Ranjan Nayak Rasmi Ranjan Nayak - 25 days ago 7
C Question

How does software recognize an interrupt has occured?

As we know we write

Embedded C
programming, for
task management, memory management, ISR, File system
and all.

I would like to know if some
task or process is running
and at the same time an
interrupt occurred
, then
how SW or process or system comes to know that, the interrupt has occurred?
and
pauses
the current
task execution
and
starts serving ISR
.

Suppose if I will write the below code like;

// Dummy Code
void main()
{
for(;;)
printf("\n forever");
}

// Dummy code for ISR for understanding
void ISR()
{
printf("\n Interrupt occurred");
}


In this above code if an
external interrupt(ISR) occurs
, then how
main()
comes to know that the interrupt occurred? So that it would start serving ISR first?

Answer

your query: I understood your answer. But I wanted to know when Interrupt occurs how the current task execution gets stopped/paused and the ISR starts executing?

well Rashmi to answer your query read below,

when microcontroller detects interrupt, it stops exucution of the program after executing current instruction. Then it pushes PC(program counter) on to stack and loads PC with the vector location of that inerrupt hence, program flow is directed to interrrupt service routine. On completion of ISR the microcontroller again pops the stored program counter from stack and loads it on to PC hence, program execution again resumes from next location it was stopped. does that replied to your query?

Comments