configuration

This commit is contained in:
Wolfgang Hottgenroth 2020-11-27 16:19:01 +01:00
parent 39ca9d963b
commit ba6ac21069
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F

View File

@ -51,7 +51,7 @@ static const uint8_t NUM_OF_BLOCKS = 2;
static const uint16_t BLOCK_ADDR[] = { 64, 4128 }; static const uint16_t BLOCK_ADDR[] = { 64, 4128 };
#define EEPROM_WRITE_BLOCK_SIZE 32 #define EEPROM_WRITE_BLOCK_SIZE 32
#define EEPROM_AFTER_WRITE_DELAY 7
typedef union { typedef union {
struct __attribute__((__packed__)) s_spiMsg { struct __attribute__((__packed__)) s_spiMsg {
@ -140,6 +140,7 @@ void eepromReadConfigBlock(uint8_t blockNum, t_configBlock *destConfigBlock) {
void eepromWriteConfigBlock(uint8_t blockNum, t_configBlock *srcConfigBlock) { void eepromWriteConfigBlock(uint8_t blockNum, t_configBlock *srcConfigBlock) {
for (uint8_t i = 0; i < (sizeof(*srcConfigBlock) / EEPROM_WRITE_BLOCK_SIZE); i++) { for (uint8_t i = 0; i < (sizeof(*srcConfigBlock) / EEPROM_WRITE_BLOCK_SIZE); i++) {
eepromWrite(BLOCK_ADDR[blockNum] + (i * EEPROM_WRITE_BLOCK_SIZE), ((uint8_t*)srcConfigBlock) + (i * EEPROM_WRITE_BLOCK_SIZE), EEPROM_WRITE_BLOCK_SIZE); eepromWrite(BLOCK_ADDR[blockNum] + (i * EEPROM_WRITE_BLOCK_SIZE), ((uint8_t*)srcConfigBlock) + (i * EEPROM_WRITE_BLOCK_SIZE), EEPROM_WRITE_BLOCK_SIZE);
eepromActiveDelay(EEPROM_AFTER_WRITE_DELAY);
} }
} }
@ -165,7 +166,7 @@ void eepromInit() {
deviceStats.s.totalFailures = 0; deviceStats.s.totalFailures = 0;
logMsg("eeI, about to write device stats for the first time"); logMsg("eeI, about to write device stats for the first time");
eepromWrite(DEVICE_STATS_ADDR, deviceStats.b, sizeof(deviceStats)); eepromWrite(DEVICE_STATS_ADDR, deviceStats.b, sizeof(deviceStats));
eepromActiveDelay(7); eepromActiveDelay(EEPROM_AFTER_WRITE_DELAY);
uint8_t emptyBlock[32]; uint8_t emptyBlock[32];
memset(emptyBlock, 0, sizeof(emptyBlock)); memset(emptyBlock, 0, sizeof(emptyBlock));
@ -173,7 +174,7 @@ void eepromInit() {
for (uint8_t j = 0; j <= 127; j++) { for (uint8_t j = 0; j <= 127; j++) {
uint16_t addr = BLOCK_ADDR[i] + sizeof(emptyBlock) * j; uint16_t addr = BLOCK_ADDR[i] + sizeof(emptyBlock) * j;
eepromWrite(addr, emptyBlock, sizeof(emptyBlock)); eepromWrite(addr, emptyBlock, sizeof(emptyBlock));
eepromActiveDelay(7); eepromActiveDelay(EEPROM_AFTER_WRITE_DELAY);
} }
} }
logMsg("eeI, storage blocks initialized"); logMsg("eeI, storage blocks initialized");
@ -184,7 +185,7 @@ void eepromInit() {
eepromHeader.s.writeCounter = 1; eepromHeader.s.writeCounter = 1;
logMsg("eeI, about to write header for the first time"); logMsg("eeI, about to write header for the first time");
eepromWrite(EEPROM_HEADER_ADDR, eepromHeader.b, sizeof(eepromHeader)); eepromWrite(EEPROM_HEADER_ADDR, eepromHeader.b, sizeof(eepromHeader));
eepromActiveDelay(7); eepromActiveDelay(EEPROM_AFTER_WRITE_DELAY);
logMsg("eeI, eeprom has been initialized"); logMsg("eeI, eeprom has been initialized");
} else { } else {
logMsg("eeI, eeprom is initialized"); logMsg("eeI, eeprom is initialized");
@ -200,7 +201,7 @@ void eepromInit() {
deviceStats.s.totalPowercycles += 1; deviceStats.s.totalPowercycles += 1;
logMsg("eeI, about to write device stats with updated power cycles counter"); logMsg("eeI, about to write device stats with updated power cycles counter");
eepromWrite(DEVICE_STATS_ADDR, deviceStats.b, sizeof(deviceStats)); eepromWrite(DEVICE_STATS_ADDR, deviceStats.b, sizeof(deviceStats));
eepromActiveDelay(7); eepromActiveDelay(EEPROM_AFTER_WRITE_DELAY);
schAdd(eepromHourlyUpdateDeviceStats, NULL, 0, 60 * 60 * 1000); schAdd(eepromHourlyUpdateDeviceStats, NULL, 0, 60 * 60 * 1000);
logMsg("eeI, hourly device stats update scheduled"); logMsg("eeI, hourly device stats update scheduled");