Fix recursion loop in safety controller
This commit is contained in:
		@@ -155,19 +155,14 @@ static void safety_controller_process_active_timing_mons()
 | 
			
		||||
static void safety_controller_process_checks()
 | 
			
		||||
{
 | 
			
		||||
	static bool startup_completed = false;
 | 
			
		||||
	static uint64_t last_systick = 0;
 | 
			
		||||
	enum analog_monitor_status amon_state;
 | 
			
		||||
	float amon_value;
 | 
			
		||||
	uint64_t systick;
 | 
			
		||||
 | 
			
		||||
	systick = systick_get_global_tick();
 | 
			
		||||
	if (systick == last_systick) {
 | 
			
		||||
		safety_controller_report_error(ERR_FLAG_SYSTICK);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (systick >= 1000) {
 | 
			
		||||
 | 
			
		||||
	if (!startup_completed && systick_get_global_tick() >= 1000)
 | 
			
		||||
		startup_completed = true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	if (startup_completed) {
 | 
			
		||||
		amon_state = safety_controller_get_analog_mon_value(ERR_AMON_VREF, &amon_value);
 | 
			
		||||
@@ -201,8 +196,6 @@ int safety_controller_report_error_with_key(enum safety_flag flag, uint32_t key)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	safety_controller_process_checks();
 | 
			
		||||
 | 
			
		||||
	return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -225,7 +218,6 @@ void safety_controller_report_timing(enum timing_monitor monitor)
 | 
			
		||||
		tim->enabled = true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	safety_controller_process_checks();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void safety_controller_report_analog_value(enum analog_value_monitor monitor, float value)
 | 
			
		||||
@@ -241,7 +233,6 @@ void safety_controller_report_analog_value(enum analog_value_monitor monitor, fl
 | 
			
		||||
		ana->value = value;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	safety_controller_process_checks();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void safety_controller_init()
 | 
			
		||||
@@ -254,6 +245,8 @@ void safety_controller_init()
 | 
			
		||||
	safety_adc_init();
 | 
			
		||||
	watchdog_setup(WATCHDOG_PRESCALER);
 | 
			
		||||
 | 
			
		||||
	if (watchdog_check_reset_source())
 | 
			
		||||
		safety_controller_report_error(ERR_FLAG_WTCHDG_FIRED);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void safety_controller_check_stack()
 | 
			
		||||
@@ -307,17 +300,26 @@ static void safety_controller_handle_safety_adc()
 | 
			
		||||
 | 
			
		||||
int safety_controller_handle()
 | 
			
		||||
{
 | 
			
		||||
	static
 | 
			
		||||
	static uint64_t last_systick;
 | 
			
		||||
	static uint32_t same_systick_cnt = 0UL;
 | 
			
		||||
	uint64_t systick;
 | 
			
		||||
 | 
			
		||||
	int ret = 0;
 | 
			
		||||
 | 
			
		||||
	safety_controller_check_stack();
 | 
			
		||||
	safety_controller_handle_safety_adc();
 | 
			
		||||
	if (watchdog_check_reset_source())
 | 
			
		||||
		safety_controller_report_error(ERR_FLAG_WTCHDG_FIRED);
 | 
			
		||||
 | 
			
		||||
	systick = systick_get_global_tick();
 | 
			
		||||
	if (systick == last_systick) {
 | 
			
		||||
		same_systick_cnt++;
 | 
			
		||||
		if (same_systick_cnt > 1000)
 | 
			
		||||
			safety_controller_report_error(ERR_FLAG_SYSTICK);
 | 
			
		||||
	} else {
 | 
			
		||||
		same_systick_cnt = 0UL;
 | 
			
		||||
	}
 | 
			
		||||
	last_systick = systick;
 | 
			
		||||
 | 
			
		||||
	safety_controller_process_checks();
 | 
			
		||||
 | 
			
		||||
	/* TODO: Check flags for PID and HALT */
 | 
			
		||||
 | 
			
		||||
	ret |= watchdog_ack(WATCHDOG_MAGIC_KEY);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user