Removed power_all/enable/disable, useless. Added a multiples of the wakeup.
This commit is contained in:
parent
ee4568ede4
commit
4ef1f4b8e6
|
@ -70,6 +70,9 @@ typedef enum { wdt_16ms = 0, wdt_32ms, wdt_64ms, wdt_128ms, wdt_250ms, wdt_500ms
|
||||||
void setup_watchdog(uint8_t prescalar);
|
void setup_watchdog(uint8_t prescalar);
|
||||||
void do_sleep(void);
|
void do_sleep(void);
|
||||||
|
|
||||||
|
const short sleep_cycles_per_transmission = 4;
|
||||||
|
volatile short sleep_cycles_remaining = sleep_cycles_per_transmission;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Normal operation
|
// Normal operation
|
||||||
//
|
//
|
||||||
|
@ -106,7 +109,7 @@ void setup(void)
|
||||||
|
|
||||||
// Only the ping out role sleeps. Wake up every 4s to send a ping
|
// Only the ping out role sleeps. Wake up every 4s to send a ping
|
||||||
if ( role == role_ping_out )
|
if ( role == role_ping_out )
|
||||||
setup_watchdog(wdt_4s);
|
setup_watchdog(wdt_1s);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Setup and configure rf radio
|
// Setup and configure rf radio
|
||||||
|
@ -192,13 +195,19 @@ void loop(void)
|
||||||
// Shut down the system
|
// Shut down the system
|
||||||
//
|
//
|
||||||
|
|
||||||
|
// Experiment with some delay here to see if it has an effect
|
||||||
|
delay(500);
|
||||||
|
|
||||||
// Power down the radio. Note that the radio will get powered back up
|
// Power down the radio. Note that the radio will get powered back up
|
||||||
// on the next write() call.
|
// on the next write() call.
|
||||||
radio.powerDown();
|
radio.powerDown();
|
||||||
|
|
||||||
// Sleep the MCU. The watchdog timer will awaken in a short while, and
|
// Sleep the MCU. The watchdog timer will awaken in a short while, and
|
||||||
// continue execution here.
|
// continue execution here.
|
||||||
|
while( sleep_cycles_remaining )
|
||||||
do_sleep();
|
do_sleep();
|
||||||
|
|
||||||
|
sleep_cycles_remaining = sleep_cycles_per_transmission;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -242,10 +251,9 @@ void loop(void)
|
||||||
// Sleep helpers
|
// Sleep helpers
|
||||||
//
|
//
|
||||||
|
|
||||||
// 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms
|
// 0=16ms, 1=32ms,2=64ms,3=125ms,4=250ms,5=500ms
|
||||||
// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
|
// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
|
||||||
|
|
||||||
|
|
||||||
void setup_watchdog(uint8_t prescalar)
|
void setup_watchdog(uint8_t prescalar)
|
||||||
{
|
{
|
||||||
prescalar = min(9,prescalar);
|
prescalar = min(9,prescalar);
|
||||||
|
@ -258,8 +266,8 @@ void setup_watchdog(uint8_t prescalar)
|
||||||
WDTCSR = _BV(WDCE) | wdtcsr | _BV(WDIE);
|
WDTCSR = _BV(WDCE) | wdtcsr | _BV(WDIE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Even though it does nothing, it's necessary to have a WDT ISR
|
|
||||||
ISR(WDT_vect) {
|
ISR(WDT_vect) {
|
||||||
|
--sleep_cycles_remaining;
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_sleep(void)
|
void do_sleep(void)
|
||||||
|
@ -267,12 +275,9 @@ void do_sleep(void)
|
||||||
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
|
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
|
||||||
sleep_enable();
|
sleep_enable();
|
||||||
|
|
||||||
power_all_disable();
|
|
||||||
sleep_mode(); // System sleeps here
|
sleep_mode(); // System sleeps here
|
||||||
|
|
||||||
sleep_disable(); // System continues execution here when watchdog timed out
|
sleep_disable(); // System continues execution here when watchdog timed out
|
||||||
power_all_enable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// vim:ai:cin:sts=2 sw=2 ft=cpp
|
// vim:ai:cin:sts=2 sw=2 ft=cpp
|
||||||
|
|
Loading…
Reference in New Issue