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.


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to