Commit mthomas changes to GCC and port those changes to IAR
[avr_bc100.git] / BaseTinyFirmware / GCC / statefunc.c
index 9fc0ae5ae08669aecee4f6b6dfa13b1d2c4117c3..e0e265901ee3cb064da476f907b735a96c16e890 100644 (file)
@@ -123,7 +123,7 @@ unsigned char Initialize(unsigned char inp)
        sei();\r
 \r
        // Attempt to get ADC-readings (also gets RID-data) from both batteries.\r
-       for (i = 0; i < 2; i++) {\r
+       for (i = 0; i < BATCONN; i++)   {\r
                EnableBattery(i);\r
                ADC_Wait();\r
                BatteryStatusRefresh();\r
@@ -174,7 +174,7 @@ unsigned char BatteryControl(unsigned char inp)
 \r
        // Get ADC-readings, try to read EPROM, and start prequalification\r
        // of any uncharged battery.\r
-       for (i = 0; i < 2; i++) {\r
+       for (i = 0; i < BATCONN; i++) {\r
                if (eeprom_read_byte(&BattControl[i]) & BIT_BATTERY_ENABLED) {\r
                        EnableBattery(i);\r
                        ADC_Wait();\r
@@ -228,11 +228,13 @@ unsigned char Sleep(unsigned char inp)
 \r
                // If any batteries need charging, go to ST_BATCON.\r
                // Otherwise, keep sleeping.\r
-               for (i = 0; i < 2; i++) {\r
+               for (i = 0; i < BATCONN; i++) {\r
                        EnableBattery(i);\r
                        ADC_Wait();\r
-                       if ((BatteryStatusRefresh()) && (!BattData.Charged)) {\r
-                               return(ST_BATCON);\r
+                       if ( BatteryStatusRefresh() ) {\r
+                               if ( !BattData.Charged ) {\r
+                                  return(ST_BATCON);\r
+                                }\r
                        }\r
                }\r
 \r
@@ -282,6 +284,7 @@ void Doze(void)
                sleep_cpu();                            // Go to sleep, wake up by WDT.\r
        }\r
        else {\r
+               // stay awake if PB6 is pulled low by master\r
                do {\r
                } while ( !(WatchdogFlag) );\r
        }\r