Browse Source

AP_IOMCU: added a health check based on status read errors

if we have more than 1 in 128 read status requests failing then mark
IOMCU unhealthy
copter407
Andrew Tridgell 5 years ago
parent
commit
ac26aea18b
  1. 9
      libraries/AP_IOMCU/AP_IOMCU.cpp
  2. 2
      libraries/AP_IOMCU/AP_IOMCU.h

9
libraries/AP_IOMCU/AP_IOMCU.cpp

@ -300,8 +300,14 @@ void AP_IOMCU::read_status()
{ {
uint16_t *r = (uint16_t *)&reg_status; uint16_t *r = (uint16_t *)&reg_status;
if (!read_registers(PAGE_STATUS, 0, sizeof(reg_status)/2, r)) { if (!read_registers(PAGE_STATUS, 0, sizeof(reg_status)/2, r)) {
read_status_errors++;
return; return;
} }
if (read_status_ok == 0) {
// reset error count on first good read
read_status_errors = 0;
}
read_status_ok++;
check_iomcu_reset(); check_iomcu_reset();
@ -447,6 +453,7 @@ bool AP_IOMCU::read_registers(uint8_t page, uint8_t offset, uint8_t count, uint1
if (!uart.wait_timeout(count*2+4, 10)) { if (!uart.wait_timeout(count*2+4, 10)) {
debug("t=%u timeout read page=%u offset=%u count=%u\n", debug("t=%u timeout read page=%u offset=%u count=%u\n",
AP_HAL::millis(), page, offset, count); AP_HAL::millis(), page, offset, count);
protocol_fail_count++;
return false; return false;
} }
@ -859,7 +866,7 @@ void AP_IOMCU::set_safety_mask(uint16_t chmask)
*/ */
bool AP_IOMCU::healthy(void) bool AP_IOMCU::healthy(void)
{ {
return crc_is_ok && protocol_fail_count == 0 && !detected_io_reset; return crc_is_ok && protocol_fail_count == 0 && !detected_io_reset && read_status_errors < read_status_ok/128U;
} }
/* /*

2
libraries/AP_IOMCU/AP_IOMCU.h

@ -216,6 +216,8 @@ private:
uint32_t total_errors; uint32_t total_errors;
uint32_t num_delayed; uint32_t num_delayed;
uint32_t last_iocmu_timestamp_ms; uint32_t last_iocmu_timestamp_ms;
uint32_t read_status_errors;
uint32_t read_status_ok;
// firmware upload // firmware upload
const char *fw_name = "io_firmware.bin"; const char *fw_name = "io_firmware.bin";

Loading…
Cancel
Save