Restructure safety handle function. Now returns worst flag state set. Used to blink LED
This commit is contained in:
parent
6ac108e1b2
commit
aaed95cc95
@ -27,6 +27,15 @@
|
|||||||
#ifndef __SAFETY_CONFIG_H__
|
#ifndef __SAFETY_CONFIG_H__
|
||||||
#define __SAFETY_CONFIG_H__
|
#define __SAFETY_CONFIG_H__
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Weights of error flags.
|
||||||
|
*/
|
||||||
|
enum config_weight {
|
||||||
|
SAFETY_FLAG_CONFIG_WEIGHT_NONE = 0, /**< @brief This flag has no global error consequence, but might be respected by certain software modules. */
|
||||||
|
SAFETY_FLAG_CONFIG_WEIGHT_PID = 1, /**< @brief This flag will force a stop of the temperature PID controller */
|
||||||
|
SAFETY_FLAG_CONFIG_WEIGHT_PANIC = 2, /**< @brief This flag will trigger the panic mode */
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Enum type representing safety flags.
|
* @brief Enum type representing safety flags.
|
||||||
*
|
*
|
||||||
|
@ -75,9 +75,9 @@ void safety_controller_init(void);
|
|||||||
/**
|
/**
|
||||||
* @brief Handle the safety controller.
|
* @brief Handle the safety controller.
|
||||||
* @note This function must be executed periodically in order to prevent the watchdog from resetting the firmware
|
* @note This function must be executed periodically in order to prevent the watchdog from resetting the firmware
|
||||||
* @return 0 if successful
|
* @returns Worst flag weigth that is currently set.
|
||||||
*/
|
*/
|
||||||
int safety_controller_handle(void);
|
enum config_weight safety_controller_handle(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Report one or multiple errors to the safety controller
|
* @brief Report one or multiple errors to the safety controller
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <reflow-controller/safety/safety-config.h>
|
||||||
|
|
||||||
/** @addtogroup safety-memory
|
/** @addtogroup safety-memory
|
||||||
* @{
|
* @{
|
||||||
@ -131,15 +132,6 @@ enum config_override_entry_type {
|
|||||||
SAFETY_MEMORY_CONFIG_OVERRIDE_PERSISTENCE = 2,
|
SAFETY_MEMORY_CONFIG_OVERRIDE_PERSISTENCE = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Weights of error flags.
|
|
||||||
*/
|
|
||||||
enum config_weight {
|
|
||||||
SAFETY_FLAG_CONFIG_WEIGHT_NONE = 0, /**< @brief This flag has no global error consequence, but might be respected by certain software modules. */
|
|
||||||
SAFETY_FLAG_CONFIG_WEIGHT_PID = 1, /**< @brief This flag will force a stop of the temperature PID controller */
|
|
||||||
SAFETY_FLAG_CONFIG_WEIGHT_PANIC = 2, /**< @brief This flag will trigger the panic mode */
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief representation of a config override memory entry
|
* @brief representation of a config override memory entry
|
||||||
*/
|
*/
|
||||||
|
@ -286,6 +286,7 @@ int main(void)
|
|||||||
shellmatta_handle_t shell_handle;
|
shellmatta_handle_t shell_handle;
|
||||||
int menu_wait_request;
|
int menu_wait_request;
|
||||||
uint64_t quarter_sec_timestamp = 0ULL;
|
uint64_t quarter_sec_timestamp = 0ULL;
|
||||||
|
enum config_weight worst_safety_flag = SAFETY_FLAG_CONFIG_WEIGHT_NONE;
|
||||||
|
|
||||||
/** - Setup all the peripherals and external componets like LCD, EEPROM etc. and the safety controller */
|
/** - Setup all the peripherals and external componets like LCD, EEPROM etc. and the safety controller */
|
||||||
setup_system();
|
setup_system();
|
||||||
@ -328,7 +329,7 @@ int main(void)
|
|||||||
/* Check if any flags are present, that disable the PID controller. Blink
|
/* Check if any flags are present, that disable the PID controller. Blink
|
||||||
* LED 0 in this case
|
* LED 0 in this case
|
||||||
*/
|
*/
|
||||||
if (oven_pid_get_status() == OVEN_PID_ABORTED)
|
if (worst_safety_flag >= SAFETY_FLAG_CONFIG_WEIGHT_PID)
|
||||||
led_set(0u, led_get(0u) ? 0 : 1);
|
led_set(0u, led_get(0u) ? 0 : 1);
|
||||||
else
|
else
|
||||||
led_set(0u, 0);
|
led_set(0u, 0);
|
||||||
@ -346,7 +347,7 @@ int main(void)
|
|||||||
temp_profile_executer_handle();
|
temp_profile_executer_handle();
|
||||||
|
|
||||||
/** - Handle the safety controller. This must be called! Otherwise a watchdog reset will occur */
|
/** - Handle the safety controller. This must be called! Otherwise a watchdog reset will occur */
|
||||||
safety_controller_handle();
|
worst_safety_flag = safety_controller_handle();
|
||||||
|
|
||||||
/** - If the Oven PID controller is running, we handle its sample function */
|
/** - If the Oven PID controller is running, we handle its sample function */
|
||||||
if (oven_pid_get_status() == OVEN_PID_RUNNING)
|
if (oven_pid_get_status() == OVEN_PID_RUNNING)
|
||||||
|
@ -1117,12 +1117,15 @@ static void safety_controller_do_systick_checking(void)
|
|||||||
* is set, the appropriate action defined by the flag weight is executed.
|
* 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
|
* @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)
|
* (@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;
|
uint32_t flag_index;
|
||||||
volatile struct error_flag *current_flag;
|
volatile struct error_flag *current_flag;
|
||||||
enum config_weight flag_weigth;
|
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++) {
|
for (flag_index = 0u; flag_index < COUNT_OF(flags); flag_index++) {
|
||||||
current_flag = &flags[flag_index];
|
current_flag = &flags[flag_index];
|
||||||
@ -1132,6 +1135,11 @@ static void safety_controller_handle_weighted_flags(void)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
flag_weigth = get_flag_weight(current_flag);
|
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) {
|
switch (flag_weigth) {
|
||||||
case SAFETY_FLAG_CONFIG_WEIGHT_NONE:
|
case SAFETY_FLAG_CONFIG_WEIGHT_NONE:
|
||||||
break;
|
break;
|
||||||
@ -1147,6 +1155,8 @@ static void safety_controller_handle_weighted_flags(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return worst;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef DEBUGBUILD
|
#ifndef DEBUGBUILD
|
||||||
@ -1156,9 +1166,9 @@ static void external_watchdog_toggle(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int safety_controller_handle(void)
|
enum config_weight safety_controller_handle(void)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
enum config_weight worst_weight_set;
|
||||||
#ifndef DEBUGBUILD
|
#ifndef DEBUGBUILD
|
||||||
static uint32_t watchdog_counter = 0UL;
|
static uint32_t watchdog_counter = 0UL;
|
||||||
#endif
|
#endif
|
||||||
@ -1168,9 +1178,10 @@ int safety_controller_handle(void)
|
|||||||
safety_controller_handle_memory_checks();
|
safety_controller_handle_memory_checks();
|
||||||
safety_controller_do_systick_checking();
|
safety_controller_do_systick_checking();
|
||||||
safety_controller_process_monitor_checks();
|
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
|
#ifndef DEBUGBUILD
|
||||||
if (get_pcb_hardware_version() != HW_REV_V1_2) {
|
if (get_pcb_hardware_version() != HW_REV_V1_2) {
|
||||||
@ -1181,7 +1192,8 @@ int safety_controller_handle(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return (ret ? -1 : 0);
|
|
||||||
|
return worst_weight_set;
|
||||||
}
|
}
|
||||||
|
|
||||||
int safety_controller_enable_timing_mon(enum timing_monitor monitor, bool enable)
|
int safety_controller_enable_timing_mon(enum timing_monitor monitor, bool enable)
|
||||||
|
Loading…
Reference in New Issue
Block a user