[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Global variables and ISRs ???

From: David Brown
Subject: Re: [avr-gcc-list] Global variables and ISRs ???
Date: Thu, 15 Sep 2005 09:20:17 +0200

----- Original Message -----
From: "Lars Noschinski" <address@hidden>

> * Lars Noschinski <address@hidden> [2005-09-06 21:59]:
> >You must declare the global variable as volatile (or as register), if
> >you want to modify in an ISR.

Wrong - that's neither necessary nor complete (there is just as much of an
issue reading variables as writing them).

> Speaking of this, if I have an variable which is initialized during
> startup and only accessed /in/ an ISR, am I on the safe side, if don't
> declare it as volatile, right?


The point is that you need to use "volatile" if the data may change or be
used without the compiler knowing it.  If a function uses a variable, and
may be interrupted by an ISR which also uses that same variable, then the
variable should be volatile - but otherwise, there is no need for it to be
volatile.  So a variable that is only used in an ISR is safe.  If the main
function has interrupts turned off (either globally, or the specific ISR
interrupt enable), then it can happily use a non-volatile variable shared
with the ISR.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]