From 0607e921cbc7a4f900b8ac88f417af9b3fffb3a0 Mon Sep 17 00:00:00 2001 From: bugobliterator Date: Wed, 1 Nov 2023 16:04:23 +1100 Subject: [PATCH] AP_Periph: solve a potential case where last_transmit_us can change inside irqs --- Tools/AP_Periph/can.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Tools/AP_Periph/can.cpp b/Tools/AP_Periph/can.cpp index deadcd03f36f7..01adff69a5f60 100644 --- a/Tools/AP_Periph/can.cpp +++ b/Tools/AP_Periph/can.cpp @@ -1136,8 +1136,9 @@ void AP_Periph_FW::processTx(void) active if it has had a successful transmit in the last 2 seconds */ - const auto *stats = _ins.iface->get_statistics(); - if (stats == nullptr || now_us - stats->last_transmit_us < 2000000UL) { + volatile const auto *stats = _ins.iface->get_statistics(); + uint64_t last_transmit_us = stats->last_transmit_us; + if (stats == nullptr || AP_HAL::micros64() - last_transmit_us < 2000000UL) { sent = false; } } else {