Implement memory wear leveling algorithm

This commit is contained in:
2024-09-20 21:30:31 +02:00
parent e2b5c5fd42
commit 10298a99c1
3 changed files with 162 additions and 50 deletions

View File

@@ -7,6 +7,7 @@
#include <avr/interrupt.h>
// TODO: Config header for chip specifics like EEPROM size.
// TODO: Make sure wear leveling resets memory correctly.
// TODO: Implement primary state machine for update loop.
// TODO: Migrate to ATMega 1284P-PU for 2nd 16-bit timer.
// TODO: Keep persistent TEMP and DEWP targets in EEPROM.
@@ -26,8 +27,8 @@ enum state_e
};
static enum state_e state;
static float temp, temp_target;
static float dewp, dewp_target;
static word temp, temp_target;
static word dewp, dewp_target;
static int Init(void)
{
@@ -67,6 +68,18 @@ static int Init(void)
WDT_Enable();
WDT_SetTimeoutFlag(WDT2000); // 2 seconds
// Test persistent settings from EEPROM. There must
// be some sanity checking before these values are
// used.
MEM_Init();
MEM_Read(&temp_target, &dewp_target);
Info("Persistent memory contains [%d, %d]",
temp_target, dewp_target);
// MEM_Write(20, 60);
// MEM_Dump();
// There is a possiblity to use interrupt signals
// for I2C communication but only as one large
// branching routine for the whole I2C system.