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

warning: to prevent re-entrancy

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







warning: to prevent re-entrancy
PostPosted: Tue Feb 26, 2008 10:22 pm     Reply with quote

hi everybody.. just a short question. why is it that when i use this code:
Code:

#INT_RDA
void SerialInt(void)
{
   RXd_Data[Write_cntr] = fgetc(GSM);
   Write_cntr=(Write_cntr+1) % BUFFER_size;
   rda_flag=1;
}

it will create an error => interrupt disabled to prevent re-entrancy. it seems it has something to do with me using % but why? please help.. thanks guys.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 26, 2008 11:40 pm     Reply with quote

It's not an error, it's a warning. Here is the message:
Quote:

>>> Warning 216 "pcm_test.c" Line 85(0,1): Interrupts disabled during
call to prevent re-entrancy: (@DIV88)


You can fix this warning by using the #org DEFAULT command.
This is from the CCS manual:
Quote:

If the keyword DEFAULT is used then this address range is used for all
functions user and compiler generated from this point in the file until a
#ORG DEFAULT is encountered (no address range). If a compiler function
is called from the generated code while DEFAULT is in effect the compiler
generates a new version of the function within the specified address range.


Here's an example:
Code:
#include <16F877.h>
#fuses XT,NOWDT,NOPROTECT,NOPUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define BUFFER_SIZE 50
int8 index;
int8 data[BUFFER_SIZE];

#org 0x100, 0x17F DEFAULT
#INT_RDA
void SerialInt(void)
{
data[index] = getc();

index = (index + 1) % BUFFER_SIZE;
}

#org DEFAULT
//====================================
void main()
{
int8 a, b, c;

c = a % b;

while(1);
}


Here's another example:
http://www.ccsinfo.com/forum/viewtopic.php?t=25464&start=4
Ttelmah
Guest







PostPosted: Wed Feb 27, 2008 3:33 am     Reply with quote

As a 'comment' though, I'm a great advocate, of using binary buffer sizes to avoid this. If you make your buffer size, 8,16,32,64 bytes, then you can use:

Write_cntr=(Write_cntr+1) & (BUFFER_size-1);

Which (assuming buffer size is a constant), evaluates to just a couple of instructions. The compiler is smart enough to substitute just this operation, if the buffer is such a size, and '%' is used, which saves many instructions, and avoids the error message as well. :-)

Best Wishes
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Wed Feb 27, 2008 1:00 pm     Reply with quote

PCM programmer wrote:

You can fix this warning by using the #org DEFAULT command.
This is from the CCS manual:
Quote:

If the keyword DEFAULT is used then this address range is used for all
functions user and compiler generated from this point in the file until a
#ORG DEFAULT is encountered (no address range). If a compiler function
is called from the generated code while DEFAULT is in effect the compiler
generates a new version of the function within the specified address range.


..But be aware that indiscriminant use of #org DEFAULT can lead to code bloat, and the explosion of library use of your precious RAM locations. It is much better to avoid the need for this whole issue by trying to avoid the use of CCS library functions (including implicit functions like %) within an ISR. In the case at hand, you could do as Ttelmah suggested and use a power of 2 buffer size. That way you could perform your modulo addition on Write_cntr using the '&' operator, which does not invoke a CCS library function that needs to be protected from re-entrancy. Or, if you insist on a non-power-of-2 buffer size, you could to this:
Code:

Write_cntr++;
if(Write_cntr == BUFFER_size)  Write_cntr = 0;

which also does not raise the spectre of re-entrancy.

Robert Scott
Real-Time Specialties
kolio



Joined: 06 Feb 2008
Posts: 26

View user's profile Send private message

Re: warning: to prevent re-entrancy
PostPosted: Fri Feb 29, 2008 1:50 am     Reply with quote

xindy wrote:
hi everybody.. just a short question. why is it that when i use this code:
Code:

#INT_RDA
void SerialInt(void)
{
   RXd_Data[Write_cntr] = fgetc(GSM);
   Write_cntr=(Write_cntr+1) % BUFFER_size;
   rda_flag=1;
}

it will create an error => interrupt disabled to prevent re-entrancy. it seems it has something to do with me using % but why? please help.. thanks guys.


Be careful with '%', which calls a hidden library DIV-routine as well as 'fgetc(GSM)'. Do not use these functions outside ISR when the interrupt is enabled.
xindy
Guest







PostPosted: Sun Mar 02, 2008 8:28 pm     Reply with quote

thanks guys.. i really appreciate all your help...
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