#include "inc/freeEMS.h"
#include "inc/interrupts.h"
#include "inc/commsISRs.h"
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. |
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.
Definition in file realtimeISRs.c.
#define REALTIMEISRS_C |
Definition at line 39 of file realtimeISRs.c.
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.
Definition at line 148 of file realtimeISRs.c.
References engineCyclePeriod, fixedConfigs1, MCCNT, MCFLG, PORTA, tachoPeriod, fixedConfig1::tachoSettings, tachoSetting::tachoTotalFactor, and ticksPerCycleAtOneRPM.
00148 { 00149 /* Clear the modulus down counter interrupt flag */ 00150 MCFLG = 0x80; 00151 00152 /* If the rpm isn't genuine go ultra slow */ 00153 if(engineCyclePeriod == ticksPerCycleAtOneRPM){ 00154 tachoPeriod = 65535; 00155 }else{ 00156 /* Use engine cycle period to setup the frequency of this counter and thereby act as a tacho out */ 00157 tachoPeriod = (unsigned long)engineCyclePeriod / fixedConfigs1.tachoSettings.tachoTotalFactor; 00158 } 00159 /* Set the count down value */ 00160 MCCNT = tachoPeriod; 00161 00162 /* Bit bang the output port */ 00163 PORTA ^= 0x40; // SM pin (A6) 00164 }
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.
Definition at line 52 of file realtimeISRs.c.
References Clocks, coreStatusA, CRGFLG, fixedConfigs2, FORCE_READING, Clock::millisToTenths, portHDebounce, PORTP, 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, and TRUE.
00052 { 00053 /* Clear the RTI flag */ 00054 CRGFLG = 0x80; 00055 00056 /* Record time stamp for code run time reporting */ 00057 unsigned short startTimeRTI = TCNT; 00058 00059 /* Increment the counter */ 00060 Clocks.realTimeClockMain++; 00061 00062 /* 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 */ 00063 00064 // TODO add content to eighths of a milli RTC ? 00065 00066 /* Every 8th RTI execution is one milli */ 00067 if(Clocks.realTimeClockMain % 8 == 0){ 00068 /* Increment the milli counter */ 00069 Clocks.realTimeClockMillis++; 00070 00071 /* Increment the milli roll over variable */ 00072 Clocks.millisToTenths++; 00073 00074 /* Perform all tasks that are once per millisecond here or preferably main */ 00075 Clocks.timeoutADCreadingClock++; 00076 if(Clocks.timeoutADCreadingClock > fixedConfigs2.sensorSettings.readingTimeout){ 00077 /* Set force read adc flag */ 00078 coreStatusA |= FORCE_READING; 00079 Clocks.timeoutADCreadingClock = 0; 00080 } 00081 00082 /* Every 100 millis is one tenth */ 00083 if(Clocks.millisToTenths % 100 == 0){ 00084 /* Increment the tenths counter */ 00085 Clocks.realTimeClockTenths++; 00086 00087 /* Increment the tenths roll over variable */ 00088 Clocks.tenthsToSeconds++; 00089 00090 /* Reset the millis roll over variable */ 00091 Clocks.millisToTenths = 0; 00092 00093 /* Perform all tasks that are once per tenth of a second here or preferably main */ 00094 // decrement port H debounce variable till it's zero again. 00095 if(portHDebounce != 0){ 00096 portHDebounce -= 1; 00097 } 00098 00099 /* Every 10 tenths is one second */ 00100 if(Clocks.tenthsToSeconds % 10 == 0){ 00101 /* Increment the seconds counter */ 00102 Clocks.realTimeClockSeconds++; 00103 00104 /* Increment the seconds roll over variable */ 00105 Clocks.secondsToMinutes++; 00106 00107 /* Reset the tenths roll over variable */ 00108 Clocks.tenthsToSeconds = 0; 00109 /* Perform all tasks that are once per second here or preferably main */ 00110 00111 // temp throttling for log due to tuner performance issues (in the bedroom) 00112 ShouldSendLog = TRUE; 00113 /* Flash the user LED as a "heartbeat" to let new users know it's alive */ 00114 PORTP ^= 0x80; 00115 00116 /* Every 60 seconds is one minute, 65535 minutes is enough for us :-) */ 00117 if(Clocks.secondsToMinutes % 60 == 0){ 00118 /* Increment the minutes counter */ 00119 Clocks.realTimeClockMinutes++; 00120 00121 /* Potentially put an hours field in here and below, but that would be excessive */ 00122 // TODO add hours RTC ? 00123 00124 /* Reset the seconds roll over variable */ 00125 Clocks.secondsToMinutes = 0; 00126 00127 /* Perform all tasks that are once per minute here or preferably main */ 00128 // TODO add content in minutes RTC ? 00129 00130 /* Hours if statement here if we do hours which we probably won't */ 00131 } 00132 } 00133 } 00134 } 00135 RuntimeVars.RTCRuntime = TCNT - startTimeRTI; 00136 }
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.
Definition at line 175 of file realtimeISRs.c.
References TFLGOF, and timerExtensionClock.
00175 { 00176 /* Increment the timer extension variable */ 00177 timerExtensionClock++; 00178 00179 /* Clear the timer overflow interrupt flag */ 00180 TFLGOF = 0x80; 00181 }