GCC Code Coverage Report


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

Line Branch Decision Exec Source
1 /**
2 * @file trigger_mazda.cpp
3 *
4 * @date Feb 18, 2014
5 * @author Andrey Belomutskiy, (c) 2012-2020
6 *
7 * This file is part of rusEfi - see http://rusefi.com
8 *
9 * rusEfi is free software; you can redistribute it and/or modify it under the terms of
10 * the GNU General Public License as published by the Free Software Foundation; either
11 * version 3 of the License, or (at your option) any later version.
12 *
13 * rusEfi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
14 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with this program.
18 * If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "pch.h"
22
23 #include "trigger_mazda.h"
24
25 #define NB_CRANK_MAGIC 70
26
27 10 void initializeMazdaMiataNaShape(TriggerWaveform *s) {
28 10 s->initialize(FOUR_STROKE_CAM_SENSOR, SyncEdge::Both);
29 10 s->isSecondWheelCam = true;
30
31 // nominal gap is 0.325
32 10 s->setTriggerSynchronizationGap2(0.1, 0.5);
33 // nominal gap is ~1.52
34 10 s->setSecondTriggerSynchronizationGap2(0.5, 2.3);
35
36 10 s->tdcPosition = 5.181;
37
38 /**
39 * http://rusefi.com/forum/viewtopic.php?f=3&t=729&p=12983#p12983
40 */
41 10 s->addEvent720(52.960405, TriggerValue::RISE, TriggerWheel::T_SECONDARY);
42 10 s->addEvent720(122.635956, TriggerValue::FALL, TriggerWheel::T_SECONDARY);
43
44 10 s->addEvent720(216.897031, TriggerValue::RISE, TriggerWheel::T_PRIMARY);
45 10 s->addEvent720(232.640068, TriggerValue::RISE, TriggerWheel::T_SECONDARY);
46 10 s->addEvent720(288.819688, TriggerValue::FALL, TriggerWheel::T_PRIMARY); // <-- This edge is the sync point
47 10 s->addEvent720(302.646323, TriggerValue::FALL, TriggerWheel::T_SECONDARY);
48
49 10 s->addEvent720(412.448056, TriggerValue::RISE, TriggerWheel::T_SECONDARY);
50 10 s->addEvent720(482.816719, TriggerValue::FALL, TriggerWheel::T_SECONDARY);
51
52 10 s->addEvent720(577.035495, TriggerValue::RISE, TriggerWheel::T_PRIMARY);
53 10 s->addEvent720(592.878113, TriggerValue::RISE, TriggerWheel::T_SECONDARY);
54 10 s->addEvent720(662.899708, TriggerValue::FALL, TriggerWheel::T_SECONDARY);
55 10 s->addEvent720(720.0f, TriggerValue::FALL, TriggerWheel::T_PRIMARY);
56 10 s->useOnlyPrimaryForSync = true;
57 10 }
58
59 // TT_MIATA_VVT
60 9 void initializeMazdaMiataNb2Crank(TriggerWaveform *s) {
61 /**
62 * Note how we use 0..180 range while defining FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR trigger
63 * Note that only half of the physical wheel is defined here!
64 */
65 9 s->initialize(FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR, SyncEdge::RiseOnly);
66
67 9 s->tdcPosition = 60 + 655;
68
69 // Nominal gap 70/110 = 0.636
70 9 s->setTriggerSynchronizationGap2(0.35f, 1.15f);
71 // Nominal gap 110/70 = 1.571
72 9 s->setSecondTriggerSynchronizationGap2(0.8f, 1.8f);
73
74 // todo: NB2 fronts are inverted comparing to NB1, life is not perfect :(
75 9 s->addEventAngle(180.0f - NB_CRANK_MAGIC - 4, TriggerValue::FALL, TriggerWheel::T_PRIMARY);
76 9 s->addEventAngle(180.0f - NB_CRANK_MAGIC, TriggerValue::RISE, TriggerWheel::T_PRIMARY);
77 9 s->addEventAngle(180.0f - 4, TriggerValue::FALL, TriggerWheel::T_PRIMARY);
78 9 s->addEventAngle(180.0f, TriggerValue::RISE, TriggerWheel::T_PRIMARY);
79 9 }
80
81 8 static void addNBCrankTooth(TriggerWaveform *s, angle_t angle) {
82 8 s->addToothRiseFall(angle / 2 + 2, 2, TriggerWheel::T_SECONDARY);
83 8 }
84
85 1 static void initializeMazdaMiataNb1ShapeWithOffset(TriggerWaveform *s, float offset) {
86 1 s->initialize(FOUR_STROKE_CAM_SENSOR, SyncEdge::Fall);
87 1 s->setTriggerSynchronizationGap3(0, 0.065, 0.17f);
88 1 s->useOnlyPrimaryForSync = true;
89
90 1 s->tdcPosition = 276;
91
92 /**
93 * cam sensor is primary, crank sensor is secondary
94 */
95 1 s->addEvent720(20.0f, TriggerValue::FALL, TriggerWheel::T_PRIMARY);
96
97 1 addNBCrankTooth(s, offset + 66.0f);
98 1 addNBCrankTooth(s, offset + 66.0f + NB_CRANK_MAGIC);
99 1 addNBCrankTooth(s, offset + 66.0f + 180);
100 1 addNBCrankTooth(s, offset + 66.0f + 180 + NB_CRANK_MAGIC);
101
102 1 s->addEvent720(340.0f, TriggerValue::RISE, TriggerWheel::T_PRIMARY);
103 1 s->addEvent720(360.0f, TriggerValue::FALL, TriggerWheel::T_PRIMARY);
104
105 1 s->addEvent720(380.0f, TriggerValue::RISE, TriggerWheel::T_PRIMARY);
106 1 s->addEvent720(400.0f, TriggerValue::FALL, TriggerWheel::T_PRIMARY);
107
108 1 addNBCrankTooth(s, offset + 66.0f + 360);
109 1 addNBCrankTooth(s, offset + 66.0f + 360 + NB_CRANK_MAGIC);
110 1 addNBCrankTooth(s, offset + 66.0f + 540);
111 1 addNBCrankTooth(s, offset + 66.0f + 540 + NB_CRANK_MAGIC);
112
113 1 s->addEvent720(720.0f, TriggerValue::RISE, TriggerWheel::T_PRIMARY);
114 1 }
115
116 1 void initializeMazdaMiataVVtTestShape(TriggerWaveform *s) {
117 1 initializeMazdaMiataNb1ShapeWithOffset(s, -22);
118 1 }
119
120 1 void configureMazdaProtegeSOHC(TriggerWaveform *s) {
121 1 s->initialize(FOUR_STROKE_CAM_SENSOR, SyncEdge::Both);
122
123 1 float z = 0.093;
124 1 float a = 90;
125 1 s->addToothRiseFall(a, z * 360);
126
127 1 a += 90;
128 1 s->addToothRiseFall(a, z * 360);
129 1 a += 90;
130 1 s->addToothRiseFall(a, z * 360);
131 1 a += 90;
132 1 s->addToothRiseFall(a, z * 360);
133
134 1 s->isSynchronizationNeeded = false;
135 1 s->shapeWithoutTdc = true;
136 1 }
137
138 3 void configureMazdaProtegeLx(TriggerWaveform *s) {
139 3 s->initialize(FOUR_STROKE_CAM_SENSOR, SyncEdge::RiseOnly);
140 3 s->isSecondWheelCam = true;
141 /**
142 * based on https://svn.code.sf.net/p/rusefi/code/trunk/misc/logs/1993_escort_gt/MAIN_rfi_report_2015-02-01%2017_39.csv
143 */
144 3 s->addEvent720(95.329254, TriggerValue::RISE, TriggerWheel::T_PRIMARY);
145
146 3 s->addEvent720(95.329254 + 14.876692, TriggerValue::RISE, TriggerWheel::T_SECONDARY);
147 3 s->addEvent720(178.022811, TriggerValue::FALL, TriggerWheel::T_SECONDARY);
148
149 3 s->addEvent720(95.329254 + 137.119154, TriggerValue::FALL, TriggerWheel::T_PRIMARY);
150
151 3 s->addEvent720(95.329254 + 192.378308, TriggerValue::RISE, TriggerWheel::T_SECONDARY);
152 3 s->addEvent720(356.885672, TriggerValue::FALL, TriggerWheel::T_SECONDARY);
153
154 3 s->addEvent720(95.329254 + 373.060597, TriggerValue::RISE, TriggerWheel::T_SECONDARY);
155 3 s->addEvent720(538.832438, TriggerValue::FALL, TriggerWheel::T_SECONDARY);
156
157 3 s->addEvent720(720-69.32097, TriggerValue::RISE, TriggerWheel::T_SECONDARY);
158 3 s->addEvent720(720, TriggerValue::FALL, TriggerWheel::T_SECONDARY);
159
160 3 s->tdcPosition = 137.119154;
161 3 s->isSynchronizationNeeded = false;
162 3 }
163
164 11 void initializeMazdaMiataVVtCamShape(TriggerWaveform *s) {
165 11 s->initialize(FOUR_STROKE_CAM_SENSOR, SyncEdge::RiseOnly);
166
167 // Nominal gap is 8.92
168 11 s->setTriggerSynchronizationGap2(6, 20);
169 // Nominal gap is 0.128
170 11 s->setSecondTriggerSynchronizationGap2(0.04f, 0.2f);
171
172 11 s->addEvent720(325, TriggerValue::FALL, TriggerWheel::T_PRIMARY);
173 11 s->addEvent720(360, TriggerValue::RISE, TriggerWheel::T_PRIMARY);
174
175 11 s->addEvent720(641, TriggerValue::FALL, TriggerWheel::T_PRIMARY);
176 11 s->addEvent720(679, TriggerValue::RISE, TriggerWheel::T_PRIMARY);
177
178 11 s->addEvent720(700, TriggerValue::FALL, TriggerWheel::T_PRIMARY);
179 11 s->addEvent720(720, TriggerValue::RISE, TriggerWheel::T_PRIMARY);
180 11 }
181
182 // https://rusefi.com/forum/viewtopic.php?f=17&t=2417
183 // Cam pattern for intake/exhaust on all Skyactiv-G (and maybe -D/-X)
184 1 void initializeMazdaSkyactivCam(TriggerWaveform *s) {
185 1 s->initialize(FOUR_STROKE_CAM_SENSOR, SyncEdge::RiseOnly);
186
187 1 int wide = 20;
188 1 int narrow = 10;
189
190 1 s->addToothRiseFall(70, wide);
191 1 s->addToothRiseFall(90, narrow);
192
193 1 s->addToothRiseFall(160, wide);
194 1 s->addToothRiseFall(180, narrow);
195
196 1 s->addToothRiseFall(270, wide);
197 1 s->addToothRiseFall(360, wide);
198
199 1 s->setTriggerSynchronizationGap(0.43);
200 1 s->setSecondTriggerSynchronizationGap(0.78);
201 1 s->setThirdTriggerSynchronizationGap(1.12); // 3rd gap is not required but let's have it for some resiliency
202 1 }
203
204 1 void initializeMazdaLCam(TriggerWaveform* s) {
205 1 s->initialize(FOUR_STROKE_CAM_SENSOR, SyncEdge::RiseOnly);
206
207 // 6 teeth:
208 // 0, 60, 90, 150, 180, 270
209 // Tooth at 0 is just before #1 TDC
210
211 // 60
212 1 s->addEvent360(50, TriggerValue::RISE);
213 1 s->addEvent360(60, TriggerValue::FALL);
214
215 // 90
216 1 s->addEvent360(80, TriggerValue::RISE);
217 1 s->addEvent360(90, TriggerValue::FALL);
218
219 // 150
220 1 s->addEvent360(140, TriggerValue::RISE);
221 1 s->addEvent360(150, TriggerValue::FALL);
222
223 // 180
224 1 s->addEvent360(170, TriggerValue::RISE);
225 1 s->addEvent360(180, TriggerValue::FALL);
226
227 // 270
228 1 s->addEvent360(260, TriggerValue::RISE);
229 1 s->addEvent360(270, TriggerValue::FALL);
230
231 // 0 (aka 360)
232 1 s->addEvent360(350, TriggerValue::RISE);
233 1 s->addEvent360(360, TriggerValue::FALL);
234
235 1 s->setTriggerSynchronizationGap3(0, 0.32, 0.8);
236 1 s->setTriggerSynchronizationGap3(1, 1.5, 2.5);
237 1 s->setTriggerSynchronizationGap3(2, 0.32, 0.8);
238 1 }
239