GCC Code Coverage Report


Directory: ./
File: firmware/config/engines/gm_ls_4.cpp
Date: 2025-11-16 14:52:24
Coverage Exec Excl Total
Lines: 0.0% 0 0 38
Functions: 0.0% 0 0 1
Branches: -% 0 0 0
Decisions: -% 0 - 0

Line Branch Decision Exec Source
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
15 void setGmLs4() {
16 strcpy(engineConfiguration->engineMake, ENGINE_MAKE_GM);
17 strcpy(engineConfiguration->engineCode, "gen4");
18 engineConfiguration->globalTriggerAngleOffset = 86;
19 engineConfiguration->vvtMode[0] = VVT_BOSCH_QUICK_START;
20
21 engineConfiguration->etbIdleThrottleRange = 30;
22
23 engineConfiguration->cranking.rpm = 400;
24 engineConfiguration->rpmHardLimit = 6000;
25
26 engineConfiguration->etb.pFactor = 7.320831;
27 engineConfiguration->etb.iFactor = 116.5986;
28 engineConfiguration->etb.dFactor = 0.0765;
29 engineConfiguration->etb.minValue = -90;
30 engineConfiguration->etb.maxValue = 90;
31
32
33 #if HW_PROTEUS
34 engineConfiguration->etbFunctions[1] = DC_None;
35
36 setPPSInputs(PROTEUS_IN_ANALOG_VOLT_2, PROTEUS_IN_ANALOG_VOLT_11);
37 setTPS1Inputs(PROTEUS_IN_ANALOG_VOLT_4, PROTEUS_IN_ANALOG_VOLT_3);
38
39 // todo: tps
40 #endif //HW_PROTEUS
41
42 #if defined(HW_HELLEN_8CHAN)
43 engineConfiguration->injectionPins[4] = Gpio::MM176_INJ5;
44 engineConfiguration->injectionPins[5] = Gpio::MM176_INJ6;
45 engineConfiguration->injectionPins[6] = Gpio::MM176_INJ7;
46 engineConfiguration->injectionPins[7] = Gpio::MM176_INJ8;
47 engineConfiguration->ignitionPins[4] = Gpio::MM176_IGN5;
48 engineConfiguration->ignitionPins[5] = Gpio::MM176_IGN6;
49 engineConfiguration->ignitionPins[6] = Gpio::MM176_IGN7;
50 engineConfiguration->ignitionPins[7] = Gpio::MM176_IGN8;
51
52 engineConfiguration->vvtPins[0] = Gpio::MM176_OUT_PWM1; // 8D - VVT 1
53 engineConfiguration->map.sensor.hwChannel = MM176_IN_CRANK_ANALOG;
54 engineConfiguration->triggerInputPins[0] = Gpio::MM176_IN_D4; // 9A
55 engineConfiguration->camInputs[1] = Gpio::Unassigned;
56 engineConfiguration->camInputs[2] = Gpio::Unassigned;
57 engineConfiguration->camInputs[3] = Gpio::Unassigned;
58 #endif
59
60 #ifdef HW_HELLEN_UAEFI
61 engineConfiguration->injectionPins[6] = Gpio::MM100_OUT_PWM1;
62 engineConfiguration->injectionPins[7] = Gpio::MM100_INJ8;
63
64 engineConfiguration->ignitionMode = IM_WASTED_SPARK;
65 // cylinders 1 and 6
66 engineConfiguration->ignitionPins[0] = Gpio::MM100_IGN1;
67 // cylinders 2 and 3
68 engineConfiguration->ignitionPins[1] = Gpio::MM100_IGN2;
69 engineConfiguration->ignitionPins[2] = Gpio::Unassigned;
70 engineConfiguration->ignitionPins[3] = Gpio::Unassigned;
71 engineConfiguration->ignitionPins[4] = Gpio::Unassigned;
72 engineConfiguration->ignitionPins[5] = Gpio::Unassigned;
73 // cylinders 7 and 4
74 engineConfiguration->ignitionPins[6] = Gpio::MM100_IGN4;
75 // cylinders 8 and 5
76 engineConfiguration->ignitionPins[7] = Gpio::MM100_IGN3;
77
78
79 engineConfiguration->triggerInputPins[0] = Gpio::MM100_IN_D1; // HALL1
80 engineConfiguration->invertPrimaryTriggerSignal = true;
81
82 engineConfiguration->camInputs[0] = Gpio::MM100_IN_D2; // HALL2
83 engineConfiguration->camInputs[1] = Gpio::Unassigned;
84
85 #endif
86
87 engineConfiguration->fuelReferencePressure = 400; // 400 kPa, 58 psi
88 engineConfiguration->injectorCompensationMode = ICM_FixedRailPressure;
89 engineConfiguration->injector.flow = 400;
90
91 engineConfiguration->tpsAccelLookback = 0.3;
92 engineConfiguration->tpsAccelEnrichmentThreshold = 5;
93 engineConfiguration->tpsDecelEnleanmentThreshold = 7;
94 engineConfiguration->tpsAccelFractionPeriod = 3;
95 engineConfiguration->tpsAccelFractionDivisor = 1.5;
96 engineConfiguration->wwaeTau = 0;
97 engineConfiguration->wwaeBeta = 0;
98
99 engineConfiguration->cylindersCount = 8;
100 setLeftRightBanksNeedBetterName();
101 engineConfiguration->firingOrder = FO_1_8_7_2_6_5_4_3;
102 engineConfiguration->displacement = 6.2;
103 engineConfiguration->map.sensor.type = MT_GM_1_BAR;
104
105 engineConfiguration->tChargeAirIncrLimit = 5;
106 engineConfiguration->tChargeAirDecrLimit = 15;
107
108 // see https://github.com/rusefi/rusefi_documentation/tree/master/OEM-Docs/GM/Tahoe-2011
109 strncpy(config->luaScript, R"(
110
111 function getBitRange(data, bitIndex, bitWidth)
112 byteIndex = bitIndex >> 3
113 shift = bitIndex - byteIndex * 8
114 value = data[1 + byteIndex]
115 if (shift + bitWidth > 8) then
116 value = value + data[2 + byteIndex] * 256
117 end
118 mask = (1 << bitWidth) - 1
119 return (value >> shift) & mask
120 end
121
122 hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" }
123
124 function toHexString(num)
125 if num == 0 then
126 return '0'
127 end
128
129 local result = ""
130 while num > 0 do
131 local n = num % 16
132 result = hexstr[n + 1] ..result
133 num = math.floor(num / 16)
134 end
135 return result
136 end
137
138 function arrayToString(arr)
139 local str = ""
140 local index = 1
141 while arr[index] ~= nil do
142 str = str.." "..toHexString(arr[index])
143 index = index + 1
144 end
145 return str
146 end
147
148 STARTER_OUTPUT_INDEX = 0
149 startPwm(STARTER_OUTPUT_INDEX, 100, 0)
150
151 -- 201
152 ECMEngineStatus = 0xC9
153 IGN_STATUS = 0x1f1
154 -- 0x514
155 VIN_Part1 = 1300
156 -- 04E1
157 VIN_Part2 = 1249
158
159 setTickRate(100)
160
161 function canIgnStatus(bus, id, dlc, data)
162 crankingBits = getBitRange(data, 2, 2)
163 isCranking = (crankingBits == 2)
164 -- need special considerations to append boolean print('crankingBits ' .. crankingBits .. ', isCranking ' .. isCranking)
165 print('crankingBits ' .. crankingBits)
166 end
167
168 function printAny(bus, id, dlc, data)
169 print('packet ' .. id)
170 end
171
172 canRxAdd(IGN_STATUS, canIgnStatus)
173 -- canRxAddMask(0, 0xFFFFFFF, printAny)
174
175 -- todo: take VIN from configuration? encode VIN?
176 canVin1 = { 0x47, 0x4E, 0x4C, 0x43, 0x32, 0x45, 0x30, 0x34 }
177 canVin2 = { 0x42, 0x52, 0x32, 0x31, 0x36, 0x33, 0x36, 0x36 }
178 dataECMEngineStatus = { 0x84, 0x09, 0x99, 0x0A, 0x00, 0x40, 0x08, 0x00 }
179
180 -- todo: smarter loop code :)
181 canVin1[1] = vin(1)
182 canVin1[2] = vin(2)
183 canVin1[3] = vin(3)
184 canVin1[4] = vin(4)
185 canVin1[5] = vin(5)
186 canVin1[6] = vin(6)
187 canVin1[7] = vin(7)
188 canVin1[8] = vin(8)
189
190 canVin2[1] = vin(9)
191 canVin2[2] = vin(10)
192 canVin2[3] = vin(11)
193 canVin2[4] = vin(12)
194 canVin2[5] = vin(13)
195 canVin2[6] = vin(14)
196 canVin2[7] = vin(15)
197 canVin2[8] = vin(16)
198
199 function onTick()
200 txCan(1, VIN_Part1, 0, canVin1)
201 txCan(1, VIN_Part2, 0, canVin2)
202
203 -- good enough for fuel module!
204 txCan(1, ECMEngineStatus, 0, dataECMEngineStatus)
205
206 if isCranking then
207 setPwmDuty(STARTER_OUTPUT_INDEX, 1)
208 else
209 setPwmDuty(STARTER_OUTPUT_INDEX, 0)
210 end
211 end
212
213 )", efi::size(config->luaScript));
214
215 setPPSCalibration(0.51, 2.11, 1.01, 4.23);
216 setTPS1Calibration(880, 129, 118, 870);
217 }
218