View previous topic :: View next topic |
Author |
Message |
nazoa
Joined: 09 Feb 2007 Posts: 58
|
Interrupt disable from within interrupt routine |
Posted: Wed Apr 16, 2008 10:23 am |
|
|
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
|
|
Posted: Wed Apr 16, 2008 10:30 am |
|
|
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
|
Re: Interrupt disable from within interrupt routine |
Posted: Wed Apr 16, 2008 10:32 am |
|
|
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
|
|
Posted: Wed Apr 16, 2008 11:03 am |
|
|
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
|
|
Posted: Thu Apr 17, 2008 11:30 am |
|
|
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. |
|
|
|