2022-10-25 20:18:41 -07:00
|
|
|
/*
|
|
|
|
* gm_ls_4.cpp
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm_ls_4.h"
|
|
|
|
#include "defaults.h"
|
2022-10-27 17:32:35 -07:00
|
|
|
#include <rusefi/arrays.h>
|
2022-10-29 21:07:32 -07:00
|
|
|
#include "proteus_meta.h"
|
2022-10-25 20:18:41 -07:00
|
|
|
|
|
|
|
void setGmLs4() {
|
|
|
|
engineConfiguration->globalTriggerAngleOffset = 86;
|
|
|
|
|
|
|
|
engineConfiguration->fuelReferencePressure = 400; // 400 kPa, 58 psi
|
|
|
|
engineConfiguration->injectorCompensationMode = ICM_FixedRailPressure;
|
|
|
|
engineConfiguration->injector.flow = 440;
|
|
|
|
|
2023-03-27 00:58:18 -07:00
|
|
|
engineConfiguration->cylindersCount = 8;
|
2022-10-25 20:18:41 -07:00
|
|
|
setLeftRightBanksNeedBetterName();
|
2023-03-27 00:58:18 -07:00
|
|
|
engineConfiguration->firingOrder = FO_1_8_7_2_6_5_4_3;
|
|
|
|
engineConfiguration->displacement = 6.2;
|
2022-10-25 20:18:41 -07:00
|
|
|
|
|
|
|
engineConfiguration->tChargeAirIncrLimit = 5;
|
|
|
|
engineConfiguration->tChargeAirDecrLimit = 15;
|
2022-10-27 16:53:28 -07:00
|
|
|
|
2023-10-09 10:13:59 -07:00
|
|
|
// see https://github.com/rusefi/rusefi_documentation/tree/master/OEM-Docs/GM/Tahoe-2011
|
2022-10-27 16:53:28 -07:00
|
|
|
strncpy(config->luaScript, R"(
|
|
|
|
|
|
|
|
function getBitRange(data, bitIndex, bitWidth)
|
|
|
|
byteIndex = bitIndex >> 3
|
|
|
|
shift = bitIndex - byteIndex * 8
|
|
|
|
value = data[1 + byteIndex]
|
|
|
|
if (shift + bitWidth > 8) then
|
|
|
|
value = value + data[2 + byteIndex] * 256
|
|
|
|
end
|
|
|
|
mask = (1 << bitWidth) - 1
|
|
|
|
return (value >> shift) & mask
|
|
|
|
end
|
|
|
|
|
2022-10-29 19:56:12 -07:00
|
|
|
hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" }
|
|
|
|
|
|
|
|
function toHexString(num)
|
|
|
|
if num == 0 then
|
|
|
|
return '0'
|
|
|
|
end
|
|
|
|
|
|
|
|
local result = ""
|
|
|
|
while num > 0 do
|
|
|
|
local n = num % 16
|
|
|
|
result = hexstr[n + 1] ..result
|
|
|
|
num = math.floor(num / 16)
|
|
|
|
end
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
|
|
|
function arrayToString(arr)
|
|
|
|
local str = ""
|
|
|
|
local index = 1
|
|
|
|
while arr[index] ~= nil do
|
|
|
|
str = str.." "..toHexString(arr[index])
|
|
|
|
index = index + 1
|
|
|
|
end
|
|
|
|
return str
|
|
|
|
end
|
|
|
|
|
2022-10-27 16:53:28 -07:00
|
|
|
STARTER_OUTPUT_INDEX = 0
|
|
|
|
startPwm(STARTER_OUTPUT_INDEX, 100, 0)
|
|
|
|
|
|
|
|
-- 201
|
|
|
|
ECMEngineStatus = 0xC9
|
|
|
|
IGN_STATUS = 0x1f1
|
|
|
|
-- 0x514
|
|
|
|
VIN_Part1 = 1300
|
|
|
|
-- 04E1
|
|
|
|
VIN_Part2 = 1249
|
|
|
|
|
|
|
|
setTickRate(100)
|
|
|
|
|
|
|
|
function canIgnStatus(bus, id, dlc, data)
|
|
|
|
crankingBits = getBitRange(data, 2, 2)
|
|
|
|
isCranking = (crankingBits == 2)
|
2022-10-29 19:56:12 -07:00
|
|
|
-- need special considerations to append boolean print('crankingBits ' .. crankingBits .. ', isCranking ' .. isCranking)
|
|
|
|
print('crankingBits ' .. crankingBits)
|
|
|
|
end
|
|
|
|
|
|
|
|
function printAny(bus, id, dlc, data)
|
|
|
|
print('packet ' .. id)
|
2022-10-27 16:53:28 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
canRxAdd(IGN_STATUS, canIgnStatus)
|
2022-10-29 19:56:12 -07:00
|
|
|
-- canRxAddMask(0, 0xFFFFFFF, printAny)
|
2022-10-27 16:53:28 -07:00
|
|
|
|
|
|
|
-- todo: take VIN from configuration? encode VIN?
|
|
|
|
canVin1 = { 0x47, 0x4E, 0x4C, 0x43, 0x32, 0x45, 0x30, 0x34 }
|
|
|
|
canVin2 = { 0x42, 0x52, 0x32, 0x31, 0x36, 0x33, 0x36, 0x36 }
|
|
|
|
dataECMEngineStatus = { 0x84, 0x09, 0x99, 0x0A, 0x00, 0x40, 0x08, 0x00 }
|
|
|
|
|
2022-10-29 19:56:12 -07:00
|
|
|
-- todo: smarter loop code :)
|
|
|
|
canVin1[1] = vin(1)
|
|
|
|
canVin1[2] = vin(2)
|
|
|
|
canVin1[3] = vin(3)
|
|
|
|
canVin1[4] = vin(4)
|
|
|
|
canVin1[5] = vin(5)
|
|
|
|
canVin1[6] = vin(6)
|
|
|
|
canVin1[7] = vin(7)
|
|
|
|
canVin1[8] = vin(8)
|
|
|
|
|
|
|
|
canVin2[1] = vin(9)
|
|
|
|
canVin2[2] = vin(10)
|
|
|
|
canVin2[3] = vin(11)
|
|
|
|
canVin2[4] = vin(12)
|
|
|
|
canVin2[5] = vin(13)
|
|
|
|
canVin2[6] = vin(14)
|
|
|
|
canVin2[7] = vin(15)
|
|
|
|
canVin2[8] = vin(16)
|
|
|
|
|
2022-10-27 16:53:28 -07:00
|
|
|
function onTick()
|
|
|
|
txCan(1, VIN_Part1, 0, canVin1)
|
|
|
|
txCan(1, VIN_Part2, 0, canVin2)
|
|
|
|
|
|
|
|
-- good enough for fuel module!
|
|
|
|
txCan(1, ECMEngineStatus, 0, dataECMEngineStatus)
|
|
|
|
|
|
|
|
if isCranking then
|
|
|
|
setPwmDuty(STARTER_OUTPUT_INDEX, 1)
|
|
|
|
else
|
|
|
|
setPwmDuty(STARTER_OUTPUT_INDEX, 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
)", efi::size(config->luaScript));
|
|
|
|
|
2022-10-29 20:55:23 -07:00
|
|
|
setPPSCalibration(0.51, 2.11, 1.01, 4.23);
|
2022-11-04 09:38:55 -07:00
|
|
|
setTPS1Calibration(880, 129, 118, 870);
|
2022-10-27 16:53:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void setProteusGmLs4() {
|
2022-10-29 21:07:32 -07:00
|
|
|
#if HW_PROTEUS
|
2023-02-18 19:39:45 -08:00
|
|
|
engineConfiguration->etbFunctions[1] = DC_None;
|
2022-10-29 20:55:23 -07:00
|
|
|
|
2022-10-29 21:24:47 -07:00
|
|
|
setPPSInputs(PROTEUS_IN_ANALOG_VOLT_2, PROTEUS_IN_ANALOG_VOLT_11);
|
|
|
|
setTPS1Inputs(PROTEUS_IN_ANALOG_VOLT_4, PROTEUS_IN_ANALOG_VOLT_3);
|
2022-10-29 20:55:23 -07:00
|
|
|
|
2022-10-29 19:56:12 -07:00
|
|
|
// todo: tps
|
2022-10-29 21:07:32 -07:00
|
|
|
#endif //HW_PROTEUS
|
2022-10-27 16:53:28 -07:00
|
|
|
setGmLs4();
|
2022-10-25 20:18:41 -07:00
|
|
|
}
|