auto-sync

This commit is contained in:
rusEfi 2016-11-28 15:01:54 -05:00
parent c5a51fe752
commit 2e626bcf9f
5 changed files with 25 additions and 18 deletions

View File

@ -289,6 +289,7 @@ void Engine::watchdog() {
return; return;
} }
isSpinning = false; isSpinning = false;
ignitionList()->isReady = false;
#if EFI_PROD_CODE || EFI_SIMULATOR #if EFI_PROD_CODE || EFI_SIMULATOR
scheduleMsg(&logger, "engine has STOPPED"); scheduleMsg(&logger, "engine has STOPPED");
scheduleMsg(&logger, "templog engine has STOPPED [%x][%x] [%x][%x] %d", scheduleMsg(&logger, "templog engine has STOPPED [%x][%x] [%x][%x] %d",
@ -303,6 +304,11 @@ void Engine::watchdog() {
#endif #endif
} }
IgnitionEventList * Engine::ignitionList() {
int revolutionIndex = rpmCalculator.getRevolutionCounter() % 2;
return &engineConfiguration2->ignitionEvents[revolutionIndex];
}
void Engine::prepareFuelSchedule(DECLARE_ENGINE_PARAMETER_F) { void Engine::prepareFuelSchedule(DECLARE_ENGINE_PARAMETER_F) {
int rpm = rpmCalculator.rpmValue; int rpm = rpmCalculator.rpmValue;
efiAssertVoid(ENGINE(engineConfiguration2)->injectionEvents != ENGINE(engineConfiguration2)->processing, "fuel pointers"); efiAssertVoid(ENGINE(engineConfiguration2)->injectionEvents != ENGINE(engineConfiguration2)->processing, "fuel pointers");

View File

@ -260,6 +260,7 @@ public:
Engine(persistent_config_s *config); Engine(persistent_config_s *config);
void init(persistent_config_s *config); void init(persistent_config_s *config);
void prepareFuelSchedule(DECLARE_ENGINE_PARAMETER_F); void prepareFuelSchedule(DECLARE_ENGINE_PARAMETER_F);
IgnitionEventList *ignitionList(); // todo: inline/rename/refactor
WallFuel wallFuel; WallFuel wallFuel;

View File

@ -545,8 +545,7 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t trgEventIndex D
/** /**
* For spark we schedule both start of coil charge and actual spark based on trigger angle * For spark we schedule both start of coil charge and actual spark based on trigger angle
*/ */
handleSpark(revolutionIndex, limitedSpark, trgEventIndex, rpm, handleSpark(limitedSpark, trgEventIndex, rpm PASS_ENGINE_PARAMETER);
&engine->engineConfiguration2->ignitionEvents[revolutionIndex] PASS_ENGINE_PARAMETER);
#if (EFI_HISTOGRAMS && EFI_PROD_CODE) || defined(__DOXYGEN__) #if (EFI_HISTOGRAMS && EFI_PROD_CODE) || defined(__DOXYGEN__)
int diff = hal_lld_get_counter_value() - beforeCallback; int diff = hal_lld_get_counter_value() - beforeCallback;
if (diff > 0) if (diff > 0)

View File

@ -202,8 +202,7 @@ static ALWAYS_INLINE void handleSparkEvent(bool limitedSpark, uint32_t trgEventI
} }
} }
static void addIgnitionEvent(int cylinderIndex, angle_t localAdvance, angle_t dwellAngle, IgnitionEventList *list, IgnitionOutputPin *output, IgnitionOutputPin *secondOutput DECLARE_ENGINE_PARAMETER_S) { static void addIgnitionEvent(angle_t localAdvance, angle_t dwellAngle, IgnitionEvent *event, IgnitionOutputPin *output, IgnitionOutputPin *secondOutput DECLARE_ENGINE_PARAMETER_S) {
IgnitionEvent *event = &list->elements[cylinderIndex];
if (!isPinAssigned(output)) { if (!isPinAssigned(output)) {
// todo: extract method for this index math // todo: extract method for this index math
@ -222,12 +221,12 @@ static void addIgnitionEvent(int cylinderIndex, angle_t localAdvance, angle_t dw
} }
static void prepareIgnitionSchedule(int cylinderIndex, IgnitionEventList *list DECLARE_ENGINE_PARAMETER_S) { static void prepareIgnitionSchedule(IgnitionEvent *event DECLARE_ENGINE_PARAMETER_S) {
// todo: clean up this implementation? does not look too nice as is. // todo: clean up this implementation? does not look too nice as is.
// change of sign here from 'before TDC' to 'after TDC' // change of sign here from 'before TDC' to 'after TDC'
angle_t localAdvance = -ENGINE(engineState.timingAdvance) + ENGINE(angleExtra[cylinderIndex]); angle_t localAdvance = -ENGINE(engineState.timingAdvance) + ENGINE(angleExtra[event->cylinderIndex]);
const int index = ENGINE(ignitionPin[cylinderIndex]); const int index = ENGINE(ignitionPin[event->cylinderIndex]);
const int coilIndex = ID2INDEX(getCylinderId(CONFIG(specs.firingOrder), index)); const int coilIndex = ID2INDEX(getCylinderId(CONFIG(specs.firingOrder), index));
IgnitionOutputPin *output = &enginePins.coils[coilIndex]; IgnitionOutputPin *output = &enginePins.coils[coilIndex];
@ -240,7 +239,7 @@ static void prepareIgnitionSchedule(int cylinderIndex, IgnitionEventList *list D
secondOutput = NULL; secondOutput = NULL;
} }
addIgnitionEvent(cylinderIndex, localAdvance, ENGINE(engineState.dwellAngle), list, output, secondOutput PASS_ENGINE_PARAMETER); addIgnitionEvent(localAdvance, ENGINE(engineState.dwellAngle), event, output, secondOutput PASS_ENGINE_PARAMETER);
} }
static void initializeIgnitionActions(IgnitionEventList *list DECLARE_ENGINE_PARAMETER_S) { static void initializeIgnitionActions(IgnitionEventList *list DECLARE_ENGINE_PARAMETER_S) {
@ -248,12 +247,12 @@ static void initializeIgnitionActions(IgnitionEventList *list DECLARE_ENGINE_PAR
for (int cylinderIndex = 0; cylinderIndex < CONFIG(specs.cylindersCount); cylinderIndex++) { for (int cylinderIndex = 0; cylinderIndex < CONFIG(specs.cylindersCount); cylinderIndex++) {
list->elements[cylinderIndex].cylinderIndex = cylinderIndex; list->elements[cylinderIndex].cylinderIndex = cylinderIndex;
prepareIgnitionSchedule(cylinderIndex, list PASS_ENGINE_PARAMETER); prepareIgnitionSchedule(&list->elements[cylinderIndex] PASS_ENGINE_PARAMETER);
} }
list->isReady = true; list->isReady = true;
} }
static ALWAYS_INLINE void prepareIgnitionSchedule(int rpm, int revolutionIndex DECLARE_ENGINE_PARAMETER_S) { static ALWAYS_INLINE void prepareIgnitionSchedule(int rpm DECLARE_ENGINE_PARAMETER_S) {
engine->m.beforeIgnitionSch = GET_TIMESTAMP(); engine->m.beforeIgnitionSch = GET_TIMESTAMP();
/** /**
@ -278,7 +277,7 @@ static ALWAYS_INLINE void prepareIgnitionSchedule(int rpm, int revolutionIndex D
// todo: add some check for dwell overflow? like 4 times 6 ms while engine cycle is less then that // todo: add some check for dwell overflow? like 4 times 6 ms while engine cycle is less then that
IgnitionEventList *list = &engine->engineConfiguration2->ignitionEvents[revolutionIndex]; IgnitionEventList *list = engine->ignitionList();
if (cisnan(ENGINE(engineState.timingAdvance))) { if (cisnan(ENGINE(engineState.timingAdvance))) {
// error should already be reported // error should already be reported
@ -290,16 +289,19 @@ static ALWAYS_INLINE void prepareIgnitionSchedule(int rpm, int revolutionIndex D
engine->m.ignitionSchTime = GET_TIMESTAMP() - engine->m.beforeIgnitionSch; engine->m.ignitionSchTime = GET_TIMESTAMP() - engine->m.beforeIgnitionSch;
} }
void handleSpark(int revolutionIndex, bool limitedSpark, uint32_t trgEventIndex, int rpm, void handleSpark(bool limitedSpark, uint32_t trgEventIndex, int rpm
IgnitionEventList *list DECLARE_ENGINE_PARAMETER_S) { DECLARE_ENGINE_PARAMETER_S) {
if (trgEventIndex == 0) {
prepareIgnitionSchedule(rpm, revolutionIndex PASS_ENGINE_PARAMETER);
}
if (!isValidRpm(rpm) || !CONFIG(isIgnitionEnabled)) { if (!isValidRpm(rpm) || !CONFIG(isIgnitionEnabled)) {
// this might happen for instance in case of a single trigger event after a pause // this might happen for instance in case of a single trigger event after a pause
return; return;
} }
IgnitionEventList *list = engine->ignitionList();
if (trgEventIndex == 0) {
prepareIgnitionSchedule(rpm PASS_ENGINE_PARAMETER);
}
/** /**
* Ignition schedule is defined once per revolution * Ignition schedule is defined once per revolution
* See initializeIgnitionActions() * See initializeIgnitionActions()

View File

@ -11,8 +11,7 @@
#include "engine.h" #include "engine.h"
int isInjectionEnabled(engine_configuration_s *engineConfiguration); int isInjectionEnabled(engine_configuration_s *engineConfiguration);
void handleSpark(int revolutionIndex, bool limitedSpark, uint32_t trgEventIndex, int rpm, void handleSpark(bool limitedSpark, uint32_t trgEventIndex, int rpm DECLARE_ENGINE_PARAMETER_S);
IgnitionEventList *list DECLARE_ENGINE_PARAMETER_S);
void initSparkLogic(Logging *sharedLogger); void initSparkLogic(Logging *sharedLogger);
void turnSparkPinHigh(IgnitionEvent *event); void turnSparkPinHigh(IgnitionEvent *event);
void turnSparkPinLow(IgnitionEvent *event); void turnSparkPinLow(IgnitionEvent *event);