From 6bcd29c727c4dbd9ada9f83c98fb9da27ad1869e Mon Sep 17 00:00:00 2001 From: rusefillc Date: Sat, 10 Sep 2022 23:33:37 -0400 Subject: [PATCH] send more of Engine Sniffer data #4560 new API & first usage --- firmware/controllers/algo/rusefi_enums.h | 5 ++ firmware/controllers/system/efi_gpio.cpp | 6 +++ firmware/development/engine_sniffer.cpp | 26 +++++++++++ firmware/development/engine_sniffer.h | 16 +++++-- firmware/development/logic_analyzer.cpp | 59 ++++++++++++++++++------ firmware/development/logic_analyzer.h | 36 --------------- 6 files changed, 95 insertions(+), 53 deletions(-) diff --git a/firmware/controllers/algo/rusefi_enums.h b/firmware/controllers/algo/rusefi_enums.h index f1e5cde05c..8a9a164f39 100644 --- a/firmware/controllers/algo/rusefi_enums.h +++ b/firmware/controllers/algo/rusefi_enums.h @@ -36,6 +36,8 @@ typedef enum __attribute__ ((__packed__)) PIN_INVALID = 0x80 } brain_pin_diag_e; +// this header is part of firmware public API it gets consumed by code generator +// and values are available to java todo: pull this adc_channel_mode_e enum into a not-public-api header typedef enum __attribute__ ((__packed__)) { ADC_OFF = 0, ADC_SLOW = 1, @@ -43,6 +45,8 @@ typedef enum __attribute__ ((__packed__)) { } adc_channel_mode_e; +// this header is part of firmware public API it gets consumed by code generator +// and values are available to java todo: pull this trigger_value_e enum into a not-public-api header typedef enum { TV_FALL = 0, TV_RISE = 1 @@ -531,6 +535,7 @@ typedef enum __attribute__ ((__packed__)) { } idle_state_e; +// todo: should this be just a boolean? typedef enum __attribute__ ((__packed__)) { OPEN_LOOP = 0, CLOSED_LOOP = 1, diff --git a/firmware/controllers/system/efi_gpio.cpp b/firmware/controllers/system/efi_gpio.cpp index 3a761b899d..76c53e4429 100644 --- a/firmware/controllers/system/efi_gpio.cpp +++ b/firmware/controllers/system/efi_gpio.cpp @@ -44,6 +44,12 @@ const char *vvtNames[] = { PROTOCOL_VVT3_NAME, PROTOCOL_VVT4_NAME}; +const char *laNames[] = { + PROTOCOL_WA_CHANNEL_1, + PROTOCOL_WA_CHANNEL_2, + PROTOCOL_WA_CHANNEL_3, + PROTOCOL_WA_CHANNEL_4}; + // these short names are part of engine sniffer protocol static const char* const sparkShortNames[] = { PROTOCOL_COIL1_SHORT_NAME, "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "cA", "cB", "cD"}; diff --git a/firmware/development/engine_sniffer.cpp b/firmware/development/engine_sniffer.cpp index d822128381..4a7a7cf866 100644 --- a/firmware/development/engine_sniffer.cpp +++ b/firmware/development/engine_sniffer.cpp @@ -152,6 +152,31 @@ void addEngineSnifferTdcEvent(int rpm) { addEngineSnifferEvent(TOP_DEAD_CENTER_MESSAGE, (char* ) rpmBuffer); } +void addEngineSnifferLogicAnalyzerEvent(int laIndex, FrontDirection frontDirection) { + extern const char *laNames[]; + const char *name = laNames[laIndex]; + + addEngineSnifferEvent(name, frontDirection == FrontDirection::UP ? PROTOCOL_ES_UP : PROTOCOL_ES_DOWN); +} + +static char shaft_signal_msg_index[15]; +void addEngineSnifferCrankEvent(int wheelIndex, int triggerEventIndex, FrontDirection frontDirection) { + static const char *crankName[2] = { PROTOCOL_CRANK1, PROTOCOL_CRANK2 }; + + shaft_signal_msg_index[0] = frontDirection == FrontDirection::UP ? 'u' : 'd'; + // shaft_signal_msg_index[1] is assigned once and forever in the init method below + itoa10(&shaft_signal_msg_index[2], triggerEventIndex); + + addEngineSnifferEvent(crankName[wheelIndex], (char* ) shaft_signal_msg_index); +} + +void addEngineSnifferVvtEvent(int vvtIndex, FrontDirection frontDirection) { + extern const char *vvtNames[]; + const char *vvtName = vvtNames[vvtIndex]; + + addEngineSnifferEvent(vvtName, frontDirection == FrontDirection::UP ? PROTOCOL_ES_UP : PROTOCOL_ES_DOWN); +} + /** * @brief Register an event for digital sniffer */ @@ -228,6 +253,7 @@ void WaveChart::addEvent3(const char *name, const char * msg) { } void initWaveChart(WaveChart *chart) { + strcpy((char*) shaft_signal_msg_index, "x_"); /** * constructor does not work because we need specific initialization order */ diff --git a/firmware/development/engine_sniffer.h b/firmware/development/engine_sniffer.h index 430b4f1f33..ac99b74a24 100644 --- a/firmware/development/engine_sniffer.h +++ b/firmware/development/engine_sniffer.h @@ -8,14 +8,24 @@ #pragma once -#include "global.h" +#include "rusefi_enums.h" #if EFI_ENGINE_SNIFFER #include "datalogging.h" +enum class FrontDirection : uint8_t { + UP, + DOWN +}; + void addEngineSnifferTdcEvent(int rpm); -void addEngineSnifferCrankEvent(int signalType, int index, int isUp); -void addEngineSnifferVvtEvent(int vvtType, int isUp); +void addEngineSnifferLogicAnalyzerEvent(int laIndex, FrontDirection frontDirection); +/** + * @param wheelIndex 0 or 1 + * @triggerEventIndex index from sync point, from 0 to number of teeth in engine cycle + */ +void addEngineSnifferCrankEvent(int wheelIndex, int triggerEventIndex, FrontDirection frontDirection); +void addEngineSnifferVvtEvent(int vvtIndex, FrontDirection frontDirection); void addEngineSnifferOutputPinEvent(int outputPinType, int isUp); /** diff --git a/firmware/development/logic_analyzer.cpp b/firmware/development/logic_analyzer.cpp index d0872eada0..05124ab362 100644 --- a/firmware/development/logic_analyzer.cpp +++ b/firmware/development/logic_analyzer.cpp @@ -25,24 +25,56 @@ #define CHART_RESET_DELAY 1 -#if EFI_ENGINE_SNIFFER -extern WaveChart waveChart; -#endif /* EFI_ENGINE_SNIFFER */ - /** * Difference between current 1st trigger event and previous 1st trigger event. */ static volatile uint32_t engineCycleDurationUs; static volatile efitimeus_t previousEngineCycleTimeUs = 0; -static WaveReader readers[4]; +class WaveReader { +public: + void onFallEvent(); + + ioline_t line = 0; + + int laIndex; + volatile int fallEventCounter = 0; + volatile int riseEventCounter = 0; + + int currentRevolutionCounter = 0; + + /** + * Total ON time during last engine cycle + */ + efitimeus_t prevTotalOnTimeUs = 0; + + efitimeus_t totalOnTimeAccumulatorUs = 0; + + volatile efitimeus_t lastActivityTimeUs = 0; // timestamp in microseconds ticks + /** + * time of signal fall event, in microseconds + */ + volatile efitimeus_t periodEventTimeUs = 0; + volatile efitimeus_t widthEventTimeUs = 0; // time of signal rise in microseconds + + volatile efitimeus_t signalPeriodUs = 0; // period between two signal rises in microseconds + + /** + * offset from engine cycle start in microseconds + */ + volatile efitimeus_t waveOffsetUs = 0; + volatile efitimeus_t last_wave_low_widthUs = 0; // time period in systimer ticks + volatile efitimeus_t last_wave_high_widthUs = 0; // time period in systimer ticks +}; + +static WaveReader readers[LOGIC_ANALYZER_CHANNEL_COUNT]; static void riseCallback(WaveReader *reader) { efitick_t nowUs = getTimeNowUs(); reader->riseEventCounter++; reader->lastActivityTimeUs = nowUs; assertIsrContext(CUSTOM_ERR_6670); - addEngineSnifferEvent(reader->name, PROTOCOL_ES_UP); + addEngineSnifferLogicAnalyzerEvent(reader->laIndex, FrontDirection::UP); uint32_t width = nowUs - reader->periodEventTimeUs; reader->last_wave_low_widthUs = width; @@ -56,7 +88,7 @@ void WaveReader::onFallEvent() { fallEventCounter++; lastActivityTimeUs = nowUs; assertIsrContext(CUSTOM_ERR_6670); - addEngineSnifferEvent(name, PROTOCOL_ES_DOWN); + addEngineSnifferLogicAnalyzerEvent(laIndex, FrontDirection::DOWN); efitick_t width = nowUs - widthEventTimeUs; last_wave_high_widthUs = width; @@ -87,14 +119,14 @@ void logicAnalyzerCallback(void* arg, efitick_t stamp) { bool rise = palReadLine(instance->line) == PAL_HIGH; - if(rise) { + if (rise) { riseCallback(instance); } else { instance->onFallEvent(); } } -static void initWave(const char *name, int index) { +static void initWave(int index) { brain_pin_e brainPin = engineConfiguration->logicAnalyzerPins[index]; efiAssertVoid(CUSTOM_ERR_6655, index < efi::size(readers), "too many ICUs"); @@ -109,7 +141,7 @@ static void initWave(const char *name, int index) { return; } - reader->name = name; + reader->laIndex = index; reader->line = PAL_LINE(getHwPort("logic", brainPin), getHwPin("logic", brainPin)); @@ -210,10 +242,9 @@ void initWaveAnalyzer() { } void startLogicAnalyzerPins() { - initWave(PROTOCOL_WA_CHANNEL_1, 0); - initWave(PROTOCOL_WA_CHANNEL_2, 1); - initWave(PROTOCOL_WA_CHANNEL_3, 2); - initWave(PROTOCOL_WA_CHANNEL_4, 3); + for (int index = 0; index < LOGIC_ANALYZER_CHANNEL_COUNT; index++) { + initWave(index); + } } void stopLogicAnalyzerPins() { diff --git a/firmware/development/logic_analyzer.h b/firmware/development/logic_analyzer.h index ac251c5690..42fc86446c 100644 --- a/firmware/development/logic_analyzer.h +++ b/firmware/development/logic_analyzer.h @@ -13,42 +13,6 @@ #include "engine_sniffer.h" -class WaveReader { -public: - void onFallEvent(); - - ioline_t line = 0; - - const char *name = nullptr; - volatile int fallEventCounter = 0; - volatile int riseEventCounter = 0; - - int currentRevolutionCounter = 0; - - /** - * Total ON time during last engine cycle - */ - efitimeus_t prevTotalOnTimeUs = 0; - - efitimeus_t totalOnTimeAccumulatorUs = 0; - - volatile efitimeus_t lastActivityTimeUs = 0; // timestamp in microseconds ticks - /** - * time of signal fall event, in microseconds - */ - volatile efitimeus_t periodEventTimeUs = 0; - volatile efitimeus_t widthEventTimeUs = 0; // time of signal rise in microseconds - - volatile efitimeus_t signalPeriodUs = 0; // period between two signal rises in microseconds - - /** - * offset from engine cycle start in microseconds - */ - volatile efitimeus_t waveOffsetUs = 0; - volatile efitimeus_t last_wave_low_widthUs = 0; // time period in systimer ticks - volatile efitimeus_t last_wave_high_widthUs = 0; // time period in systimer ticks -}; - void initWaveAnalyzer(); void startLogicAnalyzerPins(); void stopLogicAnalyzerPins();