diff --git a/cpu/avr/rtimer-arch.c b/cpu/avr/rtimer-arch.c index 07a643018..c3f8f0220 100644 --- a/cpu/avr/rtimer-arch.c +++ b/cpu/avr/rtimer-arch.c @@ -225,3 +225,112 @@ rtimer_arch_schedule(rtimer_clock_t t) SREG = sreg; #endif /* RTIMER_ARCH_PRESCALER */ } + +#if RDC_CONF_MCU_SLEEP +/*---------------------------------------------------------------------------*/ +void +rtimer_arch_sleep(rtimer_clock_t howlong) +{ +/* Deep Sleep for howlong rtimer ticks. This will stop all timers except + * for TIMER2 which can be clocked using an external crystal. + * Unfortunately this is an 8 bit timer; a lower prescaler gives higher + * precision but smaller maximum sleep time. + * Here a maximum 128msec (contikimac 8Hz channel check sleep) is assumed. + * The rtimer and system clocks are adjusted to reflect the sleep time. + */ +#include +#include +uint32_t longhowlong; +#if AVR_CONF_USE32KCRYSTAL +/* Save TIMER2 configuration if clock.c is using it */ + uint8_t savedTCNT2=TCNT2, savedTCCR2A=TCCR2A, savedTCCR2B = TCCR2B, savedOCR2A = OCR2A; +#endif + cli(); + watchdog_stop(); + set_sleep_mode(SLEEP_MODE_PWR_SAVE); + +/* Set TIMER2 clock asynchronus from external source, CTC mode */ + ASSR |= (1 << AS2); + TCCR2A =(1<