diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index b76a2066ef..f249b2cd16 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -143,7 +143,7 @@ static void reportSensorI(Logging *log, bool fileFormat, const char *caption, co EXTERN_ENGINE ; -void printSensors(Logging *log, bool fileFormat) { +static void printSensors(Logging *log, bool fileFormat) { // current time, in milliseconds int nowMs = currentTimeMillis(); float sec = ((float) nowMs) / 1000; @@ -215,7 +215,6 @@ void writeLogLine(void) { static void printState(void) { #if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__) - printSensors(&logger, false); // todo: make SWO work // char *msg = "hello\r\n"; @@ -325,12 +324,17 @@ void updateDevConsoleState(Engine *engine) { // checkIfShouldHalt(); printPending(); + /** + * this should go before the firmware error so that console can detect connection + */ + printSensors(&logger, false); + #if EFI_PROD_CODE || defined(__DOXYGEN__) // todo: unify with simulator! if (hasFirmwareError()) { - printMsg(&logger, "firmware error: %s", errorMessageBuffer); - warningEnabled = FALSE; - chThdSleepMilliseconds(200); + scheduleMsg(&logger, "firmware error: %s", errorMessageBuffer); + warningEnabled = false; + scheduleLogging(&logger); return; } #endif diff --git a/firmware/console/status_loop.h b/firmware/console/status_loop.h index 8634fa3de5..947620dd3c 100644 --- a/firmware/console/status_loop.h +++ b/firmware/console/status_loop.h @@ -11,7 +11,6 @@ #include "engine.h" void updateDevConsoleState(Engine *engine); -void printSensors(void); void prepareTunerStudioOutputs(void); void startStatusThreads(Engine *engine); void initStatusLoop(Engine *engine); diff --git a/firmware/controllers/error_handling.cpp b/firmware/controllers/error_handling.cpp index cf672f91d9..810f15512e 100644 --- a/firmware/controllers/error_handling.cpp +++ b/firmware/controllers/error_handling.cpp @@ -58,7 +58,7 @@ static MemoryStream warningStream; int warning(obd_code_e code, const char *fmt, ...) { int now = getTimeNowSeconds(); if (absI(now - timeOfPreviousWarning) < 10 || !warningEnabled) - return TRUE; // we just had another warning, let's not spam + return true; // we just had another warning, let's not spam timeOfPreviousWarning = now; resetLogging(&logger); // todo: is 'reset' really needed here? diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index 3d97839ede..27fb983d48 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -247,14 +247,18 @@ static int findAngleIndex(float angleOffset DECLARE_ENGINE_PARAMETER_S) { float eventAngle = TRIGGER_SHAPE(eventAngles[middle]); if (middle == left) { - return middle; + /** + * in case of 'useOnlyFrontForTrigger' flag we will only use even angle indexes + */ + return engineConfiguration->useOnlyFrontForTrigger ? middle & 0xFFFFFFFE : middle; } if (angleOffset < eventAngle) { right = middle; } else if (angleOffset > eventAngle) { left = middle; } else { - return middle; + // see comment above + return engineConfiguration->useOnlyFrontForTrigger ? middle & 0xFFFFFFFE : middle; } } } diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index e5c422fa94..291ee66c91 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -75,7 +75,6 @@ static IgnitionEvent *iHead = NULL; * This queue is using global trigger event index as 'time' */ //static EventQueue triggerEventsQueue; - static cyclic_buffer ignitionErrorDetection; static Logging *logger; @@ -253,8 +252,7 @@ static ALWAYS_INLINE void handleSpark(uint32_t eventIndex, int rpm, scheduling_s * sDown = ¤t->signalTimerDown; float timeTillIgnitionUs = engine->rpmCalculator.oneDegreeUs * current->sparkPosition.angleOffset; - scheduleTask("spark 2down", sDown, (int) timeTillIgnitionUs, (schfunc_t) &turnPinLow, - current->output); + scheduleTask("spark 2down", sDown, (int) timeTillIgnitionUs, (schfunc_t) &turnPinLow, current->output); } } @@ -338,6 +336,10 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex DECL prepareOutputSignals(PASS_ENGINE_PARAMETER_F); } + if (engineConfiguration->useOnlyFrontForTrigger && engineConfiguration->ignMathCalculateAtIndex % 2 != 0) { + firmwareError("invalid ignMathCalculateAtIndex %d", engineConfiguration->ignMathCalculateAtIndex); + } + if (eventIndex == engineConfiguration->ignMathCalculateAtIndex) { if (engineConfiguration->externalKnockSenseAdc != EFI_ADC_NONE) { float externalKnockValue = getVoltageDivided(engineConfiguration->externalKnockSenseAdc); @@ -356,7 +358,6 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex DECL ENGINE(fuelMs) = getFuelMs(rpm PASS_ENGINE_PARAMETER) * engineConfiguration->globalFuelCorrection; engine->m.fuelCalcTime = GET_TIMESTAMP() - engine->m.beforeFuelCalc; - engine->m.beforeIgnitionSch = GET_TIMESTAMP(); /** * TODO: warning. there is a bit of a hack here, todo: improve. @@ -365,12 +366,15 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex DECL * but we are already repurposing the output signals, but everything works because we * are not affecting that space in memory. todo: use two instances of 'ignitionSignals' */ - float maxAllowedDwellAngle = (int)(engineConfiguration->engineCycle / 2); // the cast is about making Coverity happy + float maxAllowedDwellAngle = (int) (engineConfiguration->engineCycle / 2); // the cast is about making Coverity happy if (engineConfiguration->ignitionMode == IM_ONE_COIL) { maxAllowedDwellAngle = engineConfiguration->engineCycle / engineConfiguration->specs.cylindersCount / 1.1; } + if (engine->dwellAngle == 0) { + warning(OBD_PCM_Processor_Fault, "dwell is zero?"); + } if (engine->dwellAngle > maxAllowedDwellAngle) { warning(OBD_PCM_Processor_Fault, "dwell angle too long: %f", engine->dwellAngle); } @@ -387,13 +391,12 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex DECL engine->m.beforeInjectonSch = GET_TIMESTAMP(); - if(isCrankingR(rpm)) { - ENGINE(engineConfiguration2)->crankingInjectionEvents.addFuelEvents( - &crankingInjectonSignals, - engineConfiguration->crankingInjectionMode PASS_ENGINE_PARAMETER); + if (isCrankingR(rpm)) { + ENGINE(engineConfiguration2)->crankingInjectionEvents.addFuelEvents(&crankingInjectonSignals, + engineConfiguration->crankingInjectionMode PASS_ENGINE_PARAMETER); } else { ENGINE(engineConfiguration2)->injectionEvents.addFuelEvents(&runningInjectonSignals, - engineConfiguration->injectionMode PASS_ENGINE_PARAMETER); + engineConfiguration->injectionMode PASS_ENGINE_PARAMETER); } engine->m.injectonSchTime = GET_TIMESTAMP() - engine->m.beforeInjectonSch; } @@ -446,7 +449,6 @@ void initMainEventListener(Logging *sharedLogger, Engine *engine) { addConsoleAction("performanceinfo", showTriggerHistogram); addConsoleActionP("maininfo", (VoidPtr) showMainInfo, engine); - printMsg(logger, "initMainLoop: %d", currentTimeMillis()); if (!isInjectionEnabled(mainTriggerCallbackInstance.engine->engineConfiguration)) printMsg(logger, "!!!!!!!!!!!!!!!!!!! injection disabled"); diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index e738f5e223..b07078b53c 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -86,6 +86,7 @@ static trigger_value_e eventType[6] = { TV_LOW, TV_HIGH, TV_LOW, TV_HIGH, TV_LOW /* odd event - start accumulation */ \ timeOfPreviousEventNt[triggerWheel] = nowNt; \ } \ + if (engineConfiguration->useOnlyFrontForTrigger) {current_index++;} \ current_index++; \ } diff --git a/firmware/controllers/trigger/trigger_structure.cpp b/firmware/controllers/trigger/trigger_structure.cpp index 3bae9b4add..ac8893752d 100644 --- a/firmware/controllers/trigger/trigger_structure.cpp +++ b/firmware/controllers/trigger/trigger_structure.cpp @@ -62,14 +62,14 @@ void TriggerShape::calculateTriggerSynchPoint(DECLARE_ENGINE_PARAMETER_F) { float firstAngle = getAngle(triggerShapeSynchPointIndex); - for (int i = 0; i < engine->engineCycleEventCount; i++) { - if (i == 0) { + for (int eventIndex = 0; eventIndex < engine->engineCycleEventCount; eventIndex++) { + if (eventIndex == 0) { // explicit check for zero to avoid issues where logical zero is not exactly zero due to float nature - eventAngles[i] = 0; + eventAngles[eventIndex] = 0; } else { - float angle = getAngle((triggerShapeSynchPointIndex + i) % engine->engineCycleEventCount) - firstAngle; + float angle = getAngle((triggerShapeSynchPointIndex + eventIndex) % engine->engineCycleEventCount) - firstAngle; fixAngle(angle); - eventAngles[i] = angle; + eventAngles[eventIndex] = angle; } } }