Subaru 36 minus 2 2 2. More...
#include "inc/freeEMS.h"
#include "inc/interrupts.h"
#include "inc/DecoderInterface.h"
Go to the source code of this file.
Functions | |
void | PrimaryRPMISR (void) |
void | SecondaryRPMISR (void) |
Use the rising and falling edges................... |
Subaru 36 minus 2 2 2.
TODO This file contains SFA but [anon] is going to fill it up with
TODO wonderful goodness very soon ;-)
Definition in file Subaru-36-2-2-2.c.
void PrimaryRPMISR | ( | void | ) |
Primary RPM ISR
Definition at line 51 of file Subaru-36-2-2-2.c.
References fixedConfig1::coreSettingsA, Counters, fixedConfigs1, ISRLatencyVars, PORTJ, PRIMARY_POLARITY, ISRLatencyVar::primaryInputLatency, RuntimeVar::primaryInputLeadingRuntime, RuntimeVar::primaryInputTrailingRuntime, primaryPulsesPerSecondaryPulse, Counter::primaryTeethSeen, PTIT, RuntimeVars, TC0, TCNT, TFLG, TFLGOF, timerExtensionClock, and LongTime::timeShorts.
00052 { 00053 /* Clear the interrupt flag for this input compare channel */ 00054 TFLG = 0x01; 00055 00056 /* Save all relevant available data here */ 00057 unsigned short codeStartTimeStamp = TCNT; /* Save the current timer count */ 00058 unsigned short edgeTimeStamp = TC0; /* Save the edge time stamp */ 00059 unsigned char PTITCurrentState = PTIT; /* Save the values on port T regardless of the state of DDRT */ 00060 // unsigned short PORTS_BACurrentState = PORTS_BA; /* Save ignition output state */ 00061 00062 /* Calculate the latency in ticks */ 00063 ISRLatencyVars.primaryInputLatency = codeStartTimeStamp - edgeTimeStamp; 00064 00065 // TODO discard narrow ones! test for tooth width and tooth period 00066 00067 /* Set up edges as per config */ 00068 unsigned char risingEdge; 00069 if(fixedConfigs1.coreSettingsA & PRIMARY_POLARITY){ 00070 risingEdge = PTITCurrentState & 0x01; 00071 }else{ 00072 risingEdge = !(PTITCurrentState & 0x01); 00073 } 00074 00075 if(risingEdge){ 00076 /* Echo input condition on J7 */ 00077 PORTJ |= 0x80; 00078 00079 // increment crank pulses TODO this needs to be wrapped in tooth period and width checking 00080 primaryPulsesPerSecondaryPulse++; 00081 00082 LongTime timeStamp; 00083 00084 /* Install the low word */ 00085 timeStamp.timeShorts[1] = edgeTimeStamp; 00086 /* Find out what our timer value means and put it in the high word */ 00087 if(TFLGOF && !(edgeTimeStamp & 0x8000)){ /* see 10.3.5 paragraph 4 of 68hc11 ref manual for details */ 00088 timeStamp.timeShorts[0] = timerExtensionClock + 1; 00089 }else{ 00090 timeStamp.timeShorts[0] = timerExtensionClock; 00091 } 00092 RuntimeVars.primaryInputLeadingRuntime = TCNT - codeStartTimeStamp; 00093 }else{ 00094 PORTJ &= 0x7F; 00095 RuntimeVars.primaryInputTrailingRuntime = TCNT - codeStartTimeStamp; 00096 } 00097 00098 Counters.primaryTeethSeen++; 00099 }
void SecondaryRPMISR | ( | void | ) |
Use the rising and falling edges...................
Secondary RPM ISR
Definition at line 106 of file Subaru-36-2-2-2.c.
References fixedConfig1::coreSettingsA, Counters, fixedConfigs1, ISRLatencyVars, PORTJ, PTIT, RuntimeVars, SECONDARY_POLARITY, ISRLatencyVar::secondaryInputLatency, RuntimeVar::secondaryInputLeadingRuntime, RuntimeVar::secondaryInputTrailingRuntime, Counter::secondaryTeethSeen, TC1, TCNT, TFLG, TFLGOF, timerExtensionClock, and LongTime::timeShorts.
00107 { 00108 /* Clear the interrupt flag for this input compare channel */ 00109 TFLG = 0x02; 00110 00111 /* Save all relevant available data here */ 00112 unsigned short codeStartTimeStamp = TCNT; /* Save the current timer count */ 00113 unsigned short edgeTimeStamp = TC1; /* Save the timestamp */ 00114 unsigned char PTITCurrentState = PTIT; /* Save the values on port T regardless of the state of DDRT */ 00115 // unsigned short PORTS_BACurrentState = PORTS_BA; /* Save ignition output state */ 00116 00117 /* Calculate the latency in ticks */ 00118 ISRLatencyVars.secondaryInputLatency = codeStartTimeStamp - edgeTimeStamp; 00119 00120 // TODO discard narrow ones! test for tooth width and tooth period 00121 00122 /* Set up edges as per config */ 00123 unsigned char risingEdge; 00124 if(fixedConfigs1.coreSettingsA & SECONDARY_POLARITY){ 00125 risingEdge = PTITCurrentState & 0x02; 00126 }else{ 00127 risingEdge = !(PTITCurrentState & 0x02); 00128 } 00129 00130 if(risingEdge){ 00131 // echo input condition 00132 PORTJ |= 0x40; 00133 00134 LongTime timeStamp; 00135 00136 /* Install the low word */ 00137 timeStamp.timeShorts[1] = edgeTimeStamp; 00138 /* Find out what our timer value means and put it in the high word */ 00139 if(TFLGOF && !(edgeTimeStamp & 0x8000)){ /* see 10.3.5 paragraph 4 of 68hc11 ref manual for details */ 00140 timeStamp.timeShorts[0] = timerExtensionClock + 1; 00141 }else{ 00142 timeStamp.timeShorts[0] = timerExtensionClock; 00143 } 00144 00145 RuntimeVars.secondaryInputLeadingRuntime = TCNT - codeStartTimeStamp; 00146 }else{ 00147 PORTJ &= 0xBF; 00148 RuntimeVars.secondaryInputTrailingRuntime = TCNT - codeStartTimeStamp; 00149 } 00150 00151 Counters.secondaryTeethSeen++; 00152 }