Further rewrite safety handling
This commit is contained in:
@@ -41,9 +41,9 @@
|
||||
#include <stm-periph/uart.h>
|
||||
#include <reflow-controller/shell-uart-config.h>
|
||||
#include <reflow-controller/oven-driver.h>
|
||||
#include <reflow-controller/safety/safety-adc.h>
|
||||
#include <fatfs/ff.h>
|
||||
#include <reflow-controller/reflow-menu.h>
|
||||
#include <reflow-controller/safety/safety-controller.h>
|
||||
|
||||
bool global_error_state;
|
||||
|
||||
@@ -154,12 +154,14 @@ static inline void setup_system(void)
|
||||
led_setup();
|
||||
loudspeaker_setup();
|
||||
reflow_menu_init();
|
||||
safety_adc_init();
|
||||
|
||||
|
||||
uart_gpio_config();
|
||||
setup_shell_uart(&shell_uart);
|
||||
|
||||
setup_unused_pins();
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void handle_shell_uart_input(shellmatta_handle_t shell_handle)
|
||||
@@ -188,39 +190,12 @@ static void zero_ccm_ram(void)
|
||||
ptr[i] = 0UL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function sets the appropriate error flags in the oven PID controller
|
||||
* depending on the Safety ADC measurements.
|
||||
* The PID controller's error flags have to be cleared via the GUI by either starting a new RUN or explicitly
|
||||
* ack'ing these errors.
|
||||
*/
|
||||
static void propagate_safety_adc_error_to_oven_pid(void)
|
||||
{
|
||||
enum safety_adc_check_result safety_adc_result;
|
||||
|
||||
safety_adc_result = safety_adc_get_errors();
|
||||
|
||||
if (safety_adc_result & SAFETY_ADC_CHECK_TEMP_LOW ||
|
||||
safety_adc_result & SAFETY_ADC_CHECK_TEMP_HIGH)
|
||||
oven_pid_report_error(OVEN_PID_ERR_OVERTEMP);
|
||||
|
||||
if (safety_adc_result & SAFETY_ADC_CHECK_VREF_LOW ||
|
||||
safety_adc_result & SAFETY_ADC_CHECK_VREF_HIGH)
|
||||
oven_pid_report_error(OVEN_PID_ERR_VREF_TOL);
|
||||
|
||||
if (safety_adc_result & SAFETY_ADC_INTERNAL_ERROR)
|
||||
oven_pid_report_error(0);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
bool sd_card_mounted = false;
|
||||
shellmatta_handle_t shell_handle;
|
||||
int menu_wait_request;
|
||||
uint64_t quarter_sec_timestamp = 0ULL;
|
||||
const struct oven_pid_status *pid_status;
|
||||
enum adc_pt1000_error pt1000_status;
|
||||
|
||||
zero_ccm_ram();
|
||||
setup_system();
|
||||
|
||||
@@ -232,31 +207,20 @@ int main(void)
|
||||
while (1) {
|
||||
sd_card_mounted = mount_sd_card_if_avail(sd_card_mounted);
|
||||
|
||||
pid_status = oven_pid_get_status();
|
||||
|
||||
if (systick_ticks_have_passed(quarter_sec_timestamp, 250)) {
|
||||
quarter_sec_timestamp = systick_get_global_tick();
|
||||
|
||||
(void)handle_safety_adc();
|
||||
propagate_safety_adc_error_to_oven_pid();
|
||||
|
||||
if (global_error_state)
|
||||
if (0)
|
||||
led_set(0, !led_get(0));
|
||||
else
|
||||
led_set(0, 0);
|
||||
}
|
||||
|
||||
pt1000_status = adc_pt1000_check_error();
|
||||
global_error_state = pid_status->error_set || !!safety_adc_get_errors() || !!pt1000_status;
|
||||
|
||||
menu_wait_request = reflow_menu_handle();
|
||||
|
||||
/* Deactivate oven output in case of error! */
|
||||
if (!pid_status->active || global_error_state)
|
||||
oven_driver_set_power(0U);
|
||||
|
||||
handle_shell_uart_input(shell_handle);
|
||||
|
||||
oven_driver_apply_power_level();
|
||||
|
||||
if (menu_wait_request)
|
||||
__WFI();
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user