injectorISR.c File Reference

Injector ISR shared code. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void InjectorXISR ()

Detailed Description

Injector ISR shared code.

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

Author:
Fred Cooke

Definition in file injectorISR.c.


Function Documentation

void InjectorXISR (  ) 

Todo:
TODO *maybe* instead of checking min and increasing pulse, just force it straight off if diff between start and now+const is greater than desired pulsewidth
Todo:
TODO PIT scheduling of staged start

Definition at line 59 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.

00059                    {
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 }

Generated on Sat Oct 16 21:29:15 2010 for FreeEMS by  doxygen 1.6.3