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 CCS Technical Support

Interrupt disable from within interrupt routine

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



Joined: 09 Feb 2007
Posts: 58

View user's profile Send private message

Interrupt disable from within interrupt routine
PostPosted: Wed Apr 16, 2008 10:23 am     Reply with quote

I have a simple interrupt service routine that collects data and stores it in buffer memory which is just an array variable. The main program then routinely checks to see if there is data in the buffer to be dealt with.

The problem I have is that occasionally the PIC will be too busy to check and deal with the data in the buffer before the buffer overflows. I have reached the limit of how much memory I can allocate to my buffer.

Is there a way I could disable the interrupt from within the interrupt service routine and re-enable when the data is dealt with by the main program? I think that the CCS compiler re-enables the interrupt at the end of the service routine so I need a way around this.

Any suggestions? Thanks.
Ttelmah
Guest







PostPosted: Wed Apr 16, 2008 10:30 am     Reply with quote

Just disable the individual interrupt.
The CCS compiler does not re-enable the interrupt at the end of the service routine.
The chip's own _hardware_, disables the 'global' enable, when the interrupt handler is called, and automatically re-enables this on exit (which combined with the need to avoid re-entrancy, is why you should never try to change the global enable inside an interrupt handler), but the individual enables are happily available to you.

Best Wishes
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: Interrupt disable from within interrupt routine
PostPosted: Wed Apr 16, 2008 10:32 am     Reply with quote

nazoa wrote:
Is there a way I could disable the interrupt from within the interrupt service routine and re-enable when the data is dealt with by the main program? I think that the CCS compiler re-enables the interrupt at the end of the service routine so I need a way around this...


1. Disabling interrupts is not the way to go. If you did disable the interrupts from within the ISR, then who is going to re-enable them? Certainly not the ISR, because with interrupts disabled, it is not getting control any more. The main program would have to do it.

2. Apparently the data that you are collecting can be thrown away occasionaly, because that is what would happen if you did disable interrupts. So if that is the case, then you can just make the ISR smart enought to realize that the main program has fallen behind, and so the ISR will discard the data rather than put it in the buffer. The interrupts still continue, but no data is stored until the main program processes some of the buffer and makes more room.

3. The CCS compiler does not enable interrupts at the end of an interrupt routine. That happens automatically when the PIC executes a RETFIE instruction to return from an interrupt. If you do want to take complete control of the interrupt service code (and I don't recommend that you do!) you can use #INT_GLOBAL. But then you have to take full responsibiltiy for all the things that the CCS interrupt handler was doing for you. Again, I don't recommend this route.

Robert Scott
Real-Time Specialties
nazoa



Joined: 09 Feb 2007
Posts: 58

View user's profile Send private message

PostPosted: Wed Apr 16, 2008 11:03 am     Reply with quote

Thanks for the replies.

If I disable the interrupt the instrument sending out the data will hold fire - so no data is lost. This is OK as most of the time the PIC will be able to deal with the buffer data properly so the average throughput will be OK.

I will try disabling the individual interrupt and see if that works.

Thanks again.
nazoa



Joined: 09 Feb 2007
Posts: 58

View user's profile Send private message

PostPosted: Thu Apr 17, 2008 11:30 am     Reply with quote

In case anyone is interested, disabling the individual interrupt within the interrupt routine worked fine. I just arranged for the main program to re-enable it once the buffer queue reduced below a certain level.

Thanks for the suggestions.
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