[En-Nut-Discussion] NutOS Bug with ICCAVR

Harald Kipp harald.kipp at egnite.de
Tue Sep 11 13:37:23 CEST 2007


Jean Pierre,

Difficult stuff. I needed quite some time until I found this solution:

#define NutEnterCritical()  \
{                           \
    register u_char sreg = inb(SREG);   \
    asm("cli\n"             \
        "push %sreg\n");    \
}

#define NutExitCritical()   \
{                           \
    /* Set to 0 to force register allocation. */ \
    register u_char sreg = 0;   \
    asm("pop %sreg\n");     \
    outb(SREG, sreg);       \
}

Many thanks for pointing me in the right direction.

Harald

Jean Pierre GAUTHIER schrieb:
> Hello,
>
> NutOS (ATMEGA128, ATMEGA2561,  ICCAVR AVR 7.13A Compiler) "inlines"
> NutEnterCritical & NutExitCritical functions as a suite of asm instructions.
> Unfortunately, the register R0 is destroyed by these functions and the
> compiler ICCAVR uses R0 to memorize variables without see that R0 contains
> erroneous value after NutEnterCritical & NutExitCritical calls. 
>   




More information about the En-Nut-Discussion mailing list