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

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

Re: [avr-gcc-list] Best practice for external variable (newbie-ish quest


From: Russell Shaw
Subject: Re: [avr-gcc-list] Best practice for external variable (newbie-ish question)
Date: Sun, 20 Nov 2005 12:10:03 +1100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.11) Gecko/20050914 Debian/1.7.11-1

Matthew Smith wrote:
Hi All

I am writing a small programme where I need a couple of variables to be
accessible to various routines, including an ISR.

I have declared the variables in the main body of the programme as
volatile, as I believe that this is required for access by the ISR:

volatile uint8_t foo;
volatile uint8_t bar;

1) Am I correct in thinking that I need to declare this in the ISR thus:

SIGNAL(SIG_OUTPUT_COMPARE1A)
{
        extern uint8_t foo;
        foo++;
        // Other stuff
}

yes

2) Is this the correct way to access it in an ordinary routines, or
should I be doing something with references?

void startclock(void)
{
        extern uint8_t bar;
        // Various stuff
        bar=1;
}

Is ok because it is an atomic (single-part) variable.

Comments/suggestions would be greatly appreciated.

If you modify an integer or other multi-byte variable
that is also used in an isr, you should disable the isr
so that the variable is not read or written while
manipulation on it is only half complete.




reply via email to

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