XC8 exit from interrupt routine without re-enabling global interrupts - Page 1
Forum section: electronics / general

author: jojolepirate
author_rank: Newbie
timestamp: May 15, 2014, 09:58:45 am
content: Hi everyone!Before, in asm, I could choose to disable interrupts by using "return" instead of "retfie" in my interrupt routine.But now it seems that xc8 always puts "retfie" in the generated asm code (in the lst file).Is there a way to return without resetting the GIE flag?Thanks!

author: dannyf
author_rank: Super Contributor
timestamp: May 15, 2014, 10:25:54 am
content: QuoteWhy?QuoteYes, but why do you want to do that?

author: jojolepirate
author_rank: Newbie
timestamp: May 15, 2014, 11:40:35 am
content: Thanks for your reply!Oh, I made a mistake, I meant "I couldleave the routine without re-enabling interruptsby using return instead of retfie."I want interruptions to be enabled just in a specific part of my code, which is part of a bigger code in a loop, and just once per "loop run". Not very clear, I know ! So I enable GIE in my code, disable it one line afterwards.Even if it's not the best way to do so, it works, and now I'm migrating my code to C.What would be the way to do so?And even if there is a better way, i'm curious!Thank you!

author: dannyf
author_rank: Super Contributor
timestamp: May 15, 2014, 12:21:46 pm
content: QuoteYou can bracket the code with enable_interrupt() and disable_interrupt() (whatever the equivalents of them in your compiler).QuoteYou can use flags, counters, etc.

author: jojolepirate
author_rank: Newbie
timestamp: May 15, 2014, 12:35:11 pm
content: That's what i'm doing, but the interruption may occur multiple times in the brackets!If I simply want to exit this interruption routine:Code:void interrupt i(void){}with a simple return (asm-speaking), is there a specific instruction to tell xc8 to put "return" instead of "retfie" after the context restore? Or do I have to write my own routine in asm?

author: macboy
author_rank: Super Contributor
timestamp: May 15, 2014, 12:38:27 pm
content: Quote from: jojolepirate on May 15, 2014, 11:40:35 amA better idea is to mask/disable only the actual interrupt source that you are using, when the ISR runs. Then the ISR can exit, enabling interrupts globally, but your interrupt can't fire again until to enable it specifically in your loop code, when you are ready. Any interrupt source on the PIC can be individually enabled/disabled this way.

author: dannyf
author_rank: Super Contributor
timestamp: May 15, 2014, 12:46:18 pm
content: QuoteNo and that's not alone for PIC. Because it makes no sense at all.I am sure if you step back, you will understand this "once per loop" thing is weird as well.

author: jojolepirate
author_rank: Newbie
timestamp: May 15, 2014, 12:55:59 pm
content: Thanks for your replies!Macboy, This is a good idea, as I've just read that "Individual interrupt flag bits are set regardless of the status of their corresponding mask bit or the GIE bit."Which means if I deactivate the mask, and the interruption is triggered, it is recorded but only fired when the mask and GIE are set.But it was less instruction-hungry to simply return without modifying the mask bits (which would mean to re-enable them)Thanks for your ideas, I now see that there is a better way to accomplish what I want to do.