extract method

This commit is contained in:
rusefillc 2023-11-17 15:20:40 -05:00
parent afa1e36f46
commit cdc3371667
1 changed files with 21 additions and 13 deletions

View File

@ -398,6 +398,26 @@ void Engine::setConfig() {
injectEngineReferences();
}
/**
* This code asserts that we do not have unexpected gaps in time flow with the exception of internal flash burn.
*/
static void assertTimeIsLinear() {
static efitimems_t mostRecentMs = 0;
efitimems_t msNow = getTimeNowMs();
if (engineConfiguration->tempBooleanForVerySpecialLogic && engine->configBurnTimer.hasElapsedSec(5)) {
if (mostRecentMs != 0) {
efitimems_t gapInMs = msNow - mostRecentMs;
// todo: lower gapInMs threshold!
if (gapInMs > 500) {
firmwareError(ObdCode::WATCH_DOG_SECONDS, "gap in time: now=%d mS, was %d mS, gap=%dmS",
msNow, mostRecentMs, gapInMs);
}
}
}
mostRecentMs = msNow;
}
void Engine::efiWatchdog() {
#if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
if (isRunningPwmTest)
@ -407,19 +427,7 @@ void Engine::efiWatchdog() {
return;
}
static efitimems_t mostRecentMs = 0;
efitimems_t msNow = getTimeNowMs();
if (engineConfiguration->tempBooleanForVerySpecialLogic && engine->configBurnTimer.hasElapsedSec(5)) {
if (mostRecentMs != 0) {
efitimems_t gapInMs = msNow - mostRecentMs;
if (gapInMs > 500) {
firmwareError(ObdCode::WATCH_DOG_SECONDS, "gap in time: now=%d mS, was %d mS, gap=%dmS",
msNow, mostRecentMs, gapInMs);
}
}
}
mostRecentMs = msNow;
assertTimeIsLinear();
if (!getTriggerCentral()->isSpinningJustForWatchdog) {
if (!isRunningBenchTest() && enginePins.stopPins()) {