Merge remote-tracking branch 'origin/master'

This commit is contained in:
rusefi 2020-05-14 18:23:46 -04:00
commit 39708dcf60
14 changed files with 106 additions and 13 deletions

View File

@ -30,5 +30,10 @@ ifeq ($(LED_CRITICAL_ERROR_BRAIN_PIN),)
endif endif
# breaking TTL thus breaking Bluetooth for microRusEFI in order to enable SPI3 for SD card
EFI_CONSOLE_TTL_PINS = -DEFI_CONSOLE_TX_BRAIN_PIN=GPIOE_15 -DEFI_CONSOLE_RX_BRAIN_PIN=GPIOE_14
# Add them all together # Add them all together
DDEFS += $(MCU_DEFS) -DEFI_USE_OSC=TRUE -DFIRMWARE_ID=\"microRusEfi\" $(DEFAULT_ENGINE_TYPE) $(LED_CRITICAL_ERROR_BRAIN_PIN) DDEFS += $(MCU_DEFS) -DEFI_USE_OSC=TRUE -DFIRMWARE_ID=\"microRusEfi\" $(DEFAULT_ENGINE_TYPE) $(LED_CRITICAL_ERROR_BRAIN_PIN) $(EFI_CONSOLE_TTL_PINS)

View File

@ -86,6 +86,7 @@ static void setupVbatt() {
// set vbatt_divider 8.23 // set vbatt_divider 8.23
// R139=39k high side/R141=10k low side multiplied by above analogInputDividerCoefficient = 8.232f // R139=39k high side/R141=10k low side multiplied by above analogInputDividerCoefficient = 8.232f
engineConfiguration->vbattDividerCoeff = (49.0f / 10.0f) * engineConfiguration->analogInputDividerCoefficient; engineConfiguration->vbattDividerCoeff = (49.0f / 10.0f) * engineConfiguration->analogInputDividerCoefficient;
// PC1, pin #1 input +12 from Main Relay. Main Relay controlled by TLE8888
engineConfiguration->vbattAdcChannel = EFI_ADC_11; engineConfiguration->vbattAdcChannel = EFI_ADC_11;
engineConfiguration->adcVcc = 3.29f; engineConfiguration->adcVcc = 3.29f;
@ -198,6 +199,14 @@ void setBoardConfigurationOverrides(void) {
// GPIOE_8: "35 - GP Out 1" // GPIOE_8: "35 - GP Out 1"
engineConfiguration->fuelPumpPin = GPIOE_8; engineConfiguration->fuelPumpPin = GPIOE_8;
engineConfiguration->sdCardSpiDevice = SPI_DEVICE_3;
engineConfiguration->spi3mosiPin = GPIOC_12;
engineConfiguration->spi3misoPin = GPIOC_11;
engineConfiguration->spi3sckPin = GPIOC_10;
engineConfiguration->sdCardCsPin = GPIOB_9;
CONFIG(is_enabled_spi_3) = true;
// engineConfiguration->isSdCardEnabled = true;
// TLE8888 high current low side: VVT2 IN9 / OUT5 // TLE8888 high current low side: VVT2 IN9 / OUT5
// GPIOE_10: "3 - Lowside 2" // GPIOE_10: "3 - Lowside 2"

View File

@ -7,7 +7,7 @@
#define ts_show_gps false #define ts_show_gps false
#define ts_show_etb_pins false #define ts_show_etb_pins false
#define ts_show_analog_divider false #define ts_show_analog_divider false
#define ts_show_spi false #define ts_show_spi true
#define ts_show_sd_card false #define ts_show_sd_card true
#define ts_show_can_pins false #define ts_show_can_pins false
#define ts_show_tunerstudio_port false #define ts_show_tunerstudio_port false

View File

@ -609,6 +609,11 @@ typedef enum __attribute__ ((__packed__)) {
_150KHz _150KHz
} spi_speed_e; } spi_speed_e;
/**
* See spi3mosiPin
* See spi2MisoMode
*/
typedef enum __attribute__ ((__packed__)) { typedef enum __attribute__ ((__packed__)) {
SPI_NONE = 0, SPI_NONE = 0,
SPI_DEVICE_1 = 1, SPI_DEVICE_1 = 1,

View File

@ -161,7 +161,6 @@ typedef enum __attribute__ ((__packed__)) {
GPIOH_15 = 129, GPIOH_15 = 129,
/* TLE6240 pins go right after on chips */ /* TLE6240 pins go right after on chips */
//#define TLE6240_PIN(n) ((brain_pin_e)((int)BRAIN_PIN_LAST_ONCHIP + 1 + (n)))
TLE6240_PIN_1 = 130, TLE6240_PIN_1 = 130,
TLE6240_PIN_2 = 131, TLE6240_PIN_2 = 131,
TLE6240_PIN_3 = 132, TLE6240_PIN_3 = 132,
@ -180,7 +179,6 @@ typedef enum __attribute__ ((__packed__)) {
TLE6240_PIN_16 = 145, TLE6240_PIN_16 = 145,
/* MC33972 pins go right after TLE6240 */ /* MC33972 pins go right after TLE6240 */
//#define MC33972_PIN(n) ((brain_pin_e)((int)BRAIN_PIN_LAST_ONCHIP + 1 + 16 + (n)))
MC33972_PIN_1 = 146, MC33972_PIN_1 = 146,
MC33972_PIN_21 = 166, MC33972_PIN_21 = 166,
MC33972_PIN_22 = 167, MC33972_PIN_22 = 167,

View File

@ -696,7 +696,7 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX)
* UNUSED_SIZE contants. * UNUSED_SIZE contants.
*/ */
#ifndef RAM_UNUSED_SIZE #ifndef RAM_UNUSED_SIZE
#define RAM_UNUSED_SIZE 12200 #define RAM_UNUSED_SIZE 10900
#endif #endif
#ifndef CCM_UNUSED_SIZE #ifndef CCM_UNUSED_SIZE
#define CCM_UNUSED_SIZE 2900 #define CCM_UNUSED_SIZE 2900
@ -717,6 +717,6 @@ int getRusEfiVersion(void) {
if (initBootloader() != 0) if (initBootloader() != 0)
return 123; return 123;
#endif /* EFI_BOOTLOADER_INCLUDE_CODE */ #endif /* EFI_BOOTLOADER_INCLUDE_CODE */
return 20200512; return 20200513;
} }
#endif /* EFI_UNIT_TEST */ #endif /* EFI_UNIT_TEST */

View File

@ -168,7 +168,7 @@ void turnInjectionPinLow(InjectionEvent *event) {
ENGINE(injectionEvents.addFuelEventsForCylinder(event->ownIndex PASS_ENGINE_PARAMETER_SUFFIX)); 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) { 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; 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 * 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 // reset injection switch counter if the engine started spinning
void updatePrimeInjectionPulseState(DECLARE_ENGINE_PARAMETER_SIGNATURE); 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

@ -24,11 +24,6 @@
#define BOARD_EXT_GPIOCHIPS (BOARD_TLE6240_COUNT + BOARD_MC33972_COUNT + BOARD_TLE8888_COUNT) #define BOARD_EXT_GPIOCHIPS (BOARD_TLE6240_COUNT + BOARD_MC33972_COUNT + BOARD_TLE8888_COUNT)
#endif #endif
/* TLE6240 pins go right after on chips */
#define TLE6240_PIN(n) ((brain_pin_e)((int)BRAIN_PIN_LAST_ONCHIP + 1 + (n)))
/* MC33972 pins go right after TLE6240 */
#define MC33972_PIN(n) ((brain_pin_e)((int)BRAIN_PIN_LAST_ONCHIP + 1 + 16 + (n)))
void initSmartGpio(void); void initSmartGpio(void);
void startSmartCsPins(void); void startSmartCsPins(void);
void stopSmartCsPins(void); void stopSmartCsPins(void);

View File

@ -14,6 +14,12 @@ void TestExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs, actio
if (debugSignalExecutor) { if (debugSignalExecutor) {
printf("scheduleTask %d\r\n", delayUs); printf("scheduleTask %d\r\n", delayUs);
} }
if (m_mockExecutor) {
m_mockExecutor->scheduleForLater(scheduling, delayUs, action);
return;
}
scheduleByTimestamp(scheduling, getTimeNowUs() + delayUs, action); scheduleByTimestamp(scheduling, getTimeNowUs() + delayUs, action);
} }
@ -37,9 +43,24 @@ void TestExecutor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t tim
if (debugSignalExecutor) { if (debugSignalExecutor) {
printf("scheduleByTime %d\r\n", timeUs); printf("scheduleByTime %d\r\n", timeUs);
} }
if (m_mockExecutor) {
m_mockExecutor->scheduleByTimestamp(scheduling, timeUs, action);
return;
}
schedulingQueue.insertTask(scheduling, timeUs, action); schedulingQueue.insertTask(scheduling, timeUs, action);
} }
void TestExecutor::scheduleByTimestampNt(scheduling_s* scheduling, efitick_t timeNt, action_s 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); 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 executeAll(efitime_t now);
int size(); int size();
scheduling_s* getForUnitTest(int index); scheduling_s* getForUnitTest(int index);
void setMockExecutor(ExecutorInterface* exec);
private: private:
EventQueue schedulingQueue; EventQueue schedulingQueue;
ExecutorInterface* m_mockExecutor = nullptr;
}; };

View File

@ -40,3 +40,10 @@ class MockPwm : public SimplePwm {
public: public:
MOCK_METHOD(void, setSimplePwmDutyCycle, (float dutyCycle), (override)); 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_trigger_multi_sync.cpp \
tests/trigger/test_cam_vvt_input.cpp \ tests/trigger/test_cam_vvt_input.cpp \
tests/trigger/test_2jz_vvt.cpp \ tests/trigger/test_2jz_vvt.cpp \
tests/trigger/test_injection_scheduling.cpp \
tests/test_util.cpp \ tests/test_util.cpp \
tests/test_ion.cpp \ tests/test_ion.cpp \
tests/test_aux_valves.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);
}