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

Vesa Jääskeläinen chaac at nic.fi
Sun May 8 15:25:09 CEST 2005


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.

Thanks,
Vesa Jääskeläinen



More information about the En-Nut-Discussion mailing list