GCC Code Coverage Report


Directory: ./
File: firmware/controllers/trigger/decoders/trigger_misc.cpp
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 100.0% 113 0 113
Functions: 100.0% 11 0 11
Branches: 100.0% 8 0 8
Decisions: 100.0% 9 - 9

Line Branch Decision Exec Source
1 /*
2 * trigger_misc.cpp
3 *
4 * Created on: Oct 30, 2018
5 * @author Andrey Belomutskiy, (c) 2012-2020
6 */
7
8 #include "pch.h"
9
10 #include "trigger_misc.h"
11 #include "trigger_universal.h"
12
13 // TT_FIAT_IAW_P8
14 1 void configureFiatIAQ_P8(TriggerWaveform * s) {
15 1 s->initialize(FOUR_STROKE_CAM_SENSOR, SyncEdge::Rise);
16
17 1 int width = 60;
18 1 s->tdcPosition = width;
19
20 1 s->addEvent720(width, TriggerValue::RISE);
21 1 s->addEvent720(180, TriggerValue::FALL);
22
23 1 s->addEvent720(180 + width, TriggerValue::RISE);
24 1 s->addEvent720(720, TriggerValue::FALL);
25 1 s->setTriggerSynchronizationGap(3);
26 1 }
27
28 // TT_TRI_TACH
29 1 void configureTriTach(TriggerWaveform * s) {
30 1 s->initialize(FOUR_STROKE_CRANK_SENSOR, SyncEdge::RiseOnly);
31
32 1 s->isSynchronizationNeeded = false;
33
34 1 float toothWidth = 0.5;
35
36 1 float engineCycle = FOUR_STROKE_ENGINE_CYCLE;
37
38 1 int totalTeethCount = 135;
39 1 float offset = 0;
40
41 1 float angleDown = engineCycle / totalTeethCount * (0 + (1 - toothWidth));
42 1 float angleUp = engineCycle / totalTeethCount * (0 + 1);
43 1 s->addEventClamped(offset + angleDown, TriggerValue::RISE, TriggerWheel::T_PRIMARY, NO_LEFT_FILTER, NO_RIGHT_FILTER);
44 1 s->addEventClamped(offset + angleDown + 0.1, TriggerValue::RISE, TriggerWheel::T_SECONDARY, NO_LEFT_FILTER, NO_RIGHT_FILTER);
45 1 s->addEventClamped(offset + angleUp, TriggerValue::FALL, TriggerWheel::T_PRIMARY, NO_LEFT_FILTER, NO_RIGHT_FILTER);
46 1 s->addEventClamped(offset + angleUp + 0.1, TriggerValue::FALL, TriggerWheel::T_SECONDARY, NO_LEFT_FILTER, NO_RIGHT_FILTER);
47
48
49 1 addSkippedToothTriggerEvents(TriggerWheel::T_SECONDARY, s, totalTeethCount, /* skipped */ 0, toothWidth, offset, engineCycle,
50 1.0 * FOUR_STROKE_ENGINE_CYCLE / 135,
51 NO_RIGHT_FILTER);
52 1 }
53
54 /**
55 * based on https://fordsix.com/threads/understanding-standard-and-signature-pip-thick-film-ignition.81515/
56 * based on https://www.w8ji.com/distributor_stabbing.htm
57 */
58 1 void configureFordPip(TriggerWaveform * s) {
59 1 s->initialize(FOUR_STROKE_CAM_SENSOR, SyncEdge::Rise);
60
61 1 s->tdcPosition = 662.5;
62
63 1 s->setTriggerSynchronizationGap(0.66);
64 1 s->setSecondTriggerSynchronizationGap(1.25);
65 /**
66 * sensor is mounted on distributor but trigger shape is defined in engine cycle angles
67 */
68 1 int oneCylinder = s->getCycleDuration() / 8;
69
70 1 s->addEventAngle(oneCylinder * 0.75, TriggerValue::RISE);
71 1 s->addEventAngle(oneCylinder, TriggerValue::FALL);
72
73
74
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 time.
2/2
✓ Decision 'true' taken 7 times.
✓ Decision 'false' taken 1 time.
8 for (int i = 2;i<=8;i++) {
75 7 s->addEventAngle(oneCylinder * (i - 0.5), TriggerValue::RISE);
76 7 s->addEventAngle(oneCylinder * i, TriggerValue::FALL);
77 }
78
79 1 }
80
81 1 void configureFordST170(TriggerWaveform * s) {
82 1 s->initialize(FOUR_STROKE_CAM_SENSOR, SyncEdge::RiseOnly);
83 1 int width = 10;
84
85 1 int total = s->getCycleDuration() / 8;
86
87 1 s->addEventAngle(1 * total - width, TriggerValue::RISE);
88 1 s->addEventAngle(1 * total, TriggerValue::FALL);
89
90 1 s->addEventAngle(2 * total - width, TriggerValue::RISE);
91 1 s->addEventAngle(2 * total, TriggerValue::FALL);
92
93 1 s->addEventAngle(4 * total - width, TriggerValue::RISE);
94 1 s->addEventAngle(4 * total, TriggerValue::FALL);
95
96 1 s->addEventAngle(6 * total - width, TriggerValue::RISE);
97 1 s->addEventAngle(6 * total, TriggerValue::FALL);
98
99 1 s->addEventAngle(8 * total - width, TriggerValue::RISE);
100 1 s->addEventAngle(8 * total, TriggerValue::FALL);
101 1 }
102
103 2 static void daihatsu(TriggerWaveform * s, int count) {
104 2 s->initialize(FOUR_STROKE_CAM_SENSOR, SyncEdge::RiseOnly);
105 2 s->tdcPosition = 720 - 30;
106
107 2 int width = 10;
108
109 2 s->addEventAngle(30 - width, TriggerValue::RISE);
110 2 s->addEventAngle(30, TriggerValue::FALL);
111
112
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2 times.
2/2
✓ Decision 'true' taken 7 times.
✓ Decision 'false' taken 2 times.
9 for (int i = 1;i<=count;i++) {
113 7 s->addEventAngle(s->getCycleDuration() / count * i - width, TriggerValue::RISE);
114 7 s->addEventAngle(s->getCycleDuration() / count * i, TriggerValue::FALL);
115 }
116 2 }
117
118 1 void configureDaihatsu3cyl(TriggerWaveform * s) {
119 1 daihatsu(s, 3);
120 1 s->setTriggerSynchronizationGap(0.125);
121 1 }
122
123
124 1 void configureDaihatsu4cyl(TriggerWaveform * s) {
125 1 daihatsu(s, 4);
126 1 s->setTriggerSynchronizationGap(0.17);
127 1 }
128
129 1 void configureBarra3plus1cam(TriggerWaveform *s) {
130 1 s->initialize(FOUR_STROKE_CAM_SENSOR, SyncEdge::RiseOnly);
131
132 // This wheel has four teeth
133 // two short gaps, and two long gaps
134 // short = 60 deg
135 // long = 120 deg
136
137 {
138 1 int offset = 60;
139 1 int w = 5;
140
141 1 s->addToothRiseFall(offset, w);
142
143 // short gap 60 deg
144 1 s->addToothRiseFall(offset + 60, w);
145
146 // long gap 120 deg
147 1 s->addToothRiseFall(offset + 180, w);
148 // long gap 120 deg
149 1 s->addToothRiseFall(offset + 300, w);
150
151 // short gap, 60 deg back to zero/720
152 }
153
154 // sync tooth is the zero tooth, the first short gap after two long gaps
155 1 s->setTriggerSynchronizationGap3(0, 1.6f, 2.4f);
156 // previous gap should be 1.0
157 1 s->setTriggerSynchronizationGap3(1, 0.8f, 1.2f);
158 1 }
159
160 1 void configureBenelli(TriggerWaveform *s) {
161 1 s->initialize(FOUR_STROKE_CRANK_SENSOR, SyncEdge::RiseOnly);
162
163 1 constexpr float magic = 15;
164
165 1 float angle = 3 * magic;
166
167 1 s->addEvent360(angle / 2 /* 22.5 */, TriggerValue::RISE);
168 1 s->addEvent360(angle /* 45 */, TriggerValue::FALL);
169
170
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 1 time.
2/2
✓ Decision 'true' taken 21 times.
✓ Decision 'false' taken 1 time.
22 for (int i = 0;i< 24 - 3;i++) {
171 21 angle += magic / 2;
172 21 s->addEvent360(angle, TriggerValue::RISE);
173
174 21 angle += magic / 2;
175 21 s->addEvent360(angle, TriggerValue::FALL);
176 }
177 1 }
178
179 1 void configure60degSingleTooth(TriggerWaveform *s) {
180 /** @todo
181 * My approach was to utilize ::Both especially for single
182 * tooth and manual kikstarter, to be ready on both sides of blind.
183 * But unfortuneally, my experiments show me the Trigger can't
184 * become syncronized by 'last' and folowed 'first' events only.
185 * Also I observe phase-aligment mehanism is trying to consume a
186 * longer side of trigger as latest before TDC.
187 * I wish to setup SyncEdge::Both for my TT_60DEG_TOOTH after
188 * this case of scenario become work well. For now, ::Rise work
189 * well for my 60 degree trigger and both edges phase sync work
190 * as mush as expected for my engine startup. */
191
192
1/1
✓ Decision 'true' taken 1 time.
1 s->initialize(FOUR_STROKE_CRANK_SENSOR, SyncEdge::Rise);
193
194 1 s->addEvent360(300, TriggerValue::RISE);
195 1 s->addEvent360(360, TriggerValue::FALL);
196
197 1 s->tdcPosition = 60;
198
199 1 s->isSynchronizationNeeded = false;
200 1 s->useOnlyPrimaryForSync = true;
201 1 }
202
203 3 void configureArcticCat(TriggerWaveform *s) {
204 3 s->initialize(TWO_STROKE, SyncEdge::Rise);
205
206 3 int totalTeethCount = 24;
207 3 float engineCycle = TWO_STROKE_CYCLE_DURATION;
208 3 float toothWidth = 0.5;
209
210 3 addSkippedToothTriggerEvents(TriggerWheel::T_PRIMARY, s, totalTeethCount, 0, toothWidth, /*offset*/0, engineCycle,
211 /*from*/ 30 + 1, /* to */ 195 + 1);
212
213
214 3 addSkippedToothTriggerEvents(TriggerWheel::T_PRIMARY, s, totalTeethCount, 0, toothWidth, /*offset*/0, engineCycle,
215 /*from*/ 210 + 1, /* to */ NO_RIGHT_FILTER);
216
217 3 s->setTriggerSynchronizationGap(2);
218 3 int c = 9;
219
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 3 times.
2/2
✓ Decision 'true' taken 27 times.
✓ Decision 'false' taken 3 times.
30 for (int gapIndex = 1; gapIndex <= c; gapIndex++) {
220 27 s->setTriggerSynchronizationGap3(gapIndex, 0.75, 1.25);
221 }
222
223
224 3 }
225