What kind of optimization can the compiler perform in the absence of the “volatile” keyword in the following code?

Below is the code that points to the flash LED on the Pandaboard when starting the Barrelfish operating system. My question is why the LEDs do not blink if the keyword "volatile" is removed from the definitions gpio_oeand gpio_dataout.

static volatile uint32_t *gpio_oe = (uint32_t *)(GPIO_BASE + 0x0134);
static volatile uint32_t *gpio_dataout = (uint32_t *)(GPIO_BASE + 0x013C);

void led_flash
{
    // Enable output
    *gpio_oe &= (~(1 << 8));

    // Toggle LED on and off till eternity
    while(true)
    {
      *gpio_dataout ^= (1 << 8);  // Set means LED on; Clear means LED off
       time_delay();  // To give blinking effect
    }
}

I know that volatile needs to be used if the value of a variable can spontaneously change through a source outside the program. But I do not see such a case. What kind of optimization does the compiler do, which makes the entire while loop for the flashing LED pointless? And what is the logic of such optimization, i.e. a legitimate case where such an optimization would make sense?

+5
source share
4

volatile, , volatile. , , .

: , , .

+9

, *gpio_oe *gpio_dataout , . , . , , .

/ , "" , . volatile , , .

I/O , (, RTOS ), .

Embedded.com :

+5

, , . Volatile , , . , .

EDIT:

, , , , , gpio, , . , volatile, , ( asm, , ).

+4

volatile , , , , , :

C?

+1

All Articles