Issue #26: Add overtemp limit setting to settings module and load it from EEPROM at startup

This commit is contained in:
Mario Hüttel 2021-02-15 20:28:45 +01:00
parent 7c5b60ec6b
commit b9dfe35652
6 changed files with 50 additions and 4 deletions

View File

@ -259,7 +259,7 @@ uint32_t safety_controller_get_timing_monitor_count(void);
* @param over_temperature Over temperature to set * @param over_temperature Over temperature to set
* @return 0 if successfully saved and applied, negative if error * @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. * @brief Read the current overtemperature limit.

View File

@ -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_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); int settings_eeprom_load_overtemp_limit(float *overtemp_limit);

View File

@ -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_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); void settings_setup(void);
#endif /* __SETTINGS_SETTINGS_H__ */ #endif /* __SETTINGS_SETTINGS_H__ */

View File

@ -168,6 +168,8 @@ static inline void handle_boot_status(void)
static inline void setup_system(void) static inline void setup_system(void)
{ {
float tmp;
setup_nvic_priorities(); setup_nvic_priorities();
/* Init safety controller and safety memory */ /* Init safety controller and safety memory */
@ -182,6 +184,11 @@ static inline void setup_system(void)
uart_gpio_config(); uart_gpio_config();
settings_setup(); 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(); handle_boot_status();
setup_shell_uart(&shell_uart); setup_shell_uart(&shell_uart);

View File

@ -23,7 +23,7 @@
#include <stm-periph/crc-unit.h> #include <stm-periph/crc-unit.h>
#include <string.h> #include <string.h>
#define EEPROM_HEADER_MAGIC 0xA5 #define EEPROM_HEADER_MAGIC 0xC5
#define EEPROM_HEADER_COMP_VER 0x01 #define EEPROM_HEADER_COMP_VER 0x01
static const uint8_t expected_header[2] = {EEPROM_HEADER_MAGIC, EEPROM_HEADER_COMP_VER}; 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() static void settings_eeprom_zero()
{ {
settings_eeprom_save_calibration(0.0f, 0.0f, false); settings_eeprom_save_calibration(0.0f, 0.0f, false);
settings_eeprom_save_overtemp_limit(0.0, false);
} }
bool settings_eeprom_detect_and_prepare(void) 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; int res;
struct eeprom_over_temp_config over_temp_conf_entry; 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; over_temp_conf_entry.over_temperature = overtemp_limit;
crc_unit_reset(); crc_unit_reset();

View File

@ -64,3 +64,30 @@ void settings_setup(void)
else else
settings_use_eeprom = false; 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;
}