Fix recursion loop in safety controller

This commit is contained in:
Mario Hüttel 2020-07-28 21:00:37 +02:00
parent da96daa767
commit 97fc04399e
3 changed files with 23 additions and 25 deletions

View File

@ -1,4 +1,4 @@
/* Reflow Oven Controller
/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
@ -181,7 +181,7 @@ void adc_pt1000_set_resistance_calibration(float offset, float sensitivity_devia
pt1000_sens_dev = sensitivity_deviation;
calibration_active = active;
if (calibration_active) {
if (!calibration_active) {
safety_controller_report_error_with_key(ERR_FLAG_UNCAL, MEAS_ADC_SAFETY_FLAG_KEY);
} else {
safety_controller_ack_flag_with_key(ERR_FLAG_UNCAL, MEAS_ADC_SAFETY_FLAG_KEY);
@ -340,7 +340,7 @@ void ADC_IRQHandler(void)
if (adc1_sr & ADC_SR_AWD) {
ADC_PT1000_PERIPH->SR &= ~ADC_SR_AWD;
adc_watchdog_counter++;
if (adc_watchdog_counter >= ADC_PT1000_WATCHDOG_SAMPLE_COUNT)
if (adc_watchdog_counter >= ADC_PT1000_WATCHDOG_SAMPLE_COUNT && 0)
safety_controller_report_error(ERR_FLAG_MEAS_ADC_WATCHDOG);
}
}

View File

@ -148,7 +148,7 @@ static inline void setup_system(void)
setup_nvic_priorities();
systick_setup();
adc_pt1000_setup_meas();
oven_driver_init();
digio_setup_default_all();
led_setup();
@ -162,6 +162,7 @@ static inline void setup_system(void)
setup_unused_pins();
safety_controller_init();
adc_pt1000_setup_meas();
}
static void handle_shell_uart_input(shellmatta_handle_t shell_handle)
@ -209,11 +210,6 @@ int main(void)
if (systick_ticks_have_passed(quarter_sec_timestamp, 250)) {
quarter_sec_timestamp = systick_get_global_tick();
if (0)
led_set(0, !led_get(0));
else
led_set(0, 0);
}
menu_wait_request = reflow_menu_handle();

View File

@ -155,19 +155,14 @@ static void safety_controller_process_active_timing_mons()
static void safety_controller_process_checks()
{
static bool startup_completed = false;
static uint64_t last_systick = 0;
enum analog_monitor_status amon_state;
float amon_value;
uint64_t systick;
systick = systick_get_global_tick();
if (systick == last_systick) {
safety_controller_report_error(ERR_FLAG_SYSTICK);
}
if (systick >= 1000) {
if (!startup_completed && systick_get_global_tick() >= 1000)
startup_completed = true;
}
if (startup_completed) {
amon_state = safety_controller_get_analog_mon_value(ERR_AMON_VREF, &amon_value);
@ -201,8 +196,6 @@ int safety_controller_report_error_with_key(enum safety_flag flag, uint32_t key)
}
}
safety_controller_process_checks();
return ret;
}
@ -225,7 +218,6 @@ void safety_controller_report_timing(enum timing_monitor monitor)
tim->enabled = true;
}
safety_controller_process_checks();
}
void safety_controller_report_analog_value(enum analog_value_monitor monitor, float value)
@ -241,7 +233,6 @@ void safety_controller_report_analog_value(enum analog_value_monitor monitor, fl
ana->value = value;
}
safety_controller_process_checks();
}
void safety_controller_init()
@ -254,6 +245,8 @@ void safety_controller_init()
safety_adc_init();
watchdog_setup(WATCHDOG_PRESCALER);
if (watchdog_check_reset_source())
safety_controller_report_error(ERR_FLAG_WTCHDG_FIRED);
}
static void safety_controller_check_stack()
@ -307,17 +300,26 @@ static void safety_controller_handle_safety_adc()
int safety_controller_handle()
{
static
static uint64_t last_systick;
static uint32_t same_systick_cnt = 0UL;
uint64_t systick;
int ret = 0;
safety_controller_check_stack();
safety_controller_handle_safety_adc();
if (watchdog_check_reset_source())
safety_controller_report_error(ERR_FLAG_WTCHDG_FIRED);
systick = systick_get_global_tick();
if (systick == last_systick) {
same_systick_cnt++;
if (same_systick_cnt > 1000)
safety_controller_report_error(ERR_FLAG_SYSTICK);
} else {
same_systick_cnt = 0UL;
}
last_systick = systick;
safety_controller_process_checks();
/* TODO: Check flags for PID and HALT */
ret |= watchdog_ack(WATCHDOG_MAGIC_KEY);