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

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

RE: [avr-gcc-list] Question about gcc preprocessing and port/pin assignm


From: Larry Barello
Subject: RE: [avr-gcc-list] Question about gcc preprocessing and port/pin assignments
Date: Thu, 9 Dec 2004 06:52:34 -0800

Here is an example where an I/O pin is used for both an input and an output.

www.barello.net/ARC/Projects/LEGO

Although the sample code was written in BASIC, it would be simple to switch
to gcc code.

Question: when GCC optimizes multiple access to an object, is that limited
to the current scope?  Or can that cross curly-brace boundaries?

-----Original Message-----
From:  George Kalovyrnas

Ned Konz wrote:

>There is a useful distinction between registers whose contents are in fact
>nonvolatile (like for instance DDRB) and those whose contents can be
changed
>by hardware events (like PORTB, PINB, and the ADC value registers).
>
>
and,

>However, DDRB (say) does not have to be defined as volatile, since hardware
>isn't going to change it.
>
I think that the safe way is to declare ALL hardware registers as
volatile. You use the example of DDR registers. Consider what will
happen in this case:

DDRB = 0x01;
PORTB = 0x01;
/*
Some code here
*/
DDRB = 0x00;
temp = PINB;

I know that it is rare to use a single port pin as input and output, but
there are cases that this could happen (I know it happened to me). The
optimization would lead to disaster.



reply via email to

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