This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C-func call in ISR seems to cause stack corruption

Target: ST uPSD3454 running at 36.8864 Mhz

What seems simple is causing extreme confusion.

Enhanced template code from Keil:

;  Define instructions executed on a hardware timer interrupt.
HW_TIMER_CODE   MACRO
        EXTRN   CODE (TIMER_Update)
        USING   2       ; Registerbank 2 for following code
        LCALL   TIMER_Update ; C-func
        RETI
        ENDM


C-func:

void TIMER_Update( void )
{   unsigned char data i;

    for( i=0; i<NUM_TIMERS; i++ )
    {   timers[i]--;
        if( timers[i] == 0 )
        {   timers[i] = reload[i];
            if( events[i] < 255 )
                events[i]++;
        }
    }
}


HW_TIMER_CODE is ISR and occurring ever 10ms.
TIMER_update is attempt to implement software timers for additional systems functionality.

After about the 3rd HW_TIMER_CODE execution (between 30 and 50ms) system resets.

No stack corruption is detected in trace.

What silly thing am I overlooking?

Parents
  • By using the declaration

    void TIMER_Update( void ) using 2
    { ... }
    

    C51 is intelligent enough to generate

        PUSH    PSW
        MOV     PSW,#010H
        ...
        POP     PSW
        RET
    

    as a wrapper around the C-func.

    RTX51 Tiny is sharing RegBank 0, but the RTOS timer interrupt is using RegBank 1. Therefore, the declaration in the C-func of using 2 was specified to let the compiler keep track of the used / unused registers of RegBank 2.

    All appears to be working correctly now.
    Thanks for the insights.

    (I agree with both "I hate macros. All of them." and "I prefer interrupt handler in "C" style."!)

Reply
  • By using the declaration

    void TIMER_Update( void ) using 2
    { ... }
    

    C51 is intelligent enough to generate

        PUSH    PSW
        MOV     PSW,#010H
        ...
        POP     PSW
        RET
    

    as a wrapper around the C-func.

    RTX51 Tiny is sharing RegBank 0, but the RTOS timer interrupt is using RegBank 1. Therefore, the declaration in the C-func of using 2 was specified to let the compiler keep track of the used / unused registers of RegBank 2.

    All appears to be working correctly now.
    Thanks for the insights.

    (I agree with both "I hate macros. All of them." and "I prefer interrupt handler in "C" style."!)

Children
No data