BMW E90 Kombi (#1494)

* second can bus, first steps

* added most important messages; no more errors

* cleaned up can messages

* second can bus, first steps

* added most important messages; no more errors

* cleaned up can messages

* post rebase/merge fixes

* more rebase/merge fixes

* even more rebase/merge fixes

* more fixes, removed auto-gen files

* removed more auto-gen files...
This commit is contained in:
kon 2020-06-14 20:59:43 +00:00 committed by GitHub
parent 9a033e8670
commit 03f4efa0b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 212 additions and 9 deletions

View File

@ -858,7 +858,7 @@ typedef enum {
CAN_BUS_MAZDA_RX8 = 3,
CAN_BUS_NBC_BMW = 4,
CAN_BUS_W202_C180 = 5,
CAN_BUS_BMW_E90 = 6,
Internal_ForceMyEnumIntSize_can_nbc = ENUM_32_BITS,
} can_nbc_e;

View File

@ -268,5 +268,12 @@ typedef enum __attribute__ ((__packed__)) {
EFI_ADC_ERROR = 17,
} adc_channel_e;
typedef enum __attribute__ ((__packed__)) {
B100KBPS = 0, // 100kbps
B250KBPS = 1, // 250kbps
B500KBPS = 2, // 500kbps
B1MBPS = 3, // 1Mbps
} can_baudrate_e;
#define INCOMPATIBLE_CONFIG_CHANGE EFI_ADC_0

View File

@ -50,6 +50,30 @@ EXTERN_ENGINE;
#define W202_ALIVE 0x210
#define W202_STAT_3 0x310
//BMW E90 DASH
#define E90_ABS_COUNTER 0x0C0
#define E90_SEATBELT_COUNTER 0x0D7
#define E90_T15 0x130
#define E90_RPM 0x175
#define E90_BRAKE_COUNTER 0x19E
#define E90_SPEED 0x1A6
#define E90_TEMP 0x1D0
#define E90_GEAR 0x1D2
#define E90_FUEL 0x349
#define E90_EBRAKE 0x34F
static uint8_t rpmcounter;
static uint16_t e90msgcounter;
static uint8_t seatbeltcnt;
static uint8_t abscounter = 0xF0;
static uint8_t brakecnt_1 = 0xF0, brakecnt_2 = 0xF0;
static uint8_t mph_a, mph_2a, mph_last, tmp_cnt, gear_cnt;
static uint16_t mph_counter = 0xF000;
static time_msecs_t mph_timer;
static time_msecs_t mph_ctr;
constexpr uint8_t e90_temp_offset = 49;
void canDashboardBMW(void) {
//BMW Dashboard
{
@ -206,4 +230,143 @@ void canDashboardW202(void) {
msg[7] = 0x05; // Const
}
}
void canDashboardBMWE90()
{
if (e90msgcounter == UINT16_MAX)
e90msgcounter = 0;
e90msgcounter++;
{ //T15 'turn-on'
CanTxMessage msg(E90_T15, 5);
msg[0] = 0x45;
msg[1] = 0x41;
msg[2] = 0x61;
msg[3] = 0x8F;
msg[4] = 0xFC;
}
{ //Ebrake light
CanTxMessage msg(E90_EBRAKE, 2);
msg[0] = 0xFD;
msg[1] = 0xFF;
}
{ //RPM
rpmcounter++;
if (rpmcounter > 0xFE)
rpmcounter = 0xF0;
CanTxMessage msg(E90_RPM, 3);
msg[0] = rpmcounter;
msg[1] = (GET_RPM() * 4) & 0xFF;
msg[2] = (GET_RPM() * 4) >> 8;
}
{ //oil & coolant temp (all in C, despite gauge being F)
tmp_cnt++;
if (tmp_cnt >= 0x0F)
tmp_cnt = 0x00;
CanTxMessage msg(E90_TEMP, 8);
msg[0] = (int)(Sensor::get(SensorType::Clt).value_or(0) + e90_temp_offset); //coolant
msg[1] = (int)(Sensor::get(SensorType::AuxTemp1).value_or(0) + e90_temp_offset); //oil (AuxTemp1)
msg[2] = tmp_cnt;
msg[3] = 0xC8;
msg[4] = 0xA7;
msg[5] = 0xD3;
msg[6] = 0x0D;
msg[7] = 0xA8;
}
{ //Seatbelt counter
if (e90msgcounter % 2) {
seatbeltcnt++;
if (seatbeltcnt > 0xFE)
seatbeltcnt = 0x00;
CanTxMessage msg(E90_SEATBELT_COUNTER, 2);
msg[0] = seatbeltcnt;
msg[1] = 0xFF;
}
}
{ //Brake counter
if (e90msgcounter % 2) {
brakecnt_1 += 16;
brakecnt_2 += 16;
if (brakecnt_1 > 0xEF)
brakecnt_1 = 0x0F;
if (brakecnt_2 > 0xF0)
brakecnt_2 = 0xA0;
CanTxMessage msg(E90_BRAKE_COUNTER, 8);
msg[0] = 0x00;
msg[1] = 0xE0;
msg[2] = brakecnt_1;
msg[3] = 0xFC;
msg[4] = 0xFE;
msg[5] = 0x41;
msg[6] = 0x00;
msg[7] = brakecnt_2;
}
}
{ //ABS counter
if (e90msgcounter % 2) {
abscounter++;
if (abscounter > 0xFE)
abscounter = 0xF0;
CanTxMessage msg(E90_ABS_COUNTER, 2);
msg[0] = abscounter;
msg[1] = 0xFF;
}
}
{ //Fuel gauge
if (e90msgcounter % 2) {
CanTxMessage msg(E90_FUEL, 5); //fuel gauge
msg[0] = 0x76;
msg[1] = 0x0F;
msg[2] = 0xBE;
msg[3] = 0x1A;
msg[4] = 0x00;
}
}
{ //Gear indicator/counter
if (e90msgcounter % 2) {
gear_cnt++;
if (gear_cnt >= 0x0F)
gear_cnt = 0x00;
CanTxMessage msg(E90_GEAR, 6);
msg[0] = 0x78;
msg[1] = 0x0F;
msg[2] = 0xFF;
msg[3] = (gear_cnt << 4) | 0xC;
msg[4] = 0xF1;
msg[5] = 0xFF;
}
}
{ //E90_SPEED
if (e90msgcounter % 2) {
float mph = getVehicleSpeed() * 0.6213712;
mph_ctr = ((TIME_I2MS(chVTGetSystemTime()) - mph_timer) / 50);
mph_a = (mph_ctr * mph / 2);
mph_2a = mph_a + mph_last;
mph_last = mph_2a;
mph_counter += mph_ctr * 100;
if(mph_counter >= 0xFFF0)
mph_counter = 0xF000;
mph_timer = TIME_I2MS(chVTGetSystemTime());
CanTxMessage msg(E90_SPEED, 8);
msg[0] = mph_2a & 0xFF;
msg[1] = mph_2a >> 8;
msg[2] = mph_2a & 0xFF;
msg[3] = mph_2a >> 8;
msg[4] = mph_2a & 0xFF;
msg[5] = mph_2a >> 8;
msg[6] = mph_counter & 0xFF;
msg[7] = (mph_counter >> 8) | 0xF0;
}
}
}
#endif // EFI_CAN_SUPPORT

View File

@ -12,3 +12,4 @@ void canDashboardFiat();
void canDashboardVAG();
void canMazdaRX8();
void canDashboardW202();
void canDashboardBMWE90();

View File

@ -48,6 +48,9 @@ void CanWrite::PeriodicTask(efitime_t nowNt) {
case CAN_BUS_W202_C180:
canDashboardW202();
break;
case CAN_BUS_BMW_E90:
canDashboardBMWE90();
break;
default:
break;
}

View File

@ -35,11 +35,13 @@ static LoggingWithStorage logger("CAN driver");
// Clock rate of 42mhz for f4, 54mhz for f7
#ifdef STM32F4XX
// These have an 85.7% sample point
#define CAN_BTR_100 (CAN_BTR_SJW(0) | CAN_BTR_BRP(29) | CAN_BTR_TS1(10) | CAN_BTR_TS2(1))
#define CAN_BTR_250 (CAN_BTR_SJW(0) | CAN_BTR_BRP(11) | CAN_BTR_TS1(10) | CAN_BTR_TS2(1))
#define CAN_BTR_500 (CAN_BTR_SJW(0) | CAN_BTR_BRP(5) | CAN_BTR_TS1(10) | CAN_BTR_TS2(1))
#define CAN_BTR_1k0 (CAN_BTR_SJW(0) | CAN_BTR_BRP(2) | CAN_BTR_TS1(10) | CAN_BTR_TS2(1))
#elif defined(STM32F7XX)
// These have an 88.9% sample point
#define CAN_BTR_100 (CAN_BTR_SJW(0) | CAN_BTR_BRP(30) | CAN_BTR_TS1(15) | CAN_BTR_TS2(2))
#define CAN_BTR_250 (CAN_BTR_SJW(0) | CAN_BTR_BRP(11) | CAN_BTR_TS1(14) | CAN_BTR_TS2(1))
#define CAN_BTR_500 (CAN_BTR_SJW(0) | CAN_BTR_BRP(5) | CAN_BTR_TS1(14) | CAN_BTR_TS2(1))
#define CAN_BTR_1k0 (CAN_BTR_SJW(0) | CAN_BTR_BRP(2) | CAN_BTR_TS1(14) | CAN_BTR_TS2(1))
@ -57,6 +59,10 @@ static LoggingWithStorage logger("CAN driver");
* CAN_TI0R_STID "Standard Identifier or Extended Identifier"? not mentioned as well
*/
static const CANConfig canConfig100 = {
CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
CAN_BTR_100 };
static const CANConfig canConfig250 = {
CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
CAN_BTR_250 };
@ -69,6 +75,8 @@ static const CANConfig canConfig1000 = {
CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
CAN_BTR_1k0 };
static const CANConfig *canConfig = &canConfig500;
class CanRead final : public ThreadController<256> {
public:
CanRead()
@ -187,13 +195,30 @@ void initCan(void) {
return;
}
switch (CONFIG(canBaudRate)) {
case B100KBPS:
canConfig = &canConfig100;
break;
case B250KBPS:
canConfig = &canConfig250;
break;
case B500KBPS:
canConfig = &canConfig500;
break;
case B1MBPS:
canConfig = &canConfig1000;
break;
default:
break;
}
// Initialize hardware
#if STM32_CAN_USE_CAN2
// CAN1 is required for CAN2
canStart(&CAND1, &canConfig500);
canStart(&CAND2, &canConfig500);
canStart(&CAND1, canConfig);
canStart(&CAND2, canConfig);
#else
canStart(&CAND1, &canConfig500);
canStart(&CAND1, canConfig);
#endif /* STM32_CAN_USE_CAN2 */
// Plumb CAN device to tx system

View File

@ -496,7 +496,7 @@ float fsio_visible fanOffTemperature;+Cooling fan turn-off temperature threshold
float vehicleSpeedCoef;+This coefficient translates vehicle speed input frequency (in Hz) into vehicle speed, km/h;"coef", 1, 0, 0.01, 2000.0, 2
custom can_nbc_e 4 bits, U32, @OFFSET@, [0:7], "None", "FIAT", "VAG" , "MAZDA RX8", "BMW", "W202"
custom can_nbc_e 4 bits, U32, @OFFSET@, [0:7], "None", "FIAT", "VAG" , "MAZDA RX8", "BMW", "W202", "BMW E90"
can_nbc_e canNbcType;set can_mode X
int canSleepPeriodMs;CANbus thread period, ms;"ms", 1, 0, 0, 1000.0, 2
@ -674,7 +674,7 @@ pin_input_mode_e throttlePedalUpPinMode;
uint32_t tunerStudioSerialSpeed;Secondary TTL channel baud rate;"BPs", 1, 0, 0,1000000, 0
float compressionRatio;+Just for reference really, not taken into account by any logic at this point;"CR", 1, 0, 0, 300.0, 1
brain_pin_e[TRIGGER_SIMULATOR_PIN_COUNT iterate] triggerSimulatorPins;Each rusEfi piece can provide synthetic trigger signal for external ECU. Sometimes these wires are routed back into trigger inputs of the same rusEfi board.\nSee also directSelfStimulation which is different.
pin_output_mode_e[TRIGGER_SIMULATOR_PIN_COUNT iterate] triggerSimulatorPinModes;
output_pin_e o2heaterPin;Narrow band o2 heater, not used for CJ125. See wboHeaterPin
@ -1096,7 +1096,11 @@ int16_t tps2Max;Full throttle#2. tpsMax value as 10 bit ADC value. Not Voltage!\
float throttlePedalSecondaryUpVoltage;;"voltage", 1, 0, -6, 6, 2
float throttlePedalSecondaryWOTVoltage;+Pedal in the floor;"voltage", 1, 0, -6, 6, 2
uint32_t[6] unused_former_warmup_target_afr;
#define can_baudrate_e_enum "100kbps", "250kbps" , "500kbps", "1Mbps"
custom can_baudrate_e 1 bits, U08, @OFFSET@, [0:1], @@can_baudrate_e_enum@@
can_baudrate_e canBaudRate; set can_baudrate
uint32_t[5] unused_former_warmup_target_afr;
float boostCutPressure;kPa value at which we need to cut fuel and spark, 0 if not enabled;"kPa", 1, 0, 0, 500, 0
@ -1654,5 +1658,4 @@ end_struct
#define show_test_presets true
#define show_Frankenso_presets true
#define show_microRusEFI_presets true
#define show_Proteus_presets true
#define show_Proteus_presets true

View File

@ -2576,6 +2576,7 @@ cmd_set_engine_type_default = "w\x00\x31\x00\x00"
field = "Can Read Enabled", canReadEnabled
field = "Can Write Enabled", canWriteEnabled
field = "Can Nbc Type", canNbcType
field = "Can Baud Rate", canBaudRate
field = "Enable rusEFI CAN broadcast", enableVerboseCanTx
field = "rusEfi CAN data base address", verboseCanBaseAddress
field = "Can Sleep Period", canSleepPeriodMs