From 7c5b60ec6bb12d9d204091ce258fbf41740fe62e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 14 Feb 2021 20:06:01 +0100 Subject: [PATCH] #26: Add over temperature monitor settings to eeprom --- .../settings/settings-eeprom.h | 4 ++ stm-firmware/settings/settings-eeprom.c | 38 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) 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; +}