Issue #26: Add overtemp limit setting to settings module and load it from EEPROM at startup
This commit is contained in:
parent
7c5b60ec6b
commit
b9dfe35652
@ -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.
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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__ */
|
||||
|
@ -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);
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <stm-periph/crc-unit.h>
|
||||
#include <string.h>
|
||||
|
||||
#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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user