GCC Code Coverage Report


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

firmware/config/engines/gm_sbc.cpp
Line Branch Decision Exec Source
1 #include "pch.h"
2 #include "gm_sbc.h"
3 #include "defaults.h"
4
5 #ifdef HW_HELLEN
6 #include "hellen_meta.h"
7 #endif // HW_HELLEN
8
9 #ifdef HW_HELLEN_8CHAN
10 #include "connectors/generated_board_pin_names.h"
11 #endif // HW_HELLEN_8CHAN
12
13 #include "proteus_meta.h"
14
15 void setStepperHw() {
16 engineConfiguration->useStepperIdle = true;
17 engineConfiguration->useHbridgesToDriveIdleStepper = true;
18 engineConfiguration->stepper_dc_use_two_wires = false;
19 engineConfiguration->stepperDcInvertedPins = false;
20
21 for (size_t i = 0;i<ETB_COUNT;i++) {
22 engineConfiguration->etbFunctions[i] = DC_None;
23 }
24
25 setPPSInputs(EFI_ADC_NONE, EFI_ADC_NONE);
26
27 #ifdef HW_HELLEN_8CHAN
28 void set8chanDefaultETBPins();
29 set8chanDefaultETBPins();
30 #endif // HW_HELLEN_8CHAN
31
32 #ifdef HW_HELLEN_UAEFI
33 void setUaefiDefaultETBPins();
34 setUaefiDefaultETBPins();
35 #endif // HW_HELLEN_UAEFI
36
37 #ifdef HW_PROTEUS
38 //Coil 1 - Pin 15 DC2 positive Pin A Toyota iac pin 4
39 //Coil 1 - Pin 8 DC2 negative Pin B Toyota iac pin 6
40 //Coil 2 - Pin 7 DC1 positive Pin C Toyota iac pin 1
41 //Coil 2 - Pin 6 DC1 negative Pin D Toyota iac pin 3
42
43 // coil #1 = proteus pin 15 (DC2 positive) to BL pin "A", pin B to pin 8 (DC2 negative)
44 // PWM pin
45 engineConfiguration->stepperDcIo[0].controlPin = Gpio::D13;
46 // DIR pin
47 engineConfiguration->stepperDcIo[0].directionPin1 = Gpio::D9;
48 // Disable pin
49 engineConfiguration->stepperDcIo[0].disablePin = Gpio::D8;
50 // Unused
51 engineConfiguration->stepperDcIo[0].directionPin2 = Gpio::Unassigned;
52
53 // coil #2 - proteus pin 7 (DC1 positive) to AH pin "D", pin C to pin 6 (DC1 negative)
54 // PWM pin
55 engineConfiguration->stepperDcIo[1].controlPin = Gpio::D12;
56 // DIR pin
57 engineConfiguration->stepperDcIo[1].directionPin1 = Gpio::D10;
58 // Disable pin
59 engineConfiguration->stepperDcIo[1].disablePin = Gpio::D11;
60 // Unused
61 engineConfiguration->stepperDcIo[1].directionPin2 = Gpio::Unassigned;
62
63 #endif // HW_PROTEUS
64 }
65
66 static void gmRailSensor() {
67 engineConfiguration->highPressureFuel.v1 = 0.5; /* volts */;
68 engineConfiguration->highPressureFuel.value1 = 0;
69 engineConfiguration->highPressureFuel.v2 = 4.5; /* volts */;
70 // fun fact: twice the range of VAG B6?
71 engineConfiguration->highPressureFuel.value2 = 25300;
72 }
73
74 void setGmSbc() {
75 engineConfiguration->cylindersCount = 8;
76 // that's original firing order before gen 3
77 engineConfiguration->firingOrder = FO_1_8_4_3_6_5_7_2;
78 engineConfiguration->displacement = 5.2;
79
80 // see engine sniffer at https://github.com/rusefi/rusefi/issues/5353
81 // if injectors are wired in groups of four best to use channels 1 and 4
82 engineConfiguration->crankingInjectionMode = IM_BATCH;
83 engineConfiguration->injectionMode = IM_BATCH;
84
85 strcpy(engineConfiguration->engineMake, ENGINE_MAKE_GM);
86 strcpy(engineConfiguration->engineCode, "SBC");
87 // white wire "HEI E" plug pin D
88 engineConfiguration->ignitionMode = IM_ONE_COIL;
89 engineConfiguration->globalTriggerAngleOffset = 24;
90
91 // this is used to tell HEI that we are always in charge of timing advance
92 gppwm_channel *ignOverride = &engineConfiguration->gppwm[0];
93 ignOverride->pwmFrequency = 0;
94 strcpy(engineConfiguration->gpPwmNote[0], "ign ovrrd B");
95 setTable(ignOverride->table, 100);
96
97 #ifdef HW_HELLEN_UAEFI121
98 // coil control plug pin A
99
100 // tan wire with a black trace - "HEI B", plug pin B (we use yellow)
101 ignOverride->pin = Gpio::MM100_IGN2; // 12a Coil 2
102 // tach plug pin C
103 engineConfiguration->triggerInputPins[0] = Gpio::MM100_IN_D2; // 35a HALL2 red wire
104 engineConfiguration->camInputs[0] = Gpio::Unassigned;
105 engineConfiguration->camInputs[1] = Gpio::Unassigned;
106 engineConfiguration->ignitionPins[1] = Gpio::Unassigned;
107 #endif // HW_HELLEN_UAEFI121
108
109 #ifdef HW_HELLEN_SUPER_UAEFI
110 engineConfiguration->triggerInputPins[0] = Gpio::MM100_IN_D2; // HALL2
111 engineConfiguration->camInputs[1] = Gpio::Unassigned;
112 #endif // HW_HELLEN_SUPER_UAEFI
113
114 #if HW_PROTEUS
115 // tan wire with a black trace - "HEI B", plug pin B
116 ignOverride->pin = Gpio::PROTEUS_IGN_12;
117 engineConfiguration->fanPin = Gpio::Unassigned;
118 // reminder about D101
119 engineConfiguration->injectionPins[0] = Gpio::PROTEUS_LS_14; // #1
120 // reminder about D104
121 engineConfiguration->injectionPins[3] = Gpio::PROTEUS_LS_15; // #4
122
123 // wow high side relay control on MEFI1 ELECTRONIC-FUEL-INJECTION-MEFI-1-2-5.7L-350CID-8.2L-502CID.pdf page 46
124 engineConfiguration->fuelPumpPin = Gpio::PROTEUS_HS_1;
125 // low side on MEFI3 ELECTRONIC-FUEL-INJECTION-MEFI-3-5.7L-350CID-8.2L-502CID.pdf page 487
126
127 setGmCltSensor(&engineConfiguration->clt);
128 #endif // HW_PROTEUS
129 engineConfiguration->mainRelayPin = Gpio::Unassigned; // vehicle controls main relay
130
131 // for instance IWP069
132 engineConfiguration->injector.flow = 482.5;
133
134 setStepperHw();
135
136 // 8 cylinders one coil HEI trigger
137 engineConfiguration->trigger.type = trigger_type_e::TT_TOOTHED_WHEEL;
138 engineConfiguration->trigger.customTotalToothCount = 8;
139 engineConfiguration->trigger.customSkippedToothCount = 0;
140 engineConfiguration->skippedWheelOnCam = true;
141 // Proteus Digital 1 is Tach input "HEI R", plug pin C
142
143 engineConfiguration->map.sensor.type = MT_GM_1_BAR;
144 }
145
146 static void setGmGdi() {
147 engineConfiguration->camSyncOnSecondCrankRevolution = true;
148 engineConfiguration->globalTriggerAngleOffset = 90;
149 engineConfiguration->vvtMode[0] = VVT_BOSCH_QUICK_START;
150 engineConfiguration->lowPressureFuel.hwChannel = EFI_ADC_NONE;
151 gmRailSensor();
152
153 // is this oddly high or OKis?
154 engineConfiguration->mc33_hpfp_i_peak = 10;
155 engineConfiguration->mc33_hpfp_i_hold = 7;
156
157 #ifdef HW_HELLEN_4K_GDI
158 engineConfiguration->invertCamVVTSignal = true;
159 engineConfiguration->invertExhaustCamVVTSignal = true;
160
161 engineConfiguration->triggerInputPins[0] = Gpio::H144_IN_SENS2; // Digital Input 3
162 engineConfiguration->camInputs[0] = Gpio::H144_IN_SENS3; // Digital Input 4
163 engineConfiguration->camInputs[1] = Gpio::Unassigned;
164 engineConfiguration->sentInputPins[0] = Gpio::H144_IN_AUX2_DIGITAL;
165 setGmCltSensor(&engineConfiguration->clt);
166
167 // engineConfiguration->starterControlPin = high side :()
168 #endif // HW_HELLEN_4K_GDI
169
170 #ifdef HW_HELLEN_8CHAN
171 engineConfiguration->sentInputPins[0] = Gpio::MM176_IN_D3;
172 engineConfiguration->starterControlPin = Gpio::MM176_IGN5; // 14C
173
174 engineConfiguration->map.sensor.hwChannel = MM176_IN_CRANK_ANALOG; // 1A Aux Analog 1. Important to use analog without muxing!
175 engineConfiguration->fuelPumpPin = Gpio::MM176_OUT_IO2; // 6C - High Side 2 orange/brown
176 engineConfiguration->hpfpValvePin = Gpio::MM176_GP17; // 19D Injector 9
177
178 engineConfiguration->camInputs[2] = Gpio::Unassigned;
179 engineConfiguration->camInputs[3] = Gpio::Unassigned;
180 config->boardUseCrankPullUp = true;
181
182 engineConfiguration->starterControlPin = Gpio::PIN_5C; // 5C - High Side 1, ignition output is not enough at least on HHR
183 setGmCltSensor(&engineConfiguration->clt);
184 #endif // HW_HELLEN_8CHAN
185
186 setPPSCalibration(1, 4.25, 0.5, 2.14);
187
188 strcpy(engineConfiguration->engineMake, ENGINE_MAKE_GM);
189 engineConfiguration->etbFunctions[1] = DC_None;
190 setGDIFueling();
191 }
192
193 static void setGmEcotec3() {
194 setGmGdi();
195 engineConfiguration->sentEtbType = SentEtbType::GM_TYPE_1;
196 setTPS1Inputs(EFI_ADC_NONE, EFI_ADC_NONE);
197 engineConfiguration->EtbSentInput = SentInput::INPUT1;
198 }
199
200 static void set4CylGmEcotec3() {
201 setGmEcotec3();
202 engineConfiguration->hpfpCamLobes = 4;
203 setHpfpLobeProfileAngle(engineConfiguration->hpfpCamLobes);
204 engineConfiguration->vvtMode[1] = VVT_BOSCH_QUICK_START;
205 setInline4();
206 }
207
208 void setGmLcv() {
209 set4CylGmEcotec3();
210 engineConfiguration->displacement = 2.5;
211 engineConfiguration->map.sensor.type = MT_GM_1_BAR;
212 strcpy(engineConfiguration->engineCode, "LCV");
213 }
214
215 void setGmLnf() {
216 setGmGdi();
217 engineConfiguration->displacement = 2.0;
218 strcpy(engineConfiguration->engineCode, "LNF");
219 setTPS1Calibration(880, 129, 118, 870);
220
221 engineConfiguration->hpfpPeakPos = 0;
222
223 // todo: engineConfiguration->hpfpCam = HPFP_CAM_IN1;
224 #ifdef HW_HELLEN_8CHAN
225 engineConfiguration->vvtMode[1] = VVT_BOSCH_QUICK_START;
226 engineConfiguration->invertCamVVTSignal = true;
227 engineConfiguration->invertPrimaryTriggerSignal = true;
228 engineConfiguration->highPressureFuel.hwChannel = MM176_IN_MAP1_ANALOG; // 2A Aux Analog 4
229
230 engineConfiguration->vvtPins[0] = Gpio::MM176_OUT_PWM1;
231 engineConfiguration->vvtPins[1] = Gpio::MM176_OUT_PWM2;
232 #endif // HW_HELLEN_8CHAN
233 }
234
235 // 2.0T
236 void setGmLtg() {
237 set4CylGmEcotec3();
238 engineConfiguration->displacement = 2.0;
239 #ifdef HW_HELLEN_8CHAN
240 engineConfiguration->oilPressure.hwChannel = MM176_IN_MAP1_ANALOG; // 2A Aux Analog 4
241 engineConfiguration->invertCamVVTSignal = true;
242
243 engineConfiguration->triggerInputPins[0] = Gpio::MM176_IN_D4; // 9A - Hall Input 4
244
245 engineConfiguration->luaOutputPins[0] = Gpio::MM176_OUT_IO1; // 7C - High Side 3 - unusual starter
246 engineConfiguration->luaOutputPins[1] = Gpio::MM176_OUT_IO4, // 9C - Low Side 4 - unusual starter
247 #endif // HW_HELLEN_8CHAN
248 strcpy(engineConfiguration->engineCode, "LTG");
249 }
250
251 void setGmSbcGen5() {
252 setGmEcotec3();
253 engineConfiguration->hpfpCamLobes = 3;
254 engineConfiguration->displacement = 5.3;
255 engineConfiguration->cylindersCount = 8;
256 engineConfiguration->firingOrder = FO_1_8_7_2_6_5_4_3;
257 engineConfiguration->map.sensor.type = MT_GM_1_BAR;
258
259 // engineConfiguration->hpfpPumpVolume = 0.623; // LT4
260 engineConfiguration->hpfpPumpVolume = 0.49; // cc per stroke
261
262 // LT 17.7 g/sec at 100bar which 1440
263 // todo: real flow!
264 engineConfiguration->injector.flow = 990; // 12.6g/sec
265
266 #ifdef HW_HELLEN_8CHAN
267 engineConfiguration->mc33_hpfp_i_peak = 15;
268 engineConfiguration->mc33_hpfp_i_hold = 7;
269
270 engineConfiguration->injectionPins[4] = Gpio::MM176_INJ5;
271 engineConfiguration->injectionPins[5] = Gpio::MM176_INJ6;
272 engineConfiguration->injectionPins[6] = Gpio::MM176_INJ7;
273 engineConfiguration->injectionPins[7] = Gpio::MM176_INJ8;
274
275 engineConfiguration->ignitionPins[4] = Gpio::MM176_IGN5;
276 engineConfiguration->ignitionPins[5] = Gpio::MM176_IGN6;
277 engineConfiguration->ignitionPins[6] = Gpio::MM176_IGN7;
278 engineConfiguration->ignitionPins[7] = Gpio::MM176_IGN8;
279
280 engineConfiguration->starterControlPin = Gpio::MM176_SPI3_SCK; // 29C - Ignition 9
281
282 engineConfiguration->invertCamVVTSignal = true;
283 engineConfiguration->invertPrimaryTriggerSignal = true;
284 engineConfiguration->vvtMode[1] = VVT_INACTIVE;
285 engineConfiguration->camInputs[1] = Gpio::Unassigned;
286
287 // early models before SENT
288 // todo: early gen5 LS engines have redundant high pressure sensors #7364
289 engineConfiguration->highPressureFuel.v1 = 0.57; /* volts */;
290 engineConfiguration->highPressureFuel.value1 = 500;
291 engineConfiguration->highPressureFuel.v2 = 2.25; /* volts */;
292 engineConfiguration->highPressureFuel.value2 = 10900;
293
294 engineConfiguration->lowPressureFuel.v1 = 2.9; /* volts */;
295 engineConfiguration->lowPressureFuel.value1 = 435;
296 engineConfiguration->lowPressureFuel.v2 = 3.7; /* volts */;
297 engineConfiguration->lowPressureFuel.value2 = 576;
298
299 engineConfiguration->oilPressure.v1 = 0.6;
300 engineConfiguration->oilPressure.value1 = 0; // 100 kPa absolute
301 engineConfiguration->oilPressure.v2 = 2.6f;
302 engineConfiguration->oilPressure.value2 = 420; // 520 kPa absolute
303
304 engineConfiguration->oilPressure.hwChannel = MM176_IN_MAP1_ANALOG; // 2A Aux Analog 4
305 engineConfiguration->fuelLevelSensor = MM176_IN_O2S_ANALOG; // 3A - Aux Analog 2
306 engineConfiguration->lowPressureFuel.hwChannel = MM176_IN_AUX2_ANALOG; // 4A - Aux Analog 7
307 engineConfiguration->acPressure.hwChannel = MM176_IN_MAP2_ANALOG;// 10A - Aux Analog 5
308 engineConfiguration->flexSensorPin = Gpio::MM176_IN_SENS3;
309 #endif // HW_HELLEN_8CHAN
310 }
311