Issue #26: Add configuration for overtemperature flag to safety controller and include the config in the memory checking

This commit is contained in:
2021-02-02 20:35:45 +01:00
parent 64bb06882f
commit 50ad31d58a
4 changed files with 92 additions and 1 deletions

View File

@@ -41,6 +41,7 @@
#include <reflow-controller/oven-driver.h>
#include <helper-macros/helper-macros.h>
#include <stm-periph/rcc-manager.h>
#include <reflow-controller/temp-converter.h>
/**
* @brief Macro that checks if a given @ref error_flag is persistent
@@ -144,6 +145,13 @@ struct analog_mon {
uint64_t timestamp;
};
struct overtemp_config {
uint32_t crc_dummy_seed;
float overtemp_deg_celsius;
float overtemp_equiv_resistance;
uint32_t crc;
};
/**
* @brief All safety error flags.
*/
@@ -234,6 +242,45 @@ static volatile struct safety_weight IN_SECTION(.ccm.bss) flag_weights[COUNT_OF(
*/
static uint32_t IN_SECTION(.ccm.bss) flag_weight_crc;
/**
* @brief Configuration struct containing the overtemperature flag configuration
*/
static struct overtemp_config IN_SECTION(.ccm.bss) safety_controller_overtemp_config;
/**
* @brief Configure the overtemperature flag's settings
* @param over_temperature Temperature to set the limit to.
*/
static void set_overtemp_config(float over_temperature)
{
int result;
float resistance;
result = temp_convertet_convert_temp_to_resistance(over_temperature, &resistance);
/* An error in this function is really bad... */
if (result < -1)
panic_mode();
crc_unit_reset();
safety_controller_overtemp_config.crc_dummy_seed = 0xA4F5C7E6UL;
safety_controller_overtemp_config.overtemp_deg_celsius = over_temperature;
safety_controller_overtemp_config.overtemp_equiv_resistance = resistance;
crc_unit_input_array((const uint32_t *)&safety_controller_overtemp_config, wordsize_of(struct overtemp_config) - 1);
safety_controller_overtemp_config.crc = crc_unit_get_crc();
}
static bool over_temperature_config_check(void)
{
if (safety_controller_overtemp_config.crc_dummy_seed != 0xA4F5C7E6UL)
return true;
crc_unit_reset();
crc_unit_input_array((const uint32_t *)&safety_controller_overtemp_config, wordsize_of(struct overtemp_config) - 1);
if (crc_unit_get_crc() != safety_controller_overtemp_config.crc)
return true;
return false;
}
/**
* @brief Convert a flag enum to the flag number.
*
@@ -721,6 +768,9 @@ void safety_controller_init()
init_safety_flag_persistencies_from_default();
apply_config_overrides();
/* Set the default limit of the overtemperature check */
set_overtemp_config(SAFETY_DEFAULT_OVERTEMP_LIMIT_DEGC);
if (found_memory_state == SAFETY_MEMORY_INIT_CORRUPTED)
safety_controller_report_error(ERR_FLAG_SAFETY_MEM_CORRUPT);
else if (found_memory_state == SAFETY_MEMORY_INIT_VALID_MEMORY) {
@@ -842,6 +892,7 @@ static void safety_controller_handle_safety_adc()
* Aditionally, the default flag weights are restored from Flash.
* 3) The flag persistency table is CRC checked. In case of an error, the @ref ERR_FLAG_SAFETY_TAB_CORRUPT flag is set.
* Aditionally, the default values of the flag persistence is restored from Flash.
* 4) Check the Overtemperature flag configuration structure
*/
static void safety_controller_handle_memory_checks(void)
{
@@ -870,6 +921,12 @@ static void safety_controller_handle_memory_checks(void)
safety_controller_report_error(ERR_FLAG_SAFETY_TAB_CORRUPT);
init_safety_flag_persistencies_from_default();
}
/* check overtemp struct */
if (over_temperature_config_check()) {
safety_controller_report_error(ERR_FLAG_SAFETY_TAB_CORRUPT);
set_overtemp_config(SAFETY_DEFAULT_OVERTEMP_LIMIT_DEGC);
}
}
}
@@ -1220,4 +1277,15 @@ int safety_controller_get_timing_mon_by_index(uint32_t index, struct timing_moni
return 0;
}
int safety_controller_set_overtemp_limit(float over_temperature)
{
set_overtemp_config(over_temperature);
return 0;
}
float safety_controller_get_overtemp_limit(void)
{
return safety_controller_overtemp_config.overtemp_deg_celsius;
}
/** @} */