FreeEMS  0.2.0-SNAPSHOT-285-g028e24c
Macros | Functions
realtimeISRs.c File Reference

Real time interrupts. More...

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

Go to the source code of this file.

Macros

#define REALTIMEISRS_C

Functions

void RTIISR ()
 Real Time Interrupt Handler.
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.

Definition in file realtimeISRs.c.

Macro Definition Documentation

#define REALTIMEISRS_C

Definition at line 39 of file realtimeISRs.c.

Function Documentation

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.

Todo:
TODO refactor this entire file, especially to remove apparently expensive modulus operations which could be replaced with >= instead. Maybe much more.
Todo:
TODO This is too quick to turn off, average 0.5 seconds, which is OK, but fastest = 0seconds which is difficult to understand, needs a flag and to be 1 - 2 with average 1.5.

Definition at line 52 of file realtimeISRs.c.

References BIT3, BIT6, BIT7, CLEAR_FUEL_PUMP_PRIME, Clocks, coreStatusA, CoreVars, CRGFLG, DEBUG_TURN_PIN_OFF, DEBUG_TURN_PIN_ON, DECODER_BENCHMARKS, fixedConfigs2, FORCE_READING, FUEL_PUMP_PRIME, sensorSetting::fuelPumpPrimePeriod, Clock::millisToTenths, NBIT3, NBIT7, PORTA, PORTB, portHDebounce, sensorSetting::readingTimeout, Clock::realTimeClockMain, Clock::realTimeClockMillis, Clock::realTimeClockMinutes, Clock::realTimeClockSeconds, Clock::realTimeClockTenths, CoreVar::RPM, Clock::secondsToMinutes, fixedConfig2::sensorSettings, Clock::tenthsToSeconds, and Clock::timeoutADCreadingClock.

{
/* Clear the RTI flag */
CRGFLG = 0x80;
/* Increment the counter */
/* 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 */
// TODO add content to eighths of a milli RTC ?
/// @todo TODO refactor this entire file, especially to remove apparently expensive modulus operations which could be replaced with >= instead. Maybe much more.
/* Every 8th RTI execution is one milli */
if(Clocks.realTimeClockMain % 8 == 0){
/* Increment the milli counter */
/* Increment the milli roll over variable */
/* Perform all tasks that are once per millisecond here or preferably main */
/* Set force read adc flag */
}else if (CoreVars->RPM > 0){ // turn on very quickly if rpm appears non zero, temp impl...
PORTA |= BIT7;
}
#ifdef XGATE_TESTS
#include "xgateTests.c"
#endif
/* Every 100 millis is one tenth */
if(Clocks.millisToTenths % 100 == 0){
/* Increment the tenths counter */
/* Increment the tenths roll over variable */
/* Reset the millis roll over variable */
/* Perform all tasks that are once per tenth of a second here or preferably main */
// decrement port H debounce variable till it's zero again.
if(portHDebounce != 0){
}
/* Every 10 tenths is one second */
if(Clocks.tenthsToSeconds % 10 == 0){
/* Increment the seconds counter */
/* Increment the seconds roll over variable */
/* Reset the tenths roll over variable */
/* Perform all tasks that are once per second here or preferably main */
// Toggle the CEL on the same pin as the SM load/run switch
PORTA ^= BIT6;
// temp fuel pump prime and safety off impl
}
}else if(CoreVars->RPM == 0){ /// @todo TODO This is too quick to turn off, average 0.5 seconds, which is OK, but fastest = 0seconds which is difficult to understand, needs a flag and to be 1 - 2 with average 1.5.
}
/* Every 60 seconds is one minute, 65535 minutes is enough for us :-) */
if(Clocks.secondsToMinutes % 60 == 0){
/* Increment the minutes counter */
/* Potentially put an hours field in here and below, but that would be excessive */
// TODO add hours RTC ?
/* Reset the seconds roll over variable */
/* Perform all tasks that are once per minute here or preferably main */
// TODO add content in minutes RTC ?
/* Hours if statement here if we do hours which we probably won't */
}
}
}
}
}
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. Please see section 10.5.5 of the 68HC11 reference manual for more information on this technique!

Warning
The extension var should be incremented before the flag is cleared!

Definition at line 164 of file realtimeISRs.c.

References BIT5, DEBUG_TURN_PIN_OFF, DEBUG_TURN_PIN_ON, DECODER_BENCHMARKS, NBIT5, PORTB, TFLGOF, and timerExtensionClock.

{
/* Increment the timer extension variable */
DEBUG_TURN_PIN_ON(DECODER_BENCHMARKS, BIT5, PORTB); // TODO Should this go after the flag, or before the timer inc??? 6 possibilities here!
/* Clear the timer overflow interrupt flag */
TFLGOF = 0x80;
}