]> www.fi.muni.cz Git - bike-lights.git/commitdiff
main.c: split up the main() function
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Fri, 7 Jun 2013 16:00:31 +0000 (18:00 +0200)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Fri, 7 Jun 2013 16:03:05 +0000 (18:03 +0200)
- 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

firmware/main.c

index 0fbdb1e9f804421fca1a07fe69f33d72bd0890a2..e6f03b01fafa1156aeb86cc01cb7da7eabc62f1c 100644 (file)
@@ -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);