Issue #15: Implement redundancy for error flags
This commit is contained in:
		@@ -112,6 +112,15 @@ static volatile struct analog_mon IN_SECTION(.ccm.data) analog_mons[] = {
 | 
			
		||||
		      ERR_FLAG_AMON_UC_TEMP),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static bool error_flag_get_status(const volatile struct error_flag *flag)
 | 
			
		||||
{
 | 
			
		||||
	if (flag->error_state == flag->error_state_inv) {
 | 
			
		||||
		return true;
 | 
			
		||||
	} else {
 | 
			
		||||
		return flag->error_state;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static volatile struct analog_mon *find_analog_mon(enum analog_value_monitor mon)
 | 
			
		||||
{
 | 
			
		||||
	uint32_t i;
 | 
			
		||||
@@ -185,7 +194,6 @@ static void safety_controller_process_checks()
 | 
			
		||||
		amon_state = safety_controller_get_analog_mon_value(ERR_AMON_UC_TEMP, &amon_value);
 | 
			
		||||
		if (amon_state != ANALOG_MONITOR_OK)
 | 
			
		||||
			safety_controller_report_error(ERR_FLAG_AMON_UC_TEMP);
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	safety_controller_process_active_timing_mons();
 | 
			
		||||
@@ -204,6 +212,7 @@ int safety_controller_report_error_with_key(enum safety_flag flag, uint32_t key)
 | 
			
		||||
	for (i = 0; i < COUNT_OF(flags); i++) {
 | 
			
		||||
		if (flags[i].flag & flag) {
 | 
			
		||||
			flags[i].error_state = true;
 | 
			
		||||
			flags[i].error_state_inv = !flags[i].error_state;
 | 
			
		||||
			flags[i].key = key;
 | 
			
		||||
			ret = 0;
 | 
			
		||||
		}
 | 
			
		||||
@@ -436,13 +445,15 @@ int safety_controller_get_flag(enum safety_flag flag, bool *status, bool try_ack
 | 
			
		||||
 | 
			
		||||
	found_flag = find_error_flag(flag);
 | 
			
		||||
	if (found_flag) {
 | 
			
		||||
		*status = found_flag->error_state;
 | 
			
		||||
		*status = error_flag_get_status(found_flag);
 | 
			
		||||
		if (try_ack && !found_flag->persistent) {
 | 
			
		||||
			/* Flag is generally non persistent
 | 
			
		||||
			 * If key is set, this function cannot remove the flag
 | 
			
		||||
			 */
 | 
			
		||||
			if (found_flag->key == 0UL)
 | 
			
		||||
			if (found_flag->key == 0UL) {
 | 
			
		||||
				found_flag->error_state = false;
 | 
			
		||||
				found_flag->error_state_inv = !found_flag->error_state;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -467,6 +478,7 @@ int safety_controller_ack_flag_with_key(enum safety_flag flag, uint32_t key)
 | 
			
		||||
	if (found_flag) {
 | 
			
		||||
		if (!found_flag->persistent && (found_flag->key == key || !key)) {
 | 
			
		||||
			found_flag->error_state = false;
 | 
			
		||||
			found_flag->error_state_inv = true;
 | 
			
		||||
			ret = 0;
 | 
			
		||||
		} else {
 | 
			
		||||
			ret = -2;
 | 
			
		||||
@@ -482,7 +494,7 @@ bool safety_controller_get_flags_by_mask(enum safety_flag mask)
 | 
			
		||||
	bool ret = false;
 | 
			
		||||
 | 
			
		||||
	for (i = 0; i < COUNT_OF(flags); i++) {
 | 
			
		||||
		if ((flags[i].flag & mask) && flags[i].error_state) {
 | 
			
		||||
		if ((flags[i].flag & mask) && error_flag_get_status(&flags[i])) {
 | 
			
		||||
			ret = true;
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
@@ -557,7 +569,7 @@ int safety_controller_get_flag_by_index(uint32_t index, bool *status, enum safet
 | 
			
		||||
 | 
			
		||||
	if (index < COUNT_OF(flags)) {
 | 
			
		||||
		if (status)
 | 
			
		||||
			*status = flags[index].error_state;
 | 
			
		||||
			*status = error_flag_get_status(&flags[index]);
 | 
			
		||||
		if (flag_enum)
 | 
			
		||||
			*flag_enum = flags[index].flag;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user