From 848a6963d25b1cd0ffd6ebbed4c218582ab8fe31 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sun, 28 Dec 2014 11:03:29 -0600 Subject: [PATCH] auto-sync --- firmware/config/engines/dodge_neon.cpp | 4 ++ firmware/console/status_loop.cpp | 35 ++++++++------ .../controllers/algo/engine_configuration.h | 2 + firmware/hw_layer/can_hw.cpp | 4 +- firmware/hw_layer/hardware.cpp | 3 ++ firmware/hw_layer/vehicle_speed.cpp | 48 ++++++++++++++++++- firmware/hw_layer/vehicle_speed.h | 3 +- firmware/rusefi.cpp | 2 +- firmware/tunerstudio/rusefi.ini | 3 ++ .../models/src/com/irnems/core/Sensor.java | 1 + .../src/com/irnems/core/SensorCentral.java | 1 + java_console/ui/src/com/irnems/Launcher.java | 2 +- 12 files changed, 87 insertions(+), 21 deletions(-) diff --git a/firmware/config/engines/dodge_neon.cpp b/firmware/config/engines/dodge_neon.cpp index 70d8b70369..d58b1615cb 100644 --- a/firmware/config/engines/dodge_neon.cpp +++ b/firmware/config/engines/dodge_neon.cpp @@ -360,6 +360,10 @@ void setDodgeNeonNGCEngineConfiguration(engine_configuration_s *engineConfigurat engineConfiguration->bc.fsio_setting[0] = 0.2; setFsioExt(engineConfiguration, 0, GPIOE_5, "0 fsio_setting", 400); + boardConfiguration->logicAnalyzerPins[0] = GPIO_UNASSIGNED; + engineConfiguration->vehicleSpeedSensorInputPin = GPIOA_8; + engineConfiguration->hasVehicleSpeedSensor = true; + // engineConfiguration->isCanEnabled = true; boardConfiguration->canTxPin = GPIOB_6; boardConfiguration->canRxPin = GPIOB_12; diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 218a413116..da1161daba 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -29,7 +29,7 @@ #include "ec2.h" #include "adc_inputs.h" -#if EFI_WAVE_ANALYZER +#if EFI_WAVE_ANALYZER || defined(__DOXYGEN__) #include "wave_analyzer.h" #endif @@ -54,7 +54,7 @@ #include "engine.h" #include "lcd_controller.h" -#if EFI_PROD_CODE +#if EFI_PROD_CODE || defined(__DOXYGEN__) // todo: move this logic to algo folder! #include "rtc_helper.h" #include "lcd_HD44780.h" @@ -62,6 +62,7 @@ #include "pin_repository.h" #include "flash_main.h" #include "max31855.h" +#include "vehicle_speed.h" #endif // this 'true' value is needed for simulator @@ -73,7 +74,7 @@ extern board_configuration_s *boardConfiguration; extern bool hasFirmwareErrorFlag; #define FULL_LOGGING_KEY "fl" -#if EFI_PROD_CODE || EFI_SIMULATOR +#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__) static Logging logger; static void setWarningEnabled(int value) { @@ -82,25 +83,25 @@ static void setWarningEnabled(int value) { #endif /* EFI_PROD_CODE || EFI_SIMULATOR */ -#if EFI_FILE_LOGGING +#if EFI_FILE_LOGGING || defined(__DOXYGEN__) static Logging fileLogger; #endif /* EFI_FILE_LOGGING */ static void reportSensorF(const char *caption, float value, int precision) { -#if EFI_PROD_CODE || EFI_SIMULATOR +#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__) debugFloat(&logger, caption, value, precision); #endif /* EFI_PROD_CODE || EFI_SIMULATOR */ -#if EFI_FILE_LOGGING +#if EFI_FILE_LOGGING || defined(__DOXYGEN__) debugFloat(&fileLogger, caption, value, precision); #endif /* EFI_FILE_LOGGING */ } static void reportSensorI(const char *caption, int value) { -#if EFI_PROD_CODE || EFI_SIMULATOR +#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__) debugInt(&logger, caption, value); #endif /* EFI_PROD_CODE || EFI_SIMULATOR */ -#if EFI_FILE_LOGGING +#if EFI_FILE_LOGGING || defined(__DOXYGEN__) debugInt(&fileLogger, caption, value); #endif /* EFI_FILE_LOGGING */ } @@ -110,7 +111,7 @@ static const char* boolean2string(int value) { } void printSensors(Engine *engine) { -#if EFI_FILE_LOGGING +#if EFI_FILE_LOGGING || defined(__DOXYGEN__) resetLogging(&fileLogger); #endif /* EFI_FILE_LOGGING */ @@ -134,7 +135,11 @@ void printSensors(Engine *engine) { if (engineConfiguration->hasAfrSensor) { reportSensorF("afr", getAfr(), 2); } - +#if EFI_PROD_CODE || defined(__DOXYGEN__) + if (engineConfiguration->hasVehicleSpeedSensor) { + reportSensorF("vss", getVehicleSpeed(), 2); + } +#endif /* EFI_PROD_CODE */ reportSensorF("vref", getVRef(engineConfiguration), 2); reportSensorF("vbatt", getVBatt(engineConfiguration), 2); @@ -151,7 +156,7 @@ void printSensors(Engine *engine) { // debugFloat(&logger, "tch", getTCharge1(tps), 2); -#if EFI_FILE_LOGGING +#if EFI_FILE_LOGGING || defined(__DOXYGEN__) appendPrintf(&fileLogger, "\r\n"); appendToLog(fileLogger.buffer); #endif /* EFI_FILE_LOGGING */ @@ -205,7 +210,7 @@ static void printStatus(void) { */ static systime_t timeOfPreviousPrintVersion = (systime_t) -1; -#if EFI_PROD_CODE +#if EFI_PROD_CODE || defined(__DOXYGEN__) static void printOutPin(const char *pinName, brain_pin_e hwPin) { appendPrintf(&logger, "outpin%s%s@%s%s", DELIMETER, pinName, hwPortname(hwPin), DELIMETER); } @@ -225,7 +230,7 @@ static void printInfo(Engine *engine, systime_t nowSeconds) { appendPrintf(&logger, "rusEfiVersion%s%d@%s %s%s", DELIMETER, getRusEfiVersion(), VCS_VERSION, getConfigurationName(engineConfiguration->engineType), DELIMETER); -#if EFI_PROD_CODE +#if EFI_PROD_CODE || defined(__DOXYGEN__) printOutPin(WC_CRANK1, boardConfiguration->triggerInputPins[0]); printOutPin(WC_CRANK2, boardConfiguration->triggerInputPins[1]); #if EFI_WAVE_ANALYZER || defined(__DOXYGEN__) @@ -261,7 +266,7 @@ void updateDevConsoleState(Engine *engine) { // checkIfShouldHalt(); printPending(); -#if EFI_PROD_CODE +#if EFI_PROD_CODE || defined(__DOXYGEN__) // todo: unify with simulator! if (hasFirmwareError()) { printMsg(&logger, "firmware error: %s", errorMessageBuffer); @@ -476,7 +481,7 @@ void updateTunerStudioState(Engine *engine, TunerStudioOutputChannels *tsOutputC tsOutputChannels->cylinder_cleanup_enabled = engineConfiguration->isCylinderCleanupEnabled; tsOutputChannels->cylinder_cleanup_activated = engine->isCylinderCleanupMode; tsOutputChannels->secondTriggerChannelEnabled = engineConfiguration->secondTriggerChannelEnabled; - + tsOutputChannels->vehicleSpeedKph = getVehicleSpeed(); tsOutputChannels->isCltError = !isValidCoolantTemperature(getCoolantTemperature(engine)); tsOutputChannels->isIatError = !isValidIntakeAirTemperature(getIntakeAirTemperature(engine)); #endif diff --git a/firmware/controllers/algo/engine_configuration.h b/firmware/controllers/algo/engine_configuration.h index c1da74981d..062215420a 100644 --- a/firmware/controllers/algo/engine_configuration.h +++ b/firmware/controllers/algo/engine_configuration.h @@ -407,6 +407,7 @@ typedef struct { */ float fanOffTemperature; + // offset 960 brain_pin_e vehicleSpeedSensorInputPin; /** @@ -504,6 +505,7 @@ typedef struct { bool_t hasCltSensor : 1; // bit 6 bool_t canReadEnabled : 1; // bit 7 bool_t canWriteEnabled : 1; // bit 8 + bool_t hasVehicleSpeedSensor : 1; // bit 9 int unused6284; diff --git a/firmware/hw_layer/can_hw.cpp b/firmware/hw_layer/can_hw.cpp index 39210035f9..4c6411cf1f 100644 --- a/firmware/hw_layer/can_hw.cpp +++ b/firmware/hw_layer/can_hw.cpp @@ -16,6 +16,7 @@ #include "engine_state.h" #include "can_header.h" #include "engine_configuration.h" +#include "vehicle_speed.h" #if EFI_CAN_SUPPORT || defined(__DOXYGEN__) @@ -122,8 +123,7 @@ static void canMazdaRX8(void) { commonTxInit(CAN_MAZDA_RX_RPM_SPEED); - float mph = 123; - float kph = mph * 1.60934; + float kph = getVehicleSpeed(); setShortValue(&txmsg, SWAP_UINT16(engine_rpm * 4), 0); setShortValue(&txmsg, 0xFFFF, 2); diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 8cee70ff27..44a20d8f0a 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -16,6 +16,7 @@ #include "adc_inputs.h" #include "stepper.h" +#include "vehicle_speed.h" #include "trigger_input.h" #include "eficonsole.h" @@ -331,6 +332,8 @@ void initHardware(Logging *logger, Engine *engine) { // } // } + initVehicleSpeed(logger); + printMsg(logger, "initHardware() OK!"); } diff --git a/firmware/hw_layer/vehicle_speed.cpp b/firmware/hw_layer/vehicle_speed.cpp index 0271956743..63c52b1b2d 100644 --- a/firmware/hw_layer/vehicle_speed.cpp +++ b/firmware/hw_layer/vehicle_speed.cpp @@ -6,8 +6,54 @@ */ #include "vehicle_speed.h" +#include "engine.h" +#include "wave_analyzer_hw.h" +#include "pin_repository.h" -void initVehicleSpeed(void) { +EXTERN_ENGINE +; +static Logging *logger; + +static WaveReaderHw vehicleSpeedInput; + +static uint64_t lastSignalTimeNt = 0; +static uint64_t vssDiff = 0; +static int vssCounter = 0; + +/** + * @return vehicle speed, in kilometers per hour + */ +float getVehicleSpeed(void) { + uint64_t nowNt = getTimeNowNt(); + if (nowNt - lastSignalTimeNt > US2NT(US_PER_SECOND_LL)) + return 0; // previous signal time is too long ago - we are stopped + + return engineConfiguration->vehicleSpeedCoef * US_PER_SECOND_LL / vssDiff; } +static void vsAnaWidthCallback(void) { + vssCounter++; + uint64_t nowNt = getTimeNowNt(); + vssDiff = nowNt - lastSignalTimeNt; + lastSignalTimeNt = nowNt; +} + +static void speedInfo(void) { + scheduleMsg(logger, "VSS@%s c=%f eventCounter=%d speed=%f", + hwPortname(engineConfiguration->vehicleSpeedSensorInputPin), + engineConfiguration->vehicleSpeedCoef, + vssCounter, + getVehicleSpeed()); +} + +void initVehicleSpeed(Logging *l) { + logger = l; + if (engineConfiguration->vehicleSpeedSensorInputPin == GPIO_UNASSIGNED) + return; + initWaveAnalyzerDriver(&vehicleSpeedInput, engineConfiguration->vehicleSpeedSensorInputPin); + startInputDriver(&vehicleSpeedInput, true); + + registerCallback(&vehicleSpeedInput.widthListeners, (IntListener) vsAnaWidthCallback, NULL); + addConsoleAction("speedinfo", speedInfo); +} diff --git a/firmware/hw_layer/vehicle_speed.h b/firmware/hw_layer/vehicle_speed.h index 5a7fa4e7cf..2e85e01a60 100644 --- a/firmware/hw_layer/vehicle_speed.h +++ b/firmware/hw_layer/vehicle_speed.h @@ -10,6 +10,7 @@ #include "main.h" -void initVehicleSpeed(void); +float getVehicleSpeed(void); +void initVehicleSpeed(Logging *logger); #endif /* HW_LAYER_VEHICLE_SPEED_H_ */ diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 3a9f414b4c..aaefe3ac79 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -265,5 +265,5 @@ int getRusEfiVersion(void) { return 1; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE == 0) return 1; // this is here to make the compiler happy about the unused array - return 20141227; + return 20141228; } diff --git a/firmware/tunerstudio/rusefi.ini b/firmware/tunerstudio/rusefi.ini index 3bf166cbbf..2d2536330d 100644 --- a/firmware/tunerstudio/rusefi.ini +++ b/firmware/tunerstudio/rusefi.ini @@ -452,6 +452,7 @@ fileVersion = { 20141225 } ind_check_engine= bits, U32, 72, [8:8], "true", "false"; ind_need_burn = bits, U32, 72, [9:9], "true", "false"; ind_2nd_trigger_en=bits, U32, 72, [10:10], "true", "false"; + vehicleSpeedKph = scalar, F32, 76, "kph", 1, 0.0; ind_tps_error = bits, U32, 80, [0:0], "true", "false"; ind_clt_error = bits, U32, 80, [1:1], "true", "false"; @@ -594,6 +595,7 @@ fileVersion = { 20141225 } ; accelEnrichGauge = accDecEnrich, "Accel Enrich", "%", 50, 150, -1, -1, 999, 999, 0, 0 dwellGauge = sparkDwell, "Dwell", "mSec", 0, 10, 0.5, 1.0, 6.0, 8.0, 1, 1 egt0Gauge = egt0, "EGT#0", "C", 0, 2000 + vssGauge = vehicleSpeedKph, "Speed", "kmh", 0, 200, 0, 1, 3, 4, 1, 1 [FrontPage] ; Gauges are numbered left to right, top to bottom. @@ -650,6 +652,7 @@ fileVersion = { 20141225 } entry = pulseWidth, "injPulse", float, "%.3f" entry = baseFuel, "baseFuel", float, "%.2f" entry = ign_adv, "ignAdv", float, "%.2f" + entry = vehicleSpeedKph, "speed", float, "%.2f" ; tpsADC = U16, "ADC", ; alignmet = U16, "al", diff --git a/java_console/models/src/com/irnems/core/Sensor.java b/java_console/models/src/com/irnems/core/Sensor.java index 61661d37b6..1844401d58 100644 --- a/java_console/models/src/com/irnems/core/Sensor.java +++ b/java_console/models/src/com/irnems/core/Sensor.java @@ -23,6 +23,7 @@ public enum Sensor { AFR("A/F ratio", SensorCategory.SENSOR_INPUTS, "", 0, 20), MAF("MAF", SensorCategory.SENSOR_INPUTS, "Volts", 4), TPS("throttle", SensorCategory.SENSOR_INPUTS, "%", 100), + VSS("Speed", SensorCategory.SENSOR_INPUTS, "kph", 100), TRG_0_DUTY("trg0 duty", SensorCategory.SENSOR_INPUTS, "%", 100), TRG_1_DUTY("trg1 duty", SensorCategory.SENSOR_INPUTS, "%", 100), diff --git a/java_console/models/src/com/irnems/core/SensorCentral.java b/java_console/models/src/com/irnems/core/SensorCentral.java index d998f46325..79ed0a50e2 100644 --- a/java_console/models/src/com/irnems/core/SensorCentral.java +++ b/java_console/models/src/com/irnems/core/SensorCentral.java @@ -90,6 +90,7 @@ public class SensorCentral { addDoubleSensor("clt", Sensor.CLT, es); addDoubleSensor("tp", Sensor.TPS, es); + addDoubleSensor(Sensor.VSS, es); addDoubleSensor(Sensor.DWELL0, es); addDoubleSensor(Sensor.DWELL1, es); addDoubleSensor(Sensor.DWELL2, es); diff --git a/java_console/ui/src/com/irnems/Launcher.java b/java_console/ui/src/com/irnems/Launcher.java index b6a6beb074..d6964e6cd3 100644 --- a/java_console/ui/src/com/irnems/Launcher.java +++ b/java_console/ui/src/com/irnems/Launcher.java @@ -19,7 +19,7 @@ import javax.swing.*; * @see WavePanel */ public class Launcher extends FrameHelper { - public static final int CONSOLE_VERSION = 20141213; + public static final int CONSOLE_VERSION = 20141228; public static final boolean SHOW_STIMULATOR = true; private final String port;