From 730b26d034eee39fea9b0390cc032fe394c10e6c Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Fri, 27 Aug 2021 22:39:55 -0700 Subject: [PATCH] remove old vss implementation (#3208) * dead vss * remove --- firmware/console/status_loop.cpp | 1 - .../controllers/actuators/idle_thread.cpp | 1 - firmware/controllers/algo/dynoview.cpp | 3 +- firmware/controllers/algo/engine.h | 6 - firmware/controllers/algo/launch_control.cpp | 3 +- firmware/controllers/can/can_dash.cpp | 1 - firmware/controllers/can/can_verbose.cpp | 1 - firmware/controllers/can/can_vss.cpp | 1 - firmware/controllers/can/obd2.cpp | 1 - firmware/controllers/serial/serial_rx.cpp | 2 - firmware/controllers/settings.cpp | 5 - firmware/hw_layer/hardware.cpp | 13 -- firmware/hw_layer/hw_layer.mk | 1 - firmware/hw_layer/vehicle_speed.cpp | 135 ------------------ firmware/hw_layer/vehicle_speed.h | 20 --- .../init/sensor/init_vehicle_speed_sensor.cpp | 1 - unit_tests/tests/test_dynoview.cpp | 1 - unit_tests/tests/test_launch.cpp | 1 - unit_tests/tests/test_vehicle_speed.cpp | 67 --------- unit_tests/tests/tests.mk | 1 - 20 files changed, 2 insertions(+), 263 deletions(-) delete mode 100644 firmware/hw_layer/vehicle_speed.cpp delete mode 100644 firmware/hw_layer/vehicle_speed.h delete mode 100644 unit_tests/tests/test_vehicle_speed.cpp diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index e3309398c5..14cdeb97de 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -65,7 +65,6 @@ extern bool main_loop_started; #include "pin_repository.h" #include "flash_main.h" #include "max31855.h" -#include "vehicle_speed.h" #include "single_timer_executor.h" #include "periodic_task.h" extern int icuRisingCallbackCounter; diff --git a/firmware/controllers/actuators/idle_thread.cpp b/firmware/controllers/actuators/idle_thread.cpp index 2370ecce30..7dcfcbd857 100644 --- a/firmware/controllers/actuators/idle_thread.cpp +++ b/firmware/controllers/actuators/idle_thread.cpp @@ -34,7 +34,6 @@ #include "idle_hardware.h" #include "periodic_task.h" -#include "vehicle_speed.h" #include "dc_motors.h" #if EFI_TUNER_STUDIO diff --git a/firmware/controllers/algo/dynoview.cpp b/firmware/controllers/algo/dynoview.cpp index 68efc11e16..96690ca5c7 100644 --- a/firmware/controllers/algo/dynoview.cpp +++ b/firmware/controllers/algo/dynoview.cpp @@ -9,9 +9,8 @@ #if EFI_DYNO_VIEW #include "dynoview.h" -#include "vehicle_speed.h" -DynoView dynoInstance; +static DynoView dynoInstance; void DynoView::update(vssSrc src) { diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index e960486c7a..4f5c8fa950 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -106,12 +106,6 @@ public: GearControllerBase *gearController; - - float mockVehicleSpeed = DEFAULT_MOCK_SPEED; // in kilometers per hour - - efitick_t vssLastSignalTimeNt = 0; - efitick_t vssDiff = 0; - efitick_t mostRecentSparkEvent; efitick_t mostRecentTimeBetweenSparkEvents; efitick_t mostRecentIgnitionEvent; diff --git a/firmware/controllers/algo/launch_control.cpp b/firmware/controllers/algo/launch_control.cpp index 6e2b9e6ed2..7c8bc30ec1 100644 --- a/firmware/controllers/algo/launch_control.cpp +++ b/firmware/controllers/algo/launch_control.cpp @@ -9,7 +9,6 @@ #if EFI_LAUNCH_CONTROL #include "boost_control.h" -#include "vehicle_speed.h" #include "launch_control.h" #include "periodic_task.h" #include "advance_map.h" @@ -18,7 +17,7 @@ static bool isInit = false; -LaunchControlBase launchInstance; +static LaunchControlBase launchInstance; static int retardThresholdRpm; diff --git a/firmware/controllers/can/can_dash.cpp b/firmware/controllers/can/can_dash.cpp index c783d6cb4c..4717b0b288 100644 --- a/firmware/controllers/can/can_dash.cpp +++ b/firmware/controllers/can/can_dash.cpp @@ -13,7 +13,6 @@ #include "can_dash.h" #include "can_msg_tx.h" -#include "vehicle_speed.h" #include "rtc_helper.h" #include "fuel_math.h" // CAN Bus ID for broadcast diff --git a/firmware/controllers/can/can_verbose.cpp b/firmware/controllers/can/can_verbose.cpp index ee8810dd71..6825b0d1a0 100644 --- a/firmware/controllers/can/can_verbose.cpp +++ b/firmware/controllers/can/can_verbose.cpp @@ -14,7 +14,6 @@ #include "can.h" #include "fuel_math.h" #include "spark_logic.h" -#include "vehicle_speed.h" struct Status { uint16_t warningCounter; diff --git a/firmware/controllers/can/can_vss.cpp b/firmware/controllers/can/can_vss.cpp index f801fa1344..8b243f1def 100644 --- a/firmware/controllers/can/can_vss.cpp +++ b/firmware/controllers/can/can_vss.cpp @@ -11,7 +11,6 @@ #if EFI_CAN_SUPPORT #include "can.h" -#include "vehicle_speed.h" #include "dynoview.h" static bool isInit = false; diff --git a/firmware/controllers/can/obd2.cpp b/firmware/controllers/can/obd2.cpp index a54b6abcff..62b0408f26 100644 --- a/firmware/controllers/can/obd2.cpp +++ b/firmware/controllers/can/obd2.cpp @@ -28,7 +28,6 @@ #include "obd2.h" #include "can.h" #include "can_msg_tx.h" -#include "vehicle_speed.h" #include "fuel_math.h" static const int16_t supportedPids0120[] = { diff --git a/firmware/controllers/serial/serial_rx.cpp b/firmware/controllers/serial/serial_rx.cpp index 983e6960a9..9abfb79a4a 100644 --- a/firmware/controllers/serial/serial_rx.cpp +++ b/firmware/controllers/serial/serial_rx.cpp @@ -14,8 +14,6 @@ #include "serial_hw.h" #include "serial_sensor.h" -#include "vehicle_speed.h" - uint8_t ser_buffer[SERBUFFLEN] = {}; size_t innovate_msg_len = 1; innovate_serial_id_state_t innovate_serial_id_state = UNKNOWN; diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index a2ac729f04..2f21789027 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -18,7 +18,6 @@ #include "trigger_emulator_algo.h" #if EFI_PROD_CODE -#include "vehicle_speed.h" #include "rtc_helper.h" #include "can_hw.h" #include "rusefi.h" @@ -1051,10 +1050,6 @@ const command_f_s commandsF[] = { {"fsio_curve_1_value", setFsioCurve1Value}, {"fsio_curve_2_value", setFsioCurve2Value}, #if EFI_PROD_CODE -#if EFI_VEHICLE_SPEED - //todo: This function become deprecated soon - {"mock_vehicle_speed", setMockVehicleSpeed}, -#endif /* EFI_VEHICLE_SPEED */ #if EFI_IDLE_CONTROL {"idle_offset", setIdleOffset}, {"idle_p", setIdlePFactor}, diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index f1e739e502..296713302c 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -16,7 +16,6 @@ #include "rtc_helper.h" #include "os_util.h" #include "bench_test.h" -#include "vehicle_speed.h" #include "yaw_rate_sensor.h" #include "pin_repository.h" #include "max31855.h" @@ -399,10 +398,6 @@ void applyNewHardwareSettings(DECLARE_ENGINE_PARAMETER_SIGNATURE) { } #endif -/* #if EFI_VEHICLE_SPEED && ! EFI_UNIT_TEST - startVSSPins(); -#endif EFI_VEHICLE_SPEED */ - #if EFI_BOOST_CONTROL startBoostPin(); #endif @@ -483,10 +478,6 @@ void stopHardware(DECLARE_ENGINE_PARAMETER_SIGNATURE) { stopSmartCsPins(); #endif /* (BOARD_EXT_GPIOCHIPS > 0) */ -/* #if EFI_VEHICLE_SPEED - stopVSSPins(); -#endif EFI_VEHICLE_SPEED */ - #if EFI_LOGIC_ANALYZER stopLogicAnalyzerPins(); #endif /* EFI_LOGIC_ANALYZER */ @@ -605,10 +596,6 @@ void initHardware(DECLARE_ENGINE_PARAMETER_SIGNATURE) { initAuxSerial(); #endif /* EFI_AUX_SERIAL */ -/*#if EFI_VEHICLE_SPEED - initVehicleSpeed(); -#endif // EFI_VEHICLE_SPEED*/ - #if EFI_CAN_SUPPORT initCanVssSupport(); #endif // EFI_CAN_SUPPORT diff --git a/firmware/hw_layer/hw_layer.mk b/firmware/hw_layer/hw_layer.mk index 4ea03ac382..7d66bd1320 100644 --- a/firmware/hw_layer/hw_layer.mk +++ b/firmware/hw_layer/hw_layer.mk @@ -29,7 +29,6 @@ HW_LAYER_EMS_CPP = \ $(PROJECT_DIR)/hw_layer/sensors/hip9011.cpp \ $(PROJECT_DIR)/hw_layer/sensors/hip9011_logic.cpp \ $(PROJECT_DIR)/hw_layer/mc33816.cpp \ - $(PROJECT_DIR)/hw_layer/vehicle_speed.cpp \ $(PROJECT_DIR)/hw_layer/stepper.cpp \ $(PROJECT_DIR)/hw_layer/stepper_dual_hbridge.cpp \ $(PROJECT_DIR)/hw_layer/servo.cpp \ diff --git a/firmware/hw_layer/vehicle_speed.cpp b/firmware/hw_layer/vehicle_speed.cpp deleted file mode 100644 index 32672e4924..0000000000 --- a/firmware/hw_layer/vehicle_speed.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/** - * @file vehicle_speed.cpp - * - * @date Dec 26, 2014 - * @author Andrey Belomutskiy, (c) 2012-2020 - */ - -#include "pch.h" - -#include "vehicle_speed.h" -#include "pch.h" - -#if EFI_VEHICLE_SPEED - -#include "digital_input_icu.h" -#include "digital_input_exti.h" -#include "can_vss.h" - -/** - * @return vehicle speed, in kilometers per hour - */ -float getVehicleSpeed(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - if (engine->mockVehicleSpeed != DEFAULT_MOCK_SPEED) - return engine->mockVehicleSpeed; -#if EFI_CAN_SUPPORT - if (CONFIG(enableCanVss)) { - return getVehicleCanSpeed(); - } -#endif /* EFI_CAN_SUPPORT */ - if (!hasVehicleSpeedSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) - return 0; - efitick_t nowNt = getTimeNowNt(); - if (nowNt - engine->vssLastSignalTimeNt > NT_PER_SECOND) - return 0; // previous signal time is too long ago - we are stopped - - return engineConfiguration->vehicleSpeedCoef * NT_PER_SECOND / engine->vssDiff; -} - -// todo: make this method public and invoke this method from test -void vsCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - engine->engineState.vssEventCounter++; - efitick_t nowNt = getTimeNowNt(); - engine->vssDiff = nowNt - engine->vssLastSignalTimeNt; - engine->vssLastSignalTimeNt = nowNt; -} - -#if ! EFI_UNIT_TEST - -static void vsAnaWidthCallback() { - vsCallback(PASS_ENGINE_PARAMETER_SIGNATURE); -} - -static void speedInfo(void) { - efiPrintf("VSS input at %s", - hwPortname(CONFIG(vehicleSpeedSensorInputPin))); - - efiPrintf("c=%.2f eventCounter=%d speed=%.2f", - engineConfiguration->vehicleSpeedCoef, - engine->engineState.vssEventCounter, - getVehicleSpeed(PASS_ENGINE_PARAMETER_SIGNATURE)); - efiPrintf("vss diff %d", engine->vssDiff); -} -#endif // EFI_UNIT_TEST - -bool hasVehicleSpeedSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - return (isBrainPinValid(CONFIG(vehicleSpeedSensorInputPin))); -} - -#if HAL_VSS_USE_PAL -static void vsExtiCallback(void *) { - vsAnaWidthCallback(); -} -#endif /* HAL_VSS_USE_PAL */ - -void stopVSSPins(void) { -#if HAL_VSS_USE_PAL - efiExtiDisablePin(activeConfiguration.vehicleSpeedSensorInputPin); -#elif HAL_USE_ICU - stopDigitalCapture("VSS", activeConfiguration.vehicleSpeedSensorInputPin); -#endif /* HAL_VSS_USE_PAL, HAL_USE_ICU */ -} - -#if ! EFI_UNIT_TEST - -void startVSSPins(void) { - if (!hasVehicleSpeedSensor()) { - return; - } - -// todo: refactor https://github.com/rusefi/rusefi/issues/2123 -#if HAL_VSS_USE_PAL - efiExtiEnablePin("VSS", CONFIG(vehicleSpeedSensorInputPin), PAL_EVENT_MODE_BOTH_EDGES, vsExtiCallback, nullptr); -#elif HAL_USE_ICU - digital_input_s* vehicleSpeedInput = startDigitalCapture("VSS", CONFIG(vehicleSpeedSensorInputPin)); - - if (vehicleSpeedInput) { - vehicleSpeedInput->widthListeners.registerCallback((VoidInt) vsAnaWidthCallback, nullptr); - } -#else - #error "HAL_USE_ICU or HAL_VSS_USE_PAL should be enabled to use EFI_VEHICLE_SPEED" -#endif /* HAL_VSS_USE_PAL, HAL_USE_ICU */ -} -#endif - -void initVehicleSpeed() { -#if ! EFI_UNIT_TEST - addConsoleAction("speedinfo", speedInfo); - startVSSPins(); -#endif // EFI_UNIT_TEST -} -#else /* EFI_VEHICLE_SPEED */ - -#if EFI_UNIT_TEST - -float getVehicleSpeed(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - - // Mock return to be used in unit tests - return mockVehicleSpeed; -} -#else -float getVehicleSpeed(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - - // no VSS support - return 0; -} -#endif /* EFI_UNIT_TEST */ -#endif /* EFI_VEHICLE_SPEED */ - - - - -void setMockVehicleSpeed(float speedKPH DECLARE_ENGINE_PARAMETER_SUFFIX) { - engine->mockVehicleSpeed = speedKPH; -} - diff --git a/firmware/hw_layer/vehicle_speed.h b/firmware/hw_layer/vehicle_speed.h deleted file mode 100644 index c5b93fa4d3..0000000000 --- a/firmware/hw_layer/vehicle_speed.h +++ /dev/null @@ -1,20 +0,0 @@ -/** - * @file vehicle_speed.h - * - *@date Dec 26, 2014 - * @author Andrey Belomutskiy, (c) 2012-2020 - */ - -#pragma once - -#include "global.h" - -/** - * @return vehicle speed, in kilometers per hour - */ -float getVehicleSpeed(DECLARE_ENGINE_PARAMETER_SIGNATURE); -void initVehicleSpeed(); -void setMockVehicleSpeed(float speedKPH DECLARE_ENGINE_PARAMETER_SUFFIX); -bool hasVehicleSpeedSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE); -void stopVSSPins(void); -void startVSSPins(void); diff --git a/firmware/init/sensor/init_vehicle_speed_sensor.cpp b/firmware/init/sensor/init_vehicle_speed_sensor.cpp index 849b440452..309a7f9319 100644 --- a/firmware/init/sensor/init_vehicle_speed_sensor.cpp +++ b/firmware/init/sensor/init_vehicle_speed_sensor.cpp @@ -1,7 +1,6 @@ #include "pch.h" #include "init.h" -#include "vehicle_speed.h" #include "frequency_sensor.h" #include "vehicle_speed_converter.h" diff --git a/unit_tests/tests/test_dynoview.cpp b/unit_tests/tests/test_dynoview.cpp index 30b23ad679..9fe914775f 100644 --- a/unit_tests/tests/test_dynoview.cpp +++ b/unit_tests/tests/test_dynoview.cpp @@ -1,7 +1,6 @@ #include "pch.h" #include "dynoview.h" -#include "vehicle_speed.h" void printResults(DynoView *dut) { #ifdef DBG_TESTS diff --git a/unit_tests/tests/test_launch.cpp b/unit_tests/tests/test_launch.cpp index 779676d238..284f6da7c9 100644 --- a/unit_tests/tests/test_launch.cpp +++ b/unit_tests/tests/test_launch.cpp @@ -1,7 +1,6 @@ #include "pch.h" #include "launch_control.h" -#include "vehicle_speed.h" TEST(LaunchControl, TpsCondition) { WITH_ENGINE_TEST_HELPER(TEST_ENGINE); diff --git a/unit_tests/tests/test_vehicle_speed.cpp b/unit_tests/tests/test_vehicle_speed.cpp deleted file mode 100644 index abf6c92c0e..0000000000 --- a/unit_tests/tests/test_vehicle_speed.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "pch.h" - -#include "vehicle_speed.h" - -extern void vsCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE); -typedef void(*vss_callback_fp)(DECLARE_ENGINE_PARAMETER_SIGNATURE) ; - -static constexpr brain_pin_e anyPin = GPIOA_0; -static constexpr const char* const vehicleSpeedSensorMessage = "VSS"; - -/* - * Used to convert expected speed into simulation frequency - */ -static float speedToSimulationFrequency(float speedCoef, float speed) { - return speed/speedCoef; -} - -/* - * Use engine test helper as time source, - * to simulate periodic signal on input pin with passed callback. - */ -static void simulatePeriodicSignalForCallback( - EngineTestHelper& eth, - float freqHz, - vss_callback_fp cb - DECLARE_ENGINE_PARAMETER_SUFFIX) -{ - constexpr auto periods = 50; - auto period = (1 / freqHz); - - for (auto i = 0; i < periods; i++) { - cb(PASS_ENGINE_PARAMETER_SIGNATURE); - // Time rewind after the callback, due internal vehicle_speed.cpp logic - // (last signal time check for stop tracking) - eth.moveTimeForwardSec(period); - } - -} - -TEST(VehicleSpeedSensor, testValidSpeedDetection) { - WITH_ENGINE_TEST_HELPER(TEST_ENGINE); - CONFIG(vehicleSpeedSensorInputPin) = anyPin; - engineConfiguration->vehicleSpeedCoef = 0.5f; - - // Valid speed 15kmh should be returned - float freq = speedToSimulationFrequency(engineConfiguration->vehicleSpeedCoef, 15.0f); - simulatePeriodicSignalForCallback(eth, freq, vsCallback PASS_ENGINE_PARAMETER_SUFFIX); - float measuredSpeed = getVehicleSpeed(PASS_ENGINE_PARAMETER_SIGNATURE); - EXPECT_NEAR(15.0f, measuredSpeed, 0.01); - -} - -TEST(VehicleSpeedSensor, testInvalidSpeed) { - - WITH_ENGINE_TEST_HELPER(TEST_ENGINE); - CONFIG(vehicleSpeedSensorInputPin) = anyPin; - engineConfiguration->vehicleSpeedCoef = 0.5f; - - // Invalid (slow) interval, should return 0 speed - simulatePeriodicSignalForCallback(eth, 0.5f, vsCallback PASS_ENGINE_PARAMETER_SUFFIX); - float measuredSpeed = getVehicleSpeed(PASS_ENGINE_PARAMETER_SIGNATURE); - - // Direct comparasion as invalid speed shoud return true zero - EXPECT_EQ(0.0f, measuredSpeed); - -} - diff --git a/unit_tests/tests/tests.mk b/unit_tests/tests/tests.mk index 585eb1a599..d5451e1824 100644 --- a/unit_tests/tests/tests.mk +++ b/unit_tests/tests/tests.mk @@ -86,7 +86,6 @@ TESTS_SRC_CPP = \ tests/trigger/test_all_triggers.cpp \ tests/test_stepper.cpp \ tests/sensor/test_frequency_sensor.cpp \ - tests/sensor/test_vehicle_speed.cpp \ tests/sensor/test_vehicle_speed_converter.cpp