c - What is the significance of the "volatile" key word with respect to Embedded Systems? -


i have been working on learning embedded systems programming on own. have observed high usage of keyword volatile qualifier when declaring variables?

what significance of volatile when declaring variable in embedded system programming?

basically when should key word used. did read compiler optimization , use of keyword. related memory mapping registers.

for example, read stackoverflow post didn't understand how applied in embedded environment. more specifically, don't understand when key word should used. did read compiler optimization , use of keyword. related memory mapping registers, don't understand when use it.

in embedded systems world, 1 of key aspects of volatile key-word denotes variable may change @ time (eg external/hardware data input - eg adc) , therefore compiler must not optimise use.

but specifically, when used control register, indicates read access may in fact change data!

as general rule of thumb, recommend use of volatile qualifier in of following:

  • all hardware register accesses(read , write)
  • all variables accessible in multiple threads (especially interrupt handlers)

note: accessing volatile not atomic, imperative know hardware , code structure.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

php - How do you embed a video into a custom theme on WordPress? -