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

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

Re: [avr-gcc-list] C structs for Hardware definitions


From: E. Weddington
Subject: Re: [avr-gcc-list] C structs for Hardware definitions
Date: Mon, 26 May 2003 16:29:50 -0600


Larry Barello wrote:

> Before I go type in a bunch of stuff, is there any good reason why C structs 
> & bitfields
> can't be used to access hardware, like the USART control registers?  Is it a 
> matter of
> efficiency: with a dereferenced pointer GCC has to treat it like memory and 
> not use the
> bit test/set instructions?  Or is it dealing with the screwy I/O map of the 
> AVR?  Then I
> can write one set of handlers for the USARTs and pass the pointer to make 
> things happen.
>
> e.g.
>
> typedef struct
> {
>     unsigned char UDR;
>     struct
>     {
>         unsigned char bitthis:1;
>         unsigned char bitthat:1;
>         unsigned char etc:3;
>     } USCRA;
>     struct
>     {
>         ...
>     } USCRB;
>     ...
>     unsigned UBRR;
>
> } *pUSART;
>
> pUSART USART0 = 0xXX, USART1 = 0xYYY;
>
> ...
>
> if (USART0->bitthis == 0) ...

I don't know how efficient bitfields would be in this regard. You're best bet 
would be to
experiment and take a look at the assembly listing. The big thing to remember 
is to put
volatile on all your register definitions. All the registers are defined as 
such:

#define REGISTER     (*((volatile unsigned char *)0x0000))

with of course the number being the address of the register.

Eric






reply via email to

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