[En-Nut-Discussion] NutEnterCritical and gcc issue.

Vesa Jääskeläinen chaac at nic.fi
Fri May 13 23:51:30 CEST 2005


Vesa Jääskeläinen wrote:
> Hi,
> 
> I was just looking at NutEnterCritical code and noticed a small 
> inconsistency within atomic operations in gcc version:
> 
> from include/sys/atom.h:
> 
> #define NutEnterCritical_nt()               \
>     asm volatile(                           \
>         "in  __tmp_reg__, __SREG__" "\n\t"  \
>         "push __tmp_reg__"          "\n\t"  \
>         "cli"                       "\n\t"  \
>     )
> 
> I would propose following change to NutEnterCritical_nt:
> 
> #define NutEnterCritical_nt()               \
>     asm volatile(                           \
>         "in  __tmp_reg__, __SREG__" "\n\t"  \
>         "cli"                       "\n\t"  \
>         "push __tmp_reg__"          "\n\t"  \
>     )
> 
> Now it will allow faster execution of critical code and follows 
> AtomicInc() and Atmel's code example in CLI instruction. Also gcc seems 
> to use this scheme when saving stack pointers in non-optimized code.
> 
> Without this change there is window of two cycles for interrupts to fire 
> before we disable them.
> 
> If no-one spots any problems in the change, I will commit it within a 
> week or so.

Now it is there for AVR's. I also modified Imagecraft version. Could 
someone test that it still compiles correctly (though there should not 
be any problems as it was a easy looking change).

Thanks,
Vesa Jääskeläinen



More information about the En-Nut-Discussion mailing list