realtimeISRs.c File Reference

Real time interrupts. More...

#include "inc/freeEMS.h"
#include "inc/interrupts.h"
#include "inc/commsISRs.h"
Include dependency graph for realtimeISRs.c:

Go to the source code of this file.

Defines

#define REALTIMEISRS_C

Functions

void RTIISR ()
 Real Time Interrupt Handler.
void ModDownCtrISR ()
 Tacho pulse generator.
void TimerOverflow ()
 ECT overflow handler.

Detailed Description

Real time interrupts.

This file contains real time interrupt handlers. Mainly it holds the RTI handler itself, however the modulus down counter and ETC timer overflow functions are here too.

Author:
Fred Cooke

Definition in file realtimeISRs.c.


Define Documentation

#define REALTIMEISRS_C

Definition at line 40 of file realtimeISRs.c.


Function Documentation

void ModDownCtrISR ( void   ) 

Tacho pulse generator.

Currently this is being used to generate a variable frequency tachometer output. Although this is a bit of a waste of a timer resource it does allow tachometers that were intended for engines with a different cylinder count to be used where it would otherwise not be possible.

Author:
Fred Cooke

Definition at line 150 of file realtimeISRs.c.

References engineCyclePeriod, fixedConfigs1, MCCNT, MCFLG, PORTA, tachoPeriod, fixedConfig1::tachoSettings, tachoSetting::tachoTotalFactor, and ticksPerCycleAtOneRPM.

00150                     {
00151     /* Clear the modulus down counter interrupt flag */
00152     MCFLG = 0x80;
00153 
00154     /* If the rpm isn't genuine go ultra slow */
00155     if(engineCyclePeriod == ticksPerCycleAtOneRPM){
00156         tachoPeriod = 65535;
00157     }else{
00158         /* Use engine cycle period to setup the frequency of this counter and thereby act as a tacho out */
00159         tachoPeriod = (unsigned long)engineCyclePeriod / fixedConfigs1.tachoSettings.tachoTotalFactor;
00160     }
00161     /* Set the count down value */
00162     MCCNT = tachoPeriod;
00163 
00164     /* Bit bang the output port */
00165     PORTA ^= 0x40; // SM pin (A6)
00166 }

void RTIISR ( void   ) 

Real Time Interrupt Handler.

Handles time keeping, including all internal clocks, and generic periodic tasks that run quickly and must be done on time.

Author:
Fred Cooke

Definition at line 53 of file realtimeISRs.c.

References Clocks, coreStatusA, CRGFLG, fixedConfigs2, FORCE_READING, Clock::millisToTenths, portHDebounce, sensorSetting::readingTimeout, Clock::realTimeClockMain, Clock::realTimeClockMillis, Clock::realTimeClockMinutes, Clock::realTimeClockSeconds, Clock::realTimeClockTenths, RuntimeVar::RTCRuntime, RuntimeVars, Clock::secondsToMinutes, fixedConfig2::sensorSettings, ShouldSendLog, TCNT, Clock::tenthsToSeconds, Clock::timeoutADCreadingClock, TRUE, and XGSWT.

00053              {
00054     /* Clear the RTI flag */
00055     CRGFLG = 0x80;
00056 
00057     /* Record time stamp for code run time reporting */
00058     unsigned short startTimeRTI = TCNT;
00059 
00060     /* Increment the counter */
00061     Clocks.realTimeClockMain++;
00062 
00063     /* This function could be performed without the extra variables by rolling over the main ones at the largest multiples of the next ones, but I'm not sure thats better */
00064 
00065     // TODO add content to eighths of a milli RTC ?
00066 
00067     /* Every 8th RTI execution is one milli */
00068     if(Clocks.realTimeClockMain % 8 == 0){
00069         /* Increment the milli counter */
00070         Clocks.realTimeClockMillis++;
00071 
00072         /* Increment the milli roll over variable */
00073         Clocks.millisToTenths++;
00074 
00075         /* Perform all tasks that are once per millisecond here or preferably main */
00076         Clocks.timeoutADCreadingClock++;
00077         if(Clocks.timeoutADCreadingClock > fixedConfigs2.sensorSettings.readingTimeout){
00078             /* Set force read adc flag */
00079             coreStatusA |= FORCE_READING;
00080             Clocks.timeoutADCreadingClock = 0;
00081         }
00082 
00083         /* Every 100 millis is one tenth */
00084         if(Clocks.millisToTenths % 100 == 0){
00085             /* Increment the tenths counter */
00086             Clocks.realTimeClockTenths++;
00087 
00088             /* Increment the tenths roll over variable */
00089             Clocks.tenthsToSeconds++;
00090 
00091             /* Reset the millis roll over variable */
00092             Clocks.millisToTenths = 0;
00093 
00094             /* Perform all tasks that are once per tenth of a second here or preferably main */
00095             // decrement port H debounce variable till it's zero again.
00096             if(portHDebounce != 0){
00097                 portHDebounce -= 1;
00098             }
00099 
00100             /* Every 10 tenths is one second */
00101             if(Clocks.tenthsToSeconds % 10 == 0){
00102                 /* Increment the seconds counter */
00103                 Clocks.realTimeClockSeconds++;
00104                 XGSWT = 0x0101; /* set off software trigger 0 that is handled by xgate */
00105 
00106                 /* Increment the seconds roll over variable */
00107                 Clocks.secondsToMinutes++;
00108 
00109                 /* Reset the tenths roll over variable */
00110                 Clocks.tenthsToSeconds = 0;
00111                 /* Perform all tasks that are once per second here or preferably main */
00112 
00113                 // temp throttling for log due to tuner performance issues (in the bedroom)
00114                 ShouldSendLog = TRUE;
00115                 /* Flash the user LED as a "heartbeat" to let new users know it's alive */
00116                 //PORTP ^= 0x80;
00117 
00118                 /* Every 60 seconds is one minute, 65535 minutes is enough for us :-) */
00119                 if(Clocks.secondsToMinutes % 60 == 0){
00120                     /* Increment the minutes counter */
00121                     Clocks.realTimeClockMinutes++;
00122 
00123                     /* Potentially put an hours field in here and below, but that would be excessive */
00124                     // TODO add hours RTC ?
00125 
00126                     /* Reset the seconds roll over variable */
00127                     Clocks.secondsToMinutes = 0;
00128 
00129                     /* Perform all tasks that are once per minute here or preferably main */
00130                     // TODO add content in minutes RTC ?
00131 
00132                     /* Hours if statement here if we do hours which we probably won't */
00133                 }
00134             }
00135         }
00136     }
00137     RuntimeVars.RTCRuntime = TCNT - startTimeRTI;
00138 }

void TimerOverflow ( void   ) 

ECT overflow handler.

When the ECT free running timer hits 65535 and rolls over, this is run. Its job is to extend the timer to an effective 32 bits for longer measuring much longer periods with the same resolution.

Author:
Fred Cooke

Definition at line 177 of file realtimeISRs.c.

References TFLGOF, and timerExtensionClock.

00177                     {
00178     /* Increment the timer extension variable */
00179     timerExtensionClock++;
00180 
00181     /* Clear the timer overflow interrupt flag */
00182     TFLGOF = 0x80;
00183 }

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