/** * 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) //#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() { //PRINTF("\r\n*** HB FLAGS %x ***\r\n", heartbeat_flags); 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 } }