WIP: on-demand sleep modes
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Fri, 10 May 2013 15:17:00 +0000 (17:17 +0200)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Fri, 10 May 2013 15:17:00 +0000 (17:17 +0200)
This does not compile yet, to be fixed.

projects/step-up/lights.h
projects/step-up/main.c

index 6cf5a30..2980cd3 100644 (file)
@@ -21,11 +21,13 @@ void inline log_word(uint16_t word) { }
 /* adc.c */
 #define PWMLED_ADC_SHIFT 1 /* 1<<1 measurements per single callback */
 extern volatile unsigned char need_battery_adc;
+extern volatile unsigned char adc_running;
 void init_adc();
 void susp_adc();
 
 /* pwm.c */
 #define PWM_MAX 0xFF
+extern volatile unsigned char pwm_running;
 void init_pwm();
 void susp_pwm();
 void pwm_off();
index e514102..c1ee381 100644 (file)
@@ -71,7 +71,18 @@ int main(void)
        sei();
 #if 1
        while (1) {
-               sleep_mode();
+               cli();
+               if (pwm_running) {
+                       set_sleep_mode(SLEEP_MODE_IDLE);
+               } else if (adc_running) {
+                       set_sleep_mode(SLEEP_MODE_ADC);
+               } else {
+                       set_sleep_mode(SLEEP_MODE_PWR_DOWN);
+               }
+               // keep BOD active, no sleep_bod_disable();
+               sei();
+               sleep_cpu();
+               sleep_disable();
        }
 #endif