auto-sync

This commit is contained in:
rusEfi 2016-01-25 02:03:01 -05:00
parent d2a790bd0c
commit a3ed8d4d8f
11 changed files with 42 additions and 53 deletions

View File

@ -180,7 +180,7 @@ void Engine::preCalculate() {
} }
} }
void Engine::init() { void Engine::init(persistent_config_s *config) {
} }
static bool stopPin(NamedOutputPin *output) { static bool stopPin(NamedOutputPin *output) {

View File

@ -44,6 +44,7 @@ public:
void addFuelEvents(injection_mode_e mode DECLARE_ENGINE_PARAMETER_S); void addFuelEvents(injection_mode_e mode DECLARE_ENGINE_PARAMETER_S);
InjectionEventList injectionEvents; InjectionEventList injectionEvents;
/** /**
* This is a performance optimization for https://sourceforge.net/p/rusefi/tickets/64/ * This is a performance optimization for https://sourceforge.net/p/rusefi/tickets/64/
* TODO: better data structure? better algorithm? * TODO: better data structure? better algorithm?
@ -69,10 +70,11 @@ public:
engine_configuration2_s(); engine_configuration2_s();
#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) #if EFI_ENGINE_CONTROL || defined(__DOXYGEN__)
FuelSchedule crankingInjectionEvents;
FuelSchedule injectionEvents; FuelSchedule injectionEvents;
#endif #endif
OutputSignal fuelActuators[MAX_INJECTION_OUTPUT_COUNT];
float fsioLastValue[LE_COMMAND_COUNT]; float fsioLastValue[LE_COMMAND_COUNT];
/** /**
@ -210,7 +212,7 @@ typedef void (*configuration_callback_t)(Engine*);
class Engine { class Engine {
public: public:
Engine(persistent_config_s *config); Engine(persistent_config_s *config);
void init(); void init(persistent_config_s *config);
RpmCalculator rpmCalculator; RpmCalculator rpmCalculator;
persistent_config_s *config; persistent_config_s *config;
engine_configuration_s *engineConfiguration; engine_configuration_s *engineConfiguration;

View File

@ -12,8 +12,6 @@
#include "signal_executor.h" #include "signal_executor.h"
#include "fl_stack.h" #include "fl_stack.h"
#define MAX_EVENT_COUNT 80
/** /**
* This structure defines an angle position within the trigger * This structure defines an angle position within the trigger
*/ */
@ -34,14 +32,15 @@ public:
class InjectionEvent { class InjectionEvent {
public: public:
InjectionEvent(); InjectionEvent();
event_trigger_position_s injectionStart;
OutputSignal actuator;
int injectorIndex;
/** /**
* This is a performance optimization - it's more efficient to handle all * This is a performance optimization - it's more efficient to handle all
* injectors together if that's the case * injectors together if that's the case
*/ */
bool isSimultanious; bool isSimultanious;
NamedOutputPin *output;
int injectorIndex;
event_trigger_position_s injectionStart;
}; };
class IgnitionEvent { class IgnitionEvent {
@ -57,10 +56,11 @@ public:
char *name; char *name;
}; };
#define OUTPUT_SIGNAL_MAX_SIZE2 45 #define MAX_INJECTION_OUTPUT_COUNT 45
#define MAX_IGNITION_EVENT_COUNT 80
typedef ArrayList<InjectionEvent, OUTPUT_SIGNAL_MAX_SIZE2> InjectionEventList; typedef ArrayList<InjectionEvent, MAX_INJECTION_OUTPUT_COUNT> InjectionEventList;
typedef ArrayList<IgnitionEvent, MAX_EVENT_COUNT> IgnitionEventList; typedef ArrayList<IgnitionEvent, MAX_IGNITION_EVENT_COUNT> IgnitionEventList;
#endif /* EVENT_REGISTRY_H_ */ #endif /* EVENT_REGISTRY_H_ */

View File

@ -34,7 +34,7 @@
EXTERN_ENGINE; EXTERN_ENGINE;
#if EFI_ENGINE_SNIFFER #if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__)
#include "engine_sniffer.h" #include "engine_sniffer.h"
extern WaveChart waveChart; extern WaveChart waveChart;
#endif #endif
@ -59,22 +59,19 @@ void initSignalExecutor(void) {
} }
} }
//uint32_t dbgStart;
//uint32_t dbgDurr;
void turnPinHigh(NamedOutputPin *output) { void turnPinHigh(NamedOutputPin *output) {
efiAssertVoid(output!=NULL, "NULL @ turnPinHigh"); efiAssertVoid(output!=NULL, "NULL @ turnPinHigh");
#if EFI_DEFAILED_LOGGING #if EFI_DEFAILED_LOGGING || defined(__DOXYGEN__)
// signal->hi_time = hTimeNow(); // signal->hi_time = hTimeNow();
#endif /* EFI_DEFAILED_LOGGING */ #endif /* EFI_DEFAILED_LOGGING */
#if EFI_GPIO #if EFI_GPIO || defined(__DOXYGEN__)
// turn the output level ACTIVE // turn the output level ACTIVE
// todo: this XOR should go inside the setOutputPinValue method // todo: this XOR should go inside the setOutputPinValue method
doSetOutputPinValue2(output, true); doSetOutputPinValue2(output, true);
// sleep for the needed duration // sleep for the needed duration
#endif #endif
#if EFI_ENGINE_SNIFFER #if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__)
// explicit check here is a performance optimization to speed up no-chart mode // explicit check here is a performance optimization to speed up no-chart mode
if (CONFIG(isEngineChartEnabled)) { if (CONFIG(isEngineChartEnabled)) {
// this is a performance optimization - array index is cheaper then invoking a method with 'switch' // 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); addWaveChartEvent(pinName, WC_UP);
} }
#endif /* EFI_WAVE_ANALYZER */ #endif /* EFI_ENGINE_SNIFFER */
// dbgDurr = hal_lld_get_counter_value() - dbgStart; // dbgDurr = hal_lld_get_counter_value() - dbgStart;
} }
void turnPinLow(NamedOutputPin *output) { void turnPinLow(NamedOutputPin *output) {
efiAssertVoid(output!=NULL, "NULL turnPinLow"); efiAssertVoid(output!=NULL, "NULL turnPinLow");
#if EFI_GPIO #if EFI_GPIO || defined(__DOXYGEN__)
// turn off the output // turn off the output
doSetOutputPinValue2(output, false); doSetOutputPinValue2(output, false);
#endif #endif /* EFI_GPIO */
#if EFI_DEFAILED_LOGGING #if EFI_DEFAILED_LOGGING || defined(__DOXYGEN__)
systime_t after = hTimeNow(); systime_t after = hTimeNow();
debugInt(&signal->logging, "a_time", after - signal->hi_time); debugInt(&signal->logging, "a_time", after - signal->hi_time);
scheduleLogging(&signal->logging); scheduleLogging(&signal->logging);
#endif /* EFI_DEFAILED_LOGGING */ #endif /* EFI_DEFAILED_LOGGING */
#if EFI_ENGINE_SNIFFER #if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__)
if (CONFIG(isEngineChartEnabled)) { if (CONFIG(isEngineChartEnabled)) {
// this is a performance optimization - array index is cheaper then invoking a method with 'switch' // this is a performance optimization - array index is cheaper then invoking a method with 'switch'
const char *pinName = output->name; const char *pinName = output->name;
addWaveChartEvent(pinName, WC_DOWN); addWaveChartEvent(pinName, WC_DOWN);
} }
#endif /* EFI_WAVE_ANALYZER */ #endif /* EFI_ENGINE_SNIFFER */
} }
int getRevolutionCounter(void); int getRevolutionCounter(void);
@ -119,7 +116,7 @@ int getRevolutionCounter(void);
* @param dwell the number of ticks of output duration * @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 EFI_GPIO
if (durationUs < 0) { if (durationUs < 0) {
warning(OBD_PCM_Processor_Fault, "duration cannot be negative: %d", durationUs); 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 * sUp = &signal->signalTimerUp[index];
scheduling_s * sDown = &signal->signalTimerDown[index]; scheduling_s * sDown = &signal->signalTimerDown[index];
scheduleByTime("out up", sUp, nowUs + (int) delayUs, (schfunc_t) &turnPinHigh, signal->output); scheduleByTime("out up", sUp, nowUs + (int) delayUs, (schfunc_t) &turnPinHigh, output);
scheduleByTime("out down", sDown, nowUs + (int) (delayUs + durationUs), (schfunc_t) &turnPinLow, signal->output); scheduleByTime("out down", sDown, nowUs + (int) (delayUs + durationUs), (schfunc_t) &turnPinLow, output);
#endif #endif
} }

View File

@ -29,7 +29,6 @@
*/ */
typedef struct OutputSignal_struct OutputSignal; typedef struct OutputSignal_struct OutputSignal;
struct OutputSignal_struct { struct OutputSignal_struct {
NamedOutputPin *output;
/** /**
* We are alternating instances so that events which extend into next revolution are not reused while * 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]; 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 initSignalExecutor(void);
void initSignalExecutorImpl(void); void initSignalExecutorImpl(void);

View File

@ -98,6 +98,7 @@ engine_configuration2_s * engineConfiguration2 = &ec2;
#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__) #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? * todo: this should probably become 'static', i.e. private, and propagated around explicitly?
*/ */
Engine _engine(&persistentState.persistentConfiguration); Engine _engine(&persistentState.persistentConfiguration);

View File

@ -149,7 +149,7 @@ void FuelSchedule::registerInjectionEvent(int injectorIndex, float angle,
} }
ev->injectorIndex = injectorIndex; ev->injectorIndex = injectorIndex;
ev->actuator.output = output; ev->output = output;
ev->isSimultanious = isSimultanious; ev->isSimultanious = isSimultanious;
@ -396,10 +396,7 @@ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) {
for (int i = 0; i < CONFIG(specs.cylindersCount); i++) { for (int i = 0; i < CONFIG(specs.cylindersCount); i++) {
ENGINE(angleExtra[i])= ENGINE(engineCycle) * i / CONFIG(specs.cylindersCount); ENGINE(angleExtra[i])= ENGINE(engineCycle) * i / CONFIG(specs.cylindersCount);
ENGINE(ignitionPin[i]) = getIgnitionPinForIndex(i PASS_ENGINE_PARAMETER); ENGINE(ignitionPin[i]) = getIgnitionPinForIndex(i PASS_ENGINE_PARAMETER);
} }
int engineCycleInt = (int) ENGINE(engineCycle); int engineCycleInt = (int) ENGINE(engineCycle);
@ -410,10 +407,8 @@ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) {
TRIGGER_SHAPE(triggerIndexByAngle[angle]) = triggerShapeIndex; TRIGGER_SHAPE(triggerIndexByAngle[angle]) = triggerShapeIndex;
} }
engineConfiguration2->crankingInjectionEvents.addFuelEvents(
engineConfiguration->crankingInjectionMode PASS_ENGINE_PARAMETER);
engineConfiguration2->injectionEvents.addFuelEvents( engineConfiguration2->injectionEvents.addFuelEvents(
engineConfiguration->injectionMode PASS_ENGINE_PARAMETER); engineConfiguration->crankingInjectionMode PASS_ENGINE_PARAMETER);
} }
#endif #endif

View File

@ -15,7 +15,7 @@ class scheduling_s {
public: public:
scheduling_s(); scheduling_s();
#if EFI_SIGNAL_EXECUTOR_SLEEP #if EFI_SIGNAL_EXECUTOR_SLEEP || defined(__DOXYGEN__)
VirtualTimer timer; VirtualTimer timer;
#endif /* EFI_SIGNAL_EXECUTOR_SLEEP */ #endif /* EFI_SIGNAL_EXECUTOR_SLEEP */

View File

@ -103,7 +103,7 @@ static void endSimultaniousInjection(Engine *engine) {
extern WallFuel wallFuel; 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) { int rpm DECLARE_ENGINE_PARAMETER_S) {
if (limitedFuel) if (limitedFuel)
return; // todo: move this check up 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; floatus_t injectionStartDelayUs = ENGINE(rpmCalculator.oneDegreeUs) * event->injectionStart.angleOffset;
OutputSignal *signal = &ENGINE(engineConfiguration2)->fuelActuators[eventIndex];
if (event->isSimultanious) { if (event->isSimultanious) {
if (injectionDuration < 0) { if (injectionDuration < 0) {
firmwareError("duration cannot be negative: %d", injectionDuration); 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 * 'scheduleOutput' is currently only used for injection, so maybe it should be
* changed into 'scheduleInjection' and unified? todo: think about it. * changed into 'scheduleInjection' and unified? todo: think about it.
*/ */
OutputSignal *signal = &event->actuator;
efiAssertVoid(signal!=NULL, "signal is NULL"); efiAssertVoid(signal!=NULL, "signal is NULL");
int index = getRevolutionCounter() % 2; int index = getRevolutionCounter() % 2;
scheduling_s * sUp = &signal->signalTimerUp[index]; scheduling_s * sUp = &signal->signalTimerUp[index];
@ -155,7 +156,7 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(bool limitedFuel, InjectionEv
(schfunc_t) &endSimultaniousInjection, engine); (schfunc_t) &endSimultaniousInjection, engine);
} else { } 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 * Ignition events are defined by addFuelEvents() according to selected
* fueling strategy * fueling strategy
*/ */
FuelSchedule *fs = FuelSchedule *fs = &ENGINE(engineConfiguration2)->injectionEvents;
isCrankingR(rpm) ?
&ENGINE(engineConfiguration2)->crankingInjectionEvents : &ENGINE(engineConfiguration2)->injectionEvents;
InjectionEventList *source = &fs->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]; InjectionEvent *event = &source->elements[i];
if (event->injectionStart.eventIndex != eventIndex) if (event->injectionStart.eventIndex != eventIndex)
continue; 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(); ENGINE(m.beforeInjectonSch) = GET_TIMESTAMP();
if (isCrankingR(rpm)) { injection_mode_e mode = isCrankingR(rpm) ? CONFIG(crankingInjectionMode) : CONFIG(injectionMode);
ENGINE(engineConfiguration2)->crankingInjectionEvents.addFuelEvents(
engineConfiguration->crankingInjectionMode PASS_ENGINE_PARAMETER); ENGINE(engineConfiguration2)->injectionEvents.addFuelEvents(
} else { mode PASS_ENGINE_PARAMETER);
ENGINE(engineConfiguration2)->injectionEvents.addFuelEvents(
CONFIG(injectionMode) PASS_ENGINE_PARAMETER);
}
ENGINE(m.injectonSchTime) = GET_TIMESTAMP() - ENGINE(m.beforeInjectonSch); ENGINE(m.injectonSchTime) = GET_TIMESTAMP() - ENGINE(m.beforeInjectonSch);
} }

View File

@ -523,7 +523,6 @@ void TriggerShape::initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMET
default: default:
firmwareError("initializeTriggerShape() not implemented: %d", triggerConfig->type); firmwareError("initializeTriggerShape() not implemented: %d", triggerConfig->type);
;
return; return;
} }
wave.checkSwitchTimes(getSize()); wave.checkSwitchTimes(getSize());

View File

@ -275,5 +275,5 @@ int getRusEfiVersion(void) {
return 123; // this is here to make the compiler happy about the unused array return 123; // this is here to make the compiler happy about the unused array
if (UNUSED_CCM_SIZE[0] * 0 != 0) if (UNUSED_CCM_SIZE[0] * 0 != 0)
return 3211; // this is here to make the compiler happy about the unused array return 3211; // this is here to make the compiler happy about the unused array
return 20160123; return 20160125;
} }