]> www.fi.muni.cz Git - tinyboard.git/commitdiff
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 6cf5a3020a02669eabc112569ea456563ed5c15e..2980cd3678b06c0eba88c649ebdcea8c6a56f1de 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 e5141024d74f214e08e75162cc7f25f824289ed5..c1ee381453a334bf43493ddb93e287f9fa2bea62 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