Fix 100% duty injection (#1431)

* skip turn-off for high duty

* mock executor injection

* test

* switch to hard cut

* test no longer relevant
This commit is contained in:
Matthew Kennedy 2020-05-14 04:44:32 -07:00 committed by GitHub
parent 4c53fac81c
commit e46d9f0c99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 82 additions and 1 deletions

View File

@ -168,7 +168,7 @@ void turnInjectionPinLow(InjectionEvent *event) {
ENGINE(injectionEvents.addFuelEventsForCylinder(event->ownIndex PASS_ENGINE_PARAMETER_SUFFIX));
}
static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionEvent *event,
void handleFuelInjectionEvent(int injEventIndex, InjectionEvent *event,
int rpm, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
/**
@ -310,6 +310,11 @@ static ALWAYS_INLINE void handleFuel(const bool limitedFuel, uint32_t trgEventIn
return;
}
// If duty cycle is high, impose a fuel cut rev limiter.
// This is safer than attempting to limp along with injectors or a pump that are out of flow.
if (getInjectorDutyCycle(rpm PASS_ENGINE_PARAMETER_SUFFIX) > 96.0f) {
return;
}
/**
* Ignition events are defined by addFuelEvents() according to selected

View File

@ -24,3 +24,7 @@ void turnInjectionPinLow(InjectionEvent *event);
// reset injection switch counter if the engine started spinning
void updatePrimeInjectionPulseState(DECLARE_ENGINE_PARAMETER_SIGNATURE);
// Internal use only - exposed for tests
void handleFuelInjectionEvent(int injEventIndex, InjectionEvent *event,
int rpm, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);

View File

@ -14,6 +14,12 @@ void TestExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs, actio
if (debugSignalExecutor) {
printf("scheduleTask %d\r\n", delayUs);
}
if (m_mockExecutor) {
m_mockExecutor->scheduleForLater(scheduling, delayUs, action);
return;
}
scheduleByTimestamp(scheduling, getTimeNowUs() + delayUs, action);
}
@ -37,9 +43,24 @@ void TestExecutor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t tim
if (debugSignalExecutor) {
printf("scheduleByTime %d\r\n", timeUs);
}
if (m_mockExecutor) {
m_mockExecutor->scheduleByTimestamp(scheduling, timeUs, action);
return;
}
schedulingQueue.insertTask(scheduling, timeUs, action);
}
void TestExecutor::scheduleByTimestampNt(scheduling_s* scheduling, efitick_t timeNt, action_s action) {
if (m_mockExecutor) {
m_mockExecutor->scheduleByTimestampNt(scheduling, timeNt, action);
return;
}
scheduleByTimestamp(scheduling, NT2US(timeNt), action);
}
void TestExecutor::setMockExecutor(ExecutorInterface* exec) {
m_mockExecutor = exec;
}

View File

@ -19,6 +19,9 @@ public:
int executeAll(efitime_t now);
int size();
scheduling_s* getForUnitTest(int index);
void setMockExecutor(ExecutorInterface* exec);
private:
EventQueue schedulingQueue;
ExecutorInterface* m_mockExecutor = nullptr;
};

View File

@ -40,3 +40,10 @@ class MockPwm : public SimplePwm {
public:
MOCK_METHOD(void, setSimplePwmDutyCycle, (float dutyCycle), (override));
};
class MockExecutor : public TestExecutor {
public:
MOCK_METHOD(void, scheduleByTimestamp, (scheduling_s *scheduling, efitimeus_t timeUs, action_s action), (override));
MOCK_METHOD(void, scheduleByTimestampNt, (scheduling_s *scheduling, efitime_t timeUs, action_s action), (override));
MOCK_METHOD(void, scheduleForLater, (scheduling_s *scheduling, int delayUs, action_s action), (override));
};

View File

@ -5,6 +5,7 @@ TESTS_SRC_CPP = \
tests/trigger/test_trigger_multi_sync.cpp \
tests/trigger/test_cam_vvt_input.cpp \
tests/trigger/test_2jz_vvt.cpp \
tests/trigger/test_injection_scheduling.cpp \
tests/test_util.cpp \
tests/test_ion.cpp \
tests/test_aux_valves.cpp \

View File

@ -0,0 +1,40 @@
#include "engine_test_helper.h"
#include "main_trigger_callback.h"
#include <gmock/gmock.h>
#include "mocks.h"
using ::testing::_;
using ::testing::StrictMock;
using ::testing::InSequence;
TEST(injectionScheduling, NormalDutyCycle) {
StrictMock<MockExecutor> mockExec;
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
engine->executor.setMockExecutor(&mockExec);
efitick_t nowNt = 1000000;
InjectionEvent event;
InjectorOutputPin pin;
pin.injectorIndex = 0;
event.outputs[0] = &pin;
// Injection duration of 20ms
engine->injectionDuration = 20.0f;
{
InSequence is;
// Should schedule one normal injection:
// rising edge now
EXPECT_CALL(mockExec, scheduleByTimestampNt(&event.signalTimerUp, nowNt + 0, _));
// falling edge 10ms later
EXPECT_CALL(mockExec, scheduleByTimestampNt(&event.endOfInjectionEvent, nowNt + MS2NT(20), _));
}
engine->rpmCalculator.oneDegreeUs = 100;
handleFuelInjectionEvent(0, &event, 1000, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
}