GCC Code Coverage Report


Directory: ./
File: firmware/config/engines/gm_ls_4.cpp
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 0.0% 0 0 21
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
20 #if HW_PROTEUS
21 engineConfiguration->etbFunctions[1] = DC_None;
22
23 setPPSInputs(PROTEUS_IN_ANALOG_VOLT_2, PROTEUS_IN_ANALOG_VOLT_11);
24 setTPS1Inputs(PROTEUS_IN_ANALOG_VOLT_4, PROTEUS_IN_ANALOG_VOLT_3);
25
26 // todo: tps
27 #endif //HW_PROTEUS
28
29 #if defined(HW_HELLEN_8CHAN)
30 engineConfiguration->injectionPins[4] = Gpio::MM176_INJ5;
31 engineConfiguration->injectionPins[5] = Gpio::MM176_INJ6;
32 engineConfiguration->injectionPins[6] = Gpio::MM176_INJ7;
33 engineConfiguration->injectionPins[7] = Gpio::MM176_INJ8;
34 engineConfiguration->ignitionPins[4] = Gpio::MM176_IGN5;
35 engineConfiguration->ignitionPins[5] = Gpio::MM176_IGN6;
36 engineConfiguration->ignitionPins[6] = Gpio::MM176_IGN7;
37 engineConfiguration->ignitionPins[7] = Gpio::MM176_IGN8;
38
39 engineConfiguration->vvtPins[0] = Gpio::MM176_OUT_PWM1; // 8D - VVT 1
40 engineConfiguration->map.sensor.hwChannel = MM176_IN_CRANK_ANALOG;
41 engineConfiguration->triggerInputPins[0] = Gpio::MM176_IN_D4; // 9A
42 engineConfiguration->camInputs[1] = Gpio::Unassigned;
43 engineConfiguration->camInputs[2] = Gpio::Unassigned;
44 engineConfiguration->camInputs[3] = Gpio::Unassigned;
45 #endif
46
47 engineConfiguration->fuelReferencePressure = 400; // 400 kPa, 58 psi
48 engineConfiguration->injectorCompensationMode = ICM_FixedRailPressure;
49 engineConfiguration->injector.flow = 440;
50
51 engineConfiguration->cylindersCount = 8;
52 setLeftRightBanksNeedBetterName();
53 engineConfiguration->firingOrder = FO_1_8_7_2_6_5_4_3;
54 engineConfiguration->displacement = 6.2;
55
56 engineConfiguration->tChargeAirIncrLimit = 5;
57 engineConfiguration->tChargeAirDecrLimit = 15;
58
59 // see https://github.com/rusefi/rusefi_documentation/tree/master/OEM-Docs/GM/Tahoe-2011
60 strncpy(config->luaScript, R"(
61
62 function getBitRange(data, bitIndex, bitWidth)
63 byteIndex = bitIndex >> 3
64 shift = bitIndex - byteIndex * 8
65 value = data[1 + byteIndex]
66 if (shift + bitWidth > 8) then
67 value = value + data[2 + byteIndex] * 256
68 end
69 mask = (1 << bitWidth) - 1
70 return (value >> shift) & mask
71 end
72
73 hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" }
74
75 function toHexString(num)
76 if num == 0 then
77 return '0'
78 end
79
80 local result = ""
81 while num > 0 do
82 local n = num % 16
83 result = hexstr[n + 1] ..result
84 num = math.floor(num / 16)
85 end
86 return result
87 end
88
89 function arrayToString(arr)
90 local str = ""
91 local index = 1
92 while arr[index] ~= nil do
93 str = str.." "..toHexString(arr[index])
94 index = index + 1
95 end
96 return str
97 end
98
99 STARTER_OUTPUT_INDEX = 0
100 startPwm(STARTER_OUTPUT_INDEX, 100, 0)
101
102 -- 201
103 ECMEngineStatus = 0xC9
104 IGN_STATUS = 0x1f1
105 -- 0x514
106 VIN_Part1 = 1300
107 -- 04E1
108 VIN_Part2 = 1249
109
110 setTickRate(100)
111
112 function canIgnStatus(bus, id, dlc, data)
113 crankingBits = getBitRange(data, 2, 2)
114 isCranking = (crankingBits == 2)
115 -- need special considerations to append boolean print('crankingBits ' .. crankingBits .. ', isCranking ' .. isCranking)
116 print('crankingBits ' .. crankingBits)
117 end
118
119 function printAny(bus, id, dlc, data)
120 print('packet ' .. id)
121 end
122
123 canRxAdd(IGN_STATUS, canIgnStatus)
124 -- canRxAddMask(0, 0xFFFFFFF, printAny)
125
126 -- todo: take VIN from configuration? encode VIN?
127 canVin1 = { 0x47, 0x4E, 0x4C, 0x43, 0x32, 0x45, 0x30, 0x34 }
128 canVin2 = { 0x42, 0x52, 0x32, 0x31, 0x36, 0x33, 0x36, 0x36 }
129 dataECMEngineStatus = { 0x84, 0x09, 0x99, 0x0A, 0x00, 0x40, 0x08, 0x00 }
130
131 -- todo: smarter loop code :)
132 canVin1[1] = vin(1)
133 canVin1[2] = vin(2)
134 canVin1[3] = vin(3)
135 canVin1[4] = vin(4)
136 canVin1[5] = vin(5)
137 canVin1[6] = vin(6)
138 canVin1[7] = vin(7)
139 canVin1[8] = vin(8)
140
141 canVin2[1] = vin(9)
142 canVin2[2] = vin(10)
143 canVin2[3] = vin(11)
144 canVin2[4] = vin(12)
145 canVin2[5] = vin(13)
146 canVin2[6] = vin(14)
147 canVin2[7] = vin(15)
148 canVin2[8] = vin(16)
149
150 function onTick()
151 txCan(1, VIN_Part1, 0, canVin1)
152 txCan(1, VIN_Part2, 0, canVin2)
153
154 -- good enough for fuel module!
155 txCan(1, ECMEngineStatus, 0, dataECMEngineStatus)
156
157 if isCranking then
158 setPwmDuty(STARTER_OUTPUT_INDEX, 1)
159 else
160 setPwmDuty(STARTER_OUTPUT_INDEX, 0)
161 end
162 end
163
164 )", efi::size(config->luaScript));
165
166 setPPSCalibration(0.51, 2.11, 1.01, 4.23);
167 setTPS1Calibration(880, 129, 118, 870);
168 }
169