GCC Code Coverage Report


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