00001 /* FreeEMS - the open source engine management system 00002 * 00003 * Copyright 2008, 2009 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 00026 00040 #define REALTIMEISRS_C 00041 #include "inc/freeEMS.h" 00042 #include "inc/interrupts.h" 00043 #include "inc/commsISRs.h" 00044 00045 00053 void RTIISR(){ 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 } 00139 00140 00150 void ModDownCtrISR(){ 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 } 00167 00168 00177 void TimerOverflow(){ 00178 /* Increment the timer extension variable */ 00179 timerExtensionClock++; 00180 00181 /* Clear the timer overflow interrupt flag */ 00182 TFLGOF = 0x80; 00183 } 00184 00185