Go to the documentation of this file.
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)
156 #define _SLEEP_CONTROL_REG MCUCR
157 #define _SLEEP_ENABLE_MASK _BV(SE)
163 #if defined(__AVR_ATmega161__)
165 #define SLEEP_MODE_IDLE 0
166 #define SLEEP_MODE_PWR_DOWN 1
167 #define SLEEP_MODE_PWR_SAVE 2
169 #define set_sleep_mode(mode) \
171 MCUCR = ((MCUCR & ~_BV(SM1)) | ((mode) == SLEEP_MODE_PWR_DOWN || (mode) == SLEEP_MODE_PWR_SAVE ? _BV(SM1) : 0)); \
172 EMCUCR = ((EMCUCR & ~_BV(SM0)) | ((mode) == SLEEP_MODE_PWR_SAVE ? _BV(SM0) : 0)); \
176 #elif defined(__AVR_ATmega162__) \
177 || defined(__AVR_ATmega8515__)
179 #define SLEEP_MODE_IDLE 0
180 #define SLEEP_MODE_PWR_DOWN 1
181 #define SLEEP_MODE_PWR_SAVE 2
182 #define SLEEP_MODE_ADC 3
183 #define SLEEP_MODE_STANDBY 4
184 #define SLEEP_MODE_EXT_STANDBY 5
186 #define set_sleep_mode(mode) \
188 MCUCR = ((MCUCR & ~_BV(SM1)) | ((mode) == SLEEP_MODE_IDLE ? 0 : _BV(SM1))); \
189 MCUCSR = ((MCUCSR & ~_BV(SM2)) | ((mode) == SLEEP_MODE_STANDBY || (mode) == SLEEP_MODE_EXT_STANDBY ? _BV(SM2) : 0)); \
190 EMCUCR = ((EMCUCR & ~_BV(SM0)) | ((mode) == SLEEP_MODE_PWR_SAVE || (mode) == SLEEP_MODE_EXT_STANDBY ? _BV(SM0) : 0)); \
193 #elif defined(__AVR_AT90S2313__) \
194 || defined(__AVR_AT90S2323__) \
195 || defined(__AVR_AT90S2333__) \
196 || defined(__AVR_AT90S2343__) \
197 || defined(__AVR_AT43USB320__) \
198 || defined(__AVR_AT43USB355__) \
199 || defined(__AVR_AT90S4414__) \
200 || defined(__AVR_AT90S4433__) \
201 || defined(__AVR_AT90S8515__) \
202 || defined(__AVR_ATtiny22__)
204 #define SLEEP_MODE_IDLE 0
205 #define SLEEP_MODE_PWR_DOWN _BV(SM)
207 #define set_sleep_mode(mode) \
209 _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~__BV(SM)) | (mode)); \
212 #elif defined(__AVR_ATtiny167__) \
213 || defined(__AVR_ATtiny87__)
215 #define SLEEP_MODE_IDLE 0
216 #define SLEEP_MODE_ADC _BV(SM0)
217 #define SLEEP_MODE_PWR_DOWN _BV(SM1)
219 #define set_sleep_mode(mode) \
221 _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1))) | (mode)); \
224 #elif defined(__AVR_AT90S4434__) \
225 || defined(__AVR_AT76C711__) \
226 || defined(__AVR_AT90S8535__) \
227 || defined(__AVR_ATmega103__) \
228 || defined(__AVR_ATmega161__) \
229 || defined(__AVR_ATmega163__) \
230 || defined(__AVR_ATmega16HVB__) \
231 || defined(__AVR_ATmega16HVBREVB__) \
232 || defined(__AVR_ATmega32HVB__) \
233 || defined(__AVR_ATmega32HVBREVB__) \
234 || defined(__AVR_ATtiny13__) \
235 || defined(__AVR_ATtiny13A__) \
236 || defined(__AVR_ATtiny15__) \
237 || defined(__AVR_ATtiny24__) \
238 || defined(__AVR_ATtiny24A__) \
239 || defined(__AVR_ATtiny44__) \
240 || defined(__AVR_ATtiny44A__) \
241 || defined(__AVR_ATtiny84__) \
242 || defined(__AVR_ATtiny84A__) \
243 || defined(__AVR_ATtiny25__) \
244 || defined(__AVR_ATtiny45__) \
245 || defined(__AVR_ATtiny48__) \
246 || defined(__AVR_ATtiny85__) \
247 || defined(__AVR_ATtiny88__)
249 #define SLEEP_MODE_IDLE 0
250 #define SLEEP_MODE_ADC _BV(SM0)
251 #define SLEEP_MODE_PWR_DOWN _BV(SM1)
252 #define SLEEP_MODE_PWR_SAVE (_BV(SM0) | _BV(SM1))
254 #define set_sleep_mode(mode) \
256 _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1))) | (mode)); \
259 #elif defined(__AVR_ATtiny2313__) \
260 || defined(__AVR_ATtiny2313A__) \
261 || defined(__AVR_ATtiny4313__)
263 #define SLEEP_MODE_IDLE 0
264 #define SLEEP_MODE_PWR_DOWN (_BV(SM0) | _BV(SM1))
265 #define SLEEP_MODE_STANDBY _BV(SM1)
267 #define set_sleep_mode(mode) \
269 _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1))) | (mode)); \
272 #elif defined(__AVR_AT94K__)
274 #define SLEEP_MODE_IDLE 0
275 #define SLEEP_MODE_PWR_DOWN _BV(SM1)
276 #define SLEEP_MODE_PWR_SAVE (_BV(SM0) | _BV(SM1))
278 #define set_sleep_mode(mode) \
280 _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1))) | (mode)); \
283 #elif defined(__AVR_ATtiny26__) \
284 || defined(__AVR_ATtiny261__) \
285 || defined(__AVR_ATtiny261A__) \
286 || defined(__AVR_ATtiny461__) \
287 || defined(__AVR_ATtiny461A__) \
288 || defined(__AVR_ATtiny861__) \
289 || defined(__AVR_ATtiny861A__) \
290 || defined(__AVR_ATtiny43U__)
292 #define SLEEP_MODE_IDLE 0
293 #define SLEEP_MODE_ADC _BV(SM0)
294 #define SLEEP_MODE_PWR_DOWN _BV(SM1)
295 #define SLEEP_MODE_STANDBY (_BV(SM0) | _BV(SM1))
297 #define set_sleep_mode(mode) \
299 _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1))) | (mode)); \
302 #elif defined(__AVR_AT90PWM216__) \
303 || defined(__AVR_AT90PWM316__) \
304 || defined(__AVR_AT90PWM81__)
306 #define SLEEP_MODE_IDLE 0
307 #define SLEEP_MODE_ADC _BV(SM0)
308 #define SLEEP_MODE_PWR_DOWN _BV(SM1)
309 #define SLEEP_MODE_STANDBY (_BV(SM1) | _BV(SM2))
311 #define set_sleep_mode(mode) \
313 _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1) | _BV(SM2))) | (mode)); \
316 #elif defined(__AVR_AT90CAN128__) \
317 || defined(__AVR_AT90CAN32__) \
318 || defined(__AVR_AT90CAN64__) \
319 || defined(__AVR_AT90PWM1__) \
320 || defined(__AVR_AT90PWM2__) \
321 || defined(__AVR_AT90PWM2B__) \
322 || defined(__AVR_AT90PWM3__) \
323 || defined(__AVR_AT90PWM3B__) \
324 || defined(__AVR_AT90USB162__) \
325 || defined(__AVR_AT90USB82__) \
326 || defined(__AVR_AT90USB1286__) \
327 || defined(__AVR_AT90USB1287__) \
328 || defined(__AVR_AT90USB646__) \
329 || defined(__AVR_AT90USB647__) \
330 || defined(__AVR_ATmega128__) \
331 || defined(__AVR_ATmega1280__) \
332 || defined(__AVR_ATmega1281__) \
333 || defined(__AVR_ATmega1284P__) \
334 || defined(__AVR_ATmega128RFA1__) \
335 || defined(__AVR_ATmega16__) \
336 || defined(__AVR_ATmega16A__) \
337 || defined(__AVR_ATmega162__) \
338 || defined(__AVR_ATmega164A__) \
339 || defined(__AVR_ATmega164P__) \
340 || defined(__AVR_ATmega165__) \
341 || defined(__AVR_ATmega165A__) \
342 || defined(__AVR_ATmega165P__) \
343 || defined(__AVR_ATmega168__) \
344 || defined(__AVR_ATmega168A__) \
345 || defined(__AVR_ATmega168P__) \
346 || defined(__AVR_ATmega169__) \
347 || defined(__AVR_ATmega169A__) \
348 || defined(__AVR_ATmega169P__) \
349 || defined(__AVR_ATmega169PA__) \
350 || defined(__AVR_ATmega16HVA__) \
351 || defined(__AVR_ATmega16HVA2__) \
352 || defined(__AVR_ATmega16M1__) \
353 || defined(__AVR_ATmega16U2__) \
354 || defined(__AVR_ATmega16U4__) \
355 || defined(__AVR_ATmega2560__) \
356 || defined(__AVR_ATmega2561__) \
357 || defined(__AVR_ATmega32__) \
358 || defined(__AVR_ATmega323__) \
359 || defined(__AVR_ATmega324A__) \
360 || defined(__AVR_ATmega324P__) \
361 || defined(__AVR_ATmega324PA__) \
362 || defined(__AVR_ATmega325__) \
363 || defined(__AVR_ATmega325A__) \
364 || defined(__AVR_ATmega3250__) \
365 || defined(__AVR_ATmega3250A__) \
366 || defined(__AVR_ATmega328__) \
367 || defined(__AVR_ATmega328P__) \
368 || defined(__AVR_ATmega329__) \
369 || defined(__AVR_ATmega329A__) \
370 || defined(__AVR_ATmega329P__) \
371 || defined(__AVR_ATmega329PA__) \
372 || defined(__AVR_ATmega3290__) \
373 || defined(__AVR_ATmega3290A__) \
374 || defined(__AVR_ATmega3290P__) \
375 || defined(__AVR_ATmega32C1__) \
376 || defined(__AVR_ATmega32M1__) \
377 || defined(__AVR_ATmega32U2__) \
378 || defined(__AVR_ATmega32U4__) \
379 || defined(__AVR_ATmega32U6__) \
380 || defined(__AVR_ATmega406__) \
381 || defined(__AVR_ATmega48__) \
382 || defined(__AVR_ATmega48A__) \
383 || defined(__AVR_ATmega48P__) \
384 || defined(__AVR_ATmega64__) \
385 || defined(__AVR_ATmega640__) \
386 || defined(__AVR_ATmega644__) \
387 || defined(__AVR_ATmega644A__) \
388 || defined(__AVR_ATmega644P__) \
389 || defined(__AVR_ATmega644PA__) \
390 || defined(__AVR_ATmega645__) \
391 || defined(__AVR_ATmega645A__) \
392 || defined(__AVR_ATmega645P__) \
393 || defined(__AVR_ATmega6450__) \
394 || defined(__AVR_ATmega6450A__) \
395 || defined(__AVR_ATmega6450P__) \
396 || defined(__AVR_ATmega649__) \
397 || defined(__AVR_ATmega649A__) \
398 || defined(__AVR_ATmega6490__) \
399 || defined(__AVR_ATmega6490A__) \
400 || defined(__AVR_ATmega6490P__) \
401 || defined(__AVR_ATmega649P__) \
402 || defined(__AVR_ATmega64C1__) \
403 || defined(__AVR_ATmega64HVE__) \
404 || defined(__AVR_ATmega64M1__) \
405 || defined(__AVR_ATmega8__) \
406 || defined(__AVR_ATmega8515__) \
407 || defined(__AVR_ATmega8535__) \
408 || defined(__AVR_ATmega88__) \
409 || defined(__AVR_ATmega88A__) \
410 || defined(__AVR_ATmega88P__) \
411 || defined(__AVR_ATmega88PA__) \
412 || defined(__AVR_ATmega8HVA__) \
413 || defined(__AVR_ATmega8U2__)
416 #define SLEEP_MODE_IDLE (0)
417 #define SLEEP_MODE_ADC _BV(SM0)
418 #define SLEEP_MODE_PWR_DOWN _BV(SM1)
419 #define SLEEP_MODE_PWR_SAVE (_BV(SM0) | _BV(SM1))
420 #define SLEEP_MODE_STANDBY (_BV(SM1) | _BV(SM2))
421 #define SLEEP_MODE_EXT_STANDBY (_BV(SM0) | _BV(SM1) | _BV(SM2))
424 #define set_sleep_mode(mode) \
426 _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1) | _BV(SM2))) | (mode)); \
429 #elif defined(__AVR_ATxmega16A4__) \
430 || defined(__AVR_ATxmega16D4__) \
431 || defined(__AVR_ATxmega32A4__) \
432 || defined(__AVR_ATxmega32D4__) \
433 || defined(__AVR_ATxmega64A1__) \
434 || defined(__AVR_ATxmega64A1U__) \
435 || defined(__AVR_ATxmega64A3__) \
436 || defined(__AVR_ATxmega64D3__) \
437 || defined(__AVR_ATxmega128A1__) \
438 || defined(__AVR_ATxmega128A1U__) \
439 || defined(__AVR_ATxmega128A3__) \
440 || defined(__AVR_ATxmega128D3__) \
441 || defined(__AVR_ATxmega192A3__) \
442 || defined(__AVR_ATxmega192D3__) \
443 || defined(__AVR_ATxmega256A3__) \
444 || defined(__AVR_ATxmega256D3__) \
445 || defined(__AVR_ATxmega256A3B__)
447 #define SLEEP_MODE_IDLE (0)
448 #define SLEEP_MODE_PWR_DOWN (SLEEP_SMODE1_bm)
449 #define SLEEP_MODE_PWR_SAVE (SLEEP_SMODE1_bm | SLEEP_SMODE0_bm)
450 #define SLEEP_MODE_STANDBY (SLEEP_SMODE2_bm | SLEEP_SMODE1_bm)
451 #define SLEEP_MODE_EXT_STANDBY (SLEEP_SMODE2_bm | SLEEP_SMODE1_bm | SLEEP_SMODE0_bm)
453 #define set_sleep_mode(mode) \
455 _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(SLEEP_SMODE2_bm | SLEEP_SMODE1_bm | SLEEP_SMODE0_bm)) | (mode)); \
458 #elif defined(__AVR_AT90SCR100__)
460 #define SLEEP_MODE_IDLE (0)
461 #define SLEEP_MODE_PWR_DOWN _BV(SM1)
462 #define SLEEP_MODE_PWR_SAVE (_BV(SM0) | _BV(SM1))
463 #define SLEEP_MODE_STANDBY (_BV(SM1) | _BV(SM2))
464 #define SLEEP_MODE_EXT_STANDBY (_BV(SM0) | _BV(SM1) | _BV(SM2))
466 #define set_sleep_mode(mode) \
468 _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1) | _BV(SM2))) | (mode)); \
471 #elif defined(__AVR_ATA6289__)
473 #define SLEEP_MODE_IDLE (0)
474 #define SLEEP_MODE_SENSOR_NOISE_REDUCTION (_BV(SM0))
475 #define SLEEP_MODE_PWR_DOWN (_BV(SM1))
477 #define set_sleep_mode(mode) \
479 _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1) | _BV(SM2))) | (mode)); \
482 #elif defined(__AVR_ATtiny4__) \
483 || defined(__AVR_ATtiny5__) \
484 || defined(__AVR_ATtiny9__) \
485 || defined(__AVR_ATtiny10__) \
486 || defined(__AVR_ATtiny20__) \
487 || defined(__AVR_ATtiny40__)
489 #define SLEEP_MODE_IDLE 0
490 #define SLEEP_MODE_ADC _BV(SM0)
491 #define SLEEP_MODE_PWR_DOWN _BV(SM1)
492 #define SLEEP_MODE_STANDBY _BV(SM2)
494 #define set_sleep_mode(mode) \
496 _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(_BV(SM0) | _BV(SM1) | _BV(SM2))) | (mode)); \
501 #error "No SLEEP mode defined for this device."
514 #if defined(__DOXYGEN__)
524 #define sleep_enable() \
526 _SLEEP_CONTROL_REG |= (uint8_t)_SLEEP_ENABLE_MASK; \
532 #if defined(__DOXYGEN__)
542 #define sleep_disable() \
544 _SLEEP_CONTROL_REG &= (uint8_t)(~_SLEEP_ENABLE_MASK); \
555 #if defined(__DOXYGEN__)
561 #define sleep_cpu() \
563 __asm__ __volatile__ ( "sleep" "\n\t" :: ); \
569 #if defined(__DOXYGEN__)
571 extern void sleep_mode (
void);
575 #define sleep_mode() \
585 #if defined(__DOXYGEN__)
587 extern void sleep_bod_disable (
void);
591 #if defined(BODS) && defined(BODSE)
593 #define sleep_bod_disable() \
596 __asm__ __volatile__("in %[tempreg], %[mcucr]" "\n\t" \
597 "ori %[tempreg], %[bods_bodse]" "\n\t" \
598 "out %[mcucr], %[tempreg]" "\n\t" \
599 "andi %[tempreg], %[not_bodse]" "\n\t" \
600 "out %[mcucr], %[tempreg]" \
601 : [tempreg] "=&d" (tempreg) \
602 : [mcucr] "I" _SFR_IO_ADDR(MCUCR), \
603 [bods_bodse] "i" (_BV(BODS) | _BV(BODSE)), \
604 [not_bodse] "i" (~_BV(BODSE))); \
Automatically generated by Doxygen 1.8.7 on Tue Jul 8 2014. Dash Docset conversion by Matt Kane