parent
0a0ccf7bc3
commit
b397856366
@ -0,0 +1,64 @@ |
||||
/**
|
||||
* 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) |
||||
|
||||
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
|
||||
} |
||||
} |
@ -0,0 +1,30 @@ |
||||
/**
|
||||
* TODO file description |
||||
*/ |
||||
|
||||
#ifndef BLUEPILLTROUBA_APP_SAFETY_H |
||||
#define BLUEPILLTROUBA_APP_SAFETY_H |
||||
|
||||
/**
|
||||
* Check the pass flags. If all are set, reset the WD and clear flags. |
||||
* |
||||
* This effectively makes the WD bite when either of the subsystems fails. |
||||
*/ |
||||
void app_safety_poll(); |
||||
|
||||
void app_emergency_stop() |
||||
__attribute__((noreturn)); |
||||
|
||||
void app_safety_pass_temp_normal(); |
||||
|
||||
void app_safety_pass_adc_sampling(); |
||||
|
||||
void app_safety_pass_temp_calculation(); |
||||
|
||||
void app_safety_pass_reg_loop_running(); |
||||
|
||||
void app_safety_pass_display_updating(); |
||||
|
||||
void app_safety_pass_soc_temp_ok(); |
||||
|
||||
#endif //BLUEPILLTROUBA_APP_SAFETY_H
|
Loading…
Reference in new issue