Restructure safety handle function. Now returns worst flag state set. Used to blink LED

This commit is contained in:
2022-07-30 16:04:46 +02:00
parent 6ac108e1b2
commit aaed95cc95
5 changed files with 33 additions and 19 deletions

View File

@@ -1117,12 +1117,15 @@ static void safety_controller_do_systick_checking(void)
* is set, the appropriate action defined by the flag weight is executed.
* @note If no flag weigth is present for a given error flag, it is treated as the most critical category
* (@ref SAFETY_FLAG_CONFIG_WEIGHT_PANIC)
*
* @returns Worst config weight set
*/
static void safety_controller_handle_weighted_flags(void)
static enum config_weight safety_controller_handle_weighted_flags(void)
{
uint32_t flag_index;
volatile struct error_flag *current_flag;
enum config_weight flag_weigth;
enum config_weight worst = SAFETY_FLAG_CONFIG_WEIGHT_NONE;
for (flag_index = 0u; flag_index < COUNT_OF(flags); flag_index++) {
current_flag = &flags[flag_index];
@@ -1132,6 +1135,11 @@ static void safety_controller_handle_weighted_flags(void)
continue;
flag_weigth = get_flag_weight(current_flag);
/* Override the worst flag weigt set, if it is worse than the previous ones */
if (flag_weigth > worst)
worst = flag_weigth;
switch (flag_weigth) {
case SAFETY_FLAG_CONFIG_WEIGHT_NONE:
break;
@@ -1147,6 +1155,8 @@ static void safety_controller_handle_weighted_flags(void)
}
}
return worst;
}
#ifndef DEBUGBUILD
@@ -1156,9 +1166,9 @@ static void external_watchdog_toggle(void)
}
#endif
int safety_controller_handle(void)
enum config_weight safety_controller_handle(void)
{
int ret = 0;
enum config_weight worst_weight_set;
#ifndef DEBUGBUILD
static uint32_t watchdog_counter = 0UL;
#endif
@@ -1168,9 +1178,10 @@ int safety_controller_handle(void)
safety_controller_handle_memory_checks();
safety_controller_do_systick_checking();
safety_controller_process_monitor_checks();
safety_controller_handle_weighted_flags();
worst_weight_set = safety_controller_handle_weighted_flags();
ret |= watchdog_ack(WATCHDOG_MAGIC_KEY);
/* Ignore error here. Will trigger restart anyway */
(void)watchdog_ack(WATCHDOG_MAGIC_KEY);
#ifndef DEBUGBUILD
if (get_pcb_hardware_version() != HW_REV_V1_2) {
@@ -1181,7 +1192,8 @@ int safety_controller_handle(void)
}
}
#endif
return (ret ? -1 : 0);
return worst_weight_set;
}
int safety_controller_enable_timing_mon(enum timing_monitor monitor, bool enable)