avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AW: [avr-gcc-list] reentrant interrupt service routine


From: Pink Boy
Subject: Re: AW: [avr-gcc-list] reentrant interrupt service routine
Date: Tue, 1 Apr 2008 21:33:27 -0700 (PDT)

Sven Schlender sez,

> So far I know. There is another (or maybe the same) problem I 
> think about. Lets say there is function which is callable 
> from main() AND from any interrupt routine.

Aiiiiggggggghhhhhh!

Such a thing is safe as long as the function is truly reentrant.
That is only operates on local and passed variables.  IE, no 
global variables, and in that case it's very safe.

It's not that unusual for library routines to be not thread safe.  
And for a number for compilers I've dealt with, floating point 
operations were not reentrant safe and in one case long division 
wasn't safe either.

If global variables are accessed then the access must be
protected.  For simple things the hack I use is

   uint8_t sreg = SREG;
   cli();

   /* do something to a global data structure that 
      doesn't take too long */

   SREG = sreg;

And at the end when you set SREG back to whatever it was, you'd
better leave the global data structure in a safe state as the end.

Mr Foo





reply via email to

[Prev in Thread] Current Thread [Next in Thread]