Continue to Site

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.

Why ISR should be short?

Status
Not open for further replies.

vinothmct

Member level 1
Joined
May 2, 2012
Messages
38
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,584
Why the Interrupt service routine should be short? And i also wish to know what happens when cpu is servicing the ISR and another interrupt occurs . Say if ISR1 is being serviced , ISR2 occurs which has high priority . Will it save the address onto the stack and go and service ISR2 or what?
 

An ISR should be short to avoid another ISR being triggered, or in interrupt-generating event being missed because ISRs are disabled while one is being serviced.

For the same reason, ISRs should not call other non-native functions because doing so can add a lot of extra code and time to the ISR. ISRs should stay as much as possibly in a linear code flow and do the bare minimum of required processing.

Nesting ISRs (an ISR being activated while inside another ISR) is possible depending on the MCU. Often, ISRs are automatically disabled globally when an ISR is entered, and automatically re-enabled when the ISR returns. In that case, one would have to manually re-enable global interrupts inside the ISR if there was the requirement to service other interrupts. If nested interrupts are allowed, then care should be taken not to run out of stack space if many are nested at once.
 
Why the Interrupt service routine should be short?
If you know what you are doing, then there is no need to necessarily keep the interrupt code short. In some cases parts of code must run from inside interrupt and you will have no choice but to run even some hundreds bytes of code from the interrupt service routine. However, even in those cases it is good to use techniques to reduse the ISR code, because the main code is paused while the interrupt is running.

And i also wish to know what happens when cpu is servicing the ISR and another interrupt occurs . Say if ISR1 is being serviced , ISR2 occurs which has high priority . Will it save the address onto the stack and go and service ISR2 or what?
This depends on the MCU architecture. Some architectures have interrupt priority and others don't. If interrupts priority is available, then this is the case as you described it (at least for those architectures I have worked with). If not, then global interrupt flag will be involved as FoxyRick described.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top