auto-sync

This commit is contained in:
rusEfi 2014-09-26 15:03:02 -05:00
parent 4811563847
commit 7ebfe42b15
5 changed files with 64 additions and 14 deletions

View File

@ -13,6 +13,10 @@
#include "engine.h"
#include "engine_state.h"
#if EFI_PROD_CODE || EFI_SIMULATOR
static Logging logger;
#endif
/**
* We are executing these heavy (logarithm) methods from outside the trigger callbacks for performance reasons.
*/
@ -21,3 +25,36 @@ void Engine::updateSlowSensors() {
engineState.clt = getCoolantTemperature();
}
void Engine::onTriggerEvent(uint64_t nowUs) {
isSpinning = true;
lastTriggerEventTimeUs = nowUs;
}
void Engine::init() {
#if EFI_PROD_CODE || EFI_SIMULATOR
initLogging(&logger, "engine");
#endif
}
void Engine::watchdog() {
if (!isSpinning) {
return;
}
uint64_t nowUs = getTimeNowUs();
/**
* Lowest possible cranking is about 240 RPM, that's 4 revolutions per second.
* 0.25 second is 250000 uS
*/
if (nowUs - lastTriggerEventTimeUs < 250000) {
return;
}
isSpinning = true;
scheduleMsg(&logger, "engine has STOPPED");
for (int i = 0; i < engineConfiguration->cylindersCount; i++) {
// io_pin_e pin = (io_pin_e) ((int) INJECTOR_1_OUTPUT + i);
//pin = (io_pin_e) ((int) SPARKOUT_1_OUTPUT + i);
}
}

View File

@ -19,6 +19,25 @@ public:
float iat;
float clt;
};
class RpmCalculator;
class Engine {
public:
void init();
RpmCalculator *rpmCalculator;
engine_configuration_s *engineConfiguration;
engine_configuration2_s *engineConfiguration2;
void onTriggerEvent(uint64_t nowUs);
EngineState engineState;
uint64_t lastTriggerEventTimeUs;
void updateSlowSensors();
void watchdog();
private:
/**
* By the way:
* 'cranking' means engine is not stopped and the rpm are below crankingRpm
@ -29,18 +48,4 @@ public:
};
class RpmCalculator;
class Engine {
public:
RpmCalculator *rpmCalculator;
engine_configuration_s *engineConfiguration;
engine_configuration2_s *engineConfiguration2;
EngineState engineState;
void updateSlowSensors();
};
#endif /* ENGINE_H_ */

View File

@ -172,6 +172,7 @@ static void onEvenyGeneralMilliseconds(void *arg) {
if (!engine.rpmCalculator->isRunning())
writeToFlashIfPending();
engine.watchdog();
engine.updateSlowSensors();
updateErrorCodes();

View File

@ -93,12 +93,17 @@ static void reportEventToWaveChart(trigger_event_e ckpSignalType, int index) {
}
}
// todo: improve this
extern Engine engine;
void TriggerCentral::handleShaftSignal(configuration_s *configuration, trigger_event_e signal, uint64_t nowUs) {
efiAssertVoid(configuration!=NULL, "configuration");
efiAssertVoid(configuration->engineConfiguration!=NULL, "engineConfiguration");
efiAssertVoid(configuration->engineConfiguration2!=NULL, "engineConfiguration2");
engine.onTriggerEvent(nowUs);
#if EFI_HISTOGRAMS && EFI_PROD_CODE
int beforeCallback = hal_lld_get_counter_value();
#endif

View File

@ -150,6 +150,8 @@ void runRusEfi(void) {
initializeConsole();
initLogging(&logging, "main");
engine.init();
addConsoleAction("reset", scheduleReset);
/**