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