GCC Code Coverage Report


Directory: ./
File: firmware/config/engines/gm_ls_4.cpp
Date: 2025-12-07 16:27:22
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_UAEFI
62 engineConfiguration->injectionPins[6] = Gpio::MM100_OUT_PWM1;
63 engineConfiguration->injectionPins[7] = Gpio::MM100_INJ8;
64
65 engineConfiguration->ignitionMode = IM_WASTED_SPARK;
66 // cylinders 1 and 6
67 engineConfiguration->ignitionPins[0] = Gpio::MM100_IGN1;
68 // cylinders 2 and 3
69 engineConfiguration->ignitionPins[1] = Gpio::MM100_IGN2;
70 engineConfiguration->ignitionPins[2] = Gpio::Unassigned;
71 engineConfiguration->ignitionPins[3] = Gpio::Unassigned;
72 engineConfiguration->ignitionPins[4] = Gpio::Unassigned;
73 engineConfiguration->ignitionPins[5] = Gpio::Unassigned;
74 // cylinders 7 and 4
75 engineConfiguration->ignitionPins[6] = Gpio::MM100_IGN4;
76 // cylinders 8 and 5
77 engineConfiguration->ignitionPins[7] = Gpio::MM100_IGN3;
78
79
80 engineConfiguration->triggerInputPins[0] = Gpio::MM100_IN_D1; // HALL1
81 engineConfiguration->invertPrimaryTriggerSignal = true;
82
83 engineConfiguration->camInputs[0] = Gpio::MM100_IN_D2; // HALL2
84 engineConfiguration->camInputs[1] = Gpio::Unassigned;
85
86 #endif
87
88 engineConfiguration->fuelReferencePressure = 400; // 400 kPa, 58 psi
89 engineConfiguration->injectorCompensationMode = ICM_FixedRailPressure;
90 engineConfiguration->injector.flow = 400;
91
92 engineConfiguration->tpsAccelLookback = 0.3;
93 engineConfiguration->tpsAccelEnrichmentThreshold = 5;
94 engineConfiguration->tpsDecelEnleanmentThreshold = 7;
95 engineConfiguration->tpsAccelFractionPeriod = 3;
96 engineConfiguration->tpsAccelFractionDivisor = 1.5;
97 engineConfiguration->wwaeTau = 0;
98 engineConfiguration->wwaeBeta = 0;
99
100 engineConfiguration->cylindersCount = 8;
101 setLeftRightBanksNeedBetterName();
102 engineConfiguration->firingOrder = FO_1_8_7_2_6_5_4_3;
103 engineConfiguration->displacement = 6.2;
104 engineConfiguration->map.sensor.type = MT_GM_1_BAR;
105
106 engineConfiguration->tChargeAirIncrLimit = 5;
107 engineConfiguration->tChargeAirDecrLimit = 15;
108
109 // see https://github.com/rusefi/rusefi_documentation/tree/master/OEM-Docs/GM/Tahoe-2011
110 setLuaScript( R"(
111
112 function getBitRange(data, bitIndex, bitWidth)
113 byteIndex = bitIndex >> 3
114 shift = bitIndex - byteIndex * 8
115 value = data[1 + byteIndex]
116 if (shift + bitWidth > 8) then
117 value = value + data[2 + byteIndex] * 256
118 end
119 mask = (1 << bitWidth) - 1
120 return (value >> shift) & mask
121 end
122
123 hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" }
124
125 function toHexString(num)
126 if num == 0 then
127 return '0'
128 end
129
130 local result = ""
131 while num > 0 do
132 local n = num % 16
133 result = hexstr[n + 1] ..result
134 num = math.floor(num / 16)
135 end
136 return result
137 end
138
139 function arrayToString(arr)
140 local str = ""
141 local index = 1
142 while arr[index] ~= nil do
143 str = str.." "..toHexString(arr[index])
144 index = index + 1
145 end
146 return str
147 end
148
149 STARTER_OUTPUT_INDEX = 0
150 startPwm(STARTER_OUTPUT_INDEX, 100, 0)
151
152 -- 201
153 ECMEngineStatus = 0xC9
154 IGN_STATUS = 0x1f1
155 -- 0x514
156 VIN_Part1 = 1300
157 -- 04E1
158 VIN_Part2 = 1249
159
160 setTickRate(100)
161
162 function canIgnStatus(bus, id, dlc, data)
163 crankingBits = getBitRange(data, 2, 2)
164 isCranking = (crankingBits == 2)
165 -- need special considerations to append boolean print('crankingBits ' .. crankingBits .. ', isCranking ' .. isCranking)
166 print('crankingBits ' .. crankingBits)
167 end
168
169 function printAny(bus, id, dlc, data)
170 print('packet ' .. id)
171 end
172
173 canRxAdd(IGN_STATUS, canIgnStatus)
174 -- canRxAddMask(0, 0xFFFFFFF, printAny)
175
176 -- todo: take VIN from configuration? encode VIN?
177 canVin1 = { 0x47, 0x4E, 0x4C, 0x43, 0x32, 0x45, 0x30, 0x34 }
178 canVin2 = { 0x42, 0x52, 0x32, 0x31, 0x36, 0x33, 0x36, 0x36 }
179 dataECMEngineStatus = { 0x84, 0x09, 0x99, 0x0A, 0x00, 0x40, 0x08, 0x00 }
180
181 -- todo: smarter loop code :)
182 canVin1[1] = vin(1)
183 canVin1[2] = vin(2)
184 canVin1[3] = vin(3)
185 canVin1[4] = vin(4)
186 canVin1[5] = vin(5)
187 canVin1[6] = vin(6)
188 canVin1[7] = vin(7)
189 canVin1[8] = vin(8)
190
191 canVin2[1] = vin(9)
192 canVin2[2] = vin(10)
193 canVin2[3] = vin(11)
194 canVin2[4] = vin(12)
195 canVin2[5] = vin(13)
196 canVin2[6] = vin(14)
197 canVin2[7] = vin(15)
198 canVin2[8] = vin(16)
199
200 function onTick()
201 txCan(1, VIN_Part1, 0, canVin1)
202 txCan(1, VIN_Part2, 0, canVin2)
203
204 -- good enough for fuel module!
205 txCan(1, ECMEngineStatus, 0, dataECMEngineStatus)
206
207 if isCranking then
208 setPwmDuty(STARTER_OUTPUT_INDEX, 1)
209 else
210 setPwmDuty(STARTER_OUTPUT_INDEX, 0)
211 end
212 end
213
214 )");
215
216 setPPSCalibration(0.51, 2.11, 1.01, 4.23);
217 setTPS1Calibration(880, 129, 118, 870);
218 }
219