Add timing monitor for main loop and add monitors to safety flag command
This commit is contained in:
@@ -48,6 +48,7 @@ struct timing_mon {
|
||||
uint64_t min_delta;
|
||||
uint64_t max_delta;
|
||||
uint64_t last;
|
||||
uint64_t calculated_delta;
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
@@ -87,12 +88,14 @@ static volatile struct error_flag flags[] = {
|
||||
ERR_FLAG_ENTRY(ERR_FLAG_WTCHDG_FIRED, true),
|
||||
ERR_FLAG_ENTRY(ERR_FLAG_UNCAL, false),
|
||||
ERR_FLAG_ENTRY(ERR_FLAG_DEBUG, true),
|
||||
ERR_FLAG_ENTRY(ERR_FLAG_TIMING_MAIN_LOOP, false),
|
||||
};
|
||||
|
||||
static volatile struct timing_mon timings[] = {
|
||||
TIM_MON_ENTRY(ERR_TIMING_PID, 2, 1000, ERR_FLAG_TIMING_PID),
|
||||
TIM_MON_ENTRY(ERR_TIMING_MEAS_ADC, 0, 50, ERR_FLAG_TIMING_MEAS_ADC),
|
||||
TIM_MON_ENTRY(ERR_TIMING_SAFETY_ADC, 10, SAFETY_CONTROLLER_ADC_DELAY_MS + 1000, ERR_FLAG_SAFETY_ADC),
|
||||
TIM_MON_ENTRY(ERR_TIMING_MAIN_LOOP, 0, 1000, ERR_FLAG_TIMING_MAIN_LOOP),
|
||||
};
|
||||
|
||||
static volatile struct analog_mon analog_mons[] = {
|
||||
@@ -217,6 +220,7 @@ void safety_controller_report_timing(enum timing_monitor monitor)
|
||||
}
|
||||
}
|
||||
|
||||
tim->calculated_delta = timestamp - tim->last;
|
||||
tim->last = timestamp;
|
||||
tim->enabled = true;
|
||||
}
|
||||
@@ -463,6 +467,11 @@ uint32_t safety_controller_get_analog_monitor_count()
|
||||
return COUNT_OF(analog_mons);
|
||||
}
|
||||
|
||||
uint32_t safety_controller_get_timing_monitor_count()
|
||||
{
|
||||
return COUNT_OF(timings);
|
||||
}
|
||||
|
||||
int safety_controller_get_analog_mon_name_by_index(uint32_t index, char *buffer, size_t buffsize)
|
||||
{
|
||||
if (index >= COUNT_OF(analog_mons))
|
||||
@@ -491,6 +500,20 @@ int safety_controller_get_flag_name_by_index(uint32_t index, char *buffer, size_
|
||||
return 0;
|
||||
}
|
||||
|
||||
int safety_controller_get_timing_mon_name_by_index(uint32_t index, char *buffer, size_t buffsize)
|
||||
{
|
||||
if (index >= COUNT_OF(timings))
|
||||
return -1;
|
||||
|
||||
if (buffsize == 0 || !buffer)
|
||||
return -1000;
|
||||
|
||||
strncpy(buffer, timings[index].name, buffsize);
|
||||
buffer[buffsize - 1] = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int safety_controller_get_flag_by_index(uint32_t index, bool *status, enum safety_flag *flag_enum)
|
||||
{
|
||||
int ret = -1;
|
||||
@@ -543,4 +566,26 @@ int safety_controller_get_analog_mon_by_index(uint32_t index, struct analog_moni
|
||||
return 0;
|
||||
}
|
||||
|
||||
int safety_controller_get_timing_mon_by_index(uint32_t index, struct timing_monitor_info *info)
|
||||
{
|
||||
volatile struct timing_mon *mon;
|
||||
|
||||
if (!info)
|
||||
return -1002;
|
||||
|
||||
if (index >= COUNT_OF(timings)) {
|
||||
return -1001;
|
||||
}
|
||||
|
||||
mon = &timings[index];
|
||||
|
||||
info->max = mon->max_delta;
|
||||
info->min = mon->min_delta;
|
||||
info->enabled = mon->enabled;
|
||||
info->last_run = mon->last;
|
||||
info->delta = mon->calculated_delta;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
Reference in New Issue
Block a user