GCC Code Coverage Report


Directory: ./
File: firmware/controllers/engine_cycle/aux_valves.cpp
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 81.2% 39 0 48
Functions: 80.0% 4 0 5
Branches: 84.0% 21 0 25
Decisions: 78.6% 11 - 14

Line Branch Decision Exec Source
1 /*
2 * @file aux_valves.cpp
3 *
4 *
5 * Here we have two auxilary digital on/off outputs which would open once per each 360 degrees of engine crank revolution.
6 * The second valve is 180 degrees after the first one.
7 *
8 * Valve open and close angles are taken from scriptCurve1 and scriptCurve2 tables respectively, the position depend on TPS input.
9 *
10 * https://github.com/rusefi/rusefi/issues/490
11 *
12 * @date Nov 25, 2017
13 * @author Andrey Belomutskiy, (c) 2012-2020
14 */
15
16 #include "pch.h"
17
18 #include "aux_valves.h"
19 #include "trigger_central.h"
20 #include "spark_logic.h"
21
22 #if EFI_AUX_VALVES
23
24 static void plainPinTurnOff(NamedOutputPin *output) {
25 output->setLow();
26 }
27
28
29 5 static void scheduleOpen(AuxActor *current) {
30 5 engine->module<TriggerScheduler>()->schedule(
31 "aux-valve",
32 &current->open,
33
1/1
✓ Branch 1 taken 5 times.
5 current->extra + engine->engineState.auxValveStart,
34 10 action_s::make<auxPlainPinTurnOn>( current )
35 );
36 5 }
37
38 1 void auxPlainPinTurnOn(AuxActor *current) {
39 1 NamedOutputPin *output = &enginePins.auxValve[current->valveIndex];
40
1/1
✓ Branch 1 taken 1 time.
1 output->setHigh();
41
42
1/1
✓ Branch 1 taken 1 time.
1 scheduleOpen(current);
43
44 1 angle_t duration = engine->engineState.auxValveEnd - engine->engineState.auxValveStart;
45
46
1/1
✓ Branch 1 taken 1 time.
1 wrapAngle(duration, "duration", ObdCode::CUSTOM_ERR_6557);
47
48
1/1
✓ Branch 1 taken 1 time.
1 engine->module<TriggerScheduler>()->schedule(
49 "aux-valve",
50 &current->close,
51
1/1
✓ Branch 1 taken 1 time.
1 current->extra + engine->engineState.auxValveEnd,
52 2 action_s::make<plainPinTurnOff>( output )
53 );
54 1 }
55
56 585 void initAuxValves() {
57
2/2
✓ Branch 1 taken 584 times.
✓ Branch 2 taken 1 time.
2/2
✓ Decision 'true' taken 584 times.
✓ Decision 'false' taken 1 time.
585 if (!isBrainPinValid(engineConfiguration->auxValves[0])) {
58 584 return;
59 }
60
61
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
1/2
✗ Decision 'true' not taken.
✓ Decision 'false' taken 1 time.
1 if (!Sensor::hasSensor(SensorType::DriverThrottleIntent)) {
62 firmwareError(ObdCode::CUSTOM_OBD_91, "No TPS for Aux Valves");
63 return;
64 }
65
66 1 recalculateAuxValveTiming();
67
68
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
2/2
✓ Decision 'true' taken 2 times.
✓ Decision 'false' taken 1 time.
3 for (int valveIndex = 0; valveIndex < AUX_DIGITAL_VALVE_COUNT; valveIndex++) {
69
70
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
2/2
✓ Decision 'true' taken 4 times.
✓ Decision 'false' taken 2 times.
6 for (int phaseIndex = 0; phaseIndex < 2; phaseIndex++) {
71 4 AuxActor *actor = &engine->auxValves[valveIndex][phaseIndex];
72 4 actor->phaseIndex = phaseIndex;
73 4 actor->valveIndex = valveIndex;
74 4 actor->extra = phaseIndex * 360 + valveIndex * 180;
75
76 4 scheduleOpen(actor);
77 }
78 }
79 }
80
81 1121 void recalculateAuxValveTiming() {
82
3/3
✓ Branch 1 taken 1121 times.
✓ Branch 3 taken 1119 times.
✓ Branch 4 taken 2 times.
2/2
✓ Decision 'true' taken 1119 times.
✓ Decision 'false' taken 2 times.
1121 if (!isBrainPinValid(engineConfiguration->auxValves[0])) {
83 1119 return;
84 }
85
86
1/1
✓ Branch 2 taken 2 times.
2 auto tps = Sensor::get(SensorType::DriverThrottleIntent);
87
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
1/2
✗ Decision 'true' not taken.
✓ Decision 'false' taken 2 times.
2 if (!tps) {
88 // error should be already reported by now
89 return;
90 }
91
92 4 engine->engineState.auxValveStart = interpolate2d(tps.Value,
93 2 config->scriptCurve1Bins,
94
1/1
✓ Branch 1 taken 2 times.
2 config->scriptCurve1);
95
96 4 engine->engineState.auxValveEnd = interpolate2d(tps.Value,
97 2 config->scriptCurve2Bins,
98
1/1
✓ Branch 1 taken 2 times.
2 config->scriptCurve2);
99
100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
1/2
✗ Decision 'true' not taken.
✓ Decision 'false' taken 2 times.
2 if (engine->engineState.auxValveStart >= engine->engineState.auxValveEnd) {
101 // this is a fatal error to make this really visible
102 firmwareError(ObdCode::CUSTOM_AUX_OUT_OF_ORDER, "out of order at %.2f %.2f %.2f", tps,
103 engine->engineState.auxValveStart,
104 engine->engineState.auxValveEnd);
105 }
106 }
107
108 #endif // EFI_AUX_VALVES
109