From a3ed8d4d8f197471bfec29ef3ddfb2a8562641e5 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Mon, 25 Jan 2016 02:03:01 -0500 Subject: [PATCH] auto-sync --- firmware/controllers/algo/engine.cpp | 2 +- firmware/controllers/algo/engine.h | 6 ++-- firmware/controllers/algo/event_registry.h | 16 +++++----- firmware/controllers/algo/signal_executor.cpp | 29 +++++++++---------- firmware/controllers/algo/signal_executor.h | 3 +- firmware/controllers/engine_controller.cpp | 1 + firmware/controllers/math/engine_math.cpp | 9 ++---- firmware/controllers/system/scheduler.h | 2 +- .../trigger/main_trigger_callback.cpp | 24 +++++++-------- .../controllers/trigger/trigger_decoder.cpp | 1 - firmware/rusefi.cpp | 2 +- 11 files changed, 42 insertions(+), 53 deletions(-) diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 753d3aeba8..aa538dcbcc 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -180,7 +180,7 @@ void Engine::preCalculate() { } } -void Engine::init() { +void Engine::init(persistent_config_s *config) { } static bool stopPin(NamedOutputPin *output) { diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index c9bb2d0eb0..e5a5111add 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -44,6 +44,7 @@ public: void addFuelEvents(injection_mode_e mode DECLARE_ENGINE_PARAMETER_S); InjectionEventList injectionEvents; + /** * This is a performance optimization for https://sourceforge.net/p/rusefi/tickets/64/ * TODO: better data structure? better algorithm? @@ -69,10 +70,11 @@ public: engine_configuration2_s(); #if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) - FuelSchedule crankingInjectionEvents; FuelSchedule injectionEvents; #endif + OutputSignal fuelActuators[MAX_INJECTION_OUTPUT_COUNT]; + float fsioLastValue[LE_COMMAND_COUNT]; /** @@ -210,7 +212,7 @@ typedef void (*configuration_callback_t)(Engine*); class Engine { public: Engine(persistent_config_s *config); - void init(); + void init(persistent_config_s *config); RpmCalculator rpmCalculator; persistent_config_s *config; engine_configuration_s *engineConfiguration; diff --git a/firmware/controllers/algo/event_registry.h b/firmware/controllers/algo/event_registry.h index e4c0d26a64..f4573ec876 100644 --- a/firmware/controllers/algo/event_registry.h +++ b/firmware/controllers/algo/event_registry.h @@ -12,8 +12,6 @@ #include "signal_executor.h" #include "fl_stack.h" -#define MAX_EVENT_COUNT 80 - /** * This structure defines an angle position within the trigger */ @@ -34,14 +32,15 @@ public: class InjectionEvent { public: InjectionEvent(); - event_trigger_position_s injectionStart; - OutputSignal actuator; - int injectorIndex; /** * This is a performance optimization - it's more efficient to handle all * injectors together if that's the case */ bool isSimultanious; + NamedOutputPin *output; + int injectorIndex; + + event_trigger_position_s injectionStart; }; class IgnitionEvent { @@ -57,10 +56,11 @@ public: char *name; }; -#define OUTPUT_SIGNAL_MAX_SIZE2 45 +#define MAX_INJECTION_OUTPUT_COUNT 45 +#define MAX_IGNITION_EVENT_COUNT 80 -typedef ArrayList InjectionEventList; +typedef ArrayList InjectionEventList; -typedef ArrayList IgnitionEventList; +typedef ArrayList IgnitionEventList; #endif /* EVENT_REGISTRY_H_ */ diff --git a/firmware/controllers/algo/signal_executor.cpp b/firmware/controllers/algo/signal_executor.cpp index 839c1e1b22..d847c3cbbf 100644 --- a/firmware/controllers/algo/signal_executor.cpp +++ b/firmware/controllers/algo/signal_executor.cpp @@ -34,7 +34,7 @@ EXTERN_ENGINE; -#if EFI_ENGINE_SNIFFER +#if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__) #include "engine_sniffer.h" extern WaveChart waveChart; #endif @@ -59,22 +59,19 @@ void initSignalExecutor(void) { } } -//uint32_t dbgStart; -//uint32_t dbgDurr; - void turnPinHigh(NamedOutputPin *output) { efiAssertVoid(output!=NULL, "NULL @ turnPinHigh"); -#if EFI_DEFAILED_LOGGING +#if EFI_DEFAILED_LOGGING || defined(__DOXYGEN__) // signal->hi_time = hTimeNow(); #endif /* EFI_DEFAILED_LOGGING */ -#if EFI_GPIO +#if EFI_GPIO || defined(__DOXYGEN__) // turn the output level ACTIVE // todo: this XOR should go inside the setOutputPinValue method doSetOutputPinValue2(output, true); // sleep for the needed duration #endif -#if EFI_ENGINE_SNIFFER +#if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__) // explicit check here is a performance optimization to speed up no-chart mode if (CONFIG(isEngineChartEnabled)) { // this is a performance optimization - array index is cheaper then invoking a method with 'switch' @@ -83,31 +80,31 @@ void turnPinHigh(NamedOutputPin *output) { addWaveChartEvent(pinName, WC_UP); } -#endif /* EFI_WAVE_ANALYZER */ +#endif /* EFI_ENGINE_SNIFFER */ // dbgDurr = hal_lld_get_counter_value() - dbgStart; } void turnPinLow(NamedOutputPin *output) { efiAssertVoid(output!=NULL, "NULL turnPinLow"); -#if EFI_GPIO +#if EFI_GPIO || defined(__DOXYGEN__) // turn off the output doSetOutputPinValue2(output, false); -#endif +#endif /* EFI_GPIO */ -#if EFI_DEFAILED_LOGGING +#if EFI_DEFAILED_LOGGING || defined(__DOXYGEN__) systime_t after = hTimeNow(); debugInt(&signal->logging, "a_time", after - signal->hi_time); scheduleLogging(&signal->logging); #endif /* EFI_DEFAILED_LOGGING */ -#if EFI_ENGINE_SNIFFER +#if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__) if (CONFIG(isEngineChartEnabled)) { // this is a performance optimization - array index is cheaper then invoking a method with 'switch' const char *pinName = output->name; addWaveChartEvent(pinName, WC_DOWN); } -#endif /* EFI_WAVE_ANALYZER */ +#endif /* EFI_ENGINE_SNIFFER */ } int getRevolutionCounter(void); @@ -119,7 +116,7 @@ int getRevolutionCounter(void); * @param dwell the number of ticks of output duration * */ -void scheduleOutput(OutputSignal *signal, efitimeus_t nowUs, float delayUs, float durationUs) { +void scheduleOutput(OutputSignal *signal, efitimeus_t nowUs, float delayUs, float durationUs, NamedOutputPin *output) { #if EFI_GPIO if (durationUs < 0) { warning(OBD_PCM_Processor_Fault, "duration cannot be negative: %d", durationUs); @@ -135,7 +132,7 @@ void scheduleOutput(OutputSignal *signal, efitimeus_t nowUs, float delayUs, floa scheduling_s * sUp = &signal->signalTimerUp[index]; scheduling_s * sDown = &signal->signalTimerDown[index]; - scheduleByTime("out up", sUp, nowUs + (int) delayUs, (schfunc_t) &turnPinHigh, signal->output); - scheduleByTime("out down", sDown, nowUs + (int) (delayUs + durationUs), (schfunc_t) &turnPinLow, signal->output); + scheduleByTime("out up", sUp, nowUs + (int) delayUs, (schfunc_t) &turnPinHigh, output); + scheduleByTime("out down", sDown, nowUs + (int) (delayUs + durationUs), (schfunc_t) &turnPinLow, output); #endif } diff --git a/firmware/controllers/algo/signal_executor.h b/firmware/controllers/algo/signal_executor.h index 6ecf09ac5a..76e031da7f 100644 --- a/firmware/controllers/algo/signal_executor.h +++ b/firmware/controllers/algo/signal_executor.h @@ -29,7 +29,6 @@ */ typedef struct OutputSignal_struct OutputSignal; struct OutputSignal_struct { - NamedOutputPin *output; /** * We are alternating instances so that events which extend into next revolution are not reused while @@ -39,7 +38,7 @@ struct OutputSignal_struct { scheduling_s signalTimerDown[2]; }; -void scheduleOutput(OutputSignal *signal, efitimeus_t nowUs, float delayUs, float durationUs); +void scheduleOutput(OutputSignal *signal, efitimeus_t nowUs, float delayUs, float durationUs, NamedOutputPin *output); void initSignalExecutor(void); void initSignalExecutorImpl(void); diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 32838291a9..62ee2defbe 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -98,6 +98,7 @@ engine_configuration2_s * engineConfiguration2 = &ec2; #if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__) /** + * todo: eliminate constructor parameter so that _engine could be moved to CCM_OPTIONAL * todo: this should probably become 'static', i.e. private, and propagated around explicitly? */ Engine _engine(&persistentState.persistentConfiguration); diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index 2ad0c39266..eb8957beb7 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -149,7 +149,7 @@ void FuelSchedule::registerInjectionEvent(int injectorIndex, float angle, } ev->injectorIndex = injectorIndex; - ev->actuator.output = output; + ev->output = output; ev->isSimultanious = isSimultanious; @@ -396,10 +396,7 @@ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) { for (int i = 0; i < CONFIG(specs.cylindersCount); i++) { ENGINE(angleExtra[i])= ENGINE(engineCycle) * i / CONFIG(specs.cylindersCount); - - ENGINE(ignitionPin[i]) = getIgnitionPinForIndex(i PASS_ENGINE_PARAMETER); - } int engineCycleInt = (int) ENGINE(engineCycle); @@ -410,10 +407,8 @@ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) { TRIGGER_SHAPE(triggerIndexByAngle[angle]) = triggerShapeIndex; } - engineConfiguration2->crankingInjectionEvents.addFuelEvents( - engineConfiguration->crankingInjectionMode PASS_ENGINE_PARAMETER); engineConfiguration2->injectionEvents.addFuelEvents( - engineConfiguration->injectionMode PASS_ENGINE_PARAMETER); + engineConfiguration->crankingInjectionMode PASS_ENGINE_PARAMETER); } #endif diff --git a/firmware/controllers/system/scheduler.h b/firmware/controllers/system/scheduler.h index 62b5da0c0a..eaa3733e18 100644 --- a/firmware/controllers/system/scheduler.h +++ b/firmware/controllers/system/scheduler.h @@ -15,7 +15,7 @@ class scheduling_s { public: scheduling_s(); -#if EFI_SIGNAL_EXECUTOR_SLEEP +#if EFI_SIGNAL_EXECUTOR_SLEEP || defined(__DOXYGEN__) VirtualTimer timer; #endif /* EFI_SIGNAL_EXECUTOR_SLEEP */ diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index ca4ef679ce..9ffb2a8db9 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -103,7 +103,7 @@ static void endSimultaniousInjection(Engine *engine) { extern WallFuel wallFuel; -static ALWAYS_INLINE void handleFuelInjectionEvent(bool limitedFuel, InjectionEvent *event, +static ALWAYS_INLINE void handleFuelInjectionEvent(int eventIndex, bool limitedFuel, InjectionEvent *event, int rpm DECLARE_ENGINE_PARAMETER_S) { if (limitedFuel) return; // todo: move this check up @@ -130,6 +130,8 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(bool limitedFuel, InjectionEv floatus_t injectionStartDelayUs = ENGINE(rpmCalculator.oneDegreeUs) * event->injectionStart.angleOffset; + OutputSignal *signal = &ENGINE(engineConfiguration2)->fuelActuators[eventIndex]; + if (event->isSimultanious) { if (injectionDuration < 0) { firmwareError("duration cannot be negative: %d", injectionDuration); @@ -144,7 +146,6 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(bool limitedFuel, InjectionEv * 'scheduleOutput' is currently only used for injection, so maybe it should be * changed into 'scheduleInjection' and unified? todo: think about it. */ - OutputSignal *signal = &event->actuator; efiAssertVoid(signal!=NULL, "signal is NULL"); int index = getRevolutionCounter() % 2; scheduling_s * sUp = &signal->signalTimerUp[index]; @@ -155,7 +156,7 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(bool limitedFuel, InjectionEv (schfunc_t) &endSimultaniousInjection, engine); } else { - scheduleOutput(&event->actuator, getTimeNowUs(), injectionStartDelayUs, MS2US(injectionDuration)); + scheduleOutput(signal, getTimeNowUs(), injectionStartDelayUs, MS2US(injectionDuration), event->output); } } @@ -169,9 +170,7 @@ static ALWAYS_INLINE void handleFuel(bool limitedFuel, uint32_t eventIndex, int * Ignition events are defined by addFuelEvents() according to selected * fueling strategy */ - FuelSchedule *fs = - isCrankingR(rpm) ? - &ENGINE(engineConfiguration2)->crankingInjectionEvents : &ENGINE(engineConfiguration2)->injectionEvents; + FuelSchedule *fs = &ENGINE(engineConfiguration2)->injectionEvents; InjectionEventList *source = &fs->injectionEvents; @@ -187,7 +186,7 @@ static ALWAYS_INLINE void handleFuel(bool limitedFuel, uint32_t eventIndex, int InjectionEvent *event = &source->elements[i]; if (event->injectionStart.eventIndex != eventIndex) continue; - handleFuelInjectionEvent(limitedFuel, event, rpm PASS_ENGINE_PARAMETER); + handleFuelInjectionEvent(i, limitedFuel, event, rpm PASS_ENGINE_PARAMETER); } } @@ -363,13 +362,10 @@ static ALWAYS_INLINE void scheduleIgnitionAndFuelEvents(int rpm, int revolutionI ENGINE(m.beforeInjectonSch) = GET_TIMESTAMP(); - if (isCrankingR(rpm)) { - ENGINE(engineConfiguration2)->crankingInjectionEvents.addFuelEvents( - engineConfiguration->crankingInjectionMode PASS_ENGINE_PARAMETER); - } else { - ENGINE(engineConfiguration2)->injectionEvents.addFuelEvents( - CONFIG(injectionMode) PASS_ENGINE_PARAMETER); - } + injection_mode_e mode = isCrankingR(rpm) ? CONFIG(crankingInjectionMode) : CONFIG(injectionMode); + + ENGINE(engineConfiguration2)->injectionEvents.addFuelEvents( + mode PASS_ENGINE_PARAMETER); ENGINE(m.injectonSchTime) = GET_TIMESTAMP() - ENGINE(m.beforeInjectonSch); } diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 54d5901758..b9f919eedc 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -523,7 +523,6 @@ void TriggerShape::initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMET default: firmwareError("initializeTriggerShape() not implemented: %d", triggerConfig->type); - ; return; } wave.checkSwitchTimes(getSize()); diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 7c4347e69a..33905fac6c 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -275,5 +275,5 @@ int getRusEfiVersion(void) { return 123; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE[0] * 0 != 0) return 3211; // this is here to make the compiler happy about the unused array - return 20160123; + return 20160125; }