This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Nested Interrupts, yes or no



Hello together,

I have a program with a timer interrupt und a port interrupt. the timer ist for PWM. Now i have a question :)

Can i jump in the port ISR while the timer ISR is running and when the port ISR is passed resume in the timer ISR?

I hope you understand what i mean.

 

Thanks for help!!

  • The timer interrupt is just interrupted by the port int and not aborted. If an int is requested in general then the current SR and PC is pushed on the stack and the same SR/PC is poped from stack once the ISR returns. Therefore your timer isr will continue at the instruction of the pc as if nothing happened but it can be still interrupted by other interrupts.

  • Further to Mark's reply, you should be aware that the GIE bit is cleared on entry to any ISR (in fact the entire Status Register is cleared). That means that maskable interrupts won't nest - they'll be postponed until the ISR returns and then will trigger sequentially in priority order.

    You can override that behaviour if needed by setting GIE at the start of your ISR.

  • Robert Cowsill said:
    You can override that behaviour if needed by setting GIE at the start of your ISR.

    Doing that comes with a whole host of other issues that you should be aware of and account for in your design.

    It is not recommended to nest interrupts. Your ISRs should be short, i.e. don't do heavy processing in the ISR, so there should be very rare needs for nesting.

  • Thank for your informations!!

    So, when i will interrupt the "timer ISR" with the "port ISR" i have to set the GIE at the beginning from the "timer ISR"?

    When the timer ISR is running and i set the GIE at the beginning and then the port ISR is triggered, the timer ISR will pause and the port ISR will passed through.. and at the end the timer ISR will continued? Or have i misunderstood?!

  • Hey Brian,

    Thanks for your contribution. I have a very time-critical application and in this case, the port ISR (i will)has the highest priority. the timer ISR is mostly 5-10us long and the port ISR 15-20 and stops the TAR and sometimes there are overlaps with the interrupts. so when i am in the timer ISR and then the port ISR is triggered i have a wrong Value from TA0R, because the timer ISR is not finished. I hope you understand me.

  • Sascha W. said:
    So, when i will interrupt the "timer ISR" with the "port ISR" i have to set the GIE at the beginning from the "timer ISR"?

    This question has been asked and answered in this forum before. If you use the search box and the query "nested interrupts" you will get a list of the previous threads. Try looking through this one....

    http://e2e.ti.com/support/microcontrollers/msp430/f/166/t/182680.aspx

  • Sascha W. said:
    So, when i will interrupt the "timer ISR" with the "port ISR" i have to set the GIE at the beginning from the "timer ISR"?

    When the timer ISR is running and i set the GIE at the beginning and then the port ISR is triggered, the timer ISR will pause and the port ISR will passed through.. and at the end the timer ISR will continued? Or have i misunderstood?!

    No, you got it right. An ISR is jsut code that is being executed. Like main. The difference is that 1) GIE is auto-cleared when an ISR is entered, 2) an IRS returns with exactly the same state (all registers and status) as it was entered, so it's execution is transparent except for th epassed time and 3) it is called to handle a hardware event.

    3) is a problem: if you enable GIE at the start of an ISR; the hardware event wasn't handled yet (exception are the ADC10 ISR and the timer CCR0 ISRs, which assume the event to be handled when the ISR is enetered). Sicne th ehardware event wasn't handled, the interrutp flag of that event is stills et. If you now set GIE, the CPU will see that another interrupt is waiting and can be handled - it doesn't know that it is the itnerrupt in whose ISR you already are. So the ISR will interrupt itself - ever and ever again, until the stack overflows and the system crashes.

    So you may only set GIE when you already have handled the event. In which case you shouldn't have any reason to stay in the ISR at all. And you may only doing so if you can handle that another interrupt happens and calls your ISR wghile it hasn't exited yet (it msu tbe reentrant). In 99.9% of all cases it won't reliably work (even though it sometimes does by coincidence - until next software change)

    In general: if you need to interrupt an ISR then usually either your design is seriously wrong or you're programming a multitasking scheduler.

**Attention** This is a public forum