1 /* FreeEMS - the open source engine management system
3 Copyright 2009 Fred Cooke
5 This file is part of the FreeEMS project.
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.
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.
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/
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!
23 Thank you for choosing FreeEMS to run your engine! */
26 /** @file Subaru-36-2-2-2.c
27 * @ingroup interruptHandlers
28 * @ingroup enginePositionRPMDecoders
30 * @brief Subaru 36 minus 2 2 2
32 * @note Pseudo code that does not compile with zero warnings and errors MUST be commented out.
34 * @todo TODO This file contains SFA but [anon] is going to fill it up with
35 * @todo TODO wonderful goodness very soon ;-)
41 #include "inc/freeEMS.h"
42 #include "inc/interrupts.h"
47 * @todo TODO Docs here!
49 void PrimaryRPMISR(void)
51 /* Clear the interrupt flag for this input compare channel */
54 /* Save all relevant available data here */
55 unsigned short codeStartTimeStamp
= TCNT
; /* Save the current timer count */
56 unsigned short edgeTimeStamp
= TC0
; /* Save the edge time stamp */
57 unsigned char PTITCurrentState
= PTIT
; /* Save the values on port T regardless of the state of DDRT */
58 // unsigned short PORTS_BACurrentState = PORTS_BA; /* Save ignition output state */
60 /* Calculate the latency in ticks */
61 ISRLatencyVars
.primaryInputLatency
= codeStartTimeStamp
- edgeTimeStamp
;
63 // TODO discard narrow ones! test for tooth width and tooth period
65 /* Set up edges as per config */
66 unsigned char risingEdge
;
67 if(fixedConfigs1
.coreSettingsA
& PRIMARY_POLARITY
){
68 risingEdge
= PTITCurrentState
& 0x01;
70 risingEdge
= !(PTITCurrentState
& 0x01);
74 /* Echo input condition on J7 */
77 // increment crank pulses TODO this needs to be wrapped in tooth period and width checking
78 primaryPulsesPerSecondaryPulse
++;
82 /* Install the low word */
83 timeStamp
.timeShorts
[1] = edgeTimeStamp
;
84 /* Find out what our timer value means and put it in the high word */
85 if(TFLGOF
&& !(edgeTimeStamp
& 0x8000)){ /* see 10.3.5 paragraph 4 of 68hc11 ref manual for details */
86 timeStamp
.timeShorts
[0] = timerExtensionClock
+ 1;
88 timeStamp
.timeShorts
[0] = timerExtensionClock
;
90 RuntimeVars
.primaryInputLeadingRuntime
= TCNT
- codeStartTimeStamp
;
93 RuntimeVars
.primaryInputTrailingRuntime
= TCNT
- codeStartTimeStamp
;
96 Counters
.primaryTeethSeen
++;
100 /** Secondary RPM ISR
102 * @todo TODO Docs here!
104 void SecondaryRPMISR(void)
106 /* Clear the interrupt flag for this input compare channel */
109 /* Save all relevant available data here */
110 unsigned short codeStartTimeStamp
= TCNT
; /* Save the current timer count */
111 unsigned short edgeTimeStamp
= TC1
; /* Save the timestamp */
112 unsigned char PTITCurrentState
= PTIT
; /* Save the values on port T regardless of the state of DDRT */
113 // unsigned short PORTS_BACurrentState = PORTS_BA; /* Save ignition output state */
115 /* Calculate the latency in ticks */
116 ISRLatencyVars
.secondaryInputLatency
= codeStartTimeStamp
- edgeTimeStamp
;
118 // TODO discard narrow ones! test for tooth width and tooth period
120 /* Set up edges as per config */
121 unsigned char risingEdge
;
122 if(fixedConfigs1
.coreSettingsA
& SECONDARY_POLARITY
){
123 risingEdge
= PTITCurrentState
& 0x02;
125 risingEdge
= !(PTITCurrentState
& 0x02);
129 // echo input condition
134 /* Install the low word */
135 timeStamp
.timeShorts
[1] = edgeTimeStamp
;
136 /* Find out what our timer value means and put it in the high word */
137 if(TFLGOF
&& !(edgeTimeStamp
& 0x8000)){ /* see 10.3.5 paragraph 4 of 68hc11 ref manual for details */
138 timeStamp
.timeShorts
[0] = timerExtensionClock
+ 1;
140 timeStamp
.timeShorts
[0] = timerExtensionClock
;
143 RuntimeVars
.secondaryInputLeadingRuntime
= TCNT
- codeStartTimeStamp
;
146 RuntimeVars
.secondaryInputTrailingRuntime
= TCNT
- codeStartTimeStamp
;
149 Counters
.secondaryTeethSeen
++;