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