diff --git a/stm-firmware/include/reflow-controller/safety/safety-controller.h b/stm-firmware/include/reflow-controller/safety/safety-controller.h index 0279164..730628b 100644 --- a/stm-firmware/include/reflow-controller/safety/safety-controller.h +++ b/stm-firmware/include/reflow-controller/safety/safety-controller.h @@ -259,7 +259,7 @@ uint32_t safety_controller_get_timing_monitor_count(void); * @param over_temperature Over temperature to set * @return 0 if successfully saved and applied, negative if error */ -int safety_controller_configure_overtemp_limit(float over_temperature); +int safety_controller_set_overtemp_limit(float over_temperature); /** * @brief Read the current overtemperature limit. diff --git a/stm-firmware/include/reflow-controller/settings/settings-eeprom.h b/stm-firmware/include/reflow-controller/settings/settings-eeprom.h index 56c3aa4..f7b0ee7 100644 --- a/stm-firmware/include/reflow-controller/settings/settings-eeprom.h +++ b/stm-firmware/include/reflow-controller/settings/settings-eeprom.h @@ -29,7 +29,7 @@ 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_save_overtemp_limit(float overtemp_limit, bool active); int settings_eeprom_load_overtemp_limit(float *overtemp_limit); diff --git a/stm-firmware/include/reflow-controller/settings/settings.h b/stm-firmware/include/reflow-controller/settings/settings.h index 9168991..abe0347 100644 --- a/stm-firmware/include/reflow-controller/settings/settings.h +++ b/stm-firmware/include/reflow-controller/settings/settings.h @@ -54,6 +54,10 @@ int settings_load_calibration(float *sens_dev, float *offset); enum settings_load_result settings_load_pid_oven_parameters(struct oven_pid_settings *settings); +enum settings_load_result settings_load_overtemp_limit(float *over_temp_limit); + +int settings_save_overtemp_limit(float over_temp_limit, bool active); + void settings_setup(void); #endif /* __SETTINGS_SETTINGS_H__ */ diff --git a/stm-firmware/main.c b/stm-firmware/main.c index 7c90768..dc1f805 100644 --- a/stm-firmware/main.c +++ b/stm-firmware/main.c @@ -168,6 +168,8 @@ static inline void handle_boot_status(void) static inline void setup_system(void) { + float tmp; + setup_nvic_priorities(); /* Init safety controller and safety memory */ @@ -182,6 +184,11 @@ static inline void setup_system(void) uart_gpio_config(); settings_setup(); + /* Load the overtemperature limit from eeprom if available. Otherwise the default value will be used */ + if (settings_load_overtemp_limit(&tmp) == SETT_LOAD_SUCCESS) { + safety_controller_set_overtemp_limit(tmp); + } + handle_boot_status(); setup_shell_uart(&shell_uart); diff --git a/stm-firmware/settings/settings-eeprom.c b/stm-firmware/settings/settings-eeprom.c index 05d401f..b9d7958 100644 --- a/stm-firmware/settings/settings-eeprom.c +++ b/stm-firmware/settings/settings-eeprom.c @@ -23,7 +23,7 @@ #include #include -#define EEPROM_HEADER_MAGIC 0xA5 +#define EEPROM_HEADER_MAGIC 0xC5 #define EEPROM_HEADER_COMP_VER 0x01 static const uint8_t expected_header[2] = {EEPROM_HEADER_MAGIC, EEPROM_HEADER_COMP_VER}; @@ -57,6 +57,7 @@ static bool check_eeprom_header(void) static void settings_eeprom_zero() { settings_eeprom_save_calibration(0.0f, 0.0f, false); + settings_eeprom_save_overtemp_limit(0.0, false); } bool settings_eeprom_detect_and_prepare(void) @@ -145,10 +146,17 @@ int settings_eeprom_load_calibration(float *sens, float *offset, bool *active) } } -int settings_eeprom_save_overtemp_limit(float overtemp_limit) +int settings_eeprom_save_overtemp_limit(float overtemp_limit, bool active) { int res; struct eeprom_over_temp_config over_temp_conf_entry; + const uint8_t zero_vals[sizeof(over_temp_conf_entry)] = {0}; + + if (!active) { + res = spi_eeprom_write(EEPROM_OVER_TEMP_CONFIG_BASE_ADDR, (const uint8_t *)zero_vals, + sizeof(zero_vals)); + return res ? -1 : 0; + } over_temp_conf_entry.over_temperature = overtemp_limit; crc_unit_reset(); diff --git a/stm-firmware/settings/settings.c b/stm-firmware/settings/settings.c index 7583e45..09d2ae8 100644 --- a/stm-firmware/settings/settings.c +++ b/stm-firmware/settings/settings.c @@ -64,3 +64,30 @@ void settings_setup(void) else settings_use_eeprom = false; } + +enum settings_load_result settings_load_overtemp_limit(float *over_temp_limit) +{ + int res; + float tmp; + + if (!over_temp_limit) + return SETT_LOAD_ERR; + + if (!settings_use_eeprom) + return SETT_LOAD_FILE_NOT_FOUND; + + res = settings_eeprom_load_overtemp_limit(&tmp); + if (res) + return SETT_LOAD_DISK_ERR; + *over_temp_limit = tmp; + + return SETT_LOAD_SUCCESS; +} + +int settings_save_overtemp_limit(float over_temp_limit, bool active) +{ + if (settings_use_eeprom) + return settings_eeprom_save_overtemp_limit(over_temp_limit, active); + else + return -100; +}