Add external watchdog to safety controller for HW revision > 1.3 and Release Build
This commit is contained in:
		@@ -28,6 +28,7 @@
 | 
			
		||||
#include <reflow-controller/safety/watchdog.h>
 | 
			
		||||
#include <reflow-controller/safety/safety-adc.h>
 | 
			
		||||
#include <reflow-controller/safety/stack-check.h>
 | 
			
		||||
#include <reflow-controller/hw-version-detect.h>
 | 
			
		||||
#include <helper-macros/helper-macros.h>
 | 
			
		||||
#include <stm-periph/crc-unit.h>
 | 
			
		||||
#include <reflow-controller/systick.h>
 | 
			
		||||
@@ -475,10 +476,23 @@ static int get_safety_flags_from_error_mem(enum safety_flag *flags)
 | 
			
		||||
	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()
 | 
			
		||||
{
 | 
			
		||||
	enum safety_memory_state found_memory_state;
 | 
			
		||||
	enum safety_flag flags_in_err_mem = ERR_FLAG_NO_FLAG;
 | 
			
		||||
	enum hw_revision hw_rev;
 | 
			
		||||
 | 
			
		||||
	int res;
 | 
			
		||||
 | 
			
		||||
	/* Init the safety memory */
 | 
			
		||||
@@ -492,6 +506,12 @@ void safety_controller_init()
 | 
			
		||||
 | 
			
		||||
	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_persistencies_from_default();
 | 
			
		||||
	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 ret = 0;
 | 
			
		||||
#ifndef DEBUGBUILD
 | 
			
		||||
	static uint32_t watchdog_counter = 0UL;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
	safety_controller_check_stack();
 | 
			
		||||
	safety_controller_handle_safety_adc();
 | 
			
		||||
@@ -661,6 +691,15 @@ int safety_controller_handle()
 | 
			
		||||
 | 
			
		||||
	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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user