GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 0.0% 0 / 0 / 40
Functions: 0.0% 0 / 0 / 1
Branches: -% 0 / 0 / 0
Decisions: -% 0 / - / 0

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