Add timing monitor for main loop and add monitors to safety flag command
This commit is contained in:
parent
fa3c980207
commit
d1d2d514bd
@ -37,12 +37,14 @@ enum safety_flag {
|
|||||||
ERR_FLAG_WTCHDG_FIRED = (1<<11),
|
ERR_FLAG_WTCHDG_FIRED = (1<<11),
|
||||||
ERR_FLAG_UNCAL = (1<<12),
|
ERR_FLAG_UNCAL = (1<<12),
|
||||||
ERR_FLAG_DEBUG = (1<<13),
|
ERR_FLAG_DEBUG = (1<<13),
|
||||||
|
ERR_FLAG_TIMING_MAIN_LOOP = (1<<14),
|
||||||
};
|
};
|
||||||
|
|
||||||
enum timing_monitor {
|
enum timing_monitor {
|
||||||
ERR_TIMING_PID = (1<<0),
|
ERR_TIMING_PID = (1<<0),
|
||||||
ERR_TIMING_MEAS_ADC = (1<<1),
|
ERR_TIMING_MEAS_ADC = (1<<1),
|
||||||
ERR_TIMING_SAFETY_ADC = (1<<2),
|
ERR_TIMING_SAFETY_ADC = (1<<2),
|
||||||
|
ERR_TIMING_MAIN_LOOP = (1<<3),
|
||||||
};
|
};
|
||||||
|
|
||||||
enum analog_value_monitor {
|
enum analog_value_monitor {
|
||||||
|
@ -46,6 +46,14 @@ struct analog_monitor_info {
|
|||||||
uint64_t timestamp;
|
uint64_t timestamp;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct timing_monitor_info {
|
||||||
|
uint64_t last_run;
|
||||||
|
uint64_t min;
|
||||||
|
uint64_t max;
|
||||||
|
bool enabled;
|
||||||
|
uint64_t delta;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize the safety controller
|
* @brief Initialize the safety controller
|
||||||
*
|
*
|
||||||
@ -94,6 +102,12 @@ int safety_controller_get_analog_mon_by_index(uint32_t index, struct analog_moni
|
|||||||
|
|
||||||
int safety_controller_get_analog_mon_name_by_index(uint32_t index, char *buffer, size_t buffsize);
|
int safety_controller_get_analog_mon_name_by_index(uint32_t index, char *buffer, size_t buffsize);
|
||||||
|
|
||||||
|
int safety_controller_get_timing_mon_by_index(uint32_t index, struct timing_monitor_info *info);
|
||||||
|
|
||||||
|
int safety_controller_get_timing_mon_name_by_index(uint32_t index, char *buffer, size_t buffsize);
|
||||||
|
|
||||||
|
uint32_t safety_controller_get_timing_monitor_count();
|
||||||
|
|
||||||
#endif /* __SAFETY_CONTROLLER_H__ */
|
#endif /* __SAFETY_CONTROLLER_H__ */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
@ -206,9 +206,9 @@ int main(void)
|
|||||||
shell_print_motd(shell_handle);
|
shell_print_motd(shell_handle);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
sd_card_mounted = mount_sd_card_if_avail(sd_card_mounted);
|
|
||||||
|
|
||||||
if (systick_ticks_have_passed(quarter_sec_timestamp, 250)) {
|
if (systick_ticks_have_passed(quarter_sec_timestamp, 250)) {
|
||||||
|
sd_card_mounted = mount_sd_card_if_avail(sd_card_mounted);
|
||||||
quarter_sec_timestamp = systick_get_global_tick();
|
quarter_sec_timestamp = systick_get_global_tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,6 +220,7 @@ int main(void)
|
|||||||
oven_driver_set_power(0);
|
oven_driver_set_power(0);
|
||||||
oven_driver_apply_power_level();
|
oven_driver_apply_power_level();
|
||||||
|
|
||||||
|
safety_controller_report_timing(ERR_TIMING_MAIN_LOOP);
|
||||||
if (menu_wait_request)
|
if (menu_wait_request)
|
||||||
__WFI();
|
__WFI();
|
||||||
else
|
else
|
||||||
|
@ -48,6 +48,7 @@ struct timing_mon {
|
|||||||
uint64_t min_delta;
|
uint64_t min_delta;
|
||||||
uint64_t max_delta;
|
uint64_t max_delta;
|
||||||
uint64_t last;
|
uint64_t last;
|
||||||
|
uint64_t calculated_delta;
|
||||||
bool enabled;
|
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_WTCHDG_FIRED, true),
|
||||||
ERR_FLAG_ENTRY(ERR_FLAG_UNCAL, false),
|
ERR_FLAG_ENTRY(ERR_FLAG_UNCAL, false),
|
||||||
ERR_FLAG_ENTRY(ERR_FLAG_DEBUG, true),
|
ERR_FLAG_ENTRY(ERR_FLAG_DEBUG, true),
|
||||||
|
ERR_FLAG_ENTRY(ERR_FLAG_TIMING_MAIN_LOOP, false),
|
||||||
};
|
};
|
||||||
|
|
||||||
static volatile struct timing_mon timings[] = {
|
static volatile struct timing_mon timings[] = {
|
||||||
TIM_MON_ENTRY(ERR_TIMING_PID, 2, 1000, ERR_FLAG_TIMING_PID),
|
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_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_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[] = {
|
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->last = timestamp;
|
||||||
tim->enabled = true;
|
tim->enabled = true;
|
||||||
}
|
}
|
||||||
@ -463,6 +467,11 @@ uint32_t safety_controller_get_analog_monitor_count()
|
|||||||
return COUNT_OF(analog_mons);
|
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)
|
int safety_controller_get_analog_mon_name_by_index(uint32_t index, char *buffer, size_t buffsize)
|
||||||
{
|
{
|
||||||
if (index >= COUNT_OF(analog_mons))
|
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;
|
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 safety_controller_get_flag_by_index(uint32_t index, bool *status, enum safety_flag *flag_enum)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -543,4 +566,26 @@ int safety_controller_get_analog_mon_by_index(uint32_t index, struct analog_moni
|
|||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
@ -355,6 +355,7 @@ static shellmatta_retCode_t shell_cmd_read_flags(const shellmatta_handle_t handl
|
|||||||
bool flag;
|
bool flag;
|
||||||
int status;
|
int status;
|
||||||
struct analog_monitor_info amon_info;
|
struct analog_monitor_info amon_info;
|
||||||
|
struct timing_monitor_info timing_info;
|
||||||
|
|
||||||
shellmatta_printf(handle, "Error flags\r\n"
|
shellmatta_printf(handle, "Error flags\r\n"
|
||||||
"-----------\r\n");
|
"-----------\r\n");
|
||||||
@ -405,6 +406,22 @@ static shellmatta_retCode_t shell_cmd_read_flags(const shellmatta_handle_t handl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shellmatta_printf(handle, "\r\nTiming Monitors\r\n"
|
||||||
|
"--------------\r\n");
|
||||||
|
|
||||||
|
|
||||||
|
count = safety_controller_get_timing_monitor_count();
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
|
(void)safety_controller_get_timing_mon_by_index(i, &timing_info);
|
||||||
|
(void)safety_controller_get_timing_mon_name_by_index(i, name, sizeof(name));
|
||||||
|
|
||||||
|
shellmatta_printf(handle, "\t%2lu) %-20s\t", i+1, name);
|
||||||
|
if (timing_info.enabled)
|
||||||
|
shellmatta_printf(handle, "%lu ms ago\r\n", (unsigned long int)timing_info.delta);
|
||||||
|
else
|
||||||
|
shellmatta_printf(handle, "[disabled]\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
return SHELLMATTA_OK;
|
return SHELLMATTA_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user