diff --git a/firmware/config/boards/microrusefi/board.mk b/firmware/config/boards/microrusefi/board.mk index 6e14f99272..edcf4b3e2b 100644 --- a/firmware/config/boards/microrusefi/board.mk +++ b/firmware/config/boards/microrusefi/board.mk @@ -30,5 +30,10 @@ ifeq ($(LED_CRITICAL_ERROR_BRAIN_PIN),) 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 -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) + diff --git a/firmware/config/boards/microrusefi/board_configuration.cpp b/firmware/config/boards/microrusefi/board_configuration.cpp index e729650867..356d971c46 100644 --- a/firmware/config/boards/microrusefi/board_configuration.cpp +++ b/firmware/config/boards/microrusefi/board_configuration.cpp @@ -86,6 +86,7 @@ static void setupVbatt() { // set vbatt_divider 8.23 // R139=39k high side/R141=10k low side multiplied by above analogInputDividerCoefficient = 8.232f 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->adcVcc = 3.29f; @@ -198,6 +199,14 @@ void setBoardConfigurationOverrides(void) { // GPIOE_8: "35 - GP Out 1" 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 // GPIOE_10: "3 - Lowside 2" diff --git a/firmware/config/boards/microrusefi/prepend.txt b/firmware/config/boards/microrusefi/prepend.txt index f11e020f1a..73e90b6153 100644 --- a/firmware/config/boards/microrusefi/prepend.txt +++ b/firmware/config/boards/microrusefi/prepend.txt @@ -7,7 +7,7 @@ #define ts_show_gps false #define ts_show_etb_pins false #define ts_show_analog_divider false -#define ts_show_spi false -#define ts_show_sd_card false +#define ts_show_spi true +#define ts_show_sd_card true #define ts_show_can_pins false #define ts_show_tunerstudio_port false diff --git a/firmware/controllers/algo/rusefi_enums.h b/firmware/controllers/algo/rusefi_enums.h index 69b48ea11c..d1e5ecd7b3 100644 --- a/firmware/controllers/algo/rusefi_enums.h +++ b/firmware/controllers/algo/rusefi_enums.h @@ -609,6 +609,11 @@ typedef enum __attribute__ ((__packed__)) { _150KHz } spi_speed_e; + +/** + * See spi3mosiPin + * See spi2MisoMode + */ typedef enum __attribute__ ((__packed__)) { SPI_NONE = 0, SPI_DEVICE_1 = 1, diff --git a/firmware/controllers/algo/rusefi_hw_enums.h b/firmware/controllers/algo/rusefi_hw_enums.h index 2369fe0d28..c175c2f372 100644 --- a/firmware/controllers/algo/rusefi_hw_enums.h +++ b/firmware/controllers/algo/rusefi_hw_enums.h @@ -161,7 +161,6 @@ typedef enum __attribute__ ((__packed__)) { GPIOH_15 = 129, /* 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_2 = 131, TLE6240_PIN_3 = 132, @@ -180,7 +179,6 @@ typedef enum __attribute__ ((__packed__)) { TLE6240_PIN_16 = 145, /* 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_21 = 166, MC33972_PIN_22 = 167, diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 771be483ef..2fb41cfa90 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -696,7 +696,7 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) * UNUSED_SIZE contants. */ #ifndef RAM_UNUSED_SIZE -#define RAM_UNUSED_SIZE 12200 +#define RAM_UNUSED_SIZE 10900 #endif #ifndef CCM_UNUSED_SIZE #define CCM_UNUSED_SIZE 2900 @@ -717,6 +717,6 @@ int getRusEfiVersion(void) { if (initBootloader() != 0) return 123; #endif /* EFI_BOOTLOADER_INCLUDE_CODE */ - return 20200512; + return 20200513; } #endif /* EFI_UNIT_TEST */ diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index ecb999e941..fca28931cf 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -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 diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.h b/firmware/controllers/engine_cycle/main_trigger_callback.h index d4f1c33d4d..a61e0ca5f4 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.h +++ b/firmware/controllers/engine_cycle/main_trigger_callback.h @@ -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); diff --git a/firmware/hw_layer/smart_gpio.h b/firmware/hw_layer/smart_gpio.h index 024c6738a9..bb481a90c9 100644 --- a/firmware/hw_layer/smart_gpio.h +++ b/firmware/hw_layer/smart_gpio.h @@ -24,11 +24,6 @@ #define BOARD_EXT_GPIOCHIPS (BOARD_TLE6240_COUNT + BOARD_MC33972_COUNT + BOARD_TLE8888_COUNT) #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 startSmartCsPins(void); void stopSmartCsPins(void); diff --git a/unit_tests/global_execution_queue.cpp b/unit_tests/global_execution_queue.cpp index 24cdd0df54..4b20117b3d 100644 --- a/unit_tests/global_execution_queue.cpp +++ b/unit_tests/global_execution_queue.cpp @@ -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; +} diff --git a/unit_tests/global_execution_queue.h b/unit_tests/global_execution_queue.h index f568ad9954..c5ecec4435 100644 --- a/unit_tests/global_execution_queue.h +++ b/unit_tests/global_execution_queue.h @@ -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; }; diff --git a/unit_tests/mocks.h b/unit_tests/mocks.h index a3dca2df88..0aa45f47bf 100644 --- a/unit_tests/mocks.h +++ b/unit_tests/mocks.h @@ -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)); +}; diff --git a/unit_tests/tests/tests.mk b/unit_tests/tests/tests.mk index b54a80cad1..e4f0be8697 100644 --- a/unit_tests/tests/tests.mk +++ b/unit_tests/tests/tests.mk @@ -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 \ diff --git a/unit_tests/tests/trigger/test_injection_scheduling.cpp b/unit_tests/tests/trigger/test_injection_scheduling.cpp new file mode 100644 index 0000000000..071338461b --- /dev/null +++ b/unit_tests/tests/trigger/test_injection_scheduling.cpp @@ -0,0 +1,40 @@ +#include "engine_test_helper.h" +#include "main_trigger_callback.h" + +#include +#include "mocks.h" + +using ::testing::_; +using ::testing::StrictMock; +using ::testing::InSequence; + +TEST(injectionScheduling, NormalDutyCycle) { + StrictMock 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); +}