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

protected functions? (INTCON saving, function calls from ins

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







protected functions? (INTCON saving, function calls from ins
PostPosted: Sat Jul 12, 2003 10:41 am     Reply with quote

In the FAQ on the CCS website, there is the question:
What are the restrictions on function calls from an interrupt function?
In the answer, the following lines confused me:

1) "... the entire INTCON register is saved before A() is called and restored afterwards. Furthermore, if the global interrupt flag is enabled in A(), the program may execute incorrectly."
2) "A program should not depend on the interrupts being disabled in the above situation. The compiler may NOT disable interrupts when the function or any function it calls requires no local RAM."

I want to use a my_lcd_write(char) function both inside my interrupt handlers and inside the main line. Inside the function there are critical sections which need to be protected from interrupts (and they might not use any local RAM). I would like to save,disable,and then restore the GIE bit on my own. However, now I don't know what to do.
Also, if the compiler generates code that saves the entire INTCON register before the function call, and then restores it afterward, then isn't this bad scenario possible:

INTCON saved,GIE disabled,(T0IF flag not set) ->
protected function called ->
T0IF set by timer overflow ->
function ends, INTCON restored (T0IF gets cleared, and the overflow event is lost).

Any help is greatly appreciated,
-Ben
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515910
R.J.Hamlett
Guest







Re: protected functions? (INTCON saving, function calls from
PostPosted: Sat Jul 12, 2003 12:30 pm     Reply with quote

:=In the FAQ on the CCS website, there is the question:
:=What are the restrictions on function calls from an interrupt function?
:=In the answer, the following lines confused me:
:=
:=1) "... the entire INTCON register is saved before A() is called and restored afterwards. Furthermore, if the global interrupt flag is enabled in A(), the program may execute incorrectly."
:=2) "A program should not depend on the interrupts being disabled in the above situation. The compiler may NOT disable interrupts when the function or any function it calls requires no local RAM."
:=
:=I want to use a my_lcd_write(char) function both inside my interrupt handlers and inside the main line. Inside the function there are critical sections which need to be protected from interrupts (and they might not use any local RAM). I would like to save,disable,and then restore the GIE bit on my own. However, now I don't know what to do.
:=Also, if the compiler generates code that saves the entire INTCON register before the function call, and then restores it afterward, then isn't this bad scenario possible:
:=
:=INTCON saved,GIE disabled,(T0IF flag not set) ->
:=protected function called ->
:=T0IF set by timer overflow ->
:=function ends, INTCON restored (T0IF gets cleared, and the overflow event is lost).
:=
:=Any help is greatly appreciated,
:=-Ben
If your LCD function is doing hardware I/O, and having to wait potentially for the display, you would be _much_ better/safer, using a small screen 'buffer', and only writing to this from the main routines.
However simple 'GIE' testing, can be used to prevent problems. All you need, is ideally to 'encapsulate' your function. Hence:

//you need to specify what bit/byte, the GIE flag is on.
#bit GIE=

I_tested_function(int x) {
int iflag;
iflag=GIE;
disable_interrupts(GLOBAL);
call_protected_function(x);
if (iflag) enable_interrupts(GLOBAL);
}

This is how the default protection now seems to work itself. Basically, the interrupts are allways disabled for the 'protected function', including any register preperation, and are only enabled, if they were disabled on entry. Note that the INTCON register is not 'overwritten', instead only the global interrupt enable bit is set, this prevents the problem that you envisage with the protection desription as given. I suspect this has been 'updated', but the FAQ, still reflects the old version.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515911
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