CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Global Interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
christian.koji



Joined: 12 May 2010
Posts: 16

View user's profile Send private message

Global Interrupt
PostPosted: Fri May 28, 2010 9:04 am     Reply with quote

Hey Guys,

i'm with a doubt. I'm not sure when i should use global interrupt and when i shouldn't.
Ttelmah



Joined: 11 Mar 2010
Posts: 19364

View user's profile Send private message

PostPosted: Fri May 28, 2010 9:32 am     Reply with quote

If you are using any interrupt, and want a handler to be called, you also need to enable the global interrupt.

Interrupts are a 'layered' structure. You have the hardware event, which triggers the interrupt. Then, If the specific interrupt enable flag for that interrupt _and_ the global interrupt enable flag are both set, the interrupt handler will be called.
If you have an interrupt enabled, and the global flag disabled, then no handler will be called, _but_ if you are using 'sleep', the processor will wake up.
Think of it like a lighting system. The global interrupt flag, is the 'master switch' in the fuse box. If this is off, the lights won't work. If this is on, nothing will happen, unless the specific light switch is on (the interrupt enable flag for the particlar interrupt), and there is a bulb in the light (the actual interrupt flag).

Best Wishes
christian.koji



Joined: 12 May 2010
Posts: 16

View user's profile Send private message

PostPosted: Fri May 28, 2010 10:06 am     Reply with quote

LOL good analogy =P

Guess i undertand now..
in the datasheet is saying that:
GIE=1 Enables all unmasked interrupts
GIE=0 Disables all interrupts

what is a masked interrupt?

for example on my code i have three interrupt
enable_interrupts(INT_SSP); //enable I2C interrupts
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);

if i disable global interrupt the MSSP and the portB0 wont generate an interrupt?

if i have only the global interrupt enabled, then i have to test the bits all by myself... right?
i mean i have to do, if(tmr0if){ ... }else if(int0if){ .. }
Ttelmah



Joined: 11 Mar 2010
Posts: 19364

View user's profile Send private message

PostPosted: Fri May 28, 2010 10:13 am     Reply with quote

The operation 'enable_interrupts(INT_SSP)' 'unmasks' this interrupt.
All interrupts default to being 'masked off'.
You need to separate the idea of the global interrupt _handler_ from the global interrupt 'mask'.
The enable_interrupt instruction, affects the mask.
The enables/disables, all affect 'mask bits' that control what happens (the switches in the analogy).
If you only have one interrupt handler, and this is defined at #int_global, then this handler is called for all interrupts. In this, you need to do the following:
1) Save all registers that are changed in your handler code.
2) Test for an interrupt being enabled, _and_ it's flag set. If both are true, call it's handler.
3) Clear the interrupt.
4) Restore the registers

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group