Skip to content

Commit

Permalink
report TX error condition
Browse files Browse the repository at this point in the history
  • Loading branch information
rusefillc committed Dec 6, 2023
1 parent 56ee5c8 commit 5f45c92
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
19 changes: 18 additions & 1 deletion firmware/can_helper.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "can_helper.h"
#include "timer.h"

#include <cstring>

Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions firmware/can_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@ void transmitStruct(uint32_t eid)
// see CanTxMessage::~CanTxMessage()
populateFrame(frame.get());
}

bool isTxIssue();
7 changes: 6 additions & 1 deletion firmware/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "port.h"
#include "tunerstudio.h"
#include "indication.h"
#include "can_helper.h"

#include "wideband_config.h"

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5f45c92

Please sign in to comment.