> -----Original Message----- > From: > avr-libc-dev-bounces+eric.weddington=atmel....@nongnu.org > [mailto:avr-libc-dev-bounces+eric.weddington=atmel....@nongnu. > org] On Behalf Of Erik Walthinsen > Sent: Monday, June 07, 2010 4:17 PM > To: avr-libc-dev@nongnu.org > 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. _______________________________________________ AVR-libc-dev mailing list AVR-libc-dev@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-libc-dev