Go to the source code of this file.
Functions | |
void | InjectorXISR () |
This code is identical between all 6 channels, and thus we only want one copy of it. The X in each macro will be replaced with the number that is appropriate for the channel it is being used for at the time.
Each channel performs the following actions
1 Clear its interrupt flag 2 Record its start time 3 Measure and record its latency 4 Check to see if its just turned on 4.1 Copy the channels pulse width to a local variable 4.2 Determine the minimum pulse width based on code run time const and latency 4.3 Clamp used pulsewidth inside min and max 4.4 If used pulse width is larger than the current period of the engines cycle flag as always on 4.5 Set the action to turn off 4.6 Increment the time by pulse width 4.7 If staging required, either, switch them on and sched to turn off, or sched to turn on 5 Else it has just turned off 5.1 If staged channel is still on, turn it off 5.2 If(self schedule flagged) schedule the next start 5.3 Else disable itself 6 Calculate and record code run time 7 Return
Definition in file injectorISR.c.
void InjectorXISR | ( | ) |
Definition at line 56 of file injectorISR.c.
References fixedConfig1::coreSettingsA, coreStatusA, fixedConfigs1, INJECTOR_CHANNEL_NUMBER, injectorCodeCloseRuntimes, injectorCodeLatencies, injectorCodeOpenRuntimes, injectorMainControlRegisters, injectorMainDisableMasks, injectorMainEndTimes, injectorMainGoHighMasks, injectorMainGoLowMasks, injectorMainOffMasks, injectorMainOnMasks, injectorMainPulseWidthsRealtime, injectorMainStartTimesHolding, injectorMainTimeRegisters, injectorSwitchOnCodeTime, PTIT, selfSetTimer, STAGED_REQUIRED, STAGED_START, stagedOn, STAGEDPORT, STAGEDXOFF, STAGEDXON, TCNT, TFLG, TFLGOF, TIE, LongTime::timeLong, timerExtensionClock, and LongTime::timeShorts.
00056 { 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 }