36 #define _AVR_SLEEP_H_ 1 138 #if defined(SLEEP_CTRL) 141 #define _SLEEP_CONTROL_REG SLEEP_CTRL 142 #define _SLEEP_ENABLE_MASK SLEEP_SEN_bm 146 #define _SLEEP_CONTROL_REG SMCR 147 #define _SLEEP_ENABLE_MASK _BV(SE) 149 #elif defined(__AVR_AT94K__) 151 #define _SLEEP_CONTROL_REG MCUR 152 #define _SLEEP_ENABLE_MASK _BV(SE) 154 #elif !defined(__DOXYGEN__) 156 #define _SLEEP_CONTROL_REG MCUCR 157 #define _SLEEP_ENABLE_MASK _BV(SE) 164 #if defined(__AVR_ATmega161__) 166 #define set_sleep_mode(mode) \ 168 MCUCR = ((MCUCR & ~_BV(SM1)) | ((mode) == SLEEP_MODE_PWR_DOWN || (mode) == SLEEP_MODE_PWR_SAVE ? _BV(SM1) : 0)); \ 169 EMCUCR = ((EMCUCR & ~_BV(SM0)) | ((mode) == SLEEP_MODE_PWR_SAVE ? _BV(SM0) : 0)); \ 173 #elif defined(__AVR_ATmega162__) \ 174 || defined(__AVR_ATmega8515__) 176 #define set_sleep_mode(mode) \ 178 MCUCR = ((MCUCR & ~_BV(SM1)) | ((mode) == SLEEP_MODE_IDLE ? 0 : _BV(SM1))); \ 179 MCUCSR = ((MCUCSR & ~_BV(SM2)) | ((mode) == SLEEP_MODE_STANDBY || (mode) == SLEEP_MODE_EXT_STANDBY ? _BV(SM2) : 0)); \ 180 EMCUCR = ((EMCUCR & ~_BV(SM0)) | ((mode) == SLEEP_MODE_PWR_SAVE || (mode) == SLEEP_MODE_EXT_STANDBY ? _BV(SM0) : 0)); \ 184 #elif defined(__AVR_XMEGA__) 185 #if defined(SLEEP_SMODE2_bm) 187 #define set_sleep_mode(mode) \ 189 _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(SLEEP_SMODE2_bm | SLEEP_SMODE1_bm | SLEEP_SMODE0_bm)) | (mode)); \ 192 #elif defined(SLEEP_SMODE1_bm) 194 #define set_sleep_mode(mode) \ 196 _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(SLEEP_SMODE1_bm | SLEEP_SMODE0_bm)) | (mode)); \ 201 #define set_sleep_mode(mode) \ 203 _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~( SLEEP_SMODE0_bm)) | (mode)); \ 213 #define set_sleep_mode(mode) \ 215 _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1) | _BV(SM2))) | (mode)); \ 220 #define set_sleep_mode(mode) \ 222 _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1))) | (mode)); \ 227 #define set_sleep_mode(mode) \ 229 _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~_BV(SM)) | (mode)); \ 234 #error "No SLEEP mode defined for this device." 248 #if defined(__DOXYGEN__) 258 #define sleep_enable() \ 260 _SLEEP_CONTROL_REG |= (uint8_t)_SLEEP_ENABLE_MASK; \ 266 #if defined(__DOXYGEN__) 276 #define sleep_disable() \ 278 _SLEEP_CONTROL_REG &= (uint8_t)(~_SLEEP_ENABLE_MASK); \ 289 #if defined(__DOXYGEN__) 295 #define sleep_cpu() \ 297 __asm__ __volatile__ ( "sleep" "\n\t" :: ); \ 303 #if defined(__DOXYGEN__) 313 #define sleep_mode() \ 323 #if defined(__DOXYGEN__) 334 #if defined(BODS) && defined(BODSE) 338 #define BOD_CONTROL_REG BODCR 342 #define BOD_CONTROL_REG MCUCR 346 #define sleep_bod_disable() \ 349 __asm__ __volatile__("in %[tempreg], %[mcucr]" "\n\t" \ 350 "ori %[tempreg], %[bods_bodse]" "\n\t" \ 351 "out %[mcucr], %[tempreg]" "\n\t" \ 352 "andi %[tempreg], %[not_bodse]" "\n\t" \ 353 "out %[mcucr], %[tempreg]" \ 354 : [tempreg] "=&d" (tempreg) \ 355 : [mcucr] "I" _SFR_IO_ADDR(BOD_CONTROL_REG), \ 356 [bods_bodse] "i" (_BV(BODS) | _BV(BODSE)), \ 357 [not_bodse] "i" (~_BV(BODSE))); \
void sleep_bod_disable(void)