rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
gm_ls_4.cpp
Go to the documentation of this file.
1/*
2 * gm_ls_4.cpp
3 *
4 */
5
6#include "gm_ls_4.h"
7#include "defaults.h"
8#include <rusefi/arrays.h>
9#include "proteus_meta.h"
10
11#ifdef HW_HELLEN
12#include "hellen_meta.h"
13#endif // HW_HELLEN
14
15void setGmLs4() {
16 strcpy(engineConfiguration->engineMake, ENGINE_MAKE_GM);
17 strcpy(engineConfiguration->engineCode, "gen4");
19
20#if HW_PROTEUS
22
23 setPPSInputs(PROTEUS_IN_ANALOG_VOLT_2, PROTEUS_IN_ANALOG_VOLT_11);
24 setTPS1Inputs(PROTEUS_IN_ANALOG_VOLT_4, PROTEUS_IN_ANALOG_VOLT_3);
25
26// todo: tps
27#endif //HW_PROTEUS
28
29#if defined(HW_HELLEN_8CHAN)
30 engineConfiguration->injectionPins[4] = Gpio::MM176_INJ5;
31 engineConfiguration->injectionPins[5] = Gpio::MM176_INJ6;
32 engineConfiguration->injectionPins[6] = Gpio::MM176_INJ7;
33 engineConfiguration->injectionPins[7] = Gpio::MM176_INJ8;
34 engineConfiguration->ignitionPins[4] = Gpio::MM176_IGN5;
35 engineConfiguration->ignitionPins[5] = Gpio::MM176_IGN6;
36 engineConfiguration->ignitionPins[6] = Gpio::MM176_IGN7;
37 engineConfiguration->ignitionPins[7] = Gpio::MM176_IGN8;
38
39 engineConfiguration->vvtPins[0] = Gpio::MM176_OUT_PWM1; // 8D - VVT 1
40 engineConfiguration->map.sensor.hwChannel = MM176_IN_CRANK_ANALOG;
41 engineConfiguration->triggerInputPins[0] = Gpio::MM176_IN_D4; // 9A
45#endif
46
47 engineConfiguration->fuelReferencePressure = 400; // 400 kPa, 58 psi
48 engineConfiguration->injectorCompensationMode = ICM_FixedRailPressure;
50
53 engineConfiguration->firingOrder = FO_1_8_7_2_6_5_4_3;
55
58
59// see https://github.com/rusefi/rusefi_documentation/tree/master/OEM-Docs/GM/Tahoe-2011
60 strncpy(config->luaScript, R"(
61
62function getBitRange(data, bitIndex, bitWidth)
63 byteIndex = bitIndex >> 3
64 shift = bitIndex - byteIndex * 8
65 value = data[1 + byteIndex]
66 if (shift + bitWidth > 8) then
67 value = value + data[2 + byteIndex] * 256
68 end
69 mask = (1 << bitWidth) - 1
70 return (value >> shift) & mask
71end
72
73hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" }
74
75function toHexString(num)
76 if num == 0 then
77 return '0'
78 end
79
80 local result = ""
81 while num > 0 do
82 local n = num % 16
83 result = hexstr[n + 1] ..result
84 num = math.floor(num / 16)
85 end
86 return result
87end
88
89function arrayToString(arr)
90 local str = ""
91 local index = 1
92 while arr[index] ~= nil do
93 str = str.." "..toHexString(arr[index])
94 index = index + 1
95 end
96 return str
97end
98
99STARTER_OUTPUT_INDEX = 0
100startPwm(STARTER_OUTPUT_INDEX, 100, 0)
101
102-- 201
103ECMEngineStatus = 0xC9
104IGN_STATUS = 0x1f1
105-- 0x514
106VIN_Part1 = 1300
107-- 04E1
108VIN_Part2 = 1249
109
110setTickRate(100)
111
112function canIgnStatus(bus, id, dlc, data)
113 crankingBits = getBitRange(data, 2, 2)
114 isCranking = (crankingBits == 2)
115-- need special considerations to append boolean print('crankingBits ' .. crankingBits .. ', isCranking ' .. isCranking)
116 print('crankingBits ' .. crankingBits)
117end
118
119function printAny(bus, id, dlc, data)
120 print('packet ' .. id)
121end
122
123canRxAdd(IGN_STATUS, canIgnStatus)
124-- canRxAddMask(0, 0xFFFFFFF, printAny)
125
126-- todo: take VIN from configuration? encode VIN?
127canVin1 = { 0x47, 0x4E, 0x4C, 0x43, 0x32, 0x45, 0x30, 0x34 }
128canVin2 = { 0x42, 0x52, 0x32, 0x31, 0x36, 0x33, 0x36, 0x36 }
129dataECMEngineStatus = { 0x84, 0x09, 0x99, 0x0A, 0x00, 0x40, 0x08, 0x00 }
130
131-- todo: smarter loop code :)
132canVin1[1] = vin(1)
133canVin1[2] = vin(2)
134canVin1[3] = vin(3)
135canVin1[4] = vin(4)
136canVin1[5] = vin(5)
137canVin1[6] = vin(6)
138canVin1[7] = vin(7)
139canVin1[8] = vin(8)
140
141canVin2[1] = vin(9)
142canVin2[2] = vin(10)
143canVin2[3] = vin(11)
144canVin2[4] = vin(12)
145canVin2[5] = vin(13)
146canVin2[6] = vin(14)
147canVin2[7] = vin(15)
148canVin2[8] = vin(16)
149
150function onTick()
151 txCan(1, VIN_Part1, 0, canVin1)
152 txCan(1, VIN_Part2, 0, canVin2)
153
154 -- good enough for fuel module!
155 txCan(1, ECMEngineStatus, 0, dataECMEngineStatus)
156
157 if isCranking then
158 setPwmDuty(STARTER_OUTPUT_INDEX, 1)
159 else
160 setPwmDuty(STARTER_OUTPUT_INDEX, 0)
161 end
162end
163
164 )", efi::size(config->luaScript));
165
166 setPPSCalibration(0.51, 2.11, 1.01, 4.23);
167 setTPS1Calibration(880, 129, 118, 870);
168}
@ Unassigned
void setTPS1Calibration(uint16_t tpsMin, uint16_t tpsMax)
void setPPSInputs(adc_channel_e pps1, adc_channel_e pps2)
void setTPS1Inputs(adc_channel_e tps1, adc_channel_e tps2)
void setPPSCalibration(float primaryUp, float primaryDown, float secondaryUp, float secondaryDown)
void setLeftRightBanksNeedBetterName()
static constexpr persistent_config_s * config
static constexpr engine_configuration_s * engineConfiguration
void setGmLs4()
Definition gm_ls_4.cpp:15
brain_input_pin_e triggerInputPins[TRIGGER_INPUT_PIN_COUNT]