auto-sync

This commit is contained in:
rusEfi 2015-04-08 23:08:51 -05:00
parent bbd11d3fc0
commit 622edca2f3
7 changed files with 35 additions and 25 deletions

View File

@ -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

View File

@ -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);

View File

@ -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?

View File

@ -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;
}
}
}

View File

@ -75,7 +75,6 @@ static IgnitionEvent *iHead = NULL;
* This queue is using global trigger event index as 'time'
*/
//static EventQueue triggerEventsQueue;
static cyclic_buffer<int> ignitionErrorDetection;
static Logging *logger;
@ -253,8 +252,7 @@ static ALWAYS_INLINE void handleSpark(uint32_t eventIndex, int rpm,
scheduling_s * sDown = &current->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,9 +391,8 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex DECL
engine->m.beforeInjectonSch = GET_TIMESTAMP();
if(isCrankingR(rpm)) {
ENGINE(engineConfiguration2)->crankingInjectionEvents.addFuelEvents(
&crankingInjectonSignals,
if (isCrankingR(rpm)) {
ENGINE(engineConfiguration2)->crankingInjectionEvents.addFuelEvents(&crankingInjectonSignals,
engineConfiguration->crankingInjectionMode PASS_ENGINE_PARAMETER);
} else {
ENGINE(engineConfiguration2)->injectionEvents.addFuelEvents(&runningInjectonSignals,
@ -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");

View File

@ -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++; \
}

View File

@ -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;
}
}
}