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

Problems with interrupts: gie is cleared when I call a func

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








Problems with interrupts: gie is cleared when I call a func
PostPosted: Thu Aug 04, 2005 12:46 am     Reply with quote

I've post this in the microchip forum. I haven't found an answer yet, maybe here..

http://forum.microchip.com/tm.asp?m=104968&mpage=1&key=&anchor#104968
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

Re: Problems with interrupts: gie is cleared when I call a f
PostPosted: Thu Aug 04, 2005 2:41 am     Reply with quote

Anonymous wrote:
I've post this in the microchip forum. I haven't found an answer yet, maybe here..

http://forum.microchip.com/tm.asp?m=104968&mpage=1&key=&anchor#104968

Ask compiler questions at the forum for the compiler and you will get a faster response. You are at the right place here. Cool

Code:
.................... mensaje[1]=0;
29CC: CLRF 5F
29CE: CLRF 17 //I don't know what it's in position 0x17 ¿?
29D0: BTFSC FF2.7 //FF2.7 is the GIE bit
29D2: BSF 17.7
29D4: BCF FF2.7
....................
.................... conversion_placas();
29D6: CALL 0146
29DA: BTFSC 17.7
29DC: BSF FF2.7
....................
.................... direccion_can=cpr1;
29DE: MOVLW 60

Address 17 is just the random address of a RAM variable used by the compiler. What the compiler does here is to save the GIE bit setting before calling the function and restoring it afterwards. The compiler is doing so to prevent re-entrancy. Very likely you are calling the function conversion_placas() also from within one of your interrupts.
Two solutions:
1) Rewrite your code so that conversion_placas() is not called by the interrupt routines.
or
2) Create a copy of conversion_placas() with a different name and call that function from your interrupt.
Guest








PostPosted: Mon Sep 05, 2005 1:01 am     Reply with quote

Hi ckielstra!

Many thanks for your answer, I'm very grateful to you.

I call conversion_placas() only from main, and the result is different if conversion_placas() is either:

Quote:

this function doesn't clear GIE when called:


void conversion_placas(void)
{
array_placas_destino_byte[0]=array_placas_destino;

}


but this function clears GIE!!:


void conversion_placas(void)
{
array_placas_destino_byte[0]=array_placas_destino;
array_placas_destino_byte[1]=array_placas_destino>>8;


}


The problem is that I've many counters activated by interrupts, so if the compiler clears GIE, the counters don't work right.

What is worse, is that I have many functions like conversion_placas(), so GIE is cleared many times and my code doesn't work fine. So it's very difficult to apply one of the soultions you've propossed.

At this moment, I solve the problem writing "GIE=1" at the top of those functions that clear the GIE. It seems to work, but I don't know if doing this can corrupt something (overwrite the stack or somewhat).
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