Add external watchdog to safety controller for HW revision > 1.3 and Release Build

This commit is contained in:
Mario Hüttel 2021-01-01 18:04:14 +01:00
parent 75f9c58c54
commit 2c3c1c9861
2 changed files with 43 additions and 0 deletions

View File

@ -119,6 +119,10 @@ enum analog_value_monitor {
#define SAFETY_ADC_TEMP_HIGH_LIM (65.0f) #define SAFETY_ADC_TEMP_HIGH_LIM (65.0f)
#define SAFETY_EXT_WATCHDOG_PORT GPIOD
#define SAFETY_EXT_WATCHDOG_RCC_MASK RCC_AHB1ENR_GPIODEN
#define SAFETY_EXT_WATCHDOG_PIN (12)
/** /**
* @brief Key used to lock the safety flags coming from the measurment ADC from external ack'ing * @brief Key used to lock the safety flags coming from the measurment ADC from external ack'ing
*/ */

View File

@ -28,6 +28,7 @@
#include <reflow-controller/safety/watchdog.h> #include <reflow-controller/safety/watchdog.h>
#include <reflow-controller/safety/safety-adc.h> #include <reflow-controller/safety/safety-adc.h>
#include <reflow-controller/safety/stack-check.h> #include <reflow-controller/safety/stack-check.h>
#include <reflow-controller/hw-version-detect.h>
#include <helper-macros/helper-macros.h> #include <helper-macros/helper-macros.h>
#include <stm-periph/crc-unit.h> #include <stm-periph/crc-unit.h>
#include <reflow-controller/systick.h> #include <reflow-controller/systick.h>
@ -475,10 +476,23 @@ static int get_safety_flags_from_error_mem(enum safety_flag *flags)
return 0; return 0;
} }
static void safety_controller_init_external_watchdog()
{
rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(SAFETY_EXT_WATCHDOG_RCC_MASK));
SAFETY_EXT_WATCHDOG_PORT->MODER &= MODER_DELETE(SAFETY_EXT_WATCHDOG_PIN);
#ifndef DEBUGBUILD
SAFETY_EXT_WATCHDOG_PORT->MODER |= OUTPUT(SAFETY_EXT_WATCHDOG_PIN);
SAFETY_EXT_WATCHDOG_PORT->ODR |= (1<<SAFETY_EXT_WATCHDOG_PIN);
#endif
__DSB();
}
void safety_controller_init() void safety_controller_init()
{ {
enum safety_memory_state found_memory_state; enum safety_memory_state found_memory_state;
enum safety_flag flags_in_err_mem = ERR_FLAG_NO_FLAG; enum safety_flag flags_in_err_mem = ERR_FLAG_NO_FLAG;
enum hw_revision hw_rev;
int res; int res;
/* Init the safety memory */ /* Init the safety memory */
@ -492,6 +506,12 @@ void safety_controller_init()
stack_check_init_corruption_detect_area(); stack_check_init_corruption_detect_area();
hw_rev = get_pcb_hardware_version();
if (hw_rev == HW_REV_ERROR)
panic_mode();
if (hw_rev != HW_REV_V1_2)
safety_controller_init_external_watchdog();
init_safety_flag_weight_table_from_default(); init_safety_flag_weight_table_from_default();
init_safety_flag_persistencies_from_default(); init_safety_flag_persistencies_from_default();
apply_config_overrides(); apply_config_overrides();
@ -648,9 +668,19 @@ static void safety_controller_handle_weighted_flags()
} }
} }
#ifndef DEBUGBUILD
static void external_watchdog_toggle()
{
SAFETY_EXT_WATCHDOG_PORT->ODR ^= (1<<SAFETY_EXT_WATCHDOG_PIN);
}
#endif
int safety_controller_handle() int safety_controller_handle()
{ {
int ret = 0; int ret = 0;
#ifndef DEBUGBUILD
static uint32_t watchdog_counter = 0UL;
#endif
safety_controller_check_stack(); safety_controller_check_stack();
safety_controller_handle_safety_adc(); safety_controller_handle_safety_adc();
@ -661,6 +691,15 @@ int safety_controller_handle()
ret |= watchdog_ack(WATCHDOG_MAGIC_KEY); ret |= watchdog_ack(WATCHDOG_MAGIC_KEY);
#ifndef DEBUGBUILD
if (get_pcb_hardware_version() != HW_REV_V1_2) {
watchdog_counter++;
if (watchdog_counter > 30) {
external_watchdog_toggle();
watchdog_counter = 0UL;
}
}
#endif
return (ret ? -1 : 0); return (ret ? -1 : 0);
} }