Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Interrupt complete process

Status
Not open for further replies.

Murugesh_89

Full Member level 5
Joined
Nov 23, 2012
Messages
266
Helped
7
Reputation
12
Reaction score
6
Trophy points
1,298
Location
India
Activity points
3,266
Hi,

I want to know every nook and corner of the process when a interrupt ( any interrupt source ) occurs say in pic microcontroller.

For example,
1. When a interrupt occurs where the currently executing variables are stored
2. What happens if two or more interrupts occurs simultaneously
3. How interrupt priority works

and so on....

Can anybody provide me a document or any website link please?
 

Murugesh_89

Full Member level 5
Joined
Nov 23, 2012
Messages
266
Helped
7
Reputation
12
Reaction score
6
Trophy points
1,298
Location
India
Activity points
3,266
Hi,
I saw the following text in a website regarding interrupts:

Common Error: The ISR software should not disable interrupts at the beginning nor should it reenable interrupts at the end. Which interrupts are allowed to run is automatically controlled by the priority set in the NVIC.

If i dont want to get other interrupt when i am already in ISR of one interrupt say A, i disable the global interrupt at the beginning of ISR of A and enabling the global interrupt at the end of this ISR.

What is the wrong in doing so?
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,870
Helped
4,860
Reputation
9,738
Reaction score
4,643
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
126,575
The interrupt flags are set regardless of whether the interrupt is enabled. The GLOBAL interrupt for that priority level is turned off automatically when the interrupt is triggered and turned on again automatically when the ISR is finished and normal program resumes. The purpose of this is to ensure other interrupts with the same priority are ignored until the present one is serviced. This is why you are not advised to change the GIE bits inside the ISR. Because the interrupt flags are still set, when the ISR exits, it will check for other pending and enabled interrupts that occurred when it was in the ISR and if necessary, enters the ISR again to service the second interrupt.

If priority interrupts are enabled and a peripheral is assigned a higher level of priority, it DOES have the ability to suspend the lower priority interrupt in the same way a low priority interrupt can suspend the main program flow. When the high priority ISR exits, it returns to the low priority routine.

So, answering your question, if you use one level of interrupt priority, a second interrupt can never interrupt the first one and the global interrupt bit is turned off anyway.
If you have more than one interrupt priority enabled, it should be because you intend it to run, if you don't want that, assign it low priority level instead.

Brian.
 

Murugesh_89

Full Member level 5
Joined
Nov 23, 2012
Messages
266
Helped
7
Reputation
12
Reaction score
6
Trophy points
1,298
Location
India
Activity points
3,266
If i am having two interrupts named A,B.
I make A as high priority and B as low priority.

The isr for B as follows.
void isr_B()
{
clear interrupt( isr_B );
function body;
1...;
2....; // int B triggers here again
3...;

}

What happens if interrupt B is again triggered while isr_B is already executing.
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,870
Helped
4,860
Reputation
9,738
Reaction score
4,643
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
126,575
Nothing happens because the global interrupt for low priority is disabled as the ISR is called. When the low priority ISR finishes it will re-enable the interrupts then check to see if the interrupt flag has been set again and if it has, the ISR will be called again. So in your example, provided you cleared the interrupt 'B' flag as you entered the ISR, the whole ISR will be called twice, once for the original reason and again because of the later interrupt.

Brian.
 

Murugesh_89

Full Member level 5
Joined
Nov 23, 2012
Messages
266
Helped
7
Reputation
12
Reaction score
6
Trophy points
1,298
Location
India
Activity points
3,266
Is it possible to say any interrupt routine as Reentrant function?

I mean, will the reentrant function/concept is also applicable for ISR's?

Could you please tell me in detail with a example?
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,870
Helped
4,860
Reputation
9,738
Reaction score
4,643
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
126,575
No, you can't have a reentrant ISR. You could possibly write reentrant or recursive code inside an ISR but you can't actually have an ISR call itself because from start to finish the global interrupt is disabled which prevents the ISR being called until it's present service is completed.

Technically, you can CALL a function inside an ISR but to do so could make your program unstable because the return address may be unavailable or even overflow the stack. Consider what might happen if you jumped into an ISR from somewhere else and executed a RETFIE instruction, it would take whatever value was on the stack and jump to it, almost certainly taking you to the wrong program address. Besides that, it is bad pogramming practice to embed or execute functions inside an ISR, it defeats the object of the interrupt being ready for immediate use at any time, the best way to use interupts is to exit them as fast as possible so they are ready in case another interupt occurs. Typically, you set a global flag in the ISR then leave, allowing the main program to check and act on the flag then reset it again.

Brian.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top