\r
#include <avr/io.h>\r
#include <avr/eeprom.h>\r
+#include <avr/interrupt.h>\r
\r
#include "structs.h"\r
#include "enums.h"\r
{\r
// Assume the worst..\r
unsigned char success = FALSE;\r
+ unsigned char sreg_saved;\r
+ unsigned int adcs_VBAT_tmp;\r
+ signed int adcs_avgIBAT_tmp;\r
\r
BattData.Present = FALSE;\r
BattData.Charged = FALSE;\r
NTCLookUp();\r
BattData.HasRID = RIDLookUp();\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
// Is the battery voltage above minimum safe cell voltage?\r
- if (ADCS.VBAT >= BAT_VOLTAGE_MIN) {\r
+ if (adcs_VBAT_tmp >= BAT_VOLTAGE_MIN) {\r
BattData.Low = FALSE;\r
}\r
\r
// Is the battery charged?\r
- if (ADCS.VBAT >= BAT_VOLTAGE_LOW) {\r
+ if (adcs_VBAT_tmp >= BAT_VOLTAGE_LOW) {\r
BattData.Charged = TRUE;\r
}\r
\r
* not 100% proof.\r
*/\r
if (((OCR1B == 0) && (!BattData.Low)) ||\r
- ((OCR1B != 0) && (ADCS.avgIBAT > 0))) {\r
+ ((OCR1B != 0) && (adcs_avgIBAT_tmp > 0))) {\r
BattData.Present = TRUE;\r
success = TRUE;\r
} else {\r
// Erase local EEPROM page if there were any errors during transfer.\r
if (!success) {\r
for (i=0; i<32; i++) {\r
- eeprom_write_byte(&BattEEPROM[page][i], 0);\r
+ eeprom_write_byte(&BattEEPROM[page][i], 0);\r
}\r
}\r
}\r
unsigned char RIDLookUp (void)\r
{\r
unsigned char i, found = FALSE;\r
+ unsigned int adcs_rawRID_tmp;\r
+ unsigned char sreg_saved;\r
\r
// Lookup in the RID-table. If measured RID is within the limits\r
// of an entry, those data are used, and TRUE is returned.\r
for (i = 0 ; i < RID_TABLE_SIZE; i++) {\r
- if (ADCS.rawRID >= RID[i].Low) {\r
- if (ADCS.rawRID <= RID[i].High) {\r
+ sreg_saved = SREG;\r
+ cli();\r
+ adcs_rawRID_tmp = ADCS.rawRID;\r
+ SREG = sreg_saved;\r
+ if (adcs_rawRID_tmp >= RID[i].Low) {\r
+ if (adcs_rawRID_tmp <= RID[i].High) {\r
BattData.Capacity = RID[i].Capacity;\r
BattData.MaxCurrent = RID[i].Icharge;\r
BattData.MaxTime = RID[i].tCutOff;\r
{\r
unsigned char i;\r
unsigned char found = FALSE;\r
+ unsigned char adcs_rawNTC_tmp;\r
+ unsigned char sreg_saved;\r
\r
// Lookup in the NTC-table. Use the first entry which is equal or below\r
// sampled NTC. Calculate temperature by using the index number, and the\r
// difference between the measured NTC value and the one in the entry.\r
for (i=0 ; (i < NTC_TABLE_SIZE) && (!found); i++) {\r
- if (ADCS.rawNTC >= NTC[i].ADCV) {\r
+ sreg_saved = SREG;\r
+ cli();\r
+ adcs_rawNTC_tmp = ADCS.rawNTC;\r
+ SREG = sreg_saved;\r
+ if (adcs_rawNTC_tmp >= NTC[i].ADCV) {\r
BattData.Temperature = (i<<2) ;\r
BattData.ADCSteps = NTC[i].ADCsteps; \r
- BattData.Temperature -= ((ADCS.rawNTC - NTC[i].ADCV)<<1) / BattData.ADCSteps;\r
+ BattData.Temperature -= ((adcs_rawNTC_tmp - NTC[i].ADCV)<<1) / BattData.ADCSteps;\r
\r
found = TRUE; // Could be done with a break, but that violates MISRA.\r
}\r