This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

volatile in c2000

hello,

I'm using c2000 ti v6.2.7 compiler

and I wrote this simple code

volatile Uint64 tick_2ms = 0ULL;

Uint64 tick_getNow()
{
	Uint64 x;

	/*DINT;*/
	x = tick_2ms;
	/*EINT;*/

	return x;
}

where tick_2ms is a variable that I increment in a ISR, so I declared them as "volatile".

I think that TI C2000 compiler add automatically DINT, EINT before, after coping this variable

in order to avoid hi/low 2-word mismatch (c2000 data bus is 32-bit wide).

But if I watch the disassembled it's not

why compiler doesn't automatically manage DINT,EINT in a volatile copying ?

  • Mauro Fantina said:
    why compiler doesn't automatically manage DINT,EINT in a volatile copying ?

    The keyword volatile means the value can change in ways the compiler cannot know.  It does not mean accesses must be protected from interrupts.  Please see this wiki article for more detail on volatile.

    Thanks and regards,

    -George