Author Topic: XC8 exit from interrupt routine without re-enabling global interrupts  (Read 4490 times)

0 Members and 1 Guest are viewing this topic.

Offline jojolepirateTopic starter

  • Newbie
  • Posts: 4
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!
« Last Edit: May 15, 2014, 11:41:39 am by jojolepirate »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Quote
I could choose to reenable interrupts by using "return"

Why?

Quote
Is there a way to return without resetting the GIE flag?

Yes, but why do you want to do that?
================================
https://dannyelectronics.wordpress.com/
 

Offline jojolepirateTopic starter

  • Newbie
  • Posts: 4
Thanks for your reply!

Oh, I made a mistake, I meant "I could leave the routine without re-enabling interrupts by 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!
« Last Edit: May 15, 2014, 11:45:31 am by jojolepirate »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Quote
I want interruptions to be enabled just in a specific part of my code,

You can bracket the code with enable_interrupt() and disable_interrupt() (whatever the equivalents of them in your compiler).

Quote
What would be the way to do so?

You can use flags, counters, etc.
================================
https://dannyelectronics.wordpress.com/
 

Offline jojolepirateTopic starter

  • Newbie
  • Posts: 4
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: [Select]
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?
« Last Edit: May 15, 2014, 12:39:40 pm by jojolepirate »
 

Offline macboy

  • Super Contributor
  • ***
  • Posts: 2254
  • Country: ca
Thanks for your reply!

Oh, I made a mistake, I meant "I could leave the routine without re-enabling interrupts by 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!
A 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.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Quote
is there a specific instruction to tell xc8 to put "return" instead of "retfie" after the context restore?

No 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.
================================
https://dannyelectronics.wordpress.com/
 

Offline jojolepirateTopic starter

  • Newbie
  • Posts: 4
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.
« Last Edit: May 15, 2014, 12:58:36 pm by jojolepirate »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf