multi CAN plumbing (#3688)

* framing for multi CAN

* typoooooooo
This commit is contained in:
Matthew Kennedy 2021-12-10 14:08:10 -08:00 committed by GitHub
parent 9e5cb6a04c
commit 408d4c6ebf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 11 deletions

View File

@ -127,13 +127,14 @@ static const CANConfig *canConfig = &canConfig500;
class CanRead final : public ThreadController<UTILITY_THREAD_STACK_SIZE> { class CanRead final : public ThreadController<UTILITY_THREAD_STACK_SIZE> {
public: public:
CanRead() CanRead(size_t index)
: ThreadController("CAN RX", PRIO_CAN_RX) : ThreadController("CAN RX", PRIO_CAN_RX)
, m_index(index)
{ {
} }
void ThreadTask() override { void ThreadTask() override {
CANDriver* device = detectCanDevice(engineConfiguration->canRxPin, engineConfiguration->canTxPin); CANDriver* device = detectCanDevice(m_index);
if (!device) { if (!device) {
warning(CUSTOM_ERR_CAN_CONFIGURATION, "CAN configuration issue"); warning(CUSTOM_ERR_CAN_CONFIGURATION, "CAN configuration issue");
@ -156,10 +157,12 @@ public:
} }
private: private:
const size_t m_index;
CANRxFrame m_buffer; CANRxFrame m_buffer;
}; };
static CanRead canRead CCM_OPTIONAL; CCM_OPTIONAL static CanRead canRead(0);
//CCM_OPTIONAL static CanRead canRead2(1);
static CanWrite canWrite CCM_OPTIONAL; static CanWrite canWrite CCM_OPTIONAL;
static void canInfo() { static void canInfo() {
@ -272,11 +275,13 @@ void initCan(void) {
canStart(&CAND1, canConfig); canStart(&CAND1, canConfig);
#endif /* STM32_CAN_USE_CAN2 */ #endif /* STM32_CAN_USE_CAN2 */
if (detectCanDevice(0) == detectCanDevice(1)) {
firmwareError(OBD_PCM_Processor_Fault, "CAN pins must be set to different devices");
return;
}
// Plumb CAN device to tx system // Plumb CAN device to tx system
CanTxMessage::setDevice(detectCanDevice( CanTxMessage::setDevice(detectCanDevice(0));
engineConfiguration->canRxPin,
engineConfiguration->canTxPin
));
// fire up threads, as necessary // fire up threads, as necessary
if (engineConfiguration->canWriteEnabled) { if (engineConfiguration->canWriteEnabled) {
@ -285,6 +290,7 @@ void initCan(void) {
if (engineConfiguration->canReadEnabled) { if (engineConfiguration->canReadEnabled) {
canRead.Start(); canRead.Start();
//canRead2.Start();
} }
isCanEnabled = true; isCanEnabled = true;
@ -294,4 +300,15 @@ bool getIsCanEnabled(void) {
return isCanEnabled; return isCanEnabled;
} }
CANDriver* detectCanDevice(size_t logicalIndex) {
switch (logicalIndex) {
case 0:
return detectCanDeviceImpl(engineConfiguration->canRxPin, engineConfiguration->canTxPin);
case 1:
return detectCanDeviceImpl(engineConfiguration->can2RxPin, engineConfiguration->can2TxPin);
}
return nullptr;
}
#endif /* EFI_CAN_SUPPORT */ #endif /* EFI_CAN_SUPPORT */

View File

@ -14,6 +14,8 @@ void setCanType(int type);
void setCanVss(int type); void setCanVss(int type);
#if EFI_CAN_SUPPORT #if EFI_CAN_SUPPORT
CANDriver* detectCanDevice(size_t logicalIndex);
void stopCanPins(); void stopCanPins();
void startCanPins(); void startCanPins();
void enableFrankensoCan(); void enableFrankensoCan();

View File

@ -224,7 +224,7 @@ bool isValidCanRxPin(brain_pin_e pin) {
return isValidCan1RxPin(pin) || isValidCan2RxPin(pin); return isValidCan1RxPin(pin) || isValidCan2RxPin(pin);
} }
CANDriver * detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx) { CANDriver* detectCanDeviceImpl(brain_pin_e pinRx, brain_pin_e pinTx) {
if (isValidCan1RxPin(pinRx) && isValidCan1TxPin(pinTx)) if (isValidCan1RxPin(pinRx) && isValidCan1TxPin(pinTx))
return &CAND1; return &CAND1;
if (isValidCan2RxPin(pinRx) && isValidCan2TxPin(pinTx)) if (isValidCan2RxPin(pinRx) && isValidCan2TxPin(pinTx))

View File

@ -216,7 +216,7 @@ bool isValidCanRxPin(brain_pin_e pin) {
return isValidCan1RxPin(pin) || isValidCan2RxPin(pin); return isValidCan1RxPin(pin) || isValidCan2RxPin(pin);
} }
CANDriver * detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx) { CANDriver* detectCanDeviceImpl(brain_pin_e pinRx, brain_pin_e pinTx) {
if (isValidCan1RxPin(pinRx) && isValidCan1TxPin(pinTx)) if (isValidCan1RxPin(pinRx) && isValidCan1TxPin(pinTx))
return &CAND1; return &CAND1;
if (isValidCan2RxPin(pinRx) && isValidCan2TxPin(pinTx)) if (isValidCan2RxPin(pinRx) && isValidCan2TxPin(pinTx))

View File

@ -23,7 +23,7 @@ bool readSlowAnalogInputs(adcsample_t* convertedSamples);
#if HAL_USE_CAN #if HAL_USE_CAN
bool isValidCanTxPin(brain_pin_e pin); bool isValidCanTxPin(brain_pin_e pin);
bool isValidCanRxPin(brain_pin_e pin); bool isValidCanRxPin(brain_pin_e pin);
CANDriver * detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx); CANDriver* detectCanDeviceImpl(brain_pin_e pinRx, brain_pin_e pinTx);
#endif // HAL_USE_CAN #endif // HAL_USE_CAN
bool isValidSerialTxPin(brain_pin_e pin); bool isValidSerialTxPin(brain_pin_e pin);

View File

@ -778,7 +778,7 @@ bool isValidCanRxPin(brain_pin_e pin) {
return isValidCan1RxPin(pin) || isValidCan2RxPin(pin); return isValidCan1RxPin(pin) || isValidCan2RxPin(pin);
} }
CANDriver * detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx) { CANDriver* detectCanDeviceImpl(brain_pin_e pinRx, brain_pin_e pinTx) {
#if STM32_CAN_USE_CAN1 || STM32_CAN_USE_FDCAN1 #if STM32_CAN_USE_CAN1 || STM32_CAN_USE_FDCAN1
if (isValidCan1RxPin(pinRx) && isValidCan1TxPin(pinTx)) if (isValidCan1RxPin(pinRx) && isValidCan1TxPin(pinTx))
return &CAND1; return &CAND1;