GCC Code Coverage Report


Directory: ./
File: firmware/config/engines/gm_ls_4.cpp
Date: 2025-10-24 14:26:41
Coverage Exec Excl Total
Lines: 0.0% 0 0 31
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 8 and 5
68 engineConfiguration->ignitionPins[1] = Gpio::MM100_IGN3;
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 2 and 3
76 engineConfiguration->ignitionPins[7] = Gpio::MM100_IGN2;
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 = 440;
90
91 engineConfiguration->cylindersCount = 8;
92 setLeftRightBanksNeedBetterName();
93 engineConfiguration->firingOrder = FO_1_8_7_2_6_5_4_3;
94 engineConfiguration->displacement = 6.2;
95 engineConfiguration->map.sensor.type = MT_GM_1_BAR;
96
97 engineConfiguration->tChargeAirIncrLimit = 5;
98 engineConfiguration->tChargeAirDecrLimit = 15;
99
100 // see https://github.com/rusefi/rusefi_documentation/tree/master/OEM-Docs/GM/Tahoe-2011
101 strncpy(config->luaScript, R"(
102
103 function getBitRange(data, bitIndex, bitWidth)
104 byteIndex = bitIndex >> 3
105 shift = bitIndex - byteIndex * 8
106 value = data[1 + byteIndex]
107 if (shift + bitWidth > 8) then
108 value = value + data[2 + byteIndex] * 256
109 end
110 mask = (1 << bitWidth) - 1
111 return (value >> shift) & mask
112 end
113
114 hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" }
115
116 function toHexString(num)
117 if num == 0 then
118 return '0'
119 end
120
121 local result = ""
122 while num > 0 do
123 local n = num % 16
124 result = hexstr[n + 1] ..result
125 num = math.floor(num / 16)
126 end
127 return result
128 end
129
130 function arrayToString(arr)
131 local str = ""
132 local index = 1
133 while arr[index] ~= nil do
134 str = str.." "..toHexString(arr[index])
135 index = index + 1
136 end
137 return str
138 end
139
140 STARTER_OUTPUT_INDEX = 0
141 startPwm(STARTER_OUTPUT_INDEX, 100, 0)
142
143 -- 201
144 ECMEngineStatus = 0xC9
145 IGN_STATUS = 0x1f1
146 -- 0x514
147 VIN_Part1 = 1300
148 -- 04E1
149 VIN_Part2 = 1249
150
151 setTickRate(100)
152
153 function canIgnStatus(bus, id, dlc, data)
154 crankingBits = getBitRange(data, 2, 2)
155 isCranking = (crankingBits == 2)
156 -- need special considerations to append boolean print('crankingBits ' .. crankingBits .. ', isCranking ' .. isCranking)
157 print('crankingBits ' .. crankingBits)
158 end
159
160 function printAny(bus, id, dlc, data)
161 print('packet ' .. id)
162 end
163
164 canRxAdd(IGN_STATUS, canIgnStatus)
165 -- canRxAddMask(0, 0xFFFFFFF, printAny)
166
167 -- todo: take VIN from configuration? encode VIN?
168 canVin1 = { 0x47, 0x4E, 0x4C, 0x43, 0x32, 0x45, 0x30, 0x34 }
169 canVin2 = { 0x42, 0x52, 0x32, 0x31, 0x36, 0x33, 0x36, 0x36 }
170 dataECMEngineStatus = { 0x84, 0x09, 0x99, 0x0A, 0x00, 0x40, 0x08, 0x00 }
171
172 -- todo: smarter loop code :)
173 canVin1[1] = vin(1)
174 canVin1[2] = vin(2)
175 canVin1[3] = vin(3)
176 canVin1[4] = vin(4)
177 canVin1[5] = vin(5)
178 canVin1[6] = vin(6)
179 canVin1[7] = vin(7)
180 canVin1[8] = vin(8)
181
182 canVin2[1] = vin(9)
183 canVin2[2] = vin(10)
184 canVin2[3] = vin(11)
185 canVin2[4] = vin(12)
186 canVin2[5] = vin(13)
187 canVin2[6] = vin(14)
188 canVin2[7] = vin(15)
189 canVin2[8] = vin(16)
190
191 function onTick()
192 txCan(1, VIN_Part1, 0, canVin1)
193 txCan(1, VIN_Part2, 0, canVin2)
194
195 -- good enough for fuel module!
196 txCan(1, ECMEngineStatus, 0, dataECMEngineStatus)
197
198 if isCranking then
199 setPwmDuty(STARTER_OUTPUT_INDEX, 1)
200 else
201 setPwmDuty(STARTER_OUTPUT_INDEX, 0)
202 end
203 end
204
205 )", efi::size(config->luaScript));
206
207 setPPSCalibration(0.51, 2.11, 1.01, 4.23);
208 setTPS1Calibration(880, 129, 118, 870);
209 }
210