From daa02842465ec9560d59b1f3db5f4d6845341e99 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Tue, 24 Feb 2015 18:11:57 -0600 Subject: [PATCH] auto-sync --- firmware/controllers/core/fsio_core.cpp | 13 +++++++++---- firmware/controllers/core/fsio_core.h | 2 +- firmware/controllers/core/interpolation.cpp | 5 ++++- firmware/controllers/engine_controller.cpp | 19 +++++++++++++------ 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/firmware/controllers/core/fsio_core.cpp b/firmware/controllers/core/fsio_core.cpp index 3ca51da7b1..ae434aad37 100644 --- a/firmware/controllers/core/fsio_core.cpp +++ b/firmware/controllers/core/fsio_core.cpp @@ -112,7 +112,7 @@ float LECalculator::pop(le_action_e action) { return stack.pop(); } -void LECalculator::doJob(Engine *engine, LEElement *element) { +bool_t LECalculator::doJob(Engine *engine, LEElement *element) { switch (element->action) { case LE_NUMERIC_VALUE: @@ -232,11 +232,12 @@ void LECalculator::doJob(Engine *engine, LEElement *element) { } break; case LE_UNDEFINED: - firmwareError("FSIO undefined action"); - break; + warning(OBD_PCM_Processor_Fault, "FSIO undefined action"); + return true; default: stack.push(getLEValue(engine, &stack, element->action)); } + return false; } float LECalculator::getValue2(LEElement *element, Engine *engine) { @@ -254,7 +255,11 @@ float LECalculator::getValue(Engine *engine) { stack.reset(); while (element != NULL) { - doJob(engine, element); + bool_t isError = doJob(engine, element); + if (isError) { + // error already reported + return NAN; + } element = element->next; } if (stack.size() != 1) { diff --git a/firmware/controllers/core/fsio_core.h b/firmware/controllers/core/fsio_core.h index b1b0bef389..53e0df5188 100644 --- a/firmware/controllers/core/fsio_core.h +++ b/firmware/controllers/core/fsio_core.h @@ -90,7 +90,7 @@ public: void reset(LEElement *element); private: - void doJob(Engine *engine, LEElement *element); + bool_t doJob(Engine *engine, LEElement *element); float pop(le_action_e action); LEElement *first; calc_stack_t stack; diff --git a/firmware/controllers/core/interpolation.cpp b/firmware/controllers/core/interpolation.cpp index 5d6bce9bb6..6271a8f2cb 100644 --- a/firmware/controllers/core/interpolation.cpp +++ b/firmware/controllers/core/interpolation.cpp @@ -101,7 +101,10 @@ float FastInterpolation::getValue(float x) { float interpolate(float x1, float y1, float x2, float y2, float x) { // todo: double comparison using EPS if (x1 == x2) { - firmwareError("interpolate: Same x1 and x2 in interpolate: %f/%f", x1, x2); + /** + * we could end up here for example while resetting bins while changing engine type + */ + warning(OBD_PCM_Processor_Fault, "interpolate: Same x1 and x2 in interpolate: %f/%f", x1, x2); return NAN; } diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 1fe5df8267..c114f881cd 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -200,6 +200,17 @@ static void cylinderCleanupControl(Engine *engine) { static LocalVersionHolder versionForConfigurationListeners; +static void onEvenyGeneralMilliseconds(Engine *engine); + +static void scheduleNextInvocation(void) { + // schedule next invocation + int period = boardConfiguration->generalPeriodicThreadPeriod; + if (period == 0) + period = 50; // this might happen while resetting config + chVTSetAny(&everyMsTimer, period * TICKS_IN_MS, (vtfunc_t) &onEvenyGeneralMilliseconds, engine); + +} + static void onEvenyGeneralMilliseconds(Engine *engine) { efiAssertVoid(getRemainingStack(chThdSelf()) > 64, "lowStckOnEv"); #if EFI_PROD_CODE @@ -238,15 +249,11 @@ static void onEvenyGeneralMilliseconds(Engine *engine) { cylinderCleanupControl(engine); - // schedule next invocation - chVTSetAny(&everyMsTimer, boardConfiguration->generalPeriodicThreadPeriod * TICKS_IN_MS, - (vtfunc_t) &onEvenyGeneralMilliseconds, engine); + scheduleNextInvocation(); } void initPeriodicEvents(Engine *engine) { - // schedule first invocation - chVTSetAny(&everyMsTimer, boardConfiguration->generalPeriodicThreadPeriod * TICKS_IN_MS, - (vtfunc_t) &onEvenyGeneralMilliseconds, engine); + scheduleNextInvocation(); } char * getPinNameByAdcChannel(adc_channel_e hwChannel, char *buffer) {