Second CAN #3687
This commit is contained in:
parent
2480a8aa2f
commit
7b0179aaa3
|
@ -777,7 +777,7 @@ void updateTunerStudioState() {
|
||||||
|
|
||||||
tsOutputChannels->revolutionCounterSinceStart = engine->rpmCalculator.getRevolutionCounterSinceStart();
|
tsOutputChannels->revolutionCounterSinceStart = engine->rpmCalculator.getRevolutionCounterSinceStart();
|
||||||
#if EFI_CAN_SUPPORT
|
#if EFI_CAN_SUPPORT
|
||||||
postCanState(tsOutputChannels);
|
postCanState();
|
||||||
#endif /* EFI_CAN_SUPPORT */
|
#endif /* EFI_CAN_SUPPORT */
|
||||||
|
|
||||||
#if EFI_CLOCK_LOCKS
|
#if EFI_CLOCK_LOCKS
|
||||||
|
|
|
@ -46,7 +46,7 @@ class CanListener;
|
||||||
class CanSensorBase;
|
class CanSensorBase;
|
||||||
|
|
||||||
#if EFI_CAN_SUPPORT
|
#if EFI_CAN_SUPPORT
|
||||||
void processCanRxMessage(const CANRxFrame& msg, efitick_t nowNt);
|
void processCanRxMessage(const size_t busIndex, const CANRxFrame& msg, efitick_t nowNt);
|
||||||
#endif // EFI_CAN_SUPPORT
|
#endif // EFI_CAN_SUPPORT
|
||||||
|
|
||||||
void registerCanListener(CanListener& listener);
|
void registerCanListener(CanListener& listener);
|
||||||
|
|
|
@ -158,7 +158,7 @@ static void processCanRxImu(const CANRxFrame& frame, efitick_t nowNt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void processCanRxMessage(const CANRxFrame &frame, efitick_t nowNt) {
|
void processCanRxMessage(const size_t busIndex, const CANRxFrame &frame, efitick_t nowNt) {
|
||||||
if (engineConfiguration->verboseCan) {
|
if (engineConfiguration->verboseCan) {
|
||||||
printPacket(frame);
|
printPacket(frame);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,6 @@
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "mpu_util.h"
|
#include "mpu_util.h"
|
||||||
|
|
||||||
static int canReadCounter = 0;
|
|
||||||
int canWriteOk = 0;
|
|
||||||
int canWriteNotOk = 0;
|
|
||||||
static bool isCanEnabled = false;
|
static bool isCanEnabled = false;
|
||||||
|
|
||||||
// Values below calculated with http://www.bittiming.can-wiki.info/
|
// Values below calculated with http://www.bittiming.can-wiki.info/
|
||||||
|
@ -150,9 +147,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process the message
|
// Process the message
|
||||||
canReadCounter++;
|
engine->outputChannels.canReadCounter++;
|
||||||
|
|
||||||
processCanRxMessage(m_buffer, getTimeNowNt());
|
processCanRxMessage(m_index, m_buffer, getTimeNowNt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +174,10 @@ static void canInfo() {
|
||||||
boolToString(engineConfiguration->canReadEnabled), boolToString(engineConfiguration->canWriteEnabled),
|
boolToString(engineConfiguration->canReadEnabled), boolToString(engineConfiguration->canWriteEnabled),
|
||||||
engineConfiguration->canSleepPeriodMs);
|
engineConfiguration->canSleepPeriodMs);
|
||||||
|
|
||||||
efiPrintf("CAN rx_cnt=%d/tx_ok=%d/tx_not_ok=%d", canReadCounter, canWriteOk, canWriteNotOk);
|
efiPrintf("CAN rx_cnt=%d/tx_ok=%d/tx_not_ok=%d",
|
||||||
|
engine->outputChannels.canReadCounter,
|
||||||
|
engine->outputChannels.canWriteOk,
|
||||||
|
engine->outputChannels.canWriteNotOk);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCanType(int type) {
|
void setCanType(int type) {
|
||||||
|
@ -186,10 +186,12 @@ void setCanType(int type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if EFI_TUNER_STUDIO
|
#if EFI_TUNER_STUDIO
|
||||||
void postCanState(TunerStudioOutputChannels *tsOutputChannels) {
|
void postCanState() {
|
||||||
tsOutputChannels->canReadCounter = isCanEnabled ? canReadCounter : -1;
|
if (!isCanEnabled) {
|
||||||
tsOutputChannels->canWriteOk = isCanEnabled ? canWriteOk : -1;
|
engine->outputChannels.canReadCounter = -1;
|
||||||
tsOutputChannels->canWriteNotOk = isCanEnabled ? canWriteNotOk : -1;
|
engine->outputChannels.canWriteOk = -1;
|
||||||
|
engine->outputChannels.canWriteNotOk = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif /* EFI_TUNER_STUDIO */
|
#endif /* EFI_TUNER_STUDIO */
|
||||||
|
|
||||||
|
@ -202,6 +204,8 @@ void enableFrankensoCan() {
|
||||||
void stopCanPins() {
|
void stopCanPins() {
|
||||||
efiSetPadUnusedIfConfigurationChanged(canTxPin);
|
efiSetPadUnusedIfConfigurationChanged(canTxPin);
|
||||||
efiSetPadUnusedIfConfigurationChanged(canRxPin);
|
efiSetPadUnusedIfConfigurationChanged(canRxPin);
|
||||||
|
efiSetPadUnusedIfConfigurationChanged(can2TxPin);
|
||||||
|
efiSetPadUnusedIfConfigurationChanged(can2RxPin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// at the moment we support only very limited runtime configuration change, still not supporting online CAN toggle
|
// at the moment we support only very limited runtime configuration change, still not supporting online CAN toggle
|
||||||
|
@ -232,6 +236,9 @@ void startCanPins() {
|
||||||
|
|
||||||
efiSetPadModeIfConfigurationChanged("CAN TX", canTxPin, PAL_MODE_ALTERNATE(EFI_CAN_TX_AF));
|
efiSetPadModeIfConfigurationChanged("CAN TX", canTxPin, PAL_MODE_ALTERNATE(EFI_CAN_TX_AF));
|
||||||
efiSetPadModeIfConfigurationChanged("CAN RX", canRxPin, PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
|
efiSetPadModeIfConfigurationChanged("CAN RX", canRxPin, PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
|
||||||
|
|
||||||
|
efiSetPadModeIfConfigurationChanged("CAN2 TX", can2TxPin, PAL_MODE_ALTERNATE(EFI_CAN_TX_AF));
|
||||||
|
efiSetPadModeIfConfigurationChanged("CAN2 RX", can2RxPin, PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
|
||||||
}
|
}
|
||||||
|
|
||||||
void initCan(void) {
|
void initCan(void) {
|
||||||
|
@ -281,7 +288,7 @@ void initCan(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plumb CAN device to tx system
|
// Plumb CAN device to tx system
|
||||||
CanTxMessage::setDevice(detectCanDevice(0));
|
CanTxMessage::setDevice(detectCanDevice(0), detectCanDevice(1));
|
||||||
|
|
||||||
// fire up threads, as necessary
|
// fire up threads, as necessary
|
||||||
if (engineConfiguration->canWriteEnabled) {
|
if (engineConfiguration->canWriteEnabled) {
|
||||||
|
|
|
@ -21,6 +21,6 @@ void startCanPins();
|
||||||
void enableFrankensoCan();
|
void enableFrankensoCan();
|
||||||
bool getIsCanEnabled(void);
|
bool getIsCanEnabled(void);
|
||||||
#if EFI_TUNER_STUDIO
|
#if EFI_TUNER_STUDIO
|
||||||
void postCanState(TunerStudioOutputChannels *tsOutputChannels);
|
void postCanState();
|
||||||
#endif /* EFI_TUNER_STUDIO */
|
#endif /* EFI_TUNER_STUDIO */
|
||||||
#endif /* EFI_CAN_SUPPORT */
|
#endif /* EFI_CAN_SUPPORT */
|
||||||
|
|
|
@ -13,14 +13,12 @@
|
||||||
|
|
||||||
#include "can.h"
|
#include "can.h"
|
||||||
|
|
||||||
extern int canWriteOk;
|
|
||||||
extern int canWriteNotOk;
|
|
||||||
|
|
||||||
#if EFI_CAN_SUPPORT
|
#if EFI_CAN_SUPPORT
|
||||||
/*static*/ CANDriver* CanTxMessage::s_device = nullptr;
|
/*static*/ CANDriver* CanTxMessage::s_devices[2] = {nullptr, nullptr};
|
||||||
|
|
||||||
/*static*/ void CanTxMessage::setDevice(CANDriver* device) {
|
/*static*/ void CanTxMessage::setDevice(CANDriver* device1, CANDriver* device2) {
|
||||||
s_device = device;
|
s_devices[0] = device1;
|
||||||
|
s_devices[1] = device2;
|
||||||
}
|
}
|
||||||
#endif // EFI_CAN_SUPPORT
|
#endif // EFI_CAN_SUPPORT
|
||||||
|
|
||||||
|
@ -50,7 +48,7 @@ CanTxMessage::CanTxMessage(uint32_t eid, uint8_t dlc, bool isExtended) {
|
||||||
|
|
||||||
CanTxMessage::~CanTxMessage() {
|
CanTxMessage::~CanTxMessage() {
|
||||||
#if EFI_CAN_SUPPORT
|
#if EFI_CAN_SUPPORT
|
||||||
auto device = s_device;
|
auto device = s_devices[0];
|
||||||
|
|
||||||
if (!device) {
|
if (!device) {
|
||||||
warning(CUSTOM_ERR_CAN_CONFIGURATION, "CAN configuration issue");
|
warning(CUSTOM_ERR_CAN_CONFIGURATION, "CAN configuration issue");
|
||||||
|
@ -71,11 +69,13 @@ CanTxMessage::~CanTxMessage() {
|
||||||
|
|
||||||
// 100 ms timeout
|
// 100 ms timeout
|
||||||
msg_t msg = canTransmit(device, CAN_ANY_MAILBOX, &m_frame, TIME_MS2I(100));
|
msg_t msg = canTransmit(device, CAN_ANY_MAILBOX, &m_frame, TIME_MS2I(100));
|
||||||
|
#if EFI_TUNER_STUDIO
|
||||||
if (msg == MSG_OK) {
|
if (msg == MSG_OK) {
|
||||||
canWriteOk++;
|
engine->outputChannels.canWriteOk++;
|
||||||
} else {
|
} else {
|
||||||
canWriteNotOk++;
|
engine->outputChannels.canWriteNotOk++;
|
||||||
}
|
}
|
||||||
|
#endif // EFI_TUNER_STUDIO
|
||||||
#endif /* EFI_CAN_SUPPORT */
|
#endif /* EFI_CAN_SUPPORT */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Configures the device for all messages to transmit from.
|
* Configures the device for all messages to transmit from.
|
||||||
*/
|
*/
|
||||||
static void setDevice(CANDriver* device);
|
static void setDevice(CANDriver* device1, CANDriver* device2);
|
||||||
#endif // EFI_CAN_SUPPORT
|
#endif // EFI_CAN_SUPPORT
|
||||||
/**
|
/**
|
||||||
* @brief Read & write the raw underlying 8-byte buffer.
|
* @brief Read & write the raw underlying 8-byte buffer.
|
||||||
|
@ -72,7 +72,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if EFI_CAN_SUPPORT
|
#if EFI_CAN_SUPPORT
|
||||||
static CANDriver* s_device;
|
static CANDriver* s_devices[2];
|
||||||
#endif // EFI_CAN_SUPPORT
|
#endif // EFI_CAN_SUPPORT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue