41 #ifndef FILE_DECODER_INTERFACE_H_SEEN
42 #define FILE_DECODER_INTERFACE_H_SEEN
49 #warning "EXTERN already defined by another header, please sort it out!"
54 #ifdef DECODER_IMPLEMENTATION_C
61 #define BENCH_TEST_NAME "BenchTest"
74 #define degreeTicksPerMinute 4166667 // rounded up by 1/3
75 #define ticks_per_degree_multiplier (10 * ANGLE_FACTOR) // FIX <<< shouldn't be done like this.
150 #define COMBUSTION_SYNC BIT0
151 #define CRANK_SYNC BIT1
152 #define CAM_SYNC BIT2
153 #define LAST_TIMESTAMP_VALID BIT3
154 #define LAST_PERIOD_VALID BIT4
155 #define LAST_MATCH_VALID BIT5
156 #define LAST_TPD_VALID BIT6
157 #define OK_TO_SCHEDULE BIT7
158 // WARNING: Entire flag var is cleared with loss of sync!
161 #define ARBITRARY_DECODER_NAME_MAX_LENGTH 64
162 #define SIZE_OF_EVENT_ARRAYS 256
163 #if (SIZE_OF_EVENT_ARRAYS > 256)
164 #error "Event array size larger than variable used to index it!"
165 #endif // Is it paranoid to check myself like this? :-)
178 #define SET_SYNC_LEVEL_TO(SYNC_LEVEL) \
180 if(!(KeyUserDebugs.decoderFlags & SYNC_LEVEL)){ \
181 KeyUserDebugs.decoderFlags |= SYNC_LEVEL; \
182 KeyUserDebugs.syncCaughtOnThisEvent = KeyUserDebugs.currentEvent; \
186 if(KeyUserDebugs.syncLostWithThisID){ \
187 if(syncConfirmationsRunningCounter){ \
188 syncConfirmationsRunningCounter--; \
190 KeyUserDebugs.decoderFlags |= OK_TO_SCHEDULE; \
193 if(syncConfirmationsStartingCounter){ \
194 syncConfirmationsStartingCounter--; \
196 KeyUserDebugs.decoderFlags |= OK_TO_SCHEDULE; \
201 #define SCHEDULE_ONE_ECT_OUTPUT() \
202 if(outputEventExtendNumberOfRepeats[outputEventNumber] > 0){ \
203 *ectMainControlRegisters[pin] &= ectMainDisableMasks[pin]; \
204 outputEventExtendNumberOfRepeatsRealtime[pin] = outputEventExtendNumberOfRepeats[outputEventNumber]; \
205 outputEventExtendNumberOfRepeatsRealtime[pin]--; \
206 outputEventExtendRepeatPeriodRealtime[pin] = outputEventExtendRepeatPeriod[outputEventNumber]; \
207 outputEventDelayFinalPeriodRealtime[pin] = outputEventDelayFinalPeriod[outputEventNumber]; \
208 *ectMainTimeRegisters[pin] = timeStamp.timeShorts[1] + outputEventExtendRepeatPeriod[outputEventNumber]; \
209 Counters.pinScheduledWithTimerExtension++; \
211 *ectMainControlRegisters[pin] |= ectMainEnableMasks[pin]; \
212 *ectMainTimeRegisters[pin] = startTime; \
213 Counters.pinScheduledToGoHigh++; \
215 TIE |= ectMainOnMasks[pin]; \
216 TFLG = ectMainOnMasks[pin]; \
217 outputEventPulseWidthsRealtime[pin] = outputEventPulseWidthsMath[outputEventNumber]; \
218 selfSetTimer &= ectMainOffMasks[pin]; // End of macro block!
221 #ifdef DECODER_IMPLEMENTATION_C // See above for information on how to set these values up.
224 #define SCHEDULE_ECT_OUTPUTS() \
225 numberScheduled = 0; \
226 if(KeyUserDebugs.decoderFlags & OK_TO_SCHEDULE){ \
227 unsigned char outputEventNumber; \
228 for(outputEventNumber=0;outputEventNumber<fixedConfigs1.schedulingSettings.numberOfConfiguredOutputEvents;outputEventNumber++){ \
229 if(outputEventInputEventNumbers[outputEventNumber] == KeyUserDebugs.currentEvent){ \
230 skipEventFlags &= ~(1UL << outputEventNumber); \
231 schedulePortTPin(outputEventNumber, timeStamp); \
233 }else if(skipEventFlags & (1UL << outputEventNumber)){ \
234 unsigned char eventBeforeCurrent = 0; \
235 if(KeyUserDebugs.currentEvent == 0){ \
236 eventBeforeCurrent = numberOfRealEvents - 1; \
238 eventBeforeCurrent = KeyUserDebugs.currentEvent - 1; \
241 if(outputEventInputEventNumbers[outputEventNumber] == eventBeforeCurrent){ \
242 schedulePortTPin(outputEventNumber, timeStamp); \
247 } // End of macro block!
251 #define COARSE_BB_IGNORE 0
252 #define COARSE_BB_GO_ON 1
253 #define COARSE_BB_GO_OFF 2
254 #define COARSE_BB_TOGGLE 3
255 #define COARSE_BB_MASK 0x03
257 #define OUTPUT_COARSE_BBS() \
258 if(fixedConfigs1.coarseBitBangSettings.outputActions[KeyUserDebugs.currentEvent]){ \
260 for(offset=0;offset<fixedConfigs1.coarseBitBangSettings.numberConfigured;offset++){ \
261 unsigned char behaviour = (fixedConfigs1.coarseBitBangSettings.outputActions[KeyUserDebugs.currentEvent] >> (offset*2)) & COARSE_BB_MASK; \
263 if(behaviour == COARSE_BB_GO_ON){ \
264 *(fixedConfigs1.coarseBitBangSettings.ports[offset]) |= fixedConfigs1.coarseBitBangSettings.masks[offset]; \
265 }else if(behaviour == COARSE_BB_GO_OFF){ \
266 *(fixedConfigs1.coarseBitBangSettings.ports[offset]) &= (unsigned char)~(fixedConfigs1.coarseBitBangSettings.masks[offset]); \
267 }else if(behaviour == COARSE_BB_TOGGLE){ \
268 *(fixedConfigs1.coarseBitBangSettings.ports[offset]) ^= fixedConfigs1.coarseBitBangSettings.masks[offset]; \
272 } // End of macro block!
276 #ifndef DECODER_MAX_CODE_TIME
277 #error "Define your code max runtime conservatively at first, then optimise once the code is complete."
279 #ifndef NUMBER_OF_REAL_EVENTS
280 #error "Define how many unique events your decoder sees!"
282 #ifndef NUMBER_OF_VIRTUAL_EVENTS
283 #error "Define the length of the event array!"
285 #if ((NUMBER_OF_VIRTUAL_EVENTS % NUMBER_OF_REAL_EVENTS) != 0)
286 #error "Virtual events should be a multiple of real events!"
293 const unsigned char decoderName[] = BASE_FILE_NAME;
506 #warning "Header file DECODER_INTERFACE_H seen before, sort it out!"