[Top][All Lists]

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

[avr-libc-dev] Sleep mode and global interrut enable

From: address@hidden
Subject: [avr-libc-dev] Sleep mode and global interrut enable
Date: Sun, 6 Nov 2005 22:52:20 +0100 (MET)

For my code, it must be guaranteed that the device goes to sleep at 
least for a moment before any ISR runs. After an ISR, it must be 
quaranteed that the device stays awake.

The macro sleep_mode() does 
not currently guarantee this. The "sleep" instruction should be 
immediately preceded with a "sei".

Now that the sleep enable bit may 
be in MCUCR or SMCR, it would be nice if the register was automatically 
chosen according the MCU type. 

Could we perhaps get some new macros 
into sleep.h? 

#define sleep_enable()                        \ 
{                                          \ 
_BV(SE);            \ 
} while (0) 

#define sleep_disable()
do {                                          
    _SLEEP_CONTROL_REG &= ~_BV(SE);           \ 
} while (0) 

#define sleep()                               \ 
{                                          \ 
  __asm__ __volatile__ ( 
"sleep" "\n\t" :: ); \ 
} while (0) 

Then I could write: 

atomically check if sleeping is allowed */ 
if ( foo == bar )   
/* foo is set from an ISR */ 
/* isr's must not run before we are asleep */ 
  sleep();     /* 
executed with ints still disabled */ 


reply via email to

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