FreeEMS  0.2.0-SNAPSHOT-285-g028e24c
syncLossIDs.h
Go to the documentation of this file.
1 /* FreeEMS - the open source engine management system
2  *
3  * Copyright 2011-2013 Fred Cooke
4  *
5  * This file is part of the FreeEMS project.
6  *
7  * FreeEMS software is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * FreeEMS software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * 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
18  * along with any FreeEMS software. If not, see http://www.gnu.org/licenses/
19  *
20  * We ask that if you make any changes to this file you email them upstream to
21  * us at admin(at)diyefi(dot)org or, even better, fork the code on github.com!
22  *
23  * Thank you for choosing FreeEMS to run your engine!
24  */
25 
26 /** @file
27  *
28  * @ingroup allHeaders
29  * @ingroup enginePositionRPMDecoders
30  *
31  * Predefined sync loss IDs to make it easy to lookup and diagnose issues.
32  *
33  * - Change all 4 hash defines to the filename uppercased and underscored
34  *
35  */
36 
37 /* Header file multiple inclusion protection courtesy eclipse Header Template */
38 /* and http://gcc.gnu.org/onlinedocs/gcc-3.1.1/cpp/ C pre processor manual */
39 #ifndef FILE_SYNC_LOSS_IDS_H_SEEN
40 #define FILE_SYNC_LOSS_IDS_H_SEEN
41 
42 // Special cases:
43 #define BUG_REACHED_UNREACHABLE_CODE 0xFF // Buggy code indicator, called from places that should not be possible to reach.
44 #define PLL_LOCK_LOST_PRECAUTIONARY 0xFE // Forced sync loss due to inaccurate timers from inaccurate clock
45 #define SELF_CLOCK_MODE_PRECAUTIONARY 0xFD // Forced sync loss due to inaccurate timers from inaccurate clock
46 
47 // Special case for timeout
48 #define EVENT_ARRIVAL_TIMEOUT 0
49 
50 // Common to all decoders
51 #define PRIMARY_EVENT_ARRIVED_TOO_LATE 1
52 #define PRIMARY_EVENT_ARRIVED_TOO_EARLY 2
53 #define SECONDARY_EVENT_ARRIVED_TOO_LATE 3
54 #define SECONDARY_EVENT_ARRIVED_TOO_EARLY 4
55 
56 // Count based decoders
57 #define COUNT_OF_EVENTS_IMPOSSIBLY_LOW_NOISE 5
58 #define COUNT_OF_EVENTS_IMPOSSIBLY_HIGH_NOISE 6
59 
60 // Logic based CAS as found on most Mitsi and Mazda engines
61 #define STATE_MISMATCH_IN_PRIMARY_RPM_ISR 7
62 #define STATE_MISMATCH_IN_SECONDARY_RPM_ISR 8
63 
64 // MissingTeeth uses from 0x40 - 0x8D, below and above are free for all other decoders to use.
65 
66 // Pair designations, possibly move this elsewhere to support defining the others as errors elsewhere too
67 #define FellThrough 64 // 0x40 The cracks, ie, no match
68 #define MatchedPair 4 // ~1:1
69 #define NarrowWide 6 // ~1:(N+1)
70 #define WideNarrow 7 // ~(N+1):1
71 #define NarrowBackward 8 // ~1:(N+2)/2
72 #define BackwardNarrow 5 // ~(N+2)/2:1
73 #define NarrowTooWide 65 // 0x41 1:>(N+1)
74 #define TooWideNarrow 66 // 0x42 >(N+1):1
75 
76 // This is for transposing errors to a unique number to indicate loss of sync different to clear during search
77 #define MaskBySumPattern 0x05 // 0xN4 >> 0xN9, 0xN8 >> 0xND, no collisions, free space for more too
78 
79 // Possible conditions of success and failure.
80 //
81 // Literals here for readability, checked below with formula and names
82 //
83 // Note, whether it is possible to strike these depends on the tolerance used
84 
85 // In sync:
86 #define MatchedPairMatchedPair 68 // 0x44 small small small - All periods match
87 #define MatchedPairNarrowWide 70 // 0x46 small small BIG - First tooth after missing
88 #define NarrowWideWideNarrow 103 // 0x67 small BIG small - Second tooth after missing, the strongest and most certain sync
89 #define WideNarrowMatchedPair 116 // 0x74 BIG small small - Third tooth after missing
90 
91 // Except when we should get something else:
92 #define MatchedPairMatchedPairPlusMask 73 // 0x49 small small small - All periods match (Indicates wrong decoder with too few teeth, same missing)
93 #define MatchedPairNarrowWidePlusMask 75 // 0x4B small small BIG - First tooth after missing (Indicates wrong decoder with too many teeth, same missing)
94 #define NarrowWideWideNarrowPlusMask 108 // 0x6C small BIG small - Second tooth after missing, the strongest and most certain sync
95 #define WideNarrowMatchedPairPlusMask 121 // 0x79 BIG small small - Third tooth after missing
96 
97 // Wild noise and bad settings:
98 #define yourVRSensorHasALoosePlugFixIt NarrowTooWide
99 #define noiseAppearedWayTooEarlyAsIfItWasAVRToothButWasnt TooWideNarrow
100 #define yourSyncToleranceIsTighterThanAWellYouGetTheIdea FellThrough
101 #define yourSyncToleranceIsLooserThanAWellYouGetTheIdea MatchedPairMatchedPair // Too many matched pairs in a row
102 
103 // Fails:
104 #define NearlySyncedNarrowWideBackwardNarrow 101 // 0x65
105 #define NearlySyncedNarrowBackwardWideNarrow 135 // 0x87
106 #define NearlySyncedNarrowBackwardBackwardNarrow 133 // 0x85
107 #define NearlySyncedMatchedPairNarrowBackward 72 // 0x48
108 #define NearlySyncedBackwardNarrowMatchedPair 84 // 0x54
109 #define ExtraToothWideNarrowNarrowWide 118 // 0x76
110 #define ExtraToothWideNarrowNarrowBackward 120 // 0x78
111 #define ExtraToothBackwardNarrowNarrowWide 86 // 0x56
112 #define ExtraToothBackwardNarrowNarrowBackward 88 // 0x58
113 #define VRWiringBackwardMatchedPairBackwardNarrow 69 // 0x45 Engineered to be 69 for humour value!
114 #define VRWiringBackwardMatchedPairWideNarrow 71 // 0x47
115 #define VRWiringBackwardNarrowWideMatchedPair 100 // 0x64
116 #define VRWiringBackwardNarrowBackwardMatchedPair 132 // 0x84
117 #define ExcessDecelerationNarrowBackwardNarrowBackward 136 // 0x88
118 #define ExcessDecelerationNarrowBackwardNarrowWide 134 // 0x86
119 #define ExcessDecelerationNarrowWideNarrowBackward 104 // 0x68
120 #define ExcessDecelerationNarrowWideNarrowWide 102 // 0x66
121 #define ExcessAccelerationBackwardNarrowBackwardNarrow 85 // 0x55
122 #define ExcessAccelerationBackwardNarrowWideNarrow 87 // 0x57
123 #define ExcessAccelerationWideNarrowBackwardNarrow 117 // 0x75
124 #define ExcessAccelerationWideNarrowWideNarrow 119 // 0x77
125 
126 // Fails while synced:
127 #define NearlySyncedNarrowWideBackwardNarrowPlusMask 106 // 0x6A
128 #define NearlySyncedNarrowBackwardWideNarrowPlusMask 140 // 0x8C
129 #define NearlySyncedNarrowBackwardBackwardNarrowPlusMask 138 // 0x8A
130 #define NearlySyncedMatchedPairNarrowBackwardPlusMask 77 // 0x4D
131 #define NearlySyncedBackwardNarrowMatchedPairPlusMask 89 // 0x59
132 #define ExtraToothWideNarrowNarrowWidePlusMask 123 // 0x7B
133 #define ExtraToothWideNarrowNarrowBackwardPlusMask 125 // 0x7D
134 #define ExtraToothBackwardNarrowNarrowWidePlusMask 91 // 0x5B
135 #define ExtraToothBackwardNarrowNarrowBackwardPlusMask 93 // 0x5D
136 #define VRWiringBackwardMatchedPairBackwardNarrowPlusMask 74 // 0x4A
137 #define VRWiringBackwardMatchedPairWideNarrowPlusMask 76 // 0x4C
138 #define VRWiringBackwardNarrowWideMatchedPairPlusMask 105 // 0x69
139 #define VRWiringBackwardNarrowBackwardMatchedPairPlusMask 137 // 0x89
140 #define ExcessDecelerationNarrowBackwardNarrowBackwardPlusMask 141 // 0x8D
141 #define ExcessDecelerationNarrowBackwardNarrowWidePlusMask 139 // 0x8B
142 #define ExcessDecelerationNarrowWideNarrowBackwardPlusMask 109 // 0x6D
143 #define ExcessDecelerationNarrowWideNarrowWidePlusMask 107 // 0x6B
144 #define ExcessAccelerationBackwardNarrowBackwardNarrowPlusMask 90 // 0x5A
145 #define ExcessAccelerationBackwardNarrowWideNarrowPlusMask 92 // 0x5C
146 #define ExcessAccelerationWideNarrowBackwardNarrowPlusMask 122 // 0x7A
147 #define ExcessAccelerationWideNarrowWideNarrowPlusMask 124 // 0x7C
148 
149 // Self-checks on the above
150 #if (MatchedPairMatchedPair != ((MatchedPair << 4) + MatchedPair))
151 #error "Header is broken, fix it!"
152 #endif
153 #if (MatchedPairNarrowWide != ((MatchedPair << 4) + NarrowWide))
154 #error "Header is broken, fix it!"
155 #endif
156 #if (NarrowWideWideNarrow != ((NarrowWide << 4) + WideNarrow))
157 #error "Header is broken, fix it!"
158 #endif
159 #if (WideNarrowMatchedPair != ((WideNarrow << 4) + MatchedPair))
160 #error "Header is broken, fix it!"
161 #endif
162 #if (NearlySyncedNarrowWideBackwardNarrow != ((NarrowWide << 4) + BackwardNarrow))
163 #error "Header is broken, fix it!"
164 #endif
165 #if (NearlySyncedNarrowBackwardWideNarrow != ((NarrowBackward << 4) + WideNarrow))
166 #error "Header is broken, fix it!"
167 #endif
168 #if (NearlySyncedNarrowBackwardBackwardNarrow != ((NarrowBackward << 4) + BackwardNarrow))
169 #error "Header is broken, fix it!"
170 #endif
171 #if (NearlySyncedMatchedPairNarrowBackward != ((MatchedPair << 4) + NarrowBackward))
172 #error "Header is broken, fix it!"
173 #endif
174 #if (NearlySyncedBackwardNarrowMatchedPair != ((BackwardNarrow << 4) + MatchedPair))
175 #error "Header is broken, fix it!"
176 #endif
177 #if (ExtraToothWideNarrowNarrowWide != ((WideNarrow << 4) + NarrowWide))
178 #error "Header is broken, fix it!"
179 #endif
180 #if (ExtraToothWideNarrowNarrowBackward != ((WideNarrow << 4) + NarrowBackward))
181 #error "Header is broken, fix it!"
182 #endif
183 #if (ExtraToothBackwardNarrowNarrowWide != ((BackwardNarrow << 4) + NarrowWide))
184 #error "Header is broken, fix it!"
185 #endif
186 #if (ExtraToothBackwardNarrowNarrowBackward != ((BackwardNarrow << 4) + NarrowBackward))
187 #error "Header is broken, fix it!"
188 #endif
189 #if (VRWiringBackwardMatchedPairBackwardNarrow != ((MatchedPair << 4) + BackwardNarrow))
190 #error "Header is broken, fix it!"
191 #endif
192 #if (VRWiringBackwardMatchedPairWideNarrow != ((MatchedPair << 4) + WideNarrow))
193 #error "Header is broken, fix it!"
194 #endif
195 #if (VRWiringBackwardNarrowWideMatchedPair != ((NarrowWide << 4) + MatchedPair))
196 #error "Header is broken, fix it!"
197 #endif
198 #if (VRWiringBackwardNarrowBackwardMatchedPair != ((NarrowBackward << 4) + MatchedPair))
199 #error "Header is broken, fix it!"
200 #endif
201 #if (ExcessDecelerationNarrowBackwardNarrowBackward != ((NarrowBackward << 4) + NarrowBackward))
202 #error "Header is broken, fix it!"
203 #endif
204 #if (ExcessDecelerationNarrowBackwardNarrowWide != ((NarrowBackward << 4) + NarrowWide))
205 #error "Header is broken, fix it!"
206 #endif
207 #if (ExcessDecelerationNarrowWideNarrowBackward != ((NarrowWide << 4) + NarrowBackward))
208 #error "Header is broken, fix it!"
209 #endif
210 #if (ExcessDecelerationNarrowWideNarrowWide != ((NarrowWide << 4) + NarrowWide))
211 #error "Header is broken, fix it!"
212 #endif
213 #if (ExcessAccelerationBackwardNarrowBackwardNarrow != ((BackwardNarrow << 4) + BackwardNarrow))
214 #error "Header is broken, fix it!"
215 #endif
216 #if (ExcessAccelerationBackwardNarrowWideNarrow != ((BackwardNarrow << 4) + WideNarrow))
217 #error "Header is broken, fix it!"
218 #endif
219 #if (ExcessAccelerationWideNarrowBackwardNarrow != ((WideNarrow << 4) + BackwardNarrow))
220 #error "Header is broken, fix it!"
221 #endif
222 #if (ExcessAccelerationWideNarrowWideNarrow != ((WideNarrow << 4) + WideNarrow))
223 #error "Header is broken, fix it!"
224 #endif
225 
226 // And for the masked ones:
227 #if (MatchedPairMatchedPairPlusMask != ((MatchedPair << 4) + MatchedPair) + MaskBySumPattern)
228 #error "Header is broken, fix it!"
229 #endif
230 #if (MatchedPairNarrowWidePlusMask != ((MatchedPair << 4) + NarrowWide) + MaskBySumPattern)
231 #error "Header is broken, fix it!"
232 #endif
233 #if (NarrowWideWideNarrowPlusMask != ((NarrowWide << 4) + WideNarrow) + MaskBySumPattern)
234 #error "Header is broken, fix it!"
235 #endif
236 #if (WideNarrowMatchedPairPlusMask != ((WideNarrow << 4) + MatchedPair) + MaskBySumPattern)
237 #error "Header is broken, fix it!"
238 #endif
239 #if (NearlySyncedNarrowWideBackwardNarrowPlusMask != ((NarrowWide << 4) + BackwardNarrow) + MaskBySumPattern)
240 #error "Header is broken, fix it!"
241 #endif
242 #if (NearlySyncedNarrowBackwardWideNarrowPlusMask != ((NarrowBackward << 4) + WideNarrow) + MaskBySumPattern)
243 #error "Header is broken, fix it!"
244 #endif
245 #if (NearlySyncedNarrowBackwardBackwardNarrowPlusMask != ((NarrowBackward << 4) + BackwardNarrow) + MaskBySumPattern)
246 #error "Header is broken, fix it!"
247 #endif
248 #if (NearlySyncedMatchedPairNarrowBackwardPlusMask != ((MatchedPair << 4) + NarrowBackward) + MaskBySumPattern)
249 #error "Header is broken, fix it!"
250 #endif
251 #if (NearlySyncedBackwardNarrowMatchedPairPlusMask != ((BackwardNarrow << 4) + MatchedPair) + MaskBySumPattern)
252 #error "Header is broken, fix it!"
253 #endif
254 #if (ExtraToothWideNarrowNarrowWidePlusMask != ((WideNarrow << 4) + NarrowWide) + MaskBySumPattern)
255 #error "Header is broken, fix it!"
256 #endif
257 #if (ExtraToothWideNarrowNarrowBackwardPlusMask != ((WideNarrow << 4) + NarrowBackward) + MaskBySumPattern)
258 #error "Header is broken, fix it!"
259 #endif
260 #if (ExtraToothBackwardNarrowNarrowWidePlusMask != ((BackwardNarrow << 4) + NarrowWide) + MaskBySumPattern)
261 #error "Header is broken, fix it!"
262 #endif
263 #if (ExtraToothBackwardNarrowNarrowBackwardPlusMask != ((BackwardNarrow << 4) + NarrowBackward) + MaskBySumPattern)
264 #error "Header is broken, fix it!"
265 #endif
266 #if (VRWiringBackwardMatchedPairBackwardNarrowPlusMask != ((MatchedPair << 4) + BackwardNarrow) + MaskBySumPattern)
267 #error "Header is broken, fix it!"
268 #endif
269 #if (VRWiringBackwardMatchedPairWideNarrowPlusMask != ((MatchedPair << 4) + WideNarrow) + MaskBySumPattern)
270 #error "Header is broken, fix it!"
271 #endif
272 #if (VRWiringBackwardNarrowWideMatchedPairPlusMask != ((NarrowWide << 4) + MatchedPair) + MaskBySumPattern)
273 #error "Header is broken, fix it!"
274 #endif
275 #if (VRWiringBackwardNarrowBackwardMatchedPairPlusMask != ((NarrowBackward << 4) + MatchedPair) + MaskBySumPattern)
276 #error "Header is broken, fix it!"
277 #endif
278 #if (ExcessDecelerationNarrowBackwardNarrowBackwardPlusMask != ((NarrowBackward << 4) + NarrowBackward) + MaskBySumPattern)
279 #error "Header is broken, fix it!"
280 #endif
281 #if (ExcessDecelerationNarrowBackwardNarrowWidePlusMask != ((NarrowBackward << 4) + NarrowWide) + MaskBySumPattern)
282 #error "Header is broken, fix it!"
283 #endif
284 #if (ExcessDecelerationNarrowWideNarrowBackwardPlusMask != ((NarrowWide << 4) + NarrowBackward) + MaskBySumPattern)
285 #error "Header is broken, fix it!"
286 #endif
287 #if (ExcessDecelerationNarrowWideNarrowWidePlusMask != ((NarrowWide << 4) + NarrowWide) + MaskBySumPattern)
288 #error "Header is broken, fix it!"
289 #endif
290 #if (ExcessAccelerationBackwardNarrowBackwardNarrowPlusMask != ((BackwardNarrow << 4) + BackwardNarrow) + MaskBySumPattern)
291 #error "Header is broken, fix it!"
292 #endif
293 #if (ExcessAccelerationBackwardNarrowWideNarrowPlusMask != ((BackwardNarrow << 4) + WideNarrow) + MaskBySumPattern)
294 #error "Header is broken, fix it!"
295 #endif
296 #if (ExcessAccelerationWideNarrowBackwardNarrowPlusMask != ((WideNarrow << 4) + BackwardNarrow) + MaskBySumPattern)
297 #error "Header is broken, fix it!"
298 #endif
299 #if (ExcessAccelerationWideNarrowWideNarrowPlusMask != ((WideNarrow << 4) + WideNarrow) + MaskBySumPattern)
300 #error "Header is broken, fix it!"
301 #endif
302 
303 
304 #else
305  /* let us know if we are being untidy with headers */
306  #warning "Header file SYNC_LOSS_IDS_H seen before, sort it out!"
307 /* end of the wrapper ifdef from the very top */
308 #endif