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

Multiple ISR's, is it safe to enable disable interrupts whil

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







Multiple ISR's, is it safe to enable disable interrupts whil
PostPosted: Thu Jun 19, 2003 5:08 pm     Reply with quote

Hello;

Another day of agonizing headbanging (yup!, I have not done this in a while), and many compiler questions/issues. The one most important to me right now is the discussion of whether it is safe to enable or disable interrupts during an interrupt service routine. Specifically I am interested in enabling / disabling the timer1 while in the portb change or ext int service routines. I have noted the comments by CCS about protected sub routines, but it does not make it clear about whether the restore at the end of the interrupt service routine will whack any enabling/disabling PIC-C C commands.

ex:
#org 0x????
void main(void){
//initialize interrupts
....
.....
.....
enable_interrupts(GLOBAL);
do{
...
...
} while (sometest);
}

#org 0x????
#int_rb

{
...
if (sometest)
{
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
set_timer1(3036); //100 milsec @20Mhz
enable_interrupts(int_timer1);
}
else
{
setup_timer_1(T1_DISABLED);
disable_interrupts(int_timer1);
}
}

Advice is really welcome. My thoughts are if this cant be done then I will have to use flags to signal from the ISR's to the main program loop. Any examples of this would also be appreciated....just take out the NOSPAM in my email address.

Thanks...

Rob
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515410
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Multiple ISR's, is it safe to enable disable interrupts
PostPosted: Thu Jun 19, 2003 5:30 pm     Reply with quote

:=
:= The one most important to me right now is the discussion of whether it is safe to enable or disable interrupts during an interrupt service routine. Specifically I am interested in enabling / disabling the timer1 while in the portb change or ext int service routines.
-----------------------------------------------------------

Yes, you can do it. Look at the CCS example file, EX_STISR.C:
<a href="http://www.cc.puv.fi/~t0101190/projekti/source/Examples/ex_stisr.c" TARGET="_blank">http://www.cc.puv.fi/~t0101190/projekti/source/Examples/ex_stisr.c</a>
They disable INT_TBE interrupts within the ISR.

The only thing you should never do, is to re-enable GLOBAL
interrupts within an isr. CCS does not support nested
interrupts.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515411
Lance Lascari
Guest







Re: Multiple ISR's, is it safe to enable disable interrupts
PostPosted: Fri Jun 20, 2003 6:39 am     Reply with quote

I've got some rare cases where routines that normally:
disable interrupts

[do something]

reenable interrupts

as part of their normal procedure.

Realizing this was a pretty key flaw (since these routines might be called when interrupts were already disabled, or during an ISR (very rare)), I did this

enter routine
check if global interrupts are enabled, store flag

disable interrupts (doesn't hurt if they're already off)

[do stuff]

if(interrupts were enabled before)
enable interrupts


Anyone have any comments on this or a better solution?

-Lance



:=:=
:=:= The one most important to me right now is the discussion of whether it is safe to enable or disable interrupts during an interrupt service routine. Specifically I am interested in enabling / disabling the timer1 while in the portb change or ext int service routines.
:=-----------------------------------------------------------
:=
:=Yes, you can do it. Look at the CCS example file, EX_STISR.C:
:= <a href="http://www.cc.puv.fi/~t0101190/projekti/source/Examples/ex_stisr.c" TARGET="_blank"> <a href="http://www.cc.puv.fi/~t0101190/projekti/source/Examples/ex_stisr.c" TARGET="_blank">http://www.cc.puv.fi/~t0101190/projekti/source/Examples/ex_stisr.c</a></a>
:=They disable INT_TBE interrupts within the ISR.
:=
:=The only thing you should never do, is to re-enable GLOBAL
:=interrupts within an isr. CCS does not support nested
:=interrupts.


:=:=
:=:= The one most important to me right now is the discussion of whether it is safe to enable or disable interrupts during an interrupt service routine. Specifically I am interested in enabling / disabling the timer1 while in the portb change or ext int service routines.
:=-----------------------------------------------------------
:=
:=Yes, you can do it. Look at the CCS example file, EX_STISR.C:
:= <a href="http://www.cc.puv.fi/~t0101190/projekti/source/Examples/ex_stisr.c" TARGET="_blank"> <a href="http://www.cc.puv.fi/~t0101190/projekti/source/Examples/ex_stisr.c" TARGET="_blank">http://www.cc.puv.fi/~t0101190/projekti/source/Examples/ex_stisr.c</a></a>
:=They disable INT_TBE interrupts within the ISR.
:=
:=The only thing you should never do, is to re-enable GLOBAL
:=interrupts within an isr. CCS does not support nested
:=interrupts.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515422
R.J.Hamlett
Guest







Re: Multiple ISR's, is it safe to enable disable interrupts
PostPosted: Fri Jun 20, 2003 7:13 am     Reply with quote

:=I've got some rare cases where routines that normally:
:=disable interrupts
:=
:=[do something]
:=
:=reenable interrupts
:=
:=as part of their normal procedure.
:=
:=Realizing this was a pretty key flaw (since these routines might be called when interrupts were already disabled, or during an ISR (very rare)), I did this
:=
:=enter routine
:=check if global interrupts are enabled, store flag
:=
:=disable interrupts (doesn't hurt if they're already off)
:=
:=[do stuff]
:=
:=if(interrupts were enabled before)
:= enable interrupts
:=
:=
:=Anyone have any comments on this or a better solution?
:=
:=-Lance
This is exactly what is done internally by some parts of the CCS code. Obviously, if there is any possibility of the routines be called from locations where the interrupts are allready enabled, as well as locations where they might be disabled, this is a better solution. I use this approach, on a block 'memory copy' routine.

Best Wishes


:=:=:= The one most important to me right now is the discussion of whether it is safe to enable or disable interrupts during an interrupt service routine. Specifically I am interested in enabling / disabling the timer1 while in the portb change or ext int service routines.
:=:=-----------------------------------------------------------
:=:=
:=:=Yes, you can do it. Look at the CCS example file, EX_STISR.C:
:=:= <a href="http://www.cc.puv.fi/~t0101190/projekti/source/Examples/ex_stisr.c" TARGET="_blank"> <a href="http://www.cc.puv.fi/~t0101190/projekti/source/Examples/ex_stisr.c" TARGET="_blank"> <a href="http://www.cc.puv.fi/~t0101190/projekti/source/Examples/ex_stisr.c" TARGET="_blank">http://www.cc.puv.fi/~t0101190/projekti/source/Examples/ex_stisr.c</a></a></a>
:=:=They disable INT_TBE interrupts within the ISR.
:=:=
:=:=The only thing you should never do, is to re-enable GLOBAL
:=:=interrupts within an isr. CCS does not support nested
:=:=interrupts.
:=
:=
:=:=:=
:=:=:= The one most important to me right now is the discussion of whether it is safe to enable or disable interrupts during an interrupt service routine. Specifically I am interested in enabling / disabling the timer1 while in the portb change or ext int service routines.
:=:=-----------------------------------------------------------
:=:=
:=:=Yes, you can do it. Look at the CCS example file, EX_STISR.C:
:=:= <a href="http://www.cc.puv.fi/~t0101190/projekti/source/Examples/ex_stisr.c" TARGET="_blank"> <a href="http://www.cc.puv.fi/~t0101190/projekti/source/Examples/ex_stisr.c" TARGET="_blank"> <a href="http://www.cc.puv.fi/~t0101190/projekti/source/Examples/ex_stisr.c" TARGET="_blank">http://www.cc.puv.fi/~t0101190/projekti/source/Examples/ex_stisr.c</a></a></a>
:=:=They disable INT_TBE interrupts within the ISR.
:=:=
:=:=The only thing you should never do, is to re-enable GLOBAL
:=:=interrupts within an isr. CCS does not support nested
:=:=interrupts.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515423
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