auto-sync
This commit is contained in:
parent
f582c90130
commit
0ee45c012f
|
@ -29,7 +29,7 @@ public:
|
|||
|
||||
};
|
||||
void initMainEventListener(Engine *engine, engine_configuration2_s *engineConfiguration2);
|
||||
void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTriggerCallback *mainTriggerCallback);
|
||||
void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex, Engine *engine);
|
||||
#endif
|
||||
|
||||
int isIgnitionTimingError(void);
|
||||
|
|
|
@ -53,7 +53,7 @@ void turnPinLow(io_pin_e pin);
|
|||
|
||||
void initSignalExecutor(void);
|
||||
void initSignalExecutorImpl(void);
|
||||
void scheduleByAngle(scheduling_s *timer, float angle, schfunc_t callback, void *param);
|
||||
void scheduleByAngle(int rpm, scheduling_s *timer, float angle, schfunc_t callback, void *param);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -126,13 +126,13 @@ static void endAveraging(void *arg) {
|
|||
/**
|
||||
* Shaft Position callback used to schedule start and end of MAP averaging
|
||||
*/
|
||||
static void shaftPositionCallback(trigger_event_e ckpEventType, uint32_t index, void *arg) {
|
||||
static void shaftPositionCallback(trigger_event_e ckpEventType, uint32_t index, Engine *arg) {
|
||||
// this callback is invoked on interrupt thread
|
||||
|
||||
if (index != 0)
|
||||
return;
|
||||
|
||||
int rpm = getRpm();
|
||||
int rpm = getRpmE(engine);
|
||||
if (!isValidRpm(rpm))
|
||||
return;
|
||||
|
||||
|
@ -150,8 +150,8 @@ static void shaftPositionCallback(trigger_event_e ckpEventType, uint32_t index,
|
|||
|
||||
int structIndex = getRevolutionCounter() % 2;
|
||||
// todo: schedule this based on closest trigger event, same as ignition works
|
||||
scheduleByAngle(&startTimer[structIndex], startAngle, startAveraging, NULL);
|
||||
scheduleByAngle(&endTimer[structIndex], startAngle + windowAngle, endAveraging, NULL);
|
||||
scheduleByAngle(rpm, &startTimer[structIndex], startAngle, startAveraging, NULL);
|
||||
scheduleByAngle(rpm, &endTimer[structIndex], startAngle + windowAngle, endAveraging, NULL);
|
||||
}
|
||||
|
||||
static void showMapStats(void) {
|
||||
|
|
|
@ -243,7 +243,7 @@ void showMainHistogram(void) {
|
|||
* This is the main trigger event handler.
|
||||
* Both injection and ignition are controlled from this method.
|
||||
*/
|
||||
void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTriggerCallback *mtc) {
|
||||
void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex, Engine *engine) {
|
||||
if (hasFirmwareError()) {
|
||||
/**
|
||||
* In case on a major error we should not process any more events.
|
||||
|
@ -252,7 +252,6 @@ void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTrig
|
|||
return;
|
||||
}
|
||||
|
||||
Engine *engine = mtc->engine;
|
||||
(void) ckpSignalType;
|
||||
efiAssertVoid(eventIndex < 2 * engine->engineConfiguration2->triggerShape.shaftPositionEventCount, "event index");
|
||||
efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "lowstck#2");
|
||||
|
@ -370,7 +369,7 @@ void initMainEventListener(Engine *engine, engine_configuration2_s *engineConfig
|
|||
initHistogram(&mainLoopHisto, "main callback");
|
||||
#endif /* EFI_HISTOGRAMS */
|
||||
|
||||
addTriggerEventListener((ShaftPositionListener) &onTriggerEvent, "main loop", &mainTriggerCallbackInstance);
|
||||
addTriggerEventListener(mainTriggerCallback, "main loop", engine);
|
||||
}
|
||||
|
||||
int isIgnitionTimingError(void) {
|
||||
|
|
|
@ -136,7 +136,9 @@ bool isCranking(void) {
|
|||
* updated here.
|
||||
* This callback is invoked on interrupt thread.
|
||||
*/
|
||||
void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index, RpmCalculator *rpmState) {
|
||||
void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index, Engine *engine) {
|
||||
RpmCalculator *rpmState = engine->rpmCalculator;
|
||||
efiAssertVoid(rpmState!=NULL, "NULL rpmState");
|
||||
uint64_t nowNt = getTimeNowNt();
|
||||
#if EFI_PROD_CODE
|
||||
efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "lowstck#2z");
|
||||
|
@ -149,7 +151,6 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index, Rpm
|
|||
#endif
|
||||
return;
|
||||
}
|
||||
rpmState->onNewEngineCycle();
|
||||
|
||||
bool hadRpmRecently = rpmState->isRunning();
|
||||
|
||||
|
@ -170,6 +171,7 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index, Rpm
|
|||
rpmState->setRpmValue(rpm > UNREALISTIC_RPM ? NOISY_RPM : rpm);
|
||||
}
|
||||
}
|
||||
rpmState->onNewEngineCycle();
|
||||
rpmState->lastRpmEventTimeNt = nowNt;
|
||||
#if EFI_ANALOG_CHART || defined(__DOXYGEN__)
|
||||
if (engineConfiguration->analogChartMode == AC_TRIGGER)
|
||||
|
@ -194,14 +196,14 @@ static void onTdcCallback(void) {
|
|||
/**
|
||||
* This trigger callback schedules the actual physical TDC callback in relation to trigger synchronization point.
|
||||
*/
|
||||
static void tdcMarkCallback(trigger_event_e ckpSignalType, uint32_t index0, void *arg) {
|
||||
(void) arg;
|
||||
static void tdcMarkCallback(trigger_event_e ckpSignalType, uint32_t index0, Engine *engine) {
|
||||
(void) ckpSignalType;
|
||||
bool isTriggerSynchronizationPoint = index0 == 0;
|
||||
if (isTriggerSynchronizationPoint) {
|
||||
int revIndex2 = getRevolutionCounter() % 2;
|
||||
int rpm = getRpm();
|
||||
// todo: use event-based scheduling, not just time-based scheduling
|
||||
scheduleByAngle(&tdcScheduler[revIndex2], engineConfiguration->globalTriggerAngleOffset,
|
||||
scheduleByAngle(rpm, &tdcScheduler[revIndex2], engineConfiguration->globalTriggerAngleOffset,
|
||||
(schfunc_t) onTdcCallback, NULL);
|
||||
}
|
||||
}
|
||||
|
@ -238,10 +240,10 @@ void initRpmCalculator(Engine *engine) {
|
|||
|
||||
tdcScheduler[0].name = "tdc0";
|
||||
tdcScheduler[1].name = "tdc1";
|
||||
addTriggerEventListener(&tdcMarkCallback, "chart TDC mark", NULL);
|
||||
addTriggerEventListener(tdcMarkCallback, "chart TDC mark", engine);
|
||||
#endif
|
||||
|
||||
addTriggerEventListener((ShaftPositionListener) &rpmShaftPositionCallback, "rpm reporter", &rpmState);
|
||||
addTriggerEventListener((ShaftPositionListener) &rpmShaftPositionCallback, "rpm reporter", engine);
|
||||
}
|
||||
|
||||
#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__)
|
||||
|
@ -250,8 +252,7 @@ void initRpmCalculator(Engine *engine) {
|
|||
* The callback would be executed once after the duration of time which
|
||||
* it takes the crankshaft to rotate to the specified angle.
|
||||
*/
|
||||
void scheduleByAngle(scheduling_s *timer, float angle, schfunc_t callback, void *param) {
|
||||
int rpm = getRpm();
|
||||
void scheduleByAngle(int rpm, scheduling_s *timer, float angle, schfunc_t callback, void *param) {
|
||||
if (!isValidRpm(rpm)) {
|
||||
/**
|
||||
* this might happen in case of a single trigger event after a pause - this is normal, so no
|
||||
|
|
|
@ -59,7 +59,7 @@ private:
|
|||
*/
|
||||
int getRpmE(Engine *engine);
|
||||
bool isCrankingE(Engine *engine);
|
||||
void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index, RpmCalculator *rpmState);
|
||||
void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index, Engine *engine);
|
||||
/**
|
||||
* @brief Initialize RPM calculator
|
||||
*/
|
||||
|
|
|
@ -43,9 +43,9 @@ uint64_t getStartOfRevolutionIndex() {
|
|||
return triggerCentral.triggerState.getStartOfRevolutionIndex();
|
||||
}
|
||||
|
||||
void TriggerCentral::addEventListener(ShaftPositionListener listener, const char *name, void *arg) {
|
||||
void TriggerCentral::addEventListener(ShaftPositionListener listener, const char *name, Engine *engine) {
|
||||
print("registerCkpListener: %s\r\n", name);
|
||||
registerCallback(&triggerListeneres, (IntListener) listener, arg);
|
||||
registerCallback(&triggerListeneres, (IntListener) listener, engine);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,8 +54,8 @@ void TriggerCentral::addEventListener(ShaftPositionListener listener, const char
|
|||
* Trigger event listener would be invoked on each trigger event. For example, for a 60/2 wheel
|
||||
* that would be 116 events: 58 SHAFT_PRIMARY_UP and 58 SHAFT_PRIMARY_DOWN events.
|
||||
*/
|
||||
void addTriggerEventListener(ShaftPositionListener listener, const char *name, void *arg) {
|
||||
triggerCentral.addEventListener(listener, name, arg);
|
||||
void addTriggerEventListener(ShaftPositionListener listener, const char *name, Engine *engine) {
|
||||
triggerCentral.addEventListener(listener, name, engine);
|
||||
}
|
||||
|
||||
#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__)
|
||||
|
|
|
@ -12,7 +12,8 @@
|
|||
#include "listener_array.h"
|
||||
#include "trigger_decoder.h"
|
||||
|
||||
typedef void (*ShaftPositionListener)(trigger_event_e signal, uint32_t index, void *arg);
|
||||
class Engine;
|
||||
typedef void (*ShaftPositionListener)(trigger_event_e signal, uint32_t index, Engine *engine);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "ec2.h"
|
||||
|
@ -23,7 +24,7 @@ typedef void (*ShaftPositionListener)(trigger_event_e signal, uint32_t index, vo
|
|||
class TriggerCentral {
|
||||
public:
|
||||
TriggerCentral();
|
||||
void addEventListener(ShaftPositionListener handler, const char *name, void *arg);
|
||||
void addEventListener(ShaftPositionListener handler, const char *name, Engine *engine);
|
||||
void handleShaftSignal(Engine *engine, trigger_event_e signal);
|
||||
int getHwEventCounter(int index);
|
||||
TriggerState triggerState;
|
||||
|
@ -44,7 +45,7 @@ void printAllCallbacksHistogram(void);
|
|||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
void addTriggerEventListener(ShaftPositionListener handler, const char *name, void *arg);
|
||||
void addTriggerEventListener(ShaftPositionListener handler, const char *name, Engine *engine);
|
||||
int isSignalDecoderError(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -137,7 +137,7 @@ static void initWave(const char *name, int index) {
|
|||
}
|
||||
#endif
|
||||
|
||||
static void waTriggerEventListener(trigger_event_e ckpSignalType, uint32_t index, void *arg) {
|
||||
static void waTriggerEventListener(trigger_event_e ckpSignalType, uint32_t index, Engine *arg) {
|
||||
(void)ckpSignalType;
|
||||
(void)arg;
|
||||
if (index != 0) {
|
||||
|
@ -251,7 +251,7 @@ void initWaveAnalyzer(void) {
|
|||
initWave(WA_CHANNEL_1, 0);
|
||||
initWave(WA_CHANNEL_2, 1);
|
||||
|
||||
addTriggerEventListener(&waTriggerEventListener, "wave analyzer", (void*) NULL);
|
||||
addTriggerEventListener(waTriggerEventListener, "wave analyzer", NULL);
|
||||
|
||||
addConsoleActionII("set_logic_input_mode", setWaveModeSilent);
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType) {
|
|||
|
||||
engine.engineConfiguration2 = &ec2;
|
||||
|
||||
engine.rpmCalculator = &rpmState;
|
||||
|
||||
prepareFuelMap(engine.engineConfiguration);
|
||||
|
||||
|
||||
|
@ -43,6 +45,6 @@ void EngineTestHelper::initTriggerShapeAndRpmCalculator() {
|
|||
initializeTriggerShape(NULL, ec, &ec2);
|
||||
incrementGlobalConfigurationVersion();
|
||||
|
||||
triggerCentral.addEventListener((ShaftPositionListener) &rpmShaftPositionCallback, "rpm reporter", &rpmState);
|
||||
triggerCentral.addEventListener((ShaftPositionListener) &rpmShaftPositionCallback, "rpm reporter", &engine);
|
||||
|
||||
}
|
||||
|
|
|
@ -403,9 +403,7 @@ static void testRpmCalculator(void) {
|
|||
|
||||
static MainTriggerCallback triggerCallbackInstance;
|
||||
triggerCallbackInstance.init(ð.engine, ec2);
|
||||
eth.triggerCentral.addEventListener((ShaftPositionListener)&onTriggerEvent, "main loop", &triggerCallbackInstance);
|
||||
|
||||
eth.engine.rpmCalculator = ð.rpmState;
|
||||
eth.triggerCentral.addEventListener((ShaftPositionListener)&mainTriggerCallback, "main loop", ð.engine);
|
||||
|
||||
// engine.rpmCalculator = ð.rpmState;
|
||||
prepareTimingMap();
|
||||
|
|
Loading…
Reference in New Issue