From: Jan "Yenya" Kasprzak Date: Fri, 7 Jun 2013 16:00:31 +0000 (+0200) Subject: main.c: split up the main() function X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=6ce11e298f73e160555e2bf4dd3d88f120fbdebd;p=bike-lights.git main.c: split up the main() function - early HW setup, run once after reset, is moved to the first_boot() function - main loop iteration is in a separate function main_loop_iteration() - both functions (and hw_suspend() as well) are made inline --- diff --git a/firmware/main.c b/firmware/main.c index 0fbdb1e..e6f03b0 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -24,7 +24,7 @@ static void hw_setup() set_sleep_mode(SLEEP_MODE_IDLE); } -static void hw_suspend() +static void inline hw_suspend() { susp_pwm(); susp_adc(); @@ -60,7 +60,7 @@ void power_down(unsigned char err) hw_setup(); } -int main(void) +static void inline first_boot() { unsigned char mcusr_save; @@ -84,24 +84,32 @@ int main(void) power_down(mcusr_save & _BV(WDRF)); sei(); -#if 1 - while (1) { - 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(); +static void inline main_loop_iteration() +{ + 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); } -#endif + + sleep_enable(); + // keep BOD active, no sleep_bod_disable(); + sei(); + sleep_cpu(); + sleep_disable(); +} + +int main(void) +{ + first_boot(); + + while (1) + main_loop_iteration(); #if 0 DDRB |= _BV(PB2);