From: Jan "Yenya" Kasprzak Date: Fri, 10 May 2013 15:17:00 +0000 (+0200) Subject: WIP: on-demand sleep modes X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=0c777e2b120ebdb407cc5cbbd29dda16353cd931;p=tinyboard.git WIP: on-demand sleep modes This does not compile yet, to be fixed. --- diff --git a/projects/step-up/lights.h b/projects/step-up/lights.h index 6cf5a30..2980cd3 100644 --- a/projects/step-up/lights.h +++ b/projects/step-up/lights.h @@ -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(); diff --git a/projects/step-up/main.c b/projects/step-up/main.c index e514102..c1ee381 100644 --- a/projects/step-up/main.c +++ b/projects/step-up/main.c @@ -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