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

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

RE: [avr-libc-dev] [RFC] Sleeping BOD API


From: Weddington, Eric
Subject: RE: [avr-libc-dev] [RFC] Sleeping BOD API
Date: Fri, 6 Feb 2009 08:20:49 -0700

 

> -----Original Message-----
> From: 
> address@hidden 
> [mailto:address@hidden
> org] On Behalf Of Dmitry K.
> Sent: Friday, February 06, 2009 12:23 AM
> To: address@hidden
> Subject: Re: [avr-libc-dev] [RFC] Sleeping BOD API
> 
> On Friday 06 February 2009 09:10, Weddington, Eric wrote:
> [...]
> > +#define sleep_bod_disable()  \
> > +(__extension__({             \
> > +    __asm__ __volatile__ (   \
> > +        "ori  %0,%1" \
> > +        : "+d" (MCUCR) \
> > +        : "i" (_BV(BODS) | _BV(BODSE)) \
> > +    ); \
> > +    __asm__ __volatile__ (   \
> > +        "andi  %0,%1" \
> > +        : "=d" (MCUCR) \
> > +        : "i" (~_BV(BODSE)) \
> > +    ); \
> > +}))
> 
> Hmm...
> It is interesting to omit IN/OUT instruction in such manner.
> I will check this for all Avr-gcc versions.
> 
> Thanks, this is new for me.

Thanks for looking into this Dmitry. It was new to me too. Interestingly the 
"+d" constraint tells gcc that it is both input and output. Since I specified 
MCUCR as "d" (high register), gcc generates the mov from memory to register 
(input) and the mov from register to memory (output), basically letting gcc do 
the main work on selecting the register (which I don't want to do).

Then, the second __asm__ statement has "=d" as the constraint on MCUCR, only 
selecting the *output* portion. This is because I don't want the MCUCR register 
reloaded into the register when it already exists.

My big question is: Do I have to worry that GCC will somehow select a different 
register for MCUCR in the second __asm__ statement? I would think that since I 
am letting gcc select the register in the first __asm__ statement and having 
gcc do the output, that gcc will know which register that MCUCR lives in and 
can match that with the second __asm__ statement. From my tests, it seems that 
it is truly the case; the registers always match so that it generates 
(pseudocode):

in   X, 85-32
ori  X, 96
out  85-32, X
andi X, -33
out  85-32, X

where "X" is always the same high register ("d" constraint).

This is important to meet the timed sequence needed to disable the BOD before 
sleeping.

Eric Weddington




reply via email to

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