00001 /* FreeEMS - the open source engine management system 00002 00003 Copyright 2008 Fred Cooke 00004 00005 This file is part of the FreeEMS project. 00006 00007 FreeEMS software is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation, either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 FreeEMS software is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with any FreeEMS software. If not, see http://www.gnu.org/licenses/ 00019 00020 We ask that if you make any changes to this file you email them upstream to 00021 us at admin(at)diyefi(dot)org or, even better, fork the code on github.com! 00022 00023 Thank you for choosing FreeEMS to run your engine! */ 00024 00025 00039 #define REALTIMEISRS_C 00040 #include "inc/freeEMS.h" 00041 #include "inc/interrupts.h" 00042 #include "inc/commsISRs.h" 00043 00044 00052 void RTIISR(){ 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 } 00137 00138 00148 void ModDownCtrISR(){ 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 } 00165 00166 00175 void TimerOverflow(){ 00176 /* Increment the timer extension variable */ 00177 timerExtensionClock++; 00178 00179 /* Clear the timer overflow interrupt flag */ 00180 TFLGOF = 0x80; 00181 } 00182 00183