avr-chat
[Top][All Lists]
Advanced

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

Re: [avr-chat] question about _SFR_IO8() and friends


From: Joerg Wunsch
Subject: Re: [avr-chat] question about _SFR_IO8() and friends
Date: Fri, 19 Sep 2014 22:25:02 +0200 (CEST)

Britton Kerin <address@hidden> wrote:

> I'd like to allow a register to be initialized using one of the
> symbolic macros, e.g. DDRD:
> 
>    uint8_t dir_reg = DDRD;

As you already noticed, this already dereferences the port, so
you're about to initialize dir_reg with the *contents* of DDRD.

What you need is basically explained in the FAQ:

http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_port_pass

const volatile uint8_t *dir_reg = &DDRD;

If you can manage to declare it "const", there are chances
the compiler can really generate optimal code (using IN/OUT,
rather than memory access instructions) when your macro uses
it.

Obviously, your macro must then be written to accept a pointer
(rather than the register name), and dereference it.
-- 
cheers, Joerg               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/
Never trust an operating system you don't have sources for. ;-)



reply via email to

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