[Top][All Lists]
[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:15:48 +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, but maybe it should be:
SIGNAL(SIG_OUTPUT_COMPARE1A)
{
extern volatile uint8_t foo;
foo++;
// Other stuff
}
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.
Also, there is less chance of errors if you put
extern volatile uint8_t foo;
extern volatile uint8_t bar;
in the header file that belongs to the file where they are defined,
and #include the header wherever you need them.
- [avr-gcc-list] Best practice for external variable (newbie-ish question), Matthew Smith, 2005/11/19
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), Russell Shaw, 2005/11/19
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question),
Russell Shaw <=
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), Joerg Wunsch, 2005/11/20
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), David Kelly, 2005/11/20
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), Matthew Smith, 2005/11/20
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), David Kelly, 2005/11/20
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), Matthew Smith, 2005/11/20
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), Matthew Smith, 2005/11/21
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), Joerg Wunsch, 2005/11/22
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), Matthew Smith, 2005/11/22
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), Joerg Wunsch, 2005/11/22
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), Russell Shaw, 2005/11/20