#26: Add over temperature monitor settings to eeprom

This commit is contained in:
Mario Hüttel 2021-02-14 20:06:01 +01:00
parent e614eaa23b
commit 7c5b60ec6b
2 changed files with 41 additions and 1 deletions

View File

@ -29,4 +29,8 @@ int settings_eeprom_save_calibration(float sens, float offset, bool active);
int settings_eeprom_load_calibration(float *sens, float *offset, bool *active); int settings_eeprom_load_calibration(float *sens, float *offset, bool *active);
int settings_eeprom_save_overtemp_limit(float overtemp_limit);
int settings_eeprom_load_overtemp_limit(float *overtemp_limit);
#endif /* __SETTINGS_SETTINGS_EEPROM_H__ */ #endif /* __SETTINGS_SETTINGS_EEPROM_H__ */

View File

@ -39,7 +39,7 @@ struct eeprom_calibration_settings {
#define EEPROM_OVER_TEMP_CONFIG_BASE_ADDR (EEPROM_CALIBRATION_BASE_ADDR + sizeof(struct eeprom_calibration_settings)) #define EEPROM_OVER_TEMP_CONFIG_BASE_ADDR (EEPROM_CALIBRATION_BASE_ADDR + sizeof(struct eeprom_calibration_settings))
struct eeprom_over_temp_config { struct eeprom_over_temp_config {
float over_temperature; float over_temperature;
float over_temperature_redundant; uint32_t over_temp_crc;
}; };
static bool check_eeprom_header(void) static bool check_eeprom_header(void)
@ -144,3 +144,39 @@ int settings_eeprom_load_calibration(float *sens, float *offset, bool *active)
return -1; return -1;
} }
} }
int settings_eeprom_save_overtemp_limit(float overtemp_limit)
{
int res;
struct eeprom_over_temp_config over_temp_conf_entry;
over_temp_conf_entry.over_temperature = overtemp_limit;
crc_unit_reset();
crc_unit_input_array((uint32_t *)&over_temp_conf_entry, 1);
over_temp_conf_entry.over_temp_crc = crc_unit_get_crc();
res = spi_eeprom_write(EEPROM_OVER_TEMP_CONFIG_BASE_ADDR, (const uint8_t *)&over_temp_conf_entry,
sizeof(over_temp_conf_entry));
return res ? -1 : 0;
}
int settings_eeprom_load_overtemp_limit(float *overtemp_limit)
{
int res;
struct eeprom_over_temp_config over_temp_conf_entry;
if (!overtemp_limit)
return -1001;
res = spi_eeprom_read(EEPROM_OVER_TEMP_CONFIG_BASE_ADDR, (uint8_t *)&over_temp_conf_entry,
sizeof(struct eeprom_over_temp_config));
if (res)
return -2;
crc_unit_reset();
crc_unit_input_array((uint32_t *)&over_temp_conf_entry, 1);
if (crc_unit_get_crc() != over_temp_conf_entry.over_temp_crc)
return -1;
*overtemp_limit = over_temp_conf_entry.over_temperature;
return 0;
}