X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=tinyboard.git;a=blobdiff_plain;f=projects%2Fstep-up%2Fmain.c;h=25d80df070bb4bf7269e89c6ee50792fdb245612;hp=383aa5eed990ead218315efe687846100b1f3df0;hb=HEAD;hpb=ffb4982594d98b8d8ecd9efcfe37c17e0f2fc53b diff --git a/projects/step-up/main.c b/projects/step-up/main.c index 383aa5e..25d80df 100644 --- a/projects/step-up/main.c +++ b/projects/step-up/main.c @@ -11,11 +11,10 @@ static void hw_setup() { power_all_disable(); - wdt_enable(WDTO_1S); - init_battery(); init_pwm(); init_adc(); + init_wdt(); init_buttons(); @@ -26,16 +25,15 @@ static void hw_setup() set_sleep_mode(SLEEP_MODE_IDLE); } -#if 0 static void hw_suspend() { susp_pwm(); susp_adc(); - susp_tmr(); - susp_gpio(); + susp_wdt(); + susp_buttons(); - wdt_disable(); + power_all_disable(); } void power_down() @@ -60,7 +58,6 @@ void power_down() // ok, so I will wake up hw_setup(); } -#endif int main(void) { @@ -69,13 +66,25 @@ int main(void) log_set_state(3); hw_setup(); - // power_down(); - not while still debugging + power_down(); sei(); #if 1 while (1) { - wdt_reset(); - sleep_mode(); + cli(); + if (pwm_enabled) { + set_sleep_mode(SLEEP_MODE_IDLE); + } else if (adc_enabled) { + set_sleep_mode(SLEEP_MODE_ADC); + } else { + set_sleep_mode(SLEEP_MODE_PWR_DOWN); + } + + sleep_enable(); + // keep BOD active, no sleep_bod_disable(); + sei(); + sleep_cpu(); + sleep_disable(); } #endif