Fix for O2 calibration not working on mega2560

This commit is contained in:
Josh Stewart 2022-01-09 17:05:05 +11:00
parent 9121b45995
commit e2dd7a388e
6 changed files with 32 additions and 10 deletions

View File

@ -13,7 +13,7 @@
#define PINMASK_TYPE uint8_t
#define COMPARE_TYPE uint16_t
#define COUNTER_TYPE uint16_t
#define SERIAL_BUFFER_SIZE 257 //Size of the serial buffer used by new comms protocol. Additional 1 byte is for flag
#define SERIAL_BUFFER_SIZE (256+7+1) //Size of the serial buffer used by new comms protocol. The largest single packet is the O2 calibration which is 256 bytes + 7 bytes of overhead
#ifdef USE_SPI_EEPROM
#define EEPROM_LIB_H "src/SPIAsEEPROM/SPIAsEEPROM.h"
typedef uint16_t eeprom_address_t;

View File

@ -239,6 +239,10 @@
#define TOOTH_LOG_SIZE 1
#endif
#define O2_CALIBRATION_PAGE 2
#define IAT_CALIBRATION_PAGE 1
#define CLT_CALIBRATION_PAGE 0
#define COMPOSITE_LOG_PRI 0
#define COMPOSITE_LOG_SEC 1
#define COMPOSITE_LOG_TRIG 2

View File

@ -237,8 +237,11 @@ void processSerialCommand()
if(isEepromWritePending())
{
//There is already a write pending, so we can't do anything
//There is already a write pending, force it through.
sendSerialReturnCode(SERIAL_RC_BUSY_ERR);
enableForceBurn();
writeAllConfig();
disableForceBurn();
break;
}
@ -642,13 +645,15 @@ void processSerialCommand()
}
}
sendSerialReturnCode(SERIAL_RC_OK);
Serial.flush();
if(valueOffset == (256*3)) { writeCalibrationPage(cmd); } //Store received values in EEPROM if this is the final chunk of calibration
}
else if(cmd == IAT_CALIBRATION_PAGE)
{
void* pnt_TargetTable_values = (uint16_t *)&iatCalibration_values;
uint16_t* pnt_TargetTable_bins = (uint16_t *)&iatCalibration_bins;
//Temperature calibrations are sent as 32 16-bit values
//Temperature calibrations are sent as 32 16-bit values (ie 64 bytes total)
if(calibrationLength == 64)
{
for (uint16_t x = 0; x < 32; x++)
@ -702,8 +707,6 @@ void processSerialCommand()
{
sendSerialReturnCode(SERIAL_RC_RANGE_ERR);
}
writeCalibration(); //Store received values in EEPROM
break;
}

View File

@ -43,11 +43,6 @@
#define SD_RTC_WRITE_ARG1 0x027E
#define SD_RTC_WRITE_ARG2 0x0009
#define O2_CALIBRATION_PAGE 2
#define IAT_CALIBRATION_PAGE 1
#define CLT_CALIBRATION_PAGE 0
#define SERIAL_CRC_LENGTH 4
#define SERIAL_LEN_SIZE 2
#define SERIAL_OVERHEAD_SIZE (SERIAL_LEN_SIZE + SERIAL_CRC_LENGTH) //The overhead for each serial command is 6 bytes. 2 bytes for the length and 4 bytes for the CRC

View File

@ -456,6 +456,25 @@ void writeCalibration()
EEPROM.put(EEPROM_CALIBRATION_CLT_VALUES, cltCalibration_values);
}
void writeCalibrationPage(uint8_t pageNum)
{
if(pageNum == O2_CALIBRATION_PAGE)
{
EEPROM.put(EEPROM_CALIBRATION_O2_BINS, o2Calibration_bins);
EEPROM.put(EEPROM_CALIBRATION_O2_VALUES, o2Calibration_values);
}
else if(pageNum == IAT_CALIBRATION_PAGE)
{
EEPROM.put(EEPROM_CALIBRATION_IAT_BINS, iatCalibration_bins);
EEPROM.put(EEPROM_CALIBRATION_IAT_VALUES, iatCalibration_values);
}
else if(pageNum == CLT_CALIBRATION_PAGE)
{
EEPROM.put(EEPROM_CALIBRATION_CLT_BINS, cltCalibration_bins);
EEPROM.put(EEPROM_CALIBRATION_CLT_VALUES, cltCalibration_values);
}
}
static eeprom_address_t compute_crc_address(uint8_t pageNum)
{
return EEPROM_LAST_BARO-((getPageCount() - pageNum)*sizeof(uint32_t));

View File

@ -113,6 +113,7 @@ void writeConfig(uint8_t pageNum);
void loadConfig();
void loadCalibration();
void writeCalibration();
void writeCalibrationPage(uint8_t pageNum);
void resetConfigPages();
void enableForceBurn();
void disableForceBurn();