[Top][All Lists]

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

Re: [avr-gcc-list] "Volatile"

From: Keith Gudger
Subject: Re: [avr-gcc-list] "Volatile"
Date: Mon, 18 Apr 2005 06:54:08 -0700 (PDT)

On Mon, 18 Apr 2005, David Brown wrote:
> Note that the assignment is atomic even if the assembly consists of more
> than one instruction (e.g., something like ldi r16, #1; st r16, flag ).  The
> point of an "atomic" access is that there is no way to break the statement
> into a "half-done" step, as viewed by interrupt functions or external
> accesses of some sort.  Even if an interrupt occured between these two
> instructions, the flag change itself would not be affected - thus it is
> atomic.
 I think I missed something here.  Why would :

ldi r16, #1; 
st r16, flag

Necessarily be atomic?  If an interrupt occured between these 2
instructions, and the interrupt changed the state of flag, wouldn't there
still be the original problem?

On to a solution, since disabling interrupts is not portable, would
something like the following be an OK solution?

void Flags_Clear(unsigned char x)
    cFlags &= ~x;

Where the CRITICAL_SECTION stuff are macros, defined on a per machine

Thanks to everyone for all their help on this issue!

reply via email to

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