M L | 11 Jun 2012 20:48
Picon

libm with pic16 port, problem with reetrancy?

Hello,
I discover some strange behaviour of sqrtf() function when usart
interrupts are enabled.
My  sdcclibs are compiled with --stack-auto option, libm too.
My program is simple and just do a sqrt calculations in endless loop
(my code compiled is with --stack-auto):

float val;
unsigned int x;
while(1){
  val=sqrtf(20000);
  x=(unsigned int) val;
 if(x!=141) printf("x=%u val=%.4f",x,val);
}

When usart receive some data (usart interrupt routine does some
integer calculations, only integer, not float) sometimes I get
randomly wrong values from sqrtf():
x=0 val=0.0000
x=19 val=19.0000
x=1 val=1.0000

I suspect some reentrancy problems, becouse when usart doesn't receive
any chars, sqrtf always return 141.4214
As I metioned above libsdcc and lib are compiled with --stack-auto, so
all helper (int/float) functions should be reentrant...

regards,
ml

(Continue reading)

M L | 12 Jun 2012 11:14
Picon

Re: libm with pic16 port, problem with reetrancy?

I did some tests and now I'm completely confused. I removed almost all
code from my usart ISR, ISR code just retrive only a byte from RCREG
register and return. So it doesn't call any other routines.

My main() routine looks like this:

volatile long d1,d2;
float tmp,dist;
unsigned int dst;

int main(){
// some intilaization code of important regs
[...]
stdout = STREAM_USART;

while (1){
        d1=d2=100;
        d1=d1*d1;
        d2=d2*d2;
        if(d1 !=10000 || d2!=10000) printf("d1=%lu d2=%lu\r\n",d1,d2);
        tmp=(float) (d1+d2);
        dist=sqrtf(tmp);
        dst=(unsigned  int) dist;
        dst=dst*2;
                if( dst != 282){
                                printf("dst=%u  dist=%.4f \r\n",dst,dist);
                               }
}

when isart int is active (usart receive data), main loops return
(Continue reading)


Gmane