]> www.fi.muni.cz Git - bike-lights.git/commitdiff
main.c: on-demand sleep modes
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Mon, 3 Jun 2013 15:56:06 +0000 (17:56 +0200)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Mon, 3 Jun 2013 15:56:06 +0000 (17:56 +0200)
firmware/main.c

index 0e3395779e9c7a2c84afd71d912ef4b64868bb9f..a83884b86f9408101f9bbf3a2bc91fa010b7b1be 100644 (file)
@@ -71,7 +71,20 @@ int main(void)
        sei();
 #if 1
        while (1) {
-               sleep_mode();
+               cli();
+               if (TIMER1_IS_ON()) {
+                       set_sleep_mode(SLEEP_MODE_IDLE);
+               } else if (adc_is_on) {
+                       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