Commit mthomas changes to GCC and port those changes to IAR
[avr_bc100.git] / BaseTinyFirmware / GCC / chargefunc.c
index 5f441b7f85dbc45970108c8fea68747f367c07ff..b3db020480f6a5991925d8bb41f2da57de7fd50e 100644 (file)
  *      AVR463: Charging NiMH Batteries with BC100\r
  *\r
  * \par Documentation\r
- *      For comprehensive code documentation, supported compilers, compiler \r
+ *      For comprehensive code documentation, supported compilers, compiler\r
  *      settings and supported devices see readme.html\r
  *\r
  * \author\r
  *      Atmel Corporation: http://www.atmel.com \n\r
  *      Support email: avr@atmel.com\r
  *\r
- * \r
+ *\r
  * $Name$\r
  * $Revision: 2299 $\r
  * $RCSfile$\r
@@ -84,7 +84,7 @@ unsigned char ConstantCurrent(void)
                      wasStopped = FALSE;\r
        unsigned char sreg_saved;\r
        signed int adcs_avgIBAT_tmp;\r
-       \r
+\r
        do      {\r
                // Wait for ADC conversions to complete.\r
                ADC_Wait();\r
@@ -99,7 +99,7 @@ unsigned char ConstantCurrent(void)
                        // Continue charging!\r
                        if (wasStopped) {\r
                                wasStopped = FALSE;\r
-                               \r
+\r
                                // Timer variables are not reset by this.\r
                                Time_Start();\r
                        }\r
@@ -113,7 +113,7 @@ unsigned char ConstantCurrent(void)
                        // +/- BAT_CURRENT_HYST.\r
                        if ((adcs_avgIBAT_tmp < 0) ||\r
                            (adcs_avgIBAT_tmp < (ChargeParameters.Current - BAT_CURRENT_HYST))) {\r
-                                        \r
+\r
                                if(!PWM_IncrementDutyCycle()) {\r
 #ifdef ABORT_IF_PWM_MAX\r
                                // If the duty cycle cannot be incremented, flag error and\r
@@ -125,7 +125,7 @@ unsigned char ConstantCurrent(void)
                                }\r
                        } else if ((adcs_avgIBAT_tmp >= 0) &&\r
                                 (adcs_avgIBAT_tmp > (ChargeParameters.Current + BAT_CURRENT_HYST))) {\r
-                                        \r
+\r
                                if(!PWM_DecrementDutyCycle()) {\r
 #ifdef ABORT_IF_PWM_MIN\r
                                        // If the duty cycle cannot be decremented, flag error and\r
@@ -165,12 +165,12 @@ unsigned char ConstantVoltage(void)
                      wasStopped = FALSE;\r
        unsigned char sreg_saved;\r
        unsigned int adcs_VBAT_tmp;\r
-       \r
+\r
        do{\r
-               \r
+\r
                // Wait for ADC conversions to complete.\r
                ADC_Wait();\r
-               \r
+\r
                // If Master has flagged for a charge inhibit, pause charging.\r
                // (This is to prevent damage during prolonged serial communication.)\r
                if (eeprom_read_byte(&BattControl[BattActive]) & BIT_BATTERY_CHARGE_INHIBIT) {\r
@@ -178,16 +178,16 @@ unsigned char ConstantVoltage(void)
                        Time_Stop();\r
                        OCR1B = 0;\r
                }\r
-               \r
+\r
                else {\r
                        // Continue charging!\r
                        if (wasStopped) {\r
                                wasStopped = FALSE;\r
-                               \r
+\r
                                // Timer variables aren't reset by this.\r
                                Time_Start();\r
                        }\r
-                       \r
+\r
                        sreg_saved = SREG;\r
                        cli();\r
                        adcs_VBAT_tmp = ADCS.VBAT;\r
@@ -237,7 +237,7 @@ unsigned char ConstantVoltage(void)
  *\r
  * The function also checks if the battery temperature is within limits,\r
  * if mains is OK, and if BatteryCheck() returns TRUE.\r
- * If an error is detected, the associated errorflag is set and \r
+ * If an error is detected, the associated errorflag is set and\r
  * ChargeParameters.NextState is changed to an appropriate state.\r
  *\r
  * \retval TRUE Halt now.\r
@@ -256,7 +256,7 @@ unsigned char HaltNow(void)
        unsigned int adcs_rawNTC_tmp, adcs_VBAT_tmp;\r
        signed int adcs_avgIBAT_tmp;\r
        unsigned char sreg_saved;\r
-       \r
+\r
        // Wait for a full ADC-cycle to finish.\r
        ADC_Wait();\r
 \r
@@ -265,29 +265,29 @@ unsigned char HaltNow(void)
        // (Gets overridden if either mains is failing, or the battery changes.)\r
        for (i = 0x01; i != 0; i <<= 1) {\r
                if (HaltParameters.HaltFlags & i) {\r
-                       \r
+\r
                        sreg_saved = SREG;\r
                        cli();\r
                        adcs_VBAT_tmp = ADCS.VBAT;\r
                        adcs_avgIBAT_tmp  = ADCS.avgIBAT;\r
                        SREG = sreg_saved;\r
-                       \r
+\r
                        switch (i) {\r
                        // Is VBAT less than the recorded maximum?\r
                        case HALT_VOLTAGE_DROP:\r
                                // Update VBATMax if VBAT is higher. Evaluate for halt otherwise.\r
                                if (adcs_VBAT_tmp > HaltParameters.VBATMax) {\r
                                        HaltParameters.VBATMax = adcs_VBAT_tmp;\r
-                               } else if((HaltParameters.VBATMax - adcs_VBAT_tmp) >= \r
+                               } else if((HaltParameters.VBATMax - adcs_VBAT_tmp) >=\r
                                          HaltParameters.VoltageDrop) {\r
                                        halt = TRUE;\r
                                }\r
                        break;\r
 \r
-                       \r
+\r
                        // Has VBAT reached the maximum limit?\r
-                       case HALT_VOLTAGE_MAX:  \r
-                               \r
+                       case HALT_VOLTAGE_MAX:\r
+\r
                                if (adcs_VBAT_tmp >= HaltParameters.VoltageMax) {\r
                                        halt = TRUE;\r
                                }\r
@@ -296,16 +296,16 @@ unsigned char HaltNow(void)
 \r
                        // Has IBAT reached the minimum limit?\r
                        case HALT_CURRENT_MIN:\r
-                               \r
+\r
                                if (adcs_avgIBAT_tmp <= HaltParameters.CurrentMin) {\r
                                        halt = TRUE;\r
                                }\r
                                break;\r
-       \r
-                               \r
+\r
+\r
                        // Is the temperature rising too fast?\r
                        case HALT_TEMPERATURE_RISE:\r
-                               \r
+\r
                                sreg_saved = SREG;\r
                                cli();\r
                                adcs_rawNTC_tmp = ADCS.rawNTC;\r
@@ -316,12 +316,12 @@ unsigned char HaltNow(void)
                                if (adcs_rawNTC_tmp > HaltParameters.LastNTC) {\r
                                        HaltParameters.LastNTC = adcs_rawNTC_tmp;\r
                                        Time_Set(TIMER_TEMP,0,30,0);\r
-                                       \r
+\r
                                // Is the increase in temperature greater than the set threshold?\r
                                } else  if ((HaltParameters.LastNTC - adcs_rawNTC_tmp) >=\r
                                  (BattData.ADCSteps * HaltParameters.TemperatureRise)) {\r
-                                       \r
-                                       // If this happened within a timeframe of 30 seconds, the \r
+\r
+                                       // If this happened within a timeframe of 30 seconds, the\r
                                        // temperature is rising faster than we want.\r
                                        // If not, update LastNTC and reset timer.\r
                                        if (Time_Left(TIMER_TEMP))  {\r
@@ -332,29 +332,31 @@ unsigned char HaltNow(void)
                                        }\r
                                }\r
                        break;\r
-       \r
-                       \r
+\r
+\r
                        // Is there any time left?\r
-                       case HALT_TIME:  \r
-                               \r
+                       case HALT_TIME:\r
+\r
                                if (!Time_Left(TIMER_CHG)) {\r
                                        halt = TRUE;\r
-                                       \r
-                                       // If exhaustion flagging is selected, stop the PWM, disable the \r
+\r
+                                       // If exhaustion flagging is selected, stop the PWM, disable the\r
                                        // battery and flag it as exhausted. Make ST_ERROR next state.\r
                                        if (HaltParameters.HaltFlags & HALT_FLAG_EXHAUSTION) {\r
                                                        PWM_Stop();\r
+\r
                                                        Battery_t tmp = eeprom_read_byte(&BattControl[BattActive]);\r
                                                                                         tmp &= ~BIT_BATTERY_ENABLED; // Enabled = FALSE;\r
                                                                                         eeprom_write_byte(&BattControl[BattActive], tmp);\r
+\r
                                                        BattData.Exhausted = TRUE;\r
                                                        SetErrorFlag(ERR_BATTERY_EXHAUSTED);\r
                                                        ChargeParameters.NextState = ST_ERROR;\r
                                        }\r
                                }\r
                        break;\r
-                       \r
-                       \r
+\r
+\r
                        default:  // Shouldn't end up here, but is needed for MISRA compliance.\r
                        break;\r
                        }\r
@@ -366,7 +368,7 @@ unsigned char HaltNow(void)
        // Battery too cold or hot?\r
        if ((BattData.Temperature <= HaltParameters.TemperatureMin) ||\r
            (BattData.Temperature >= HaltParameters.TemperatureMax)) {\r
-                       \r
+\r
                PWM_Stop();\r
                SetErrorFlag(ERR_BATTERY_TEMPERATURE);\r
                ChargeParameters.NextState = ST_ERROR;\r