realtimeISRs.c File Reference

#include "inc/freeEMS.h"
#include "inc/interrupts.h"
#include "inc/commsISRs.h"
#include "inc/realtimeISRs.h"

Include dependency graph for realtimeISRs.c:

Go to the source code of this file.

Defines

#define REALTIMEISRS_C

Functions

void RTIISR (void)
void ModDownCtrISR (void)
void TimerOverflow (void)


Define Documentation

#define REALTIMEISRS_C

Definition at line 24 of file realtimeISRs.c.


Function Documentation

void ModDownCtrISR ( void   ) 

Definition at line 118 of file realtimeISRs.c.

References engineCyclePeriod, fixedConfigs, MCCNT, MCFLG, PORTA, tachoPeriod, fixedConfig::tachoTotalFactor, and ticksPerCycleAtOneRPM.

00119 {
00120         /* Clear the modulus down counter interrupt flag */
00121         MCFLG = 0x80;
00122 
00123         /* If the rpm isn't genuine go ultra slow */
00124         if(engineCyclePeriod == ticksPerCycleAtOneRPM){
00125                 tachoPeriod = 65535;
00126         }else{
00127                 /* Use engine cycle period to setup the frequency of this counter and thereby act as a tacho out */
00128                 tachoPeriod = (unsigned long)engineCyclePeriod / fixedConfigs.tachoTotalFactor;
00129         }
00130         /* Set the count down value */
00131         MCCNT = tachoPeriod;
00132 
00133         /* Bit bang the output port */
00134         PORTA ^= 0x40; // SM pin (A6)
00135 }

void RTIISR ( void   ) 

Definition at line 32 of file realtimeISRs.c.

References Clocks, coreStatusA, CRGFLG, fixedConfigs, FORCE_READING, Clock::millisToTenths, portHDebounce, PORTP, fixedConfig::readingTimeout, Clock::realTimeClockMain, Clock::realTimeClockMillis, Clock::realTimeClockMinutes, Clock::realTimeClockSeconds, Clock::realTimeClockTenths, RuntimeVar::RTCRuntime, RuntimeVars, Clock::secondsToMinutes, TCNT, Clock::tenthsToSeconds, and Clock::timeoutADCreadingClock.

00033 {
00034         /* Clear the RTI flag */
00035         CRGFLG = 0x80;
00036 
00037         /* Record time stamp for code run time reporting */
00038         unsigned short startTimeRTI = TCNT;
00039 
00040         /* Increment the counter */
00041         Clocks.realTimeClockMain++;
00042 
00043         /* 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 */
00044 
00045         // TODO add content to eighths of a milli RTC ?
00046 
00047         /* Every 8th RTI execution is one milli */
00048         if(Clocks.realTimeClockMain % 8 == 0){
00049                 /* Increment the milli counter */
00050                 Clocks.realTimeClockMillis++;
00051 
00052                 /* Increment the milli roll over variable */
00053                 Clocks.millisToTenths++;
00054 
00055                 /* Perform all tasks that are once per millisecond here or preferably main */
00056                 Clocks.timeoutADCreadingClock++;
00057                 if(Clocks.timeoutADCreadingClock > fixedConfigs.readingTimeout){
00058                         /* Set force read adc flag */
00059                         coreStatusA |= FORCE_READING;
00060                         Clocks.timeoutADCreadingClock = 0;
00061                 }
00062 
00063                 /* Every 100 millis is one tenth */
00064                 if(Clocks.millisToTenths % 100 == 0){
00065                         /* Increment the tenths counter */
00066                         Clocks.realTimeClockTenths++;
00067 
00068                         /* Increment the tenths roll over variable */
00069                         Clocks.tenthsToSeconds++;
00070 
00071                         /* Reset the millis roll over variable */
00072                         Clocks.millisToTenths = 0;
00073 
00074                         /* Perform all tasks that are once per tenth of a second here or preferably main */
00075                         // decrement port H debounce variable till it's zero again.
00076                         if(portHDebounce != 0){
00077                                 portHDebounce -= 1;
00078                         }
00079 
00080                         /* Every 10 tenths is one second */
00081                         if(Clocks.tenthsToSeconds % 10 == 0){
00082                                 /* Increment the seconds counter */
00083                                 Clocks.realTimeClockSeconds++;
00084 
00085                                 /* Increment the seconds roll over variable */
00086                                 Clocks.secondsToMinutes++;
00087 
00088                                 /* Reset the tenths roll over variable */
00089                                 Clocks.tenthsToSeconds = 0;
00090                                 /* Perform all tasks that are once per second here or preferably main */
00091 
00092                                 /* Flash the user LED as a "heartbeat" to let new users know it's alive */
00093                                 PORTP ^= 0x80;
00094 
00095                                 /* Every 60 seconds is one minute, 65535 minutes is enough for us :-) */
00096                                 if(Clocks.secondsToMinutes % 60 == 0){
00097                                         /* Increment the minutes counter */
00098                                         Clocks.realTimeClockMinutes++;
00099 
00100                                         /* Potentially put an hours field in here and below, but that would be excessive */
00101                                         // TODO add hours RTC ?
00102 
00103                                         /* Reset the seconds roll over variable */
00104                                         Clocks.secondsToMinutes = 0;
00105 
00106                                         /* Perform all tasks that are once per minute here or preferably main */
00107                                         // TODO add content in minutes RTC ?
00108 
00109                                         /* Hours if statement here if we do hours which we probably won't */
00110                                 }
00111                         }
00112                 }
00113         }
00114         RuntimeVars.RTCRuntime = TCNT - startTimeRTI;
00115 }

void TimerOverflow ( void   ) 

Definition at line 138 of file realtimeISRs.c.

References TFLGOF, and timerExtensionClock.

00138                         {
00139         /* Increment the timer extension variable */
00140         timerExtensionClock++;
00141 
00142         /* Clear the timer overflow interrupt flag */
00143         TFLGOF = 0x80;
00144 }


Generated on Mon Nov 10 21:19:14 2008 for freeems by  doxygen 1.5.2