|
|
|
@@ -1,28 +1,36 @@
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#if PCB_REVISION >= 12
|
|
|
|
|
I2C_eeprom ee(0x50, EEPROM_SIZE_BYTES);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
LubeConfig_t LubeConfig;
|
|
|
|
|
persistenceData_t PersistenceData;
|
|
|
|
|
uint16_t eePersistenceMarker = 0;
|
|
|
|
|
uint16_t eeVersion = 0; // inc
|
|
|
|
|
const uint16_t eeVersion = 1; // inc
|
|
|
|
|
boolean eeAvailable = false;
|
|
|
|
|
|
|
|
|
|
const uint16_t startofLubeConfig = 16;
|
|
|
|
|
const uint16_t startofPersistence = 16 + sizeof(LubeConfig) + (sizeof(LubeConfig) % 16);
|
|
|
|
|
|
|
|
|
|
#if PCB_REVISION >= 12
|
|
|
|
|
boolean checkEEPROMavailable();
|
|
|
|
|
|
|
|
|
|
void InitEEPROM()
|
|
|
|
|
{
|
|
|
|
|
ee.begin();
|
|
|
|
|
if (!ee.isConnected())
|
|
|
|
|
if (!checkEEPROMavailable())
|
|
|
|
|
{
|
|
|
|
|
MaintainDTC(DTC_NO_EEPROM_FOUND, true);
|
|
|
|
|
globals.systemStatus = sysStat_Error;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
GetConfig_EEPROM();
|
|
|
|
|
|
|
|
|
|
if (LubeConfig.EEPROM_Version != eeVersion)
|
|
|
|
|
{
|
|
|
|
|
FormatConfig_EEPROM();
|
|
|
|
|
globals.systemStatus = sysStat_Error;
|
|
|
|
|
MaintainDTC(DTC_EEPROM_VERSION_BAD, true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void EEPROM_Process()
|
|
|
|
|
{
|
|
|
|
@@ -55,29 +63,18 @@ void StoreConfig_EEPROM()
|
|
|
|
|
{
|
|
|
|
|
LubeConfig.checksum = 0;
|
|
|
|
|
LubeConfig.checksum = Checksum_EEPROM((uint8_t *)&LubeConfig, sizeof(LubeConfig));
|
|
|
|
|
#if PCB_REVISION >= 12
|
|
|
|
|
if (!ee.isConnected())
|
|
|
|
|
if (!checkEEPROMavailable())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ee.updateBlock(startofLubeConfig, (uint8_t *)&LubeConfig, sizeof(LubeConfig));
|
|
|
|
|
#else
|
|
|
|
|
EEPROM.begin(512);
|
|
|
|
|
EEPROM.put(startofLubeConfig, LubeConfig);
|
|
|
|
|
EEPROM.commit();
|
|
|
|
|
EEPROM.end();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GetConfig_EEPROM()
|
|
|
|
|
{
|
|
|
|
|
#if PCB_REVISION >= 12
|
|
|
|
|
if (!ee.isConnected())
|
|
|
|
|
if (!checkEEPROMavailable())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ee.readBlock(startofLubeConfig, (uint8_t *)&LubeConfig, sizeof(LubeConfig));
|
|
|
|
|
#else
|
|
|
|
|
EEPROM.begin(512);
|
|
|
|
|
EEPROM.get(startofLubeConfig, LubeConfig);
|
|
|
|
|
EEPROM.end();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
uint32_t checksum = LubeConfig.checksum;
|
|
|
|
|
LubeConfig.checksum = 0;
|
|
|
|
@@ -105,34 +102,19 @@ void StorePersistence_EEPROM()
|
|
|
|
|
PersistenceData.checksum = 0;
|
|
|
|
|
PersistenceData.checksum = Checksum_EEPROM((uint8_t *)&PersistenceData, sizeof(PersistenceData));
|
|
|
|
|
|
|
|
|
|
#if PCB_REVISION >= 12
|
|
|
|
|
if (!ee.isConnected())
|
|
|
|
|
if (!checkEEPROMavailable())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ee.updateBlock(getPersistanceAddress(), (uint8_t *)&PersistenceData, sizeof(PersistenceData));
|
|
|
|
|
#else
|
|
|
|
|
EEPROM.put(getPersistanceAddress(), PersistenceData);
|
|
|
|
|
EEPROM.commit();
|
|
|
|
|
EEPROM.end();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GetPersistence_EEPROM()
|
|
|
|
|
{
|
|
|
|
|
#if PCB_REVISION >= 12
|
|
|
|
|
if (!ee.isConnected())
|
|
|
|
|
if (!checkEEPROMavailable())
|
|
|
|
|
return;
|
|
|
|
|
eePersistenceMarker = (ee.readByte(0) << 8) | ee.readByte(1);
|
|
|
|
|
#else
|
|
|
|
|
EEPROM.begin(512);
|
|
|
|
|
EEPROM.get(0, eePersistenceMarker);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if PCB_REVISION >= 12
|
|
|
|
|
eePersistenceMarker = (ee.readByte(0) << 8) | ee.readByte(1);
|
|
|
|
|
ee.readBlock(getPersistanceAddress(), (uint8_t *)&PersistenceData, sizeof(PersistenceData));
|
|
|
|
|
#else
|
|
|
|
|
EEPROM.get(getPersistanceAddress(), PersistenceData);
|
|
|
|
|
EEPROM.end();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
uint32_t checksum = PersistenceData.checksum;
|
|
|
|
|
PersistenceData.checksum = 0;
|
|
|
|
@@ -165,15 +147,11 @@ void MovePersistencePage_EEPROM(boolean reset)
|
|
|
|
|
eePersistenceMarker = reset ? sizeof(PersistenceData) : eePersistenceMarker + sizeof(PersistenceData);
|
|
|
|
|
PersistenceData.writeCycleCounter = 0;
|
|
|
|
|
|
|
|
|
|
#if PCB_REVISION >= 12
|
|
|
|
|
if (!ee.isConnected())
|
|
|
|
|
if (!checkEEPROMavailable())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ee.updateByte(0, (uint8_t)(eePersistenceMarker >> 8));
|
|
|
|
|
ee.updateByte(1, (uint8_t)(eePersistenceMarker & 0xFF));
|
|
|
|
|
#else
|
|
|
|
|
EEPROM.begin(512);
|
|
|
|
|
EEPROM.put(0, eePersistenceMarker);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t Checksum_EEPROM(uint8_t const *data, size_t len)
|
|
|
|
@@ -199,7 +177,7 @@ void dumpEEPROM(uint16_t memoryAddress, uint16_t length)
|
|
|
|
|
{
|
|
|
|
|
#define BLOCK_TO_LENGTH 16
|
|
|
|
|
|
|
|
|
|
if (!ee.isConnected())
|
|
|
|
|
if (!checkEEPROMavailable())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
char ascii_buf[BLOCK_TO_LENGTH + 1];
|
|
|
|
@@ -227,4 +205,14 @@ void dumpEEPROM(uint16_t memoryAddress, uint16_t length)
|
|
|
|
|
memoryAddress++;
|
|
|
|
|
}
|
|
|
|
|
Serial.println();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean checkEEPROMavailable()
|
|
|
|
|
{
|
|
|
|
|
if (!ee.isConnected())
|
|
|
|
|
{
|
|
|
|
|
MaintainDTC(DTC_NO_EEPROM_FOUND, true);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|