avr-libc-dev
[Top][All Lists]
Advanced

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

RE: [avr-libc-dev] XMEGA


From: Weddington, Eric
Subject: RE: [avr-libc-dev] XMEGA
Date: Mon, 7 Jun 2010 16:28:42 -0600

 

> -----Original Message-----
> From: 
> address@hidden 
> [mailto:address@hidden
> org] On Behalf Of Erik Walthinsen
> Sent: Monday, June 07, 2010 4:17 PM
> To: address@hidden
> Subject: Re: [avr-libc-dev] XMEGA
> 
> On 06/07/2010 01:41 PM, Rob Holbert wrote:
> > However, there is a major difference.  The fully qualified 
> (PORTC_OUTSET)
> > has volatile tied to it and
> > the (PORTC.OUTSET) does not.
> 
> Not so sure this is the case.  In the headers I have:
> 
> #define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr))
> #define _SFR_MEM8(mem_addr) _MMIO_BYTE(mem_addr)
> #define PORTC_OUT  _SFR_MEM8(0x0644)
> 
> yet
> 
> typedef volatile uint8_t register8_t;
> typedef struct PORT_struct {
>      . . .
>      register8_t OUT;  /* I/O Port Output */
>      . . .
> } PORT_t;
> #define PORTC    (*(PORT_t *) 0x0640)  /* Port C */


And importantly register8_t is defined this way in the header file:
typedef volatile uint8_t register8_t;

 
> I don't see any functional difference in the use of the volatile 
> keyword, unless the struct is doing something unexpected.
> 
> However, I do remember at one point having problems along 
> these lines, 
> and actually putting in the _ versions of some registers.  I've since 
> taken them out though, and I don't remember the details.
> 
> OTOH, I've recently done test code where I do PORT*.OUT = 
> x;PORT*.OUT = 
> y in a loop, and I scoped the expected results.

I have always been a little bit concerned between using, e.g., PORTC.OUT versus 
PORTC_OUT. The latter is time-tested, straightforward with very little 
surprises. The former is a pointer to a structure, dereferenced, and using the 
dot operator to calculate an offset. Ideally, there should be no difference in 
the generated code. What I can't remember, however, is what happens when 
optimizations are turned down or off. IIRC, the compiler might generate more 
code with the structure-and-dot-offset variety. But it's been a long time since 
I've looked at it and I don't recall what the final results were.

I would be very interested if someone shows conclusively that there are errors 
with the structure-and-dot-offset register definitions.



reply via email to

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