Issue #18: Store correct flag number in error memory

This commit is contained in:
Mario Hüttel 2020-09-08 19:23:14 +02:00
parent e0f61af709
commit 1c1d1c4c97
2 changed files with 27 additions and 1 deletions

View File

@ -23,6 +23,7 @@
enum safety_flag { enum safety_flag {
ERR_FLAG_NO_FLAG = 0,
ERR_FLAG_MEAS_ADC_OFF = (1<<0), ERR_FLAG_MEAS_ADC_OFF = (1<<0),
ERR_FLAG_MEAS_ADC_OVERFLOW = (1<<1), ERR_FLAG_MEAS_ADC_OVERFLOW = (1<<1),
ERR_FLAG_MEAS_ADC_WATCHDOG = (1<<2), ERR_FLAG_MEAS_ADC_WATCHDOG = (1<<2),

View File

@ -259,6 +259,31 @@ static void safety_controller_process_monitor_checks()
safety_controller_process_active_timing_mons(); safety_controller_process_active_timing_mons();
} }
static uint8_t flag_enum_to_flag_no(enum safety_flag flag)
{
uint32_t flag_mask;
uint8_t i;
if (!is_power_of_two(flag))
return 0xFF;
flag_mask = (uint32_t)flag;
for (i = 0; i < 32; i++) {
if ((flag_mask >> i) & 0x1U)
break;
}
return i;
}
static enum safety_flag flag_no_to_flag_enum(uint8_t no)
{
if (no >= COUNT_OF(flags))
return ERR_FLAG_NO_FLAG;
return (1U << no);
}
int safety_controller_report_error(enum safety_flag flag) int safety_controller_report_error(enum safety_flag flag)
{ {
return safety_controller_report_error_with_key(flag, 0x0UL); return safety_controller_report_error_with_key(flag, 0x0UL);
@ -281,7 +306,7 @@ int safety_controller_report_error_with_key(enum safety_flag flag, uint32_t key)
if (flags[i].persistent && !old_state) { if (flags[i].persistent && !old_state) {
err_mem_entry.counter = 1; err_mem_entry.counter = 1;
err_mem_entry.flag_num = i; err_mem_entry.flag_num = flag_enum_to_flag_no(flags[i].flag);
err_mem_entry.type = SAFETY_MEMORY_ERR_ENTRY_FLAG; err_mem_entry.type = SAFETY_MEMORY_ERR_ENTRY_FLAG;
res = safety_memory_insert_error_entry(&err_mem_entry); res = safety_memory_insert_error_entry(&err_mem_entry);
if (res) { if (res) {