diff --git a/stm-firmware/include/reflow-controller/settings/settings-eeprom.h b/stm-firmware/include/reflow-controller/settings/settings-eeprom.h index 7fc0153..56c3aa4 100644 --- a/stm-firmware/include/reflow-controller/settings/settings-eeprom.h +++ b/stm-firmware/include/reflow-controller/settings/settings-eeprom.h @@ -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_save_overtemp_limit(float overtemp_limit); + +int settings_eeprom_load_overtemp_limit(float *overtemp_limit); + #endif /* __SETTINGS_SETTINGS_EEPROM_H__ */ diff --git a/stm-firmware/settings/settings-eeprom.c b/stm-firmware/settings/settings-eeprom.c index 35e13ff..05d401f 100644 --- a/stm-firmware/settings/settings-eeprom.c +++ b/stm-firmware/settings/settings-eeprom.c @@ -39,7 +39,7 @@ 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 { float over_temperature; - float over_temperature_redundant; + uint32_t over_temp_crc; }; static bool check_eeprom_header(void) @@ -144,3 +144,39 @@ int settings_eeprom_load_calibration(float *sens, float *offset, bool *active) 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; +}