From 0c777e2b120ebdb407cc5cbbd29dda16353cd931 Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Fri, 10 May 2013 17:17:00 +0200 Subject: [PATCH 1/1] WIP: on-demand sleep modes This does not compile yet, to be fixed. --- projects/step-up/lights.h | 2 ++ projects/step-up/main.c | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) 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 -- 2.39.3