diff --git a/firmware/can_helper.cpp b/firmware/can_helper.cpp index 8615d7c5..1647b8c7 100644 --- a/firmware/can_helper.cpp +++ b/firmware/can_helper.cpp @@ -1,4 +1,5 @@ #include "can_helper.h" +#include "timer.h" #include @@ -10,9 +11,25 @@ CanTxMessage::CanTxMessage(uint32_t eid, uint8_t dlc, bool isExtended) { memset(m_frame.data8, 0, sizeof(m_frame.data8)); } +static int txFailureCounter = 0; + +static Timer txFailureCounterReset; + +bool isTxIssue() { + if (txFailureCounterReset.hasElapsedSec(10)) { + txFailureCounterReset.reset(); + txFailureCounter = 0; + } + // 10 times 100ms timeout would take a second to enter error condition + return txFailureCounter > 10; +} + CanTxMessage::~CanTxMessage() { // 100 ms timeout - canTransmitTimeout(&CAND1, CAN_ANY_MAILBOX, &m_frame, TIME_MS2I(100)); + msg_t msg = canTransmitTimeout(&CAND1, CAN_ANY_MAILBOX, &m_frame, TIME_MS2I(100)); + if (msg != MSG_OK) { + txFailureCounter++; + } } uint8_t& CanTxMessage::operator[](size_t index) { diff --git a/firmware/can_helper.h b/firmware/can_helper.h index 5ca38872..9f64773f 100644 --- a/firmware/can_helper.h +++ b/firmware/can_helper.h @@ -74,3 +74,5 @@ void transmitStruct(uint32_t eid) // see CanTxMessage::~CanTxMessage() populateFrame(frame.get()); } + +bool isTxIssue(); diff --git a/firmware/main.cpp b/firmware/main.cpp index 6430b455..bfb5a1ac 100644 --- a/firmware/main.cpp +++ b/firmware/main.cpp @@ -14,6 +14,7 @@ #include "port.h" #include "tunerstudio.h" #include "indication.h" +#include "can_helper.h" #include "wideband_config.h" @@ -60,7 +61,11 @@ int main() { /* TODO: show EGT errors */ auto fault = GetCurrentFault(0); - if (fault == Fault::None) + if (isTxIssue()) { + // temporary solution: light up both LEDs in case of TX error + palSetPad(LED_BLUE_PORT, LED_BLUE_PIN); + palSetPad(LED_BLUE_PORT, LED_GREEN_PIN); + } else if (fault == Fault::None) { // blue is off palClearPad(LED_BLUE_PORT, LED_BLUE_PIN);