GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 90.3% 365 / 0 / 404
Functions: 79.2% 57 / 0 / 72
Branches: 84.0% 21 / 0 / 25
Decisions: 85.7% 18 / - / 21

firmware/controllers/algo/engine_configuration.cpp
Line Branch Decision Exec Source
1 /**
2 * @file engine_configuration.cpp
3 * @brief Utility method related to the engine configuration data structure.
4 *
5 * @date Nov 22, 2013
6 * @author Andrey Belomutskiy, (c) 2012-2020
7 *
8 * This file is part of rusEfi - see http://rusefi.com
9 *
10 * rusEfi is free software; you can redistribute it and/or modify it under the terms of
11 * the GNU General Public License as published by the Free Software Foundation; either
12 * version 3 of the License, or (at your option) any later version.
13 *
14 * rusEfi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
15 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with this program.
19 * If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23 #include "pch.h"
24 #include "transition_events.h"
25 #include "speed_density.h"
26 #include "flash_main.h"
27
28 #include "bench_test.h"
29
30 #if EFI_ONBOARD_MEMS
31 #include "accelerometer.h"
32 #endif // EFI_ONBOARD_MEMS
33
34 #include "defaults.h"
35
36 #include "custom_engine.h"
37
38 #include "boost_control.h"
39 #include "engine_configuration_defaults.h"
40 #if EFI_IDLE_CONTROL
41 #include "idle_thread.h"
42 #endif /* EFI_IDLE_CONTROL */
43
44 #if EFI_ALTERNATOR_CONTROL
45 #include "alternator_controller.h"
46 #endif
47
48 #if EFI_ELECTRONIC_THROTTLE_BODY
49 #include "electronic_throttle.h"
50 #endif
51
52 #include "hardware.h"
53
54 #if EFI_PROD_CODE
55 #include "board.h"
56 #endif /* EFI_PROD_CODE */
57
58 #if EFI_EMULATE_POSITION_SENSORS
59 #include "trigger_emulator_algo.h"
60 #endif /* EFI_EMULATE_POSITION_SENSORS */
61
62 #if EFI_TUNER_STUDIO
63 #include "tunerstudio.h"
64 #endif
65
66 #include "board_overrides.h"
67
68 #define TS_DEFAULT_SPEED 38400
69
70 std::optional<setup_custom_board_overrides_type> custom_board_DefaultConfiguration;
71 std::optional<setup_custom_board_overrides_type> custom_board_ConfigOverrides;
72 std::optional<setup_custom_board_config_type> custom_board_OnConfigurationChange;
73
74 /**
75 * Current engine configuration. On firmware start we assign empty configuration, then
76 * we copy actual configuration after reading settings from flash.
77 * This is useful to compare old/current (activeConfiguration) and new/future (engineConfiguration) configurations in order to apply new settings.
78 *
79 * todo: place this field next to 'engineConfiguration'?
80 */
81 static bool hasRememberedConfiguration = false;
82 #if EFI_ACTIVE_CONFIGURATION_IN_FLASH
83 #include "flash_int.h"
84 engine_configuration_s & activeConfiguration = reinterpret_cast<persistent_config_container_s*>(getFlashAddrFirstCopy())->persistentConfiguration.engineConfiguration;
85 // we cannot use this activeConfiguration until we call rememberCurrentConfiguration()
86 bool isActiveConfigurationVoid = true;
87 #else
88 static engine_configuration_s activeConfigurationLocalStorage;
89 engine_configuration_s & activeConfiguration = activeConfigurationLocalStorage;
90 #endif /* EFI_ACTIVE_CONFIGURATION_IN_FLASH */
91
92 819 void rememberCurrentConfiguration() {
93 #if ! EFI_ACTIVE_CONFIGURATION_IN_FLASH
94 819 memcpy(&activeConfiguration, engineConfiguration, sizeof(engine_configuration_s));
95 #else
96 isActiveConfigurationVoid = false;
97 #endif /* EFI_ACTIVE_CONFIGURATION_IN_FLASH */
98 819 hasRememberedConfiguration = true;
99 819 }
100
101 static void fillAfterString(char *string, int size) {
102 // we have to reset bytes after \0 symbol in order to calculate correct tune CRC from MSQ file
103 for (int i = std::strlen(string) + 1; i < size; i++) {
104 string[i] = 0;
105 }
106 }
107
108 static void wipeStrings() {
109 fillAfterString(engineConfiguration->engineMake, sizeof(vehicle_info_t));
110 fillAfterString(engineConfiguration->engineCode, sizeof(vehicle_info_t));
111 fillAfterString(engineConfiguration->vehicleName, sizeof(vehicle_info_t));
112 fillAfterString(engineConfiguration->vinNumber, sizeof(vin_number_t));
113 }
114
115 void onBurnRequest() {
116 onTransitionEvent(TransitionEvent::BurnRequest);
117 wipeStrings();
118
119 incrementGlobalConfigurationVersion("burn");
120 }
121
122 /**
123 * this hook is about https://wiki.rusefi.com/Custom-Firmware and https://wiki.rusefi.com/Canned-Tune-Process
124 * todo: why two hooks? is one already dead?
125 */
126 void boardBeforeTuneDefaults() {
127 // placeholder
128 }
129
130 void boardOnConfigurationChange(engine_configuration_s* /*previousConfiguration*/) {
131 // placeholder
132 }
133
134 /**
135 * this is the top-level method which should be called in case of any changes to engine configuration
136 * online tuning of most values in the maps does not count as configuration change, but 'Burn' command does
137 *
138 * this method is NOT currently invoked on ECU start - actual user input has to happen!
139 * See 'preCalculate' or 'startHardware' which are invoked BOTH on start and configuration change
140 */
141
1/1
✓ Decision 'true' taken 221 times.
221 void incrementGlobalConfigurationVersion(const char * msg) {
142 221 onTransitionEvent(TransitionEvent::GlobalConfigurationVersion);
143 assertStackVoid("increment", ObdCode::STACK_USAGE_MISC, EXPECTED_REMAINING_STACK);
144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 221 times.
1/2
✗ Decision 'true' not taken.
✓ Decision 'false' taken 221 times.
221 if (!hasRememberedConfiguration) {
145 criticalError("too early to invoke incrementGlobalConfigurationVersion %s", msg);
146 }
147 221 engine->globalConfigurationVersion++;
148 #if EFI_DETAILED_LOGGING
149 efiPrintf("set globalConfigurationVersion=%d", globalConfigurationVersion);
150 #endif /* EFI_DETAILED_LOGGING */
151
152 221 applyNewHardwareSettings();
153
154
1/1
✓ Branch 2 taken 221 times.
221 call_board_override(custom_board_OnConfigurationChange, &activeConfiguration);
155
156 221 engine->preCalculate();
157
158 #if EFI_ELECTRONIC_THROTTLE_BODY
159 221 onConfigurationChangeElectronicThrottleCallback(&activeConfiguration);
160 #endif /* EFI_ELECTRONIC_THROTTLE_BODY */
161
162 #if EFI_ENGINE_CONTROL && EFI_PROD_CODE
163 onConfigurationChangeBenchTest();
164 #endif
165
166 #if EFI_SHAFT_POSITION_INPUT
167 221 onConfigurationChangeTriggerCallback();
168 #endif /* EFI_SHAFT_POSITION_INPUT */
169 #if EFI_EMULATE_POSITION_SENSORS && ! EFI_UNIT_TEST
170 onConfigurationChangeRpmEmulatorCallback(&activeConfiguration);
171 #endif /* EFI_EMULATE_POSITION_SENSORS */
172
173 6851 engine->engineModules.apply_all([](auto & m) {
174 6851 m.onConfigurationChange(&activeConfiguration);
175 6851 });
176 221 rememberCurrentConfiguration();
177 }
178
179 /**
180 * @brief Sets the same dwell time across the whole getRpm() range
181 * set dwell X
182 */
183 1149 void setConstantDwell(floatms_t dwellMs) {
184
2/2
✓ Branch 0 taken 9192 times.
✓ Branch 1 taken 1149 times.
2/2
✓ Decision 'true' taken 9192 times.
✓ Decision 'false' taken 1149 times.
10341 for (int i = 0; i < DWELL_CURVE_SIZE; i++) {
185 9192 config->sparkDwellRpmBins[i] = 1000 * i;
186 }
187 1149 setArrayValues(config->sparkDwellValues, dwellMs);
188 1149 }
189
190 606 void setFuelTablesLoadBin(float minValue, float maxValue) {
191 606 setLinearCurve(config->injPhaseLoadBins, minValue, maxValue, 1);
192 606 setLinearCurve(config->veLoadBins, minValue, maxValue, 1);
193 606 setLinearCurve(config->lambdaLoadBins, minValue, maxValue, 1);
194 606 }
195
196 543 void setWholeIatCorrTimingTable(float value) {
197 543 setTable(config->ignitionIatCorrTable, value);
198 543 }
199
200 /**
201 * See also crankingTimingAngle
202 */
203 18 void setWholeTimingTable(angle_t value) {
204 18 setTable(config->ignitionTable, value);
205 18 }
206
207 #if EFI_ENGINE_CONTROL
208 namespace {
209 3005 void initTemperatureCurve(
210 float * const bins,
211 float * const values,
212 const int size,
213 const float defaultValue,
214 const float initialTemperature = -40.0f,
215 const float temperatureStep = 10.0f
216 ) {
217
2/2
✓ Branch 0 taken 21636 times.
✓ Branch 1 taken 3005 times.
2/2
✓ Decision 'true' taken 21636 times.
✓ Decision 'false' taken 3005 times.
24641 for (int i = 0; i < size; i++) {
218 21636 bins[i] = initialTemperature + i * temperatureStep;
219 21636 values[i] = defaultValue; // this correction is a multiplier
220 }
221 3005 }
222
223 2404 void initBoostTemperatureCurve(float* const bins, float* const values, const float defaultValue) {
224 2404 initTemperatureCurve(bins, values, BOOST_CURVE_SIZE, defaultValue, 20.0f, 20.0f);
225 2404 }
226 }
227 #endif // EFI_ENGINE_CONTROL
228
229 601 void prepareVoidConfiguration(engine_configuration_s *p_engineConfiguration) {
230
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 601 times.
601 criticalAssertVoid(p_engineConfiguration != nullptr, "ec NULL");
231 601 efi::clear(p_engineConfiguration);
232
233 601 p_engineConfiguration->clutchDownPinMode = PI_PULLUP;
234 601 p_engineConfiguration->clutchUpPinMode = PI_PULLUP;
235 601 p_engineConfiguration->brakePedalPinMode = PI_PULLUP;
236 }
237
238 601 void setDefaultBasePins() {
239 #if EFI_PROD_CODE
240 // call overrided board-specific serial configuration setup, if needed (for custom boards only)
241 // needed also by bootloader code
242 setPinConfigurationOverrides();
243 #endif /* EFI_PROD_CODE */
244
245 // set UART pads configuration based on the board
246 // needed also by bootloader code
247 #ifdef TS_SECONDARY_UxART_PORT
248 engineConfiguration->binarySerialTxPin = Gpio::C10;
249 engineConfiguration->binarySerialRxPin = Gpio::C11;
250 #endif // TS_SECONDARY_UxART_PORT
251
252 601 engineConfiguration->tunerStudioSerialSpeed = TS_DEFAULT_SPEED;
253 601 engineConfiguration->uartConsoleSerialSpeed = 115200;
254 601 }
255
256 // needed also by bootloader code
257 // at the moment bootloader does NOT really need SD card, this is a step towards future bootloader SD card usage
258 void setDefaultSdCardParameters() {
259 engineConfiguration->isSdCardEnabled = true;
260 }
261
262 #if EFI_ENGINE_CONTROL
263
264 /**
265 * see also setTargetRpmCurve()
266 */
267 601 static void setDefaultIdleSpeedTarget() {
268 #if CLT_CURVE_SIZE == 16
269
1/1
✓ Branch 2 taken 601 times.
601 copyArray(config->cltIdleRpmBins, { -30, - 20, -10, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 , 110, 120 });
270
1/1
✓ Branch 2 taken 601 times.
601 copyArray(config->cltIdleRpm, { 1350, 1350, 1300, 1200, 1150, 1100, 1050, 1000, 1000, 950, 950, 930, 900, 900, 1000, 1100 });
271 #endif // CLT_CURVE_SIZE
272 601 }
273 #endif // EFI_ENGINE_CONTROL
274
275 /**
276 * see also setDefaultIdleSpeedTarget()
277 */
278 2 void setTargetRpmCurve(float rpm) {
279 2 setLinearCurve(config->cltIdleRpmBins, CLT_CURVE_RANGE_FROM, 140, 10);
280 2 setLinearCurve(config->cltIdleRpm, rpm, rpm, 10);
281 2 }
282
283 601 static void setDefaultGppwmParameters() {
284 // Same config for all channels
285
2/2
✓ Branch 1 taken 2404 times.
✓ Branch 2 taken 601 times.
2/2
✓ Decision 'true' taken 2404 times.
✓ Decision 'false' taken 601 times.
3005 for (size_t i = 0; i < efi::size(engineConfiguration->gppwm); i++) {
286 2404 auto& cfg = engineConfiguration->gppwm[i];
287 2404 chsnprintf(engineConfiguration->gpPwmNote[i], sizeof(engineConfiguration->gpPwmNote[0]), "GPPWM%d", i);
288
289 // Set default axes
290 2404 cfg.loadAxis = GPPWM_Zero;
291 2404 cfg.rpmAxis = GPPWM_Rpm;
292
293 2404 cfg.pin = Gpio::Unassigned;
294 2404 cfg.dutyIfError = 0;
295 2404 cfg.onAboveDuty = 60;
296 2404 cfg.offBelowDuty = 50;
297 2404 cfg.pwmFrequency = 250;
298
299
2/2
✓ Branch 1 taken 19232 times.
✓ Branch 2 taken 2404 times.
2/2
✓ Decision 'true' taken 19232 times.
✓ Decision 'false' taken 2404 times.
21636 for (size_t j = 0; j < efi::size(cfg.loadBins); j++) {
300 19232 uint8_t z = j * 100 / (efi::size(cfg.loadBins) - 1);
301 19232 cfg.loadBins[j] = z;
302
303 // Fill some values in the table
304
2/2
✓ Branch 1 taken 153856 times.
✓ Branch 2 taken 19232 times.
2/2
✓ Decision 'true' taken 153856 times.
✓ Decision 'false' taken 19232 times.
173088 for (size_t k = 0; k < efi::size(cfg.rpmBins); k++) {
305 153856 cfg.table[j][k] = z;
306 }
307
308 }
309
310
2/2
✓ Branch 1 taken 19232 times.
✓ Branch 2 taken 2404 times.
2/2
✓ Decision 'true' taken 19232 times.
✓ Decision 'false' taken 2404 times.
21636 for (size_t j = 0; j < efi::size(cfg.rpmBins); j++) {
311 19232 cfg.rpmBins[j] = 1000 * j;
312 }
313 }
314 601 }
315
316 601 static void setDefaultBoostOpenLoopParameters() {
317 601 engineConfiguration->boostOpenLoopYAxis = GPPWM_Tps;
318 601 }
319
320 #if EFI_ENGINE_CONTROL
321 601 static void setDefaultEngineNoiseTable() {
322 601 setRpmTableBin(config->knockNoiseRpmBins);
323
324 601 engineConfiguration->knockDetectionWindowStart = 15.0 + 5.0;
325 601 engineConfiguration->knockSamplingDuration = 45;
326
327 601 setArrayValues(config->knockBaseNoise, -20);
328 601 }
329 #endif // EFI_ENGINE_CONTROL
330
331 601 static void setDefaultCanSettings() {
332 // OBD-II default rate is 500kbps
333 601 engineConfiguration->canBaudRate = B500KBPS;
334 601 engineConfiguration->can2BaudRate = B500KBPS;
335 #if (EFI_CAN_BUS_COUNT >= 3)
336 engineConfiguration->can3BaudRate = B500KBPS;
337 #endif
338
339 601 engineConfiguration->canSleepPeriodMs = 50;
340 601 engineConfiguration->canReadEnabled = true;
341 601 engineConfiguration->canWriteEnabled = true;
342 601 engineConfiguration->canVssScaling = 1.0f;
343
344 // Don't enable, but set default address
345 601 engineConfiguration->verboseCanBaseAddress = CAN_DEFAULT_BASE;
346 601 }
347
348 601 static void setDefaultScriptParameters() {
349 601 setLinearCurve(config->scriptTable1LoadBins, 20, 120, 10);
350 601 setRpmTableBin(config->scriptTable1RpmBins);
351 601 setLinearCurve(config->scriptTable2LoadBins, 20, 120, 10);
352 601 setRpmTableBin(config->scriptTable2RpmBins);
353 601 setLinearCurve(config->scriptTable3LoadBins, 20, 120, 10);
354 601 setRpmTableBin(config->scriptTable3RpmBins);
355 601 setLinearCurve(config->scriptTable4LoadBins, 20, 120, 10);
356 601 setRpmTableBin(config->scriptTable4RpmBins);
357 601 }
358
359 601 static void setDefaultIdleOpenLoopParameters() {
360 601 setRpmTableBin(config->rpmIdleCorrBins);
361 601 setLinearCurve(config->cltIdleCorrBins, CLT_CURVE_RANGE_FROM, 140, 10);
362
2/2
✓ Branch 0 taken 1202 times.
✓ Branch 1 taken 601 times.
2/2
✓ Decision 'true' taken 1202 times.
✓ Decision 'false' taken 601 times.
1803 for (size_t i = 0; i < CLT_IDLE_TABLE_RPM_SIZE; i++) {
363 1202 setLinearCurve(config->cltIdleCorrTable[i], 75.0, 50, 5);
364 }
365 601 }
366
367 /**
368 * @brief Global default engine configuration
369 * This method sets the global engine configuration defaults. These default values are then
370 * overridden by engine-specific defaults and the settings are saved in flash memory.
371 *
372 * This method is invoked only when new configuration is needed:
373 * * recently re-flashed chip
374 * * flash version of configuration failed CRC check or appears to be older then FLASH_DATA_VERSION
375 * * 'rewriteconfig' command
376 * * 'set engine_type X' command
377 *
378 * This method should only change the state of the configuration data structure but should NOT change the state of
379 * anything else.
380 *
381 * This method should NOT be setting any default pinout
382 */
383 601 static void setDefaultEngineConfiguration() {
384 #if (! EFI_UNIT_TEST)
385 efi::clear(persistentState.persistentConfiguration);
386 #endif
387 601 prepareVoidConfiguration(engineConfiguration);
388
389 #if EFI_BOOST_CONTROL
390 601 setDefaultBoostParameters();
391 #endif
392
393 601 setDefaultCanSettings();
394
395 601 engineConfiguration->sdCardLogFrequency = 50;
396
397 601 setDefaultGppwmParameters();
398 601 setDefaultBoostOpenLoopParameters();
399 601 setDefaultScriptParameters();
400
401 #if EFI_ENGINE_CONTROL
402 601 setDefaultBaseEngine();
403 601 setDefaultFuel();
404 601 setDefaultIgnition();
405 601 setDefaultCranking();
406
407 // VVT closed loop, totally random values!
408 601 engineConfiguration->auxPid[0].pFactor = 2;
409 601 engineConfiguration->auxPid[0].iFactor = 0.005;
410 601 engineConfiguration->auxPid[0].dFactor = 0;
411 601 engineConfiguration->auxPid[0].offset = 33;
412 601 engineConfiguration->auxPid[0].minValue = 10;
413 601 engineConfiguration->auxPid[0].maxValue = 90;
414
415 601 engineConfiguration->vvtOutputFrequency = DEFAULT_SOLENOID_FREQUENCY; // VVT solenoid control
416
417 601 engineConfiguration->isCylinderCleanupEnabled = true;
418
419 601 engineConfiguration->auxPid[0].minValue = 10;
420 601 engineConfiguration->auxPid[0].maxValue = 90;
421 601 engineConfiguration->auxPid[1].minValue = 10;
422 601 engineConfiguration->auxPid[1].maxValue = 90;
423
424 601 engineConfiguration->turboSpeedSensorMultiplier = 1;
425
426 #if EFI_IDLE_CONTROL
427 601 setDefaultIdleParameters();
428 #endif /* EFI_IDLE_CONTROL */
429
430 #if EFI_ELECTRONIC_THROTTLE_BODY
431 601 setDefaultEtbParameters();
432 601 setDefaultEtbBiasCurve();
433 #endif /* EFI_ELECTRONIC_THROTTLE_BODY */
434
435 601 setBosch0280218037();
436
437 601 engineConfiguration->mapMinBufferLength = 1;
438 601 engineConfiguration->vvtActivationDelayMs = 6000;
439
440 601 engineConfiguration->startCrankingDuration = 3;
441
442 601 engineConfiguration->maxAcRpm = 5000;
443 601 engineConfiguration->maxAcClt = 100;
444 601 engineConfiguration->maxAcTps = 75;
445
446 601 initTemperatureCurve(IAT_FUEL_CORRECTION_CURVE, 1);
447
448 601 initBoostTemperatureCurve(config->cltBoostCorrBins, config->cltBoostCorr, 1.0f);
449 601 initBoostTemperatureCurve(config->iatBoostCorrBins, config->iatBoostCorr, 1.0f);
450 601 initBoostTemperatureCurve(config->cltBoostAdderBins, config->cltBoostAdder, 0.0f);
451 601 initBoostTemperatureCurve(config->iatBoostAdderBins, config->iatBoostAdder, 0.0f);
452
453 601 engineConfiguration->alternatorControl.minValue = 0;
454 601 engineConfiguration->alternatorControl.maxValue = 90;
455
456 601 setLinearCurve(config->scriptCurve1Bins, 0, 100, 1);
457 601 setLinearCurve(config->scriptCurve1, 0, 100, 1);
458
459 601 setLinearCurve(config->scriptCurve2Bins, 0, 100, /*precision*/1);
460 601 setLinearCurve(config->scriptCurve2, 30, 170, 1);
461
462 601 setLinearCurve(config->scriptCurve3Bins, 0, 100, 1);
463 601 setLinearCurve(config->scriptCurve4Bins, 0, 100, 1);
464 601 setLinearCurve(config->scriptCurve5Bins, 0, 100, 1);
465 601 setLinearCurve(config->scriptCurve6Bins, 0, 100, 1);
466
467 601 setLinearCurve(config->alsIgnRetardLoadBins, 2, 10, /*precision*/1);
468 601 setRpmTableBin(config->alsIgnRetardrpmBins);
469 601 setLinearCurve(config->alsFuelAdjustmentLoadBins, 2, 10, /*precision*/1);
470 601 setRpmTableBin(config->alsFuelAdjustmentrpmBins);
471 601 setLinearCurve(config->fuelLevelBins, 0, 5);
472
473
474 601 setRpmTableBin(engineConfiguration->map.samplingAngleBins);
475 601 setLinearCurve(engineConfiguration->map.samplingAngle, 100, 130, 1);
476 601 setRpmTableBin(engineConfiguration->map.samplingWindowBins);
477 601 setLinearCurve(engineConfiguration->map.samplingWindow, 50, 50, 1);
478
479 #if VVT_TABLE_SIZE == 8
480 601 setLinearCurve(config->vvtTable1LoadBins, 20, 120, 10);
481 601 setLinearCurve(config->vvtTable2LoadBins, 20, 120, 10);
482 #else
483 setLinearCurve(config->vvtTable1LoadBins, 20, 120, 5);
484 setLinearCurve(config->vvtTable2LoadBins, 20, 120, 5);
485 #endif
486 601 setRpmTableBin(config->vvtTable1RpmBins);
487 601 setRpmTableBin(config->vvtTable2RpmBins);
488
489 601 setDefaultEngineNoiseTable();
490
491 // is this same old setCommonNTCSensor?
492 601 engineConfiguration->clt.config = {0, 23.8889, 48.8889, 9500, 2100, 1000, 1500};
493
494 601 setCommonNTCSensorParameters(&engineConfiguration->iat);
495
496 // wow unit tests have much cooler setDefaultLaunchParameters method
497 601 engineConfiguration->launchRpm = 3000;
498 // engineConfiguration->launchTimingRetard = 10;
499 601 engineConfiguration->launchRpmWindow = 500;
500 601 engineConfiguration->launchSpeedThreshold = 30;
501
502 601 engineConfiguration->engineSnifferRpmThreshold = 2500;
503
504 /**
505 * Idle control defaults
506 */
507 601 setDefaultIdleSpeedTarget();
508 // setTargetRpmCurve(1200);
509
510 601 engineConfiguration->idleRpmPid.pFactor = 0.05;
511 601 engineConfiguration->idleRpmPid.iFactor = 0.002;
512
513 601 engineConfiguration->idleRpmPid.minValue = -20;
514 601 engineConfiguration->idleRpmPid.maxValue = 20;
515 /**
516 * between variation between different sensor and weather and fabrication tolerance
517 * five percent looks like a safer default
518 */
519 601 engineConfiguration->idlePidDeactivationTpsThreshold = 5;
520
521 601 engineConfiguration->idle.solenoidFrequency = DEFAULT_SOLENOID_FREQUENCY;
522 // set idle_position 50
523 601 setDefaultIdleOpenLoopParameters();
524 // engineConfiguration->idleMode = IM_AUTO;
525 601 engineConfiguration->idleMode = idle_mode_e::IM_MANUAL;
526
527 601 engineConfiguration->useStepperIdle = false;
528
529 601 setLinearCurve(config->iacCoastingRpmBins, 0, 8000, 1);
530
531 #if !EFI_UNIT_TEST
532 // todo: remove from *engine* defaults, move into boards?
533 engineConfiguration->analogInputDividerCoefficient = 2;
534 #endif
535
536
537 601 setTPS1Calibration(convertVoltageTo10bitADC(0),
538 601 convertVoltageTo10bitADC(5),
539 601 convertVoltageTo10bitADC(5),
540 601 convertVoltageTo10bitADC(0));
541
542 601 engineConfiguration->tps2Min = convertVoltageTo10bitADC(0);
543 601 engineConfiguration->tps2Max = convertVoltageTo10bitADC(5);
544 601 engineConfiguration->tps2SecondaryMin = convertVoltageTo10bitADC(5);
545 601 engineConfiguration->tps2SecondaryMax = convertVoltageTo10bitADC(0);
546
547 601 engineConfiguration->idlePositionMin = PACK_MULT_VOLTAGE * 0;
548 601 engineConfiguration->idlePositionMax = PACK_MULT_VOLTAGE * 5;
549 601 engineConfiguration->wastegatePositionClosedVoltage = 0.0;
550 601 engineConfiguration->wastegatePositionOpenedVoltage = 5.0;
551 601 engineConfiguration->tpsErrorDetectionTooLow = -10; // -10% open
552 601 engineConfiguration->tpsErrorDetectionTooHigh = 110; // 110% open
553
554 601 engineConfiguration->oilPressure.v1 = 0.5f;
555 601 engineConfiguration->oilPressure.v2 = 4.5f;
556 601 engineConfiguration->oilPressure.value1 = 0;
557 601 engineConfiguration->oilPressure.value2 = 689.476f; // 100psi = 689.476kPa
558
559 601 engineConfiguration->mapLowValueVoltage = 0;
560 // todo: start using this for custom MAP
561 601 engineConfiguration->mapHighValueVoltage = 5;
562
563 601 engineConfiguration->cylinderBore = 87.5;
564
565 601 setBoschHDEV_5_injectors();
566
567 601 setEgoSensor(ES_14Point7_Free);
568
569 // todo: remove from *engine* defaults, move into boards?
570 601 engineConfiguration->adcVcc = 3.0;
571
572 601 engineConfiguration->map.sensor.type = MT_MPX4250;
573
574 601 engineConfiguration->baroSensor.type = MT_CUSTOM;
575 601 engineConfiguration->baroSensor.lowValue = 0;
576 601 engineConfiguration->baroSensor.highValue = 500;
577
578 #if EFI_PROD_CODE
579 engineConfiguration->engineChartSize = 300;
580 #else
581 // need more events for automated test
582 601 engineConfiguration->engineChartSize = 400;
583 #endif
584
585 #if EFI_PROD_CODE || EFI_SIMULATOR
586 // some tests broke with map averaging, see https://github.com/rusefi/rusefi/issues/7868
587 engineConfiguration->isMapAveragingEnabled = true;
588 #endif
589 601 engineConfiguration->isWaveAnalyzerEnabled = true;
590
591 601 engineConfiguration->acIdleRpmTarget = 900;
592 601 engineConfiguration->acDelay = engine_configuration_defaults::AC_DELAY;
593 601 engineConfiguration->minAcPressure = engine_configuration_defaults::MIN_AC_PRESSURE;
594 601 engineConfiguration->maxAcPressure = engine_configuration_defaults::MAX_AC_PRESSURE;
595 601 engineConfiguration->acPressureEnableHyst = engine_configuration_defaults::AC_PRESSURE_ENABLE_HYST;
596 601 engineConfiguration->acIdleExtraOffset = 15;
597
598 601 engineConfiguration->nitrousMinimumTps = engine_configuration_defaults::NITROUS_MINIMUM_TPS;
599 601 engineConfiguration->nitrousMinimumClt = engine_configuration_defaults::NITROUS_MINIMUM_CLT;
600 601 engineConfiguration->nitrousMaximumAfr = engine_configuration_defaults::NITROUS_MAXIMUM_AFR;
601 601 engineConfiguration->nitrousActivationRpm = engine_configuration_defaults::NITROUS_ACTIVATION_RPM;
602 601 engineConfiguration->nitrousDeactivationRpm = engine_configuration_defaults::NITROUS_DEACTIVATION_RPM;
603 601 engineConfiguration->nitrousDeactivationRpmWindow = engine_configuration_defaults::NITROUS_DEACTIVATION_RPM_WINDOW;
604
605 601 engineConfiguration->triggerSimulatorRpm = DEFAULT_SELT_STIM_RPM;
606 601 engineConfiguration->simulatorCamPosition[0] = DEFAULT_SELT_STIM_VVT0;
607
608 601 engineConfiguration->alternatorPwmFrequency = DEFAULT_SOLENOID_FREQUENCY;
609
610 601 engineConfiguration->isAlternatorControlEnabled = false;
611
612 601 engineConfiguration->driveWheelRevPerKm = 1000;
613 601 engineConfiguration->finalGearRatio = 1;
614 601 engineConfiguration->vssGearRatio = 3.73;
615 601 engineConfiguration->vssToothCount = 21;
616
617 601 engineConfiguration->mapErrorDetectionTooLow = 5;
618 // todo: default limits should be hard-coded for each sensor type
619 // https://github.com/rusefi/rusefi/issues/4030
620 601 engineConfiguration->mapErrorDetectionTooHigh = 410;
621
622 601 setLinearCurve(config->throttleEstimateEffectiveAreaBins, 0, 100);
623 #endif // EFI_ENGINE_CONTROL
624 // Allow custom default_script.lua to be provided by BOARDINC
625 // see https://gcc.gnu.org/onlinedocs/gcc-2.95.3/cpp_1.html#SEC6
626 #include <default_script.lua>
627 601 }
628
629 #if defined(STM32F7) && defined(HARDWARE_CI)
630 // part of F7 drama looks like we are having a hard time erasing configuration on HW CI :(
631 #define IGNORE_FLASH_CONFIGURATION true
632 #endif
633
634 // by default, do not ignore config from flash! use it!
635 #ifndef IGNORE_FLASH_CONFIGURATION
636 #define IGNORE_FLASH_CONFIGURATION false
637 #endif
638
639 void loadConfiguration() {
640
641 #if ! EFI_ACTIVE_CONFIGURATION_IN_FLASH
642 // Clear the active configuration so that registered output pins (etc) detect the change on startup and init properly
643 prepareVoidConfiguration(&activeConfiguration);
644 #endif /* EFI_ACTIVE_CONFIGURATION_IN_FLASH */
645
646 /* If board have any storage */
647 #if EFI_CONFIGURATION_STORAGE
648 if (IGNORE_FLASH_CONFIGURATION) {
649 engineConfiguration->engineType = DEFAULT_ENGINE_TYPE;
650 resetConfigurationExt(engineConfiguration->engineType);
651 writeToFlashNow();
652 } else {
653 // this call reads configuration from flash memory or sets default configuration
654 // if flash state does not look right.
655 readFromFlash();
656 }
657 #else
658 // This board doesn't load configuration, initialize the default
659 engineConfiguration->engineType = DEFAULT_ENGINE_TYPE;
660 resetConfigurationExt(engineConfiguration->engineType);
661 #endif /* EFI_CONFIGURATION_STORAGE */
662
663 // Force any board configuration options that humans shouldn't be able to change
664 call_board_override(custom_board_ConfigOverrides);
665 }
666
667 601 void resetConfigurationExt(configuration_callback_t boardCallback, engine_type_e engineType) {
668 601 enginePins.reset(); // that's mostly important for functional tests
669 /**
670 * Let's apply global defaults first
671 */
672 601 setDefaultEngineConfiguration();
673
674 /**
675 * custom board engine defaults. Yes, this overlaps with (older) engine_type_e approach.
676 */
677 601 call_board_override(custom_board_BeforeTuneDefaults);
678
679 // set initial pin groups
680 601 setDefaultBasePins();
681
682
2/2
✓ Branch 0 taken 599 times.
✓ Branch 1 taken 2 times.
2/2
✓ Decision 'true' taken 599 times.
✓ Decision 'false' taken 2 times.
601 if (boardCallback != nullptr) {
683 599 boardCallback(engineConfiguration);
684 }
685
686 #if EFI_PROD_CODE
687 // call board-specific configuration setup, if needed (for custom boards only)
688 call_board_override(custom_board_DefaultConfiguration);
689 call_board_override(custom_board_ConfigOverrides);
690 #endif // EFI_PROD_CODE
691
692 601 engineConfiguration->engineType = engineType;
693 601 applyEngineType(engineType);
694 601 applyNonPersistentConfiguration();
695 601 }
696
697 590 void emptyCallbackWithConfiguration(engine_configuration_s * p_engineConfiguration) {
698 UNUSED(p_engineConfiguration);
699 590 }
700
701 1 void resetConfigurationExt(engine_type_e engineType) {
702 1 resetConfigurationExt(&emptyCallbackWithConfiguration, engineType);
703 1 }
704
705 602 void applyNonPersistentConfiguration() {
706 #if EFI_PROD_CODE
707 efiAssertVoid(ObdCode::CUSTOM_APPLY_STACK, hasLotsOfRemainingStack(), "apply c");
708 efiPrintf("applyNonPersistentConfiguration()");
709 #endif
710
711 #if EFI_ENGINE_CONTROL
712 602 engine->updateTriggerConfiguration();
713 #endif // EFI_ENGINE_CONTROL
714 602 }
715
716 666 void setCamOperationMode() {
717 666 engineConfiguration->skippedWheelOnCam = true;
718 666 }
719
720 23 void setCrankOperationMode() {
721 // this is related to 'setDefaultBaseEngine' having 'skippedWheelOnCam = true' which is a weird fact by itself
722 23 engineConfiguration->skippedWheelOnCam = false;
723 23 }
724
725 14 void commonFrankensoAnalogInputs() {
726 /**
727 * VBatt
728 */
729 14 engineConfiguration->vbattAdcChannel = EFI_ADC_14;
730 14 }
731
732 void setBoardDefaultConfiguration() {
733 // custom_board_DefaultConfiguration
734 }
735 void setBoardConfigOverrides() {
736 // time to force migration to custom_board_ConfigOverrides
737 }
738
739 PUBLIC_API_WEAK int hackHellenBoardId(int detectedId) { return detectedId; }
740
741 PUBLIC_API_WEAK void onBoardStandBy() { }
742
743 PUBLIC_API_WEAK_SOMETHING_WEIRD int getBoardMetaOutputsCount() { return 0; }
744 // default implementation: treat all outputs as low side
745 PUBLIC_API_WEAK int getBoardMetaLowSideOutputsCount() { return getBoardMetaOutputsCount(); }
746 PUBLIC_API_WEAK Gpio* getBoardMetaOutputs() { return nullptr; }
747 PUBLIC_API_WEAK int getBoardMetaDcOutputsCount() { return 0; }
748