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

A delay() is dead in AC6, but OK in AC5, help!

Hi guys:

here is my code ,it works in AC5, but when I change to AC6, it is dead in delay_1ms(), I have no idea why it happened:

struct bsl_data_t{
    uint32_t tick_1ms;
};
static struct bsl_data_t g_bsl;

void TIMER16_IRQHandler(void)
{
    if(SET == timer_interrupt_flag_get(TIMER16, TIMER_INT_UP)){

        /* clear channel 0 interrupt bit */
        timer_interrupt_flag_clear(TIMER16, TIMER_INT_UP);

        /* toggle selected led */
        g_bsl.tick_1ms++;
    }
}

uint32_t get_timer_tick(void)
{
    return g_bsl.tick_1ms;
}

/* x1ms */
#define GET_DIFF_TICK(last_tick) ( (0x100000+get_timer_tick()-last_tick)&0xFFFFF )
#define SET_TICK(var1) var1=get_timer_tick()

void delay_1ms(uint32_t xms)
{
    volatile uint32_t tick,diff=xms;

    SET_TICK(tick);
    while(GET_DIFF_TICK(tick) < diff){}  // dead in here, never come out in AC6.
}

here some picture maybe help:

AC5:

AC6:

Parents Reply Children
  • AC6 assumed the memory location "uint32_t tick_1ms" does not changed unless explicitly flagged. But interesting , should not it be a const or macro which define a unchange value?

    You really need to cut down on jumping to conclusions so violently.

    No, the compiler did not expect any explicit "flagging", nor did it assume the variable would be constant.  The only thing it assumes is that the value of a variable does not change all by itself, i.e. in ways not covered by the langauge itself.  One of those ways is that the C code's executaion is interrupted by the CPU doing something else entirely.  Which is exactly what ISRs always do.