avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] Problem with delay loop


From: Preston Wilson
Subject: Re: [avr-gcc-list] Problem with delay loop
Date: Mon, 01 Oct 2007 10:13:07 -0400
User-agent: Microsoft-Entourage/11.3.6.070618

"Eric Weddington" wrote:

> ...

> I agree with the statement above that "'volatile' is precisely to warn the
> compiler that it should not 'reason' anything about [the] variable".
> However, David brings up a good point. A local variable is put on the stack,
> generally not the place for hardware to modify the variable. And generally,
> other parts of the program (such as ISRs) don't have access to the specific
> location of the variable on the stack. Both hardware and ISRs work with
> global variables. So *could* a compiler reason that local variables could
> never be volatile? Or are there truly situations where hardware or ISRs
> could modify local variables on the stack?

Yes, ISRs and hardware can modify variables on the stack.

uint8_t *g1;

ISR1()
{
 *g1 = 1;
}

main()
{
  volatile uint8_t v = 0;

  g1 = &v;

  // configure ISRs and enable interrupts
  ... 
}

-Preston






reply via email to

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