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: Joerg Wunsch
Subject: Re: [avr-libc-dev] [RFC] Sleeping BOD API
Date: Fri, 6 Feb 2009 22:07:33 +0100
User-agent: Mutt/1.5.11

As Weddington, Eric wrote:

> > > > > +#define sleep_bod_disable()  \
> > > > > +(__extension__({             \

That complicated __extension__ gimmick is not needed here.  It's only
needed in one situation (the PSTR macro) where a braced group yields a
"return" value.

> > Is there any disadvantage to including the OUT instructions
> > directly instead of breaking up the macro into two asm statements?

> Yes. I would then have to specify the exact register to use.

Nope.  You could create a local variable within the brace group
(you've already got anyway), and pass that variable with the correct
constraint into the inline asm statements.  That's the usual way this
kind of job is implemented, and IMHO the best compromise between
readability of the code (well, this always sucks as soon as the word
"__asm__" enters the scene :) and not getting into the optimizer's
way.

If I'm not completely mistaken, the following ought to work:

#include <avr/interrupt.h>
#include <avr/sleep.h>

#define sleep_bod_disable()  \
{ \
  uint8_t tempreg; \
  __asm__ __volatile__( \
    "in %[tempreg], %[mcucr]" "\n\t"       \
    "ori %[tempreg], %[bods_bodse]" "\n\t" \
    "out %[mcucr], %[tempreg]" "\n\t"       \
    "andi %[tempreg], %[not_bodse]" "\n\t" \
    "out %[mcucr], %[tempreg]"             \
    : \
    : [tempreg] "d" (tempreg), \
      [mcucr] "I" _SFR_IO_ADDR(MCUCR), \
      [bods_bodse] "i" (_BV(BODS) | _BV(BODSE)), \
      [not_bodse] "i" (~_BV(BODSE))); \
}

int
main(void)
{
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  cli();
  if (1)
  {
    sleep_enable();
    sleep_bod_disable();
    sei();
    sleep_cpu();
    sleep_disable();
  }
  sei();

  return 42;
}


-- 
cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

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




reply via email to

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