Vss over Can implementation proposal (#1340)

* Vss over Can implementation proposal

Working for BMW e46

* fixed Firmware CI?

* kinetis fix.

* minor fixes
This commit is contained in:
shadowm60 2020-04-22 03:48:37 +03:00 committed by GitHub
parent 26ed690e03
commit fe3030bb23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 145 additions and 5 deletions

View File

@ -597,7 +597,8 @@ typedef enum __attribute__ ((__packed__)) {
} spi_device_e; } spi_device_e;
typedef enum { typedef enum {
VVS_OOPS = 2, BMW_e46 = 0,
W202 = 1,
Force_4_bytes_size_can_vss_nbc_e = ENUM_32_BITS, Force_4_bytes_size_can_vss_nbc_e = ENUM_32_BITS,
} can_vss_nbc_e; } can_vss_nbc_e;

View File

@ -15,6 +15,7 @@
#include "obd2.h" #include "obd2.h"
#include "engine.h" #include "engine.h"
#include "can_sensor.h" #include "can_sensor.h"
#include "can_vss.h"
EXTERN_ENGINE; EXTERN_ENGINE;
@ -51,6 +52,9 @@ void processCanRxMessage(const CANRxFrame& frame, Logging* logger, efitick_t now
serviceCanSubscribers(frame, nowNt); serviceCanSubscribers(frame, nowNt);
//Vss is configurable, should we handle it here:
processCanRxVss(frame, nowNt);
// TODO: if/when we support multiple lambda sensors, sensor N // TODO: if/when we support multiple lambda sensors, sensor N
// has address 0x0180 + N where N = [0, 15] // has address 0x0180 + N where N = [0, 15]
if (frame.SID == 0x0180) { if (frame.SID == 0x0180) {

View File

@ -0,0 +1,108 @@
/**
* @file can_vss.cpp
*
* This file handles incomming vss values from can.
*
* @date Apr 19, 2020
* @author Alex Miculescu, (c) 2020
*/
#include "globalaccess.h"
#if EFI_CAN_SUPPORT
#include "can.h"
#include "engine_configuration.h"
#include "engine.h"
#include "vehicle_speed.h"
EXTERN_ENGINE;
static Logging *logger;
static bool isInit = false;
static uint16_t filterCanID = 0;
static efitick_t frameTime;
static float vssSpeed = 0;
/* keep 16 bit address since till now we do not have 28bit address request */
uint32_t canIDs[] = { 0x01F0 /* BMW e46 ABS Message */,
0x0200 /* W202 C180 ABS signal */
};
#define look_up_can_id(X) canIDs[X]
/* Module specitifc processing functions */
/* source: http://z4evconversion.blogspot.com/2016/07/completely-forgot-but-it-does-live-on.html */
void processBMW_e46(const CANRxFrame& frame) {
uint16_t tmp;
/* left front wheel speed is used here */
tmp = ((frame.data8[1] & 0x0f) << 8 );
tmp |= frame.data8[0];
vssSpeed = tmp / 16;
}
void processW202(const CANRxFrame& frame) {
(void)frame;
}
/* End of specific processing functions */
void canVssInfo(void) {
scheduleMsg(logger, "vss using can option selected %x", CONFIG(canVssNbcType) );
}
void processCanRxVss(const CANRxFrame& frame, efitick_t nowNt) {
if ((CONFIG(enableCanVss)) || (!isInit)) {
return;
}
//filter it we need to process the can message or not
if ( frame.SID != filterCanID ) {
return;
}
frameTime = nowNt;
switch (CONFIG(canVssNbcType)){
case BMW_e46:
processBMW_e46(frame);
break;
case W202:
processW202(frame);
break;
default:
scheduleMsg(logger, "vss unsupported can option selected %x", CONFIG(canVssNbcType) );
break;
}
}
float getVehicleCanSpeed(void) {
efitick_t nowNt = getTimeNowNt();
if ((nowNt - frameTime ) > NT_PER_SECOND) {
return 0; /* can timeout? */
} else {
return vssSpeed;
}
}
void initCanVssSupport(Logging *logger_ptr) {
if (CONFIG(enableCanVss)) {
logger = logger_ptr;
isInit = true;
filterCanID = look_up_can_id(CONFIG(canVssNbcType));
}
}
void setCanVss(int type) {
engineConfiguration->canVssNbcType = (can_vss_nbc_e)type;
canVssInfo();
}
#endif // EFI_CAN_SUPPORT

View File

@ -0,0 +1,13 @@
/**
* @file can_vss.h
*
* @date Apr 19, 2020
* @author Alex Miculescu, (c) 2020
*/
#pragma once
float getVehicleCanSpeed(void);
void processCanRxVss(const CANRxFrame& frame, efitick_t nowNt);
void initCanVssSupport(Logging *logger_ptr);
void setCanVss(int type);

View File

@ -39,6 +39,7 @@ CONTROLLERS_SRC_CPP = \
$(CONTROLLERS_DIR)/can/can_rx.cpp \ $(CONTROLLERS_DIR)/can/can_rx.cpp \
$(CONTROLLERS_DIR)/can/can_tx.cpp \ $(CONTROLLERS_DIR)/can/can_tx.cpp \
$(CONTROLLERS_DIR)/can/can_dash.cpp \ $(CONTROLLERS_DIR)/can/can_dash.cpp \
$(CONTROLLERS_DIR)/can/can_vss.cpp \
$(CONTROLLERS_DIR)/engine_controller.cpp \ $(CONTROLLERS_DIR)/engine_controller.cpp \
$(CONTROLLERS_DIR)/engine_controller_misc.cpp \ $(CONTROLLERS_DIR)/engine_controller_misc.cpp \
$(CONTROLLERS_DIR)/persistent_store.cpp \ $(CONTROLLERS_DIR)/persistent_store.cpp \

View File

@ -1269,10 +1269,7 @@ const command_i_s commandsI[] = {{"ignition_mode", setIgnitionMode},
{"bor", setBor}, {"bor", setBor},
#if EFI_CAN_SUPPORT #if EFI_CAN_SUPPORT
{"can_mode", setCanType}, {"can_mode", setCanType},
/*
* TODO: uncomment onse we actually have setCanVss
{"can_vss", setCanVss}, {"can_vss", setCanVss},
*/
#endif /* EFI_CAN_SUPPORT */ #endif /* EFI_CAN_SUPPORT */
#if EFI_IDLE_CONTROL #if EFI_IDLE_CONTROL
{"idle_position", setIdleValvePosition}, {"idle_position", setIdleValvePosition},

View File

@ -14,6 +14,7 @@
void initCan(void); void initCan(void);
void setCanType(int type); void setCanType(int type);
void setCanVss(int type);
#if EFI_CAN_SUPPORT #if EFI_CAN_SUPPORT
void stopCanPins(DECLARE_ENGINE_PARAMETER_SIGNATURE); void stopCanPins(DECLARE_ENGINE_PARAMETER_SIGNATURE);

View File

@ -61,6 +61,10 @@
#include "flash_main.h" #include "flash_main.h"
#endif #endif
#if EFI_CAN_SUPPORT
#include "can_vss.h"
#endif
EXTERN_ENGINE; EXTERN_ENGINE;
static mutex_t spiMtx; static mutex_t spiMtx;
@ -573,6 +577,10 @@ void initHardware(Logging *l) {
initVehicleSpeed(sharedLogger); initVehicleSpeed(sharedLogger);
#endif #endif
#if EFI_CAN_SUPPORT
initCanVssSupport(sharedLogger);
#endif
#if EFI_CDM_INTEGRATION #if EFI_CDM_INTEGRATION
cdmIonInit(); cdmIonInit();
#endif #endif

View File

@ -12,6 +12,7 @@
#include "engine.h" #include "engine.h"
#include "digital_input_icu.h" #include "digital_input_icu.h"
#include "pin_repository.h" #include "pin_repository.h"
#include "can_vss.h"
EXTERN_ENGINE; EXTERN_ENGINE;
@ -33,6 +34,11 @@ void setMockVehicleSpeed(float speedKPH) {
float getVehicleSpeed(void) { float getVehicleSpeed(void) {
if (mockVehicleSpeed != DEFAULT_MOCK_SPEED) if (mockVehicleSpeed != DEFAULT_MOCK_SPEED)
return mockVehicleSpeed; return mockVehicleSpeed;
#if EFI_CAN_SUPPORT
if ( CONFIG(enableCanVss) == true ) {
return getVehicleCanSpeed();
}
#endif /* EFI_CAN_SUPPORT */
if (!hasVehicleSpeedSensor()) if (!hasVehicleSpeedSensor())
return 0; return 0;
efitick_t nowNt = getTimeNowNt(); efitick_t nowNt = getTimeNowNt();
@ -86,7 +92,8 @@ void initVehicleSpeed(Logging *l) {
#else /* EFI_VEHICLE_SPEED */ #else /* EFI_VEHICLE_SPEED */
float getVehicleSpeed(void) { float getVehicleSpeed(void) {
// no VSS support // no VSS support
return 0; return 0;
} }
#endif /* EFI_VEHICLE_SPEED */ #endif /* EFI_VEHICLE_SPEED */