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

Problem with disabled Interrupts

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







Problem with disabled Interrupts
PostPosted: Mon Dec 19, 2005 8:53 am     Reply with quote

Hi NG,

I have a application (with the PIC18F458) there is very important, that the Interrupts not disabled.

The Compilers say Warnings like:
Interrupts disabled during call to prevent re-entrancy: (@DIV1616)

Can I say the compiler to use copy's of this internal routines?

An other problem I have with read_eeprom() and write_eeprom().
Why does the compiler disable Interrupts during read_eeprom()? The Microchip Data Sheet say's it is necessary to disable Interrupts during writing to EEPROM, not at the read-sequence.

Best Regards
Just a Guest
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Mon Dec 19, 2005 1:08 pm     Reply with quote

If you call a delay_ms or delay_us function within an isr, then you'll get that re-entrancy warning. Try to refrain from even delaying in an isr. otherwise, you should write your own my_delay_ms() routine that you will use in your isr, to avoid reentrancy conflicts.
just a guest
Guest







PostPosted: Tue Dec 20, 2005 4:53 am     Reply with quote

Hi,

thank you for your replay, but this is not the problem. Let me explain.
Here is a sample code:
Code:

#include "18F458.h"

int16 x, y, z;

#int_timer0
void T0Int(){
 z = x/y;
}

int16 i, j, k;

void main(){
 k = i/j;
}


I compile it with:
ccsc +FH +EA test.c

The result (test.err):
>>> Warning 216 "C:\PROGRA~1\PICC_2~1\t.c" Line 19(0,1): Interrupts disabled during call to prevent re-entrancy: (@DIV1616)
Memory usage: ROM=1% RAM=2% - 3%
0 Errors, 1 Warnings.

In some application it is a problem to disable Interrupts. To solve this problem, at the Interrupt the compiler have to use a copy from the internal @DIV1616-Routine.

My question:
Is it possible to say the compiler to use a copy of those internal routines?

If not: Perhaps this is a suggestion for CCS. This point is one of the few disadvantage of the CCS-Compiler.

Best Regards
Just a guest[/code]
Ttelmah
Guest







PostPosted: Tue Dec 20, 2005 10:43 am     Reply with quote

You should consider the sort of durations that using arithmetic in the interrupts involves. You are talking in the order of typically 300 instructions to perform this sum, and with the perhaps 50 instruction overhead for this interrupt handler, this is quite a significant total time. Now, with that 'caveat', if you must have such a sum, then just generate a simple division routine. Something like:
Code:

int16 div16(int16 a,int16 b) {
   int16 mask=1;
   int16 res=0;
   if (a==0) return(0);
   while (a>b) {
      b=b<<1;
      mask=mask<<1;
   }
   if (a==b) return(mask);
   b=b>>1;
   mask=mask>>1;
   while (a) {
      if (a>=b) {
        a=a-b;
        res=res+mask;
      }
      mask=mask>>1;
      b=b>>1;
      if (mask==0) return(res);
   }
   return(res);
}

This gives variable duration, according to the size of the values, but is not too inefficient. Code it as inline, to remove the overhead of a call/return. If you write it directly into the handler, and allow it to use the original numbers (remember it will change these), you save about 10 instructions of setup time.
You can also reduce the times involved a lot, if the divisor, is an 8 bit value. The above is very efficient, if you want the remainder, since this is left in 'a'.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 20, 2005 12:18 pm     Reply with quote

Quote:
My question:
Is it possible to say the compiler to use a copy of those internal routines?


The following program shows how to use the "#org default" directive
to create a copy of the CCS math library code. Compile this program
and then go to the View / Disassembly Listing menu in MPLAB.
You will see there are two copies of the DIV1616 routine.
Code:

#include <18F452.h>   
#fuses XT,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#org 0x1000, 0x10FF DEFAULT
#int_timer0
void my_function(void)
{
int16 x, y, z;

z = x/y;

}

#org DEFAULT

//=============================
void main()
{
int16 a, b, c;

c = a/b;


while(1);
}
Just a Guest
Guest







PostPosted: Fri Dec 23, 2005 4:41 am     Reply with quote

Hi,

it works fine, thank you very much.
Also many thanks @Ttelmah!

Just a Guest
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