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