Skip to content

Commit

Permalink
report TX error condition with special LED state mck1117#316
Browse files Browse the repository at this point in the history
  • Loading branch information
rusefillc committed Apr 24, 2024
1 parent 27348e3 commit 389cf57
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
15 changes: 9 additions & 6 deletions firmware/can_helper.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "can_helper.h"
#include "timer.h"
#include "fault.h"

#include <cstring>

Expand All @@ -11,24 +12,26 @@ CanTxMessage::CanTxMessage(uint32_t eid, uint8_t dlc, bool isExtended) {
memset(m_frame.data8, 0, sizeof(m_frame.data8));
}

static int txFailureCounter = 0;
static void onTxIssue() {
static int txFailureCounter = 0;
static Timer txFailureCounterReset;

static Timer txFailureCounterReset;

bool isTxIssue() {
txFailureCounter++;
if (txFailureCounterReset.hasElapsedSec(10)) {
txFailureCounterReset.reset();
txFailureCounter = 0;
}
// 10 times 100ms timeout would take a second to enter error condition
return txFailureCounter > 10;
if (txFailureCounter > 10) {
SetFault(0, Fault::CanTxError);
}
}

CanTxMessage::~CanTxMessage() {
// 100 ms timeout
msg_t msg = canTransmitTimeout(&CAND1, CAN_ANY_MAILBOX, &m_frame, TIME_MS2I(100));
if (msg != MSG_OK) {
txFailureCounter++;
onTxIssue();
}
}

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

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

#include "wideband_config.h"

Expand Down Expand Up @@ -61,11 +60,7 @@ int main() {
/* TODO: show EGT errors */
auto fault = GetCurrentFault(0);

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)
if (fault == Fault::None)
{
// blue is off
palClearPad(LED_BLUE_PORT, LED_BLUE_PIN);
Expand Down
3 changes: 3 additions & 0 deletions for_rusefi/wideband_can.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ enum class Fault : uint8_t
SensorOverheat = 4,
SensorUnderheat = 5,
SensorNoHeatSupply = 6,
CanTxError = 7,
};

struct StandardData
Expand Down Expand Up @@ -78,6 +79,8 @@ static inline const char* describeFault(Fault fault) {
return "Sensor underheat";
case Fault::SensorNoHeatSupply:
return "Sensor no heat supply";
case Fault::CanTxError:
return "CanTxError";
}

return "Unknown";
Expand Down

0 comments on commit 389cf57

Please sign in to comment.