something is over-complicated here? looks like two classes should become one?
This commit is contained in:
parent
a65c8c9295
commit
2acdbf308b
|
@ -17,28 +17,6 @@
|
|||
|
||||
class Engine;
|
||||
|
||||
class InjectionEvent;
|
||||
|
||||
class InjectionSignalPair {
|
||||
public:
|
||||
InjectionSignalPair();
|
||||
scheduling_s signalTimerUp;
|
||||
scheduling_s endOfInjectionEvent;
|
||||
|
||||
/**
|
||||
* we need atomic flag so that we do not schedule a new pair of up/down before previous down was executed.
|
||||
*
|
||||
* That's because we want to be sure that no 'down' side callback would be ignored since we are counting to see
|
||||
* overlaps so we need the end counter to always have zero.
|
||||
* TODO: make watchdog decrement relevant counter
|
||||
*/
|
||||
bool isScheduled;
|
||||
|
||||
InjectorOutputPin *outputs[MAX_WIRES_COUNT];
|
||||
|
||||
InjectionEvent *event;
|
||||
};
|
||||
|
||||
class InjectionEvent {
|
||||
public:
|
||||
InjectionEvent();
|
||||
|
@ -54,7 +32,17 @@ public:
|
|||
#endif
|
||||
event_trigger_position_s injectionStart;
|
||||
|
||||
InjectionSignalPair pair;
|
||||
scheduling_s signalTimerUp;
|
||||
scheduling_s endOfInjectionEvent;
|
||||
|
||||
/**
|
||||
* we need atomic flag so that we do not schedule a new pair of up/down before previous down was executed.
|
||||
*
|
||||
* That's because we want to be sure that no 'down' side callback would be ignored since we are counting to see
|
||||
* overlaps so we need the end counter to always have zero.
|
||||
* TODO: make watchdog decrement relevant counter
|
||||
*/
|
||||
bool isScheduled = false;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ CONTROLLERS_SRC_CPP = \
|
|||
$(CONTROLLERS_DIR)/actuators/algo/aux_pid.cpp \
|
||||
$(CONTROLLERS_DIR)/actuators/lcd_controller.cpp \
|
||||
$(CONTROLLERS_DIR)/scheduling/signal_executor_sleep.cpp \
|
||||
$(CONTROLLERS_DIR)/scheduling/signal_executor.cpp \
|
||||
$(CONTROLLERS_DIR)/scheduling/single_timer_executor.cpp \
|
||||
$(CONTROLLERS_DIR)/scheduling/pwm_generator_logic.cpp \
|
||||
$(CONTROLLERS_DIR)/scheduling/event_queue.cpp \
|
||||
|
|
|
@ -22,27 +22,4 @@
|
|||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "global.h"
|
||||
#include "signal_executor.h"
|
||||
#include "efi_gpio.h"
|
||||
#include "engine.h"
|
||||
|
||||
/**
|
||||
* Signal executors feed digital events right into WaveChart used by Engine Sniffer tab of rusEfi Console
|
||||
*/
|
||||
#include "rpm_calculator.h"
|
||||
|
||||
EXTERN_ENGINE;
|
||||
|
||||
#if EFI_ENGINE_SNIFFER
|
||||
#include "engine_sniffer.h"
|
||||
extern WaveChart waveChart;
|
||||
#endif /* EFI_ENGINE_SNIFFER */
|
||||
|
||||
#include "efi_gpio.h"
|
||||
|
||||
InjectionSignalPair::InjectionSignalPair() {
|
||||
isScheduled = false;
|
||||
memset(outputs, 0, sizeof(outputs));
|
||||
event = nullptr;
|
||||
}
|
||||
|
|
|
@ -129,9 +129,9 @@ static inline void tempTurnPinHigh(InjectorOutputPin *output) {
|
|||
}
|
||||
|
||||
// todo: make these macro? kind of a penny optimization if compiler is not smart to inline
|
||||
void seTurnPinHigh(InjectionSignalPair *pair) {
|
||||
void seTurnPinHigh(InjectionEvent *event) {
|
||||
for (int i = 0;i < MAX_WIRES_COUNT;i++) {
|
||||
InjectorOutputPin *output = pair->outputs[i];
|
||||
InjectorOutputPin *output = event->outputs[i];
|
||||
if (output != NULL) {
|
||||
tempTurnPinHigh(output);
|
||||
}
|
||||
|
@ -177,25 +177,24 @@ static inline void tempTurnPinLow(InjectorOutputPin *output) {
|
|||
}
|
||||
}
|
||||
|
||||
void seTurnPinLow(InjectionSignalPair *pair) {
|
||||
pair->isScheduled = false;
|
||||
void seTurnPinLow(InjectionEvent *event) {
|
||||
event->isScheduled = false;
|
||||
for (int i = 0;i<MAX_WIRES_COUNT;i++) {
|
||||
InjectorOutputPin *output = pair->outputs[i];
|
||||
InjectorOutputPin *output = event->outputs[i];
|
||||
if (output != NULL) {
|
||||
tempTurnPinLow(output);
|
||||
}
|
||||
}
|
||||
efiAssertVoid(CUSTOM_EVENT_6626, pair->event != NULL, "pair event");
|
||||
#if EFI_UNIT_TEST
|
||||
Engine *engine = pair->event->engine;
|
||||
Engine *engine = event->engine;
|
||||
EXPAND_Engine;
|
||||
#endif
|
||||
ENGINE(injectionEvents.addFuelEventsForCylinder(pair->event->ownIndex PASS_ENGINE_PARAMETER_SUFFIX));
|
||||
ENGINE(injectionEvents.addFuelEventsForCylinder(event->ownIndex PASS_ENGINE_PARAMETER_SUFFIX));
|
||||
}
|
||||
|
||||
static void sescheduleByTimestamp(scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, InjectionSignalPair *pair DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
static void sescheduleByTimestamp(scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, InjectionEvent *event DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
#if FUEL_MATH_EXTREME_LOGGING
|
||||
InjectorOutputPin *param = pair->outputs[0];
|
||||
InjectorOutputPin *param = event->outputs[0];
|
||||
// scheduleMsg(&sharedLogger, "schX %s %x %d", prefix, scheduling, time);
|
||||
// scheduleMsg(&sharedLogger, "schX %s", param->name);
|
||||
|
||||
|
@ -203,7 +202,7 @@ static void sescheduleByTimestamp(scheduling_s *scheduling, efitimeus_t time, sc
|
|||
printf("seScheduleByTime %s %s %d sch=%d\r\n", direction, param->name, (int)time, (int)scheduling);
|
||||
#endif /* FUEL_MATH_EXTREME_LOGGING || EFI_UNIT_TEST */
|
||||
|
||||
engine->executor.scheduleByTimestamp(scheduling, time, callback, pair);
|
||||
engine->executor.scheduleByTimestamp(scheduling, time, callback, event);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionEvent *event,
|
||||
|
@ -271,7 +270,6 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionE
|
|||
getRevolutionCounter());
|
||||
#endif /* EFI_DEFAILED_LOGGING */
|
||||
|
||||
InjectionSignalPair *pair = &event->pair;
|
||||
|
||||
if (event->isSimultanious) {
|
||||
/**
|
||||
|
@ -280,9 +278,9 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionE
|
|||
* changed into 'scheduleInjection' and unified? todo: think about it.
|
||||
*/
|
||||
|
||||
scheduling_s * sUp = &pair->signalTimerUp;
|
||||
// todo: sequential need this logic as well, just do not forget to clear flag pair->isScheduled = true;
|
||||
scheduling_s * sDown = &pair->endOfInjectionEvent;
|
||||
scheduling_s * sUp = &event->signalTimerUp;
|
||||
// todo: sequential need this logic as well, just do not forget to clear flag event->isScheduled = true;
|
||||
scheduling_s * sDown = &event->endOfInjectionEvent;
|
||||
|
||||
engine->executor.scheduleForLater(sUp, (int) injectionStartDelayUs, (schfunc_t) &startSimultaniousInjection, engine);
|
||||
engine->executor.scheduleForLater(sDown, (int) injectionStartDelayUs + durationUs,
|
||||
|
@ -314,19 +312,16 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionE
|
|||
#endif /*EFI_PRINTF_FUEL_DETAILS */
|
||||
|
||||
|
||||
if (pair->isScheduled) {
|
||||
if (event->isScheduled) {
|
||||
#if EFI_UNIT_TEST || EFI_SIMULATOR
|
||||
printf("still used1 %s %d\r\n", output->name, (int)getTimeNowUs());
|
||||
#endif /* EFI_UNIT_TEST || EFI_SIMULATOR */
|
||||
return; // this InjectionSignalPair is still needed for an extremely long injection scheduled previously
|
||||
return; // this InjectionEvent is still needed for an extremely long injection scheduled previously
|
||||
}
|
||||
pair->outputs[0] = output;
|
||||
pair->outputs[1] = event->outputs[1];
|
||||
scheduling_s * sUp = &pair->signalTimerUp;
|
||||
scheduling_s * sDown = &pair->endOfInjectionEvent;
|
||||
scheduling_s * sUp = &event->signalTimerUp;
|
||||
scheduling_s * sDown = &event->endOfInjectionEvent;
|
||||
|
||||
pair->isScheduled = true;
|
||||
pair->event = event;
|
||||
event->isScheduled = true;
|
||||
efitimeus_t turnOnTime = nowUs + (int) injectionStartDelayUs;
|
||||
bool isSecondaryOverlapping = turnOnTime < output->overlappingScheduleOffTime;
|
||||
|
||||
|
@ -336,10 +331,10 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionE
|
|||
printf("please cancel %s %d %d\r\n", output->name, (int)getTimeNowUs(), output->overlappingCounter);
|
||||
#endif /* EFI_UNIT_TEST || EFI_SIMULATOR */
|
||||
} else {
|
||||
sescheduleByTimestamp(sUp, turnOnTime, (schfunc_t) &seTurnPinHigh, pair PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
sescheduleByTimestamp(sUp, turnOnTime, (schfunc_t) &seTurnPinHigh, event PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
}
|
||||
efitimeus_t turnOffTime = nowUs + (int) (injectionStartDelayUs + durationUs);
|
||||
sescheduleByTimestamp(sDown, turnOffTime, (schfunc_t) &seTurnPinLow, pair PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
sescheduleByTimestamp(sDown, turnOffTime, (schfunc_t) &seTurnPinLow, event PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -582,7 +577,7 @@ void startPrimeInjectionPulse(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
primeInjEvent.ownIndex = 0;
|
||||
primeInjEvent.isSimultanious = true;
|
||||
|
||||
scheduling_s *sDown = &ENGINE(injectionEvents.elements[0].pair).endOfInjectionEvent;
|
||||
scheduling_s *sDown = &ENGINE(injectionEvents.elements[0]).endOfInjectionEvent;
|
||||
// When the engine is hot, basically we don't need prime inj.pulse, so we use an interpolation over temperature (falloff).
|
||||
// If 'primeInjFalloffTemperature' is not specified (by default), we have a prime pulse deactivation at zero celsius degrees, which is okay.
|
||||
const float maxPrimeInjAtTemperature = -40.0f; // at this temperature the pulse is maximal.
|
||||
|
|
|
@ -24,8 +24,8 @@ void showMainHistogram(void);
|
|||
|
||||
void startSimultaniousInjection(Engine *engine);
|
||||
void endSimultaniousInjection(InjectionEvent *event);
|
||||
void seTurnPinHigh(InjectionSignalPair *pair);
|
||||
void seTurnPinLow(InjectionSignalPair *pair);
|
||||
void seTurnPinHigh(InjectionEvent *event);
|
||||
void seTurnPinLow(InjectionEvent *event);
|
||||
|
||||
float getFuel(int rpm, float key);
|
||||
|
||||
|
|
|
@ -152,13 +152,13 @@ void EngineTestHelper::fireTriggerEvents(int count) {
|
|||
}
|
||||
|
||||
void EngineTestHelper::assertInjectorUpEvent(const char *msg, int eventIndex, efitime_t momentX, long injectorIndex) {
|
||||
InjectionSignalPair *pair = &engine.injectionEvents.elements[injectorIndex].pair;
|
||||
assertEvent(msg, eventIndex, (void*)seTurnPinHigh, momentX, (long)pair);
|
||||
InjectionEvent *event = &engine.injectionEvents.elements[injectorIndex];
|
||||
assertEvent(msg, eventIndex, (void*)seTurnPinHigh, momentX, event);
|
||||
}
|
||||
|
||||
void EngineTestHelper::assertInjectorDownEvent(const char *msg, int eventIndex, efitime_t momentX, long injectorIndex) {
|
||||
InjectionSignalPair *pair = &engine.injectionEvents.elements[injectorIndex].pair;
|
||||
assertEvent(msg, eventIndex, (void*)seTurnPinLow, momentX, (long)pair);
|
||||
InjectionEvent *event = &engine.injectionEvents.elements[injectorIndex];
|
||||
assertEvent(msg, eventIndex, (void*)seTurnPinLow, momentX, event);
|
||||
}
|
||||
|
||||
scheduling_s * EngineTestHelper::assertEvent5(const char *msg, int index, void *callback, efitime_t expectedTimestamp) {
|
||||
|
@ -171,14 +171,12 @@ scheduling_s * EngineTestHelper::assertEvent5(const char *msg, int index, void *
|
|||
return event;
|
||||
}
|
||||
|
||||
void EngineTestHelper::assertEvent(const char *msg, int index, void *callback, efitime_t momentX, long param) {
|
||||
void EngineTestHelper::assertEvent(const char *msg, int index, void *callback, efitime_t momentX, InjectionEvent *expectedEvent) {
|
||||
scheduling_s *event = assertEvent5(msg, index, callback, momentX);
|
||||
|
||||
InjectionSignalPair *eventPair = (InjectionSignalPair *)event->param;
|
||||
InjectionEvent *actualEvent = (InjectionEvent *)event->param;
|
||||
|
||||
InjectionSignalPair *expectedPair = (InjectionSignalPair *)param;
|
||||
|
||||
assertEqualsLM(msg, expectedPair->outputs[0], (long)eventPair->outputs[0]);
|
||||
assertEqualsLM(msg, expectedEvent->outputs[0], (long)actualEvent->outputs[0]);
|
||||
// but this would not work assertEqualsLM(msg, expectedPair, (long)eventPair);
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
void clearQueue();
|
||||
|
||||
scheduling_s * assertEvent5(const char *msg, int index, void *callback, efitime_t expectedTimestamp);
|
||||
void assertEvent(const char *msg, int index, void *callback, efitime_t momentX, long param);
|
||||
void assertEvent(const char *msg, int index, void *callback, efitime_t momentX, InjectionEvent *event);
|
||||
void assertInjectorUpEvent(const char *msg, int eventIndex, efitime_t momentX, long injectorIndex);
|
||||
void assertInjectorDownEvent(const char *msg, int eventIndex, efitime_t momentX, long injectorIndex);
|
||||
// todo: open question if this is worth a helper method or should be inlined?
|
||||
|
|
Loading…
Reference in New Issue