00001 /* Copyright 2008 Fred Cooke 00002 00003 This file is part of the FreeEMS project. 00004 00005 FreeEMS software is free software: you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation, either version 3 of the License, or 00008 (at your option) any later version. 00009 00010 FreeEMS software is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with any FreeEMS software. If not, see http://www.gnu.org/licenses/ 00017 00018 We ask that if you make any changes to this file you email them upstream to 00019 us at admin(at)diyefi(dot)org or, even better, fork the code on github.com! 00020 00021 Thank you for choosing FreeEMS to run your engine! */ 00022 00023 00056 void InjectorXISR(){ 00057 /* Clear the interrupt flag for this channel */ 00058 TFLG = injectorMainOnMasks[INJECTOR_CHANNEL_NUMBER]; 00059 00060 /* Record the current time as start time */ 00061 unsigned short TCNTStart = TCNT; 00062 00063 /* Record the edge time stamp from the IC register */ 00064 unsigned short edgeTimeStamp = *injectorMainTimeRegisters[INJECTOR_CHANNEL_NUMBER]; 00065 00066 /* Calculate and store the latency based on compare time and start time */ 00067 injectorCodeLatencies[INJECTOR_CHANNEL_NUMBER] = TCNTStart - edgeTimeStamp; 00068 00069 /* If rising edge triggered this */ 00070 if(PTIT & injectorMainOnMasks[INJECTOR_CHANNEL_NUMBER]){ // Stuff for switch on time 00071 00072 /* Find out what max and min for pulse width are */ 00073 unsigned short localPulseWidth = injectorMainPulseWidthsRealtime[INJECTOR_CHANNEL_NUMBER]; 00074 unsigned short localMinimumPulseWidth = injectorSwitchOnCodeTime + injectorCodeLatencies[INJECTOR_CHANNEL_NUMBER]; 00075 00078 /* Ensure we dont go under minimum pulsewidth */ 00079 if(localPulseWidth < localMinimumPulseWidth){ 00080 localPulseWidth = localMinimumPulseWidth; 00081 }/* else{ just use the value } */ 00082 00083 LongTime timeStamp; 00084 00085 /* Install the low word */ 00086 timeStamp.timeShorts[1] = edgeTimeStamp; 00087 /* Find out what our timer value means and put it in the high word */ 00088 if(TFLGOF && !(edgeTimeStamp & 0x8000)){ /* see 10.3.5 paragraph 4 of 68hc11 ref manual for details */ 00089 timeStamp.timeShorts[0] = timerExtensionClock + 1; 00090 }else{ 00091 timeStamp.timeShorts[0] = timerExtensionClock; 00092 } 00093 00094 // store the end time for use in the scheduler 00095 injectorMainEndTimes[INJECTOR_CHANNEL_NUMBER] = timeStamp.timeLong + localPulseWidth; 00096 00097 /* Set the action for compare to switch off FIRST or it might inadvertently PWM the injector during opening... */ 00098 *injectorMainControlRegisters[INJECTOR_CHANNEL_NUMBER] &= injectorMainGoLowMasks[INJECTOR_CHANNEL_NUMBER]; 00099 00100 /* Set the time to turn off again */ 00101 *injectorMainTimeRegisters[INJECTOR_CHANNEL_NUMBER] += localPulseWidth; 00102 00103 /* This is the point we actually want the time to, but because the code is so simple, it can't help but be a nice short time */ 00104 00105 /* If staged injection is required, switch on or schedule corresponding staged injector and remember that we did. */ 00106 if(coreStatusA & STAGED_REQUIRED){ 00107 if(fixedConfigs1.coreSettingsA & STAGED_START){ 00108 /* Switch that channel on NOW */ 00109 STAGEDPORT |= STAGEDXON; 00110 stagedOn |= STAGEDXON; 00111 }else{ 00112 /* Schedule the start at a later time */ 00114 } 00115 } 00116 /* Calculate and store code run time */ 00117 injectorCodeOpenRuntimes[INJECTOR_CHANNEL_NUMBER] = TCNT - TCNTStart; 00118 }else{ // Stuff for switch off time 00119 /* If we switched the staged injector on and it's still on, turn it off now. */ 00120 if(stagedOn & STAGEDXON){ 00121 STAGEDPORT &= STAGEDXOFF; 00122 stagedOn &= STAGEDXOFF; 00123 } 00124 00125 /* Set the action for compare to switch on and the time to next start time, clear the self timer flag */ 00126 if(selfSetTimer & injectorMainOnMasks[INJECTOR_CHANNEL_NUMBER]){ 00127 *injectorMainTimeRegisters[INJECTOR_CHANNEL_NUMBER] = injectorMainStartTimesHolding[INJECTOR_CHANNEL_NUMBER]; 00128 *injectorMainControlRegisters[INJECTOR_CHANNEL_NUMBER] |= injectorMainGoHighMasks[INJECTOR_CHANNEL_NUMBER]; 00129 selfSetTimer &= injectorMainOffMasks[INJECTOR_CHANNEL_NUMBER]; 00130 }else{ 00131 // Disable interrupts and actions incase the period from this end to the next start is long (saves cpu) 00132 TIE &= injectorMainOffMasks[INJECTOR_CHANNEL_NUMBER]; 00133 *injectorMainControlRegisters[INJECTOR_CHANNEL_NUMBER] &= injectorMainDisableMasks[INJECTOR_CHANNEL_NUMBER]; 00134 } 00135 /* Calculate and store code run time */ 00136 injectorCodeCloseRuntimes[INJECTOR_CHANNEL_NUMBER] = TCNT - TCNTStart; 00137 } 00138 }