You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
toaster-oven-bluepill/Core/Src/app_safety.c

66 lines
1.6 KiB

/**
* TODO file description
*/
#include "app_safety.h"
#include "app_heater.h"
#include "snprintf.h"
#include "stm32f1xx_ll_iwdg.h"
#include "stm32f1xx_ll_gpio.h"
#include "main.h"
#define HB_FLAG_TEMP_NORMAL (1 << 0)
#define HB_FLAG_ADC_SAMPLING (1 << 1)
#define HB_FLAG_TEMP_CALCULATION (1 << 2)
#define HB_FLAG_REG_LOOP (1 << 3)
#define HB_FLAG_DISPLAY_UPDATING (1 << 4)
#define HB_FLAG_SOC_TEMP_OK (1 << 5)
2 years ago
//#define HB_FLAG_ALL (0b111111)
#define HB_FLAG_ALL (0b111110) // FIXME !!!! disabling the temp watchdog
static volatile uint32_t heartbeat_flags = 0;
void app_safety_pass_temp_normal() {
heartbeat_flags |= HB_FLAG_TEMP_NORMAL;
}
void app_safety_pass_adc_sampling() {
heartbeat_flags |= HB_FLAG_ADC_SAMPLING;
}
void app_safety_pass_temp_calculation() {
heartbeat_flags |= HB_FLAG_TEMP_CALCULATION;
}
void app_safety_pass_reg_loop_running() {
heartbeat_flags |= HB_FLAG_REG_LOOP;
}
void app_safety_pass_display_updating() {
heartbeat_flags |= HB_FLAG_DISPLAY_UPDATING;
}
void app_safety_pass_soc_temp_ok() {
heartbeat_flags |= HB_FLAG_SOC_TEMP_OK;
}
void app_safety_poll() {
if ((heartbeat_flags & HB_FLAG_ALL) == HB_FLAG_ALL) {
LL_IWDG_ReloadCounter(IWDG);
LL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
heartbeat_flags = 0;
}
}
// emergency shutdown, this must not block use RTOS since it can be called from fault handlers or interrupt
void __attribute__((noreturn)) app_emergency_stop() {
app_heater_emergency_shutdown();
PUTS("\r\n*** EMERGENCY STOP ***\r\n");
while (1) {
// wait for the watchdog to bite
}
}