From ac26aea18bc0e7f809b6c65d86aa5a35f76bdd9f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 17 Jan 2020 17:36:01 +1100 Subject: [PATCH] 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 --- libraries/AP_IOMCU/AP_IOMCU.cpp | 9 ++++++++- libraries/AP_IOMCU/AP_IOMCU.h | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/AP_IOMCU/AP_IOMCU.cpp b/libraries/AP_IOMCU/AP_IOMCU.cpp index 9210a8b358..df775e8813 100644 --- a/libraries/AP_IOMCU/AP_IOMCU.cpp +++ b/libraries/AP_IOMCU/AP_IOMCU.cpp @@ -300,8 +300,14 @@ void AP_IOMCU::read_status() { uint16_t *r = (uint16_t *)®_status; if (!read_registers(PAGE_STATUS, 0, sizeof(reg_status)/2, r)) { + read_status_errors++; return; } + if (read_status_ok == 0) { + // reset error count on first good read + read_status_errors = 0; + } + read_status_ok++; 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)) { debug("t=%u timeout read page=%u offset=%u count=%u\n", AP_HAL::millis(), page, offset, count); + protocol_fail_count++; return false; } @@ -859,7 +866,7 @@ void AP_IOMCU::set_safety_mask(uint16_t chmask) */ 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; } /* diff --git a/libraries/AP_IOMCU/AP_IOMCU.h b/libraries/AP_IOMCU/AP_IOMCU.h index b74c8aec04..d5d77997b5 100644 --- a/libraries/AP_IOMCU/AP_IOMCU.h +++ b/libraries/AP_IOMCU/AP_IOMCU.h @@ -216,6 +216,8 @@ private: uint32_t total_errors; uint32_t num_delayed; uint32_t last_iocmu_timestamp_ms; + uint32_t read_status_errors; + uint32_t read_status_ok; // firmware upload const char *fw_name = "io_firmware.bin";