From 8e082ebe7f14101d7c67a794e4052653cc0a567e Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sat, 23 Jan 2016 18:01:40 -0500 Subject: [PATCH] auto-sync --- firmware/config/engines/toyota_jzs147.cpp | 9 ++++ firmware/controllers/algo/engine.cpp | 23 +++++++- firmware/controllers/algo/engine.h | 15 ++++++ firmware/controllers/engine_controller.cpp | 49 ++++++++++++++++- firmware/development/engine_sniffer.cpp | 14 ----- firmware/development/engine_sniffer.h | 13 ----- win32_functional_tests/simulator/boards.cpp | 53 ++----------------- win32_functional_tests/simulator/boards.h | 2 - .../simulator/efifeatures.h | 2 + .../simulator/rusEfiFunctionalTest.cpp | 2 - 10 files changed, 98 insertions(+), 84 deletions(-) diff --git a/firmware/config/engines/toyota_jzs147.cpp b/firmware/config/engines/toyota_jzs147.cpp index fe0385ea19..0401b6e0c5 100644 --- a/firmware/config/engines/toyota_jzs147.cpp +++ b/firmware/config/engines/toyota_jzs147.cpp @@ -14,10 +14,12 @@ */ #include "toyota_jzs147.h" +#include "custom_engine.h" EXTERN_ENGINE; void setToyota_jzs147EngineConfiguration(DECLARE_ENGINE_PARAMETER_F) { + setCustomEngineConfiguration(PASS_ENGINE_PARAMETER_F); // default pinout engineConfiguration->specs.displacement = 3.0; engineConfiguration->specs.cylindersCount = 6; @@ -26,6 +28,13 @@ void setToyota_jzs147EngineConfiguration(DECLARE_ENGINE_PARAMETER_F) { setOperationMode(engineConfiguration, FOUR_STROKE_CAM_SENSOR); engineConfiguration->trigger.type = TT_2JZ; + boardConfiguration->ignitionPins[0] = GPIOE_14; + boardConfiguration->ignitionPins[1] = GPIOC_7; + boardConfiguration->ignitionPins[2] = GPIOC_9; + boardConfiguration->ignitionPins[3] = GPIOE_10; + boardConfiguration->ignitionPins[3] = GPIOE_10; + boardConfiguration->ignitionPins[3] = GPIOE_10; + } diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index f0f231ae57..9548ead540 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -20,11 +20,11 @@ #include "speed_density.h" #include "advance_map.h" -#if EFI_PROD_CODE +#if EFI_PROD_CODE || defined(__DOXYGEN__) #include "injector_central.h" #else #define isRunningBenchTest() true -#endif +#endif /* EFI_PROD_CODE */ static LoggingWithStorage logger("engine"); @@ -36,6 +36,25 @@ extern fuel_Map3D_t afrMap; EXTERN_ENGINE ; +MockAdcState::MockAdcState() { + memset(hasMockAdc, 0, sizeof(hasMockAdc)); +} + +#if EFI_ENABLE_MOCK_ADC || EFI_SIMULATOR +void MockAdcState::setMockVoltage(int hwChannel, float voltage) { + scheduleMsg(&logger, "fake voltage: channel %d value %f", hwChannel, voltage); + + fakeAdcValues[hwChannel] = voltsToAdc(voltage); + hasMockAdc[hwChannel] = true; +} +#endif /* EFI_ENABLE_MOCK_ADC */ + +int MockAdcState::getMockAdcValue(int hwChannel) { + return fakeAdcValues[hwChannel]; +} + + + /** * We are executing these heavy (logarithm) methods from outside the trigger callbacks for performance reasons. * See also periodicFastCallback diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 680d6f0d24..b35afa2b1a 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -20,6 +20,18 @@ #include "accel_enrichment.h" #include "trigger_central.h" +#define MOCK_ADC_SIZE 16 + +class MockAdcState { +public: + MockAdcState(); + bool hasMockAdc[MOCK_ADC_SIZE]; + int fakeAdcValues[MOCK_ADC_SIZE]; + + void setMockVoltage(int hwChannel, float voltage); + int getMockAdcValue(int hwChannel); +}; + /** * This class knows about when to inject fuel */ @@ -149,6 +161,9 @@ public: floatms_t tpsAccelEnrich; angle_t injectionOffset; + +// todo: surround with EFI_ENABLE_MOCK_ADC checks + MockAdcState mockAdcState; }; class RpmCalculator; diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 3022790328..32838291a9 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -443,6 +443,52 @@ static void setFloat(const char *offsetStr, const char *valueStr) { getFloat(offset); } +#if EFI_ENABLE_MOCK_ADC || EFI_SIMULATOR + +static void setMockVoltage(int hwChannel, float voltage) { + engine->engineState.mockAdcState.setMockVoltage(hwChannel, voltage); +} + +static void setCltVoltage(float voltage) { + setMockVoltage(engineConfiguration->clt.adcChannel, voltage); +} + +static void setIatVoltage(float voltage) { + setMockVoltage(engineConfiguration->iat.adcChannel, voltage); +} + +static void setMafVoltage(float voltage) { + setMockVoltage(engineConfiguration->mafAdcChannel, voltage); +} + +static void setAfrVoltage(float voltage) { + setMockVoltage(engineConfiguration->afr.hwChannel, voltage); +} + +static void setTpsVoltage(float voltage) { + setMockVoltage(engineConfiguration->tpsAdcChannel, voltage); +} + +static void setMapVoltage(float voltage) { + setMockVoltage(engineConfiguration->map.sensor.hwChannel, voltage); +} + +static void setVBattVoltage(float voltage) { + setMockVoltage(engineConfiguration->vbattAdcChannel, voltage); +} + +static void initMockVoltage(void) { + addConsoleActionF("set_mock_clt_voltage", setCltVoltage); + addConsoleActionF("set_mock_iat_voltage", setIatVoltage); + addConsoleActionF("set_mock_maf_voltage", setMafVoltage); + addConsoleActionF("set_mock_afr_voltage", setAfrVoltage); + addConsoleActionF("set_mock_tps_voltage", setTpsVoltage); + addConsoleActionF("set_mock_map_voltage", setMapVoltage); + addConsoleActionF("set_mock_vbatt_voltage", setVBattVoltage); +} + +#endif /* EFI_ENABLE_MOCK_ADC */ + static void initConfigActions(void) { addConsoleActionSS("set_float", (VoidCharPtrCharPtr) setFloat); addConsoleActionII("set_int", (VoidIntInt) setInt); @@ -465,12 +511,13 @@ static void getKnockInfo(void) { // this method is used by real firmware and simulator void commonInitEngineController(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S) { initConfigActions(); + initMockVoltage(); #if EFI_PROD_CODE || EFI_SIMULATOR initSignalExecutor(); #endif -#if EFI_PROD_CODE +#if EFI_PROD_CODE || EFI_SIMULATOR // todo: this is a mess, remove code duplication with simulator initSettings(engineConfiguration); #endif diff --git a/firmware/development/engine_sniffer.cpp b/firmware/development/engine_sniffer.cpp index ea49ff6aa4..7c2342aebc 100644 --- a/firmware/development/engine_sniffer.cpp +++ b/firmware/development/engine_sniffer.cpp @@ -28,20 +28,6 @@ #include "engine_sniffer.h" #include "adc_math.h" -MockAdcState::MockAdcState() { - memset(hasMockAdc, 0, sizeof(hasMockAdc)); -} - -void MockAdcState::setMockVoltage(int hwChannel, float voltage) { - fakeAdcValues[hwChannel] = voltsToAdc(voltage); - hasMockAdc[hwChannel] = true; -} - -int MockAdcState::getMockAdcValue(int hwChannel) { - return fakeAdcValues[hwChannel]; -} - - #if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__) #include "engine_configuration.h" diff --git a/firmware/development/engine_sniffer.h b/firmware/development/engine_sniffer.h index 0fcef43c5b..2678629ed7 100644 --- a/firmware/development/engine_sniffer.h +++ b/firmware/development/engine_sniffer.h @@ -11,19 +11,6 @@ #include "global.h" -#define MOCK_ADC_SIZE 16 - -class MockAdcState { -public: - MockAdcState(); - bool hasMockAdc[MOCK_ADC_SIZE]; - int fakeAdcValues[MOCK_ADC_SIZE]; - - void setMockVoltage(int hwChannel, float voltage); - int getMockAdcValue(int hwChannel); -}; - - #if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__) #include "datalogging.h" diff --git a/win32_functional_tests/simulator/boards.cpp b/win32_functional_tests/simulator/boards.cpp index a39c04309f..b1ed956fd8 100644 --- a/win32_functional_tests/simulator/boards.cpp +++ b/win32_functional_tests/simulator/boards.cpp @@ -7,61 +7,14 @@ #include "main.h" #include "boards.h" -#include "engine_configuration.h" +#include "engine.h" #include "adc_math.h" #include "engine_sniffer.h" static LoggingWithStorage logger("simulator board"); extern engine_configuration_s *engineConfiguration; - -MockAdcState mockAdcState; +extern Engine *engine; int getAdcValue(const char *msg, int hwChannel) { - return mockAdcState.getMockAdcValue(hwChannel); + return engine->engineState.mockAdcState.getMockAdcValue(hwChannel); } - -static void setVoltage(int hwChannel, float voltage) { - scheduleMsg(&logger, "fake voltage: channel %d value %f", hwChannel, voltage); - mockAdcState.setMockVoltage(hwChannel, voltage); -} - -static void setCltVoltage(float voltage) { - setVoltage(engineConfiguration->clt.adcChannel, voltage); -} - -static void setIatVoltage(float voltage) { - setVoltage(engineConfiguration->iat.adcChannel, voltage); -} - -static void setMafVoltage(float voltage) { - setVoltage(engineConfiguration->mafAdcChannel, voltage); -} - -static void setAfrVoltage(float voltage) { - setVoltage(engineConfiguration->afr.hwChannel, voltage); -} - -static void setTpsVoltage(float voltage) { - setVoltage(engineConfiguration->tpsAdcChannel, voltage); -} - -static void setMapVoltage(float voltage) { - setVoltage(engineConfiguration->map.sensor.hwChannel, voltage); -} - -static void setVBattVoltage(float voltage) { - setVoltage(engineConfiguration->vbattAdcChannel, voltage); -} - -void initFakeBoard(void) { - - addConsoleActionF("set_mock_clt_voltage", setCltVoltage); - addConsoleActionF("set_mock_iat_voltage", setIatVoltage); - addConsoleActionF("set_mock_maf_voltage", setMafVoltage); - addConsoleActionF("set_mock_afr_voltage", setAfrVoltage); - addConsoleActionF("set_mock_tps_voltage", setTpsVoltage); - addConsoleActionF("set_mock_map_voltage", setMapVoltage); - addConsoleActionF("set_mock_vbatt_voltage", setVBattVoltage); -} - - diff --git a/win32_functional_tests/simulator/boards.h b/win32_functional_tests/simulator/boards.h index ce9395993a..3db5e6faf7 100644 --- a/win32_functional_tests/simulator/boards.h +++ b/win32_functional_tests/simulator/boards.h @@ -20,8 +20,6 @@ #define EFI_CONSOLE_UART_DEVICE (&testStream) int getAdcValue(const char *msg, int channel); -void initFakeBoard(void); - #ifdef __cplusplus extern "C" diff --git a/win32_functional_tests/simulator/efifeatures.h b/win32_functional_tests/simulator/efifeatures.h index d2630f8cfe..1cdb740274 100644 --- a/win32_functional_tests/simulator/efifeatures.h +++ b/win32_functional_tests/simulator/efifeatures.h @@ -10,6 +10,8 @@ #define EFI_ENABLE_ASSERTS TRUE +#define EFI_ENABLE_MOCK_ADC TRUE + #define EFI_GPIO TRUE #define EFI_FSIO TRUE diff --git a/win32_functional_tests/simulator/rusEfiFunctionalTest.cpp b/win32_functional_tests/simulator/rusEfiFunctionalTest.cpp index 0e4c0fdd9c..fc50d3ac72 100644 --- a/win32_functional_tests/simulator/rusEfiFunctionalTest.cpp +++ b/win32_functional_tests/simulator/rusEfiFunctionalTest.cpp @@ -73,8 +73,6 @@ void rusEfiFunctionalTest(void) { initializeConsole(&sharedLogger); - initFakeBoard(); - initStatusLoop(engine); initDataStructures(PASS_ENGINE_PARAMETER_F);