From 329a5278a7e5d6304e2b846085f02bb7d24b978a Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Fri, 3 Nov 2023 15:22:11 +1100 Subject: [PATCH] Move CAN buffers into the relevant comms files rather than boards This should resolve #1116 --- speeduino/board_stm32_official.h | 3 --- speeduino/board_teensy35.h | 2 -- speeduino/board_teensy41.h | 2 -- speeduino/comms_CAN.cpp | 11 +++++++---- speeduino/comms_CAN.h | 5 +++++ speeduino/speeduino.ino | 22 +++++++++------------- 6 files changed, 21 insertions(+), 24 deletions(-) diff --git a/speeduino/board_stm32_official.h b/speeduino/board_stm32_official.h index c32acc9d..8b340170 100644 --- a/speeduino/board_stm32_official.h +++ b/speeduino/board_stm32_official.h @@ -386,9 +386,6 @@ void ignitionSchedule8Interrupt(HardwareTimer*); #include //This activates CAN1 interface on STM32, but it's named as Can0, because that's how Teensy implementation is done extern STM32_CAN Can0; - -static CAN_message_t outMsg; -static CAN_message_t inMsg; #endif #endif //CORE_STM32 diff --git a/speeduino/board_teensy35.h b/speeduino/board_teensy35.h index 787c52a8..cca2b5c2 100644 --- a/speeduino/board_teensy35.h +++ b/speeduino/board_teensy35.h @@ -163,8 +163,6 @@ extern FlexCAN_T4 Can0; extern FlexCAN_T4 Can1; #endif - static CAN_message_t outMsg; - static CAN_message_t inMsg; #define NATIVE_CAN_AVAILABLE #endif //CORE_TEENSY #endif //TEENSY35_H diff --git a/speeduino/board_teensy41.h b/speeduino/board_teensy41.h index 422b5681..c7a4a537 100644 --- a/speeduino/board_teensy41.h +++ b/speeduino/board_teensy41.h @@ -172,8 +172,6 @@ extern FlexCAN_T4 Can0; extern FlexCAN_T4 Can1; extern FlexCAN_T4 Can2; - static CAN_message_t outMsg; - static CAN_message_t inMsg; //#define NATIVE_CAN_AVAILABLE //Disable for now as it causes lockup #endif //CORE_TEENSY diff --git a/speeduino/comms_CAN.cpp b/speeduino/comms_CAN.cpp index 1ec25800..9694dcec 100644 --- a/speeduino/comms_CAN.cpp +++ b/speeduino/comms_CAN.cpp @@ -13,6 +13,9 @@ This is for handling the data broadcasted to various CAN dashes and instrument c #include "comms_CAN.h" #include "utilities.h" +CAN_message_t inMsg; +CAN_message_t outMsg; + // Forward declare void DashMessage(uint16_t DashMessageID); @@ -126,7 +129,7 @@ void can_Command(void) { //int currentcanCommand = inMsg.id; // currentStatus.canin[12] = (inMsg.id); - if ( (inMsg.id == uint16_t(configPage9.obd_address + 0x100)) || (inMsg.id == 0x7DF)) + if ( (inMsg.id == uint16_t(configPage9.obd_address + TS_CAN_OFFSET)) || (inMsg.id == 0x7DF)) { // The address is the speeduino specific ecu canbus address // or the 0x7df(2015 dec) broadcast address @@ -145,7 +148,7 @@ void can_Command(void) Can0.write(outMsg); // send the 8 bytes of obd data } } - if (inMsg.id == uint16_t(configPage9.obd_address + 0x100)) + if (inMsg.id == uint16_t(configPage9.obd_address + TS_CAN_OFFSET)) { // The address is only the speeduino specific ecu canbus address if (inMsg.buf[1] == 0x09) @@ -513,7 +516,7 @@ void readAuxCanBus() { for (int i = 0; i < 16; i++) { - if (inMsg.id == (configPage9.caninput_source_can_address[i] + 0x100)) //Filters frame ID + if (inMsg.id == (configPage9.caninput_source_can_address[i] + TS_CAN_OFFSET)) //Filters frame ID { if (!BIT_CHECK(configPage9.caninput_source_num_bytes, i)) @@ -537,6 +540,6 @@ void readAuxCanBus() } } } - } + } } #endif diff --git a/speeduino/comms_CAN.h b/speeduino/comms_CAN.h index 6ece9a28..48e19c5d 100644 --- a/speeduino/comms_CAN.h +++ b/speeduino/comms_CAN.h @@ -14,6 +14,8 @@ #define CAN_VAG_RPM 0x280 #define CAN_VAG_VSS 0x5A0 +#define TS_CAN_OFFSET 0x100 + void sendBMWCluster(); void sendVAGCluster(); void DashMessages(uint16_t DashMessageID); @@ -21,5 +23,8 @@ void can_Command(void); void obd_response(uint8_t therequestedPID , uint8_t therequestedPIDlow, uint8_t therequestedPIDhigh); void readAuxCanBus(); +extern CAN_message_t outMsg; +extern CAN_message_t inMsg; + #endif #endif // COMMS_CAN_H diff --git a/speeduino/speeduino.ino b/speeduino/speeduino.ino index 095797c8..f537b8a7 100644 --- a/speeduino/speeduino.ino +++ b/speeduino/speeduino.ino @@ -119,20 +119,16 @@ void loop(void) } #endif #if defined (NATIVE_CAN_AVAILABLE) - //currentStatus.canin[12] = configPage9.enable_intcan; - if (configPage9.enable_intcan == 1) // use internal can module - { - //check local can module - // if ( BIT_CHECK(LOOP_TIMER, BIT_TIMER_15HZ) or (CANbus0.available()) - while (Can0.read(inMsg) ) - { - can_Command(); - readAuxCanBus(); - //Can0.read(inMsg); - //currentStatus.canin[12] = inMsg.buf[5]; - //currentStatus.canin[13] = inMsg.id; - } + if (configPage9.enable_intcan == 1) // use internal can module + { + //check local can module + // if ( BIT_CHECK(LOOP_TIMER, BIT_TIMER_15HZ) or (CANbus0.available()) + while (Can0.read(inMsg) ) + { + can_Command(); + readAuxCanBus(); } + } #endif if(currentLoopTime > micros_safe())