From 92247c58dbf6b4357ef4504b752be0083cff8ddd Mon Sep 17 00:00:00 2001 From: shadowm60 Date: Tue, 15 Dec 2020 21:52:48 +0200 Subject: [PATCH] Logic analyzer ts report (#2080) * Logic analyzer progress of integration with debug channels * Update logic_analyzer.cpp fixed duty report in % * Update logic_analyzer.cpp * Update logic_analyzer.cpp fix for setting one channel to unused, and use the same pin for another channel. this way we clear out hw pointer and we do not have the risk of reporting wrong values. --- firmware/console/status_loop.cpp | 5 +++ firmware/development/logic_analyzer.cpp | 52 +++++++++++++++++++++++-- firmware/development/logic_analyzer.h | 1 + 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 0f84b429e3..8f840df5e9 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -866,6 +866,11 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ tle8888PostState(tsOutputChannels->getDebugChannels()); #endif /* BOARD_TLE8888_COUNT */ break; + case DBG_LOGIC_ANALYZER: +#if EFI_LOGIC_ANALYZER + reportLogicAnalyzerToTS(); +#endif /* EFI_LOGIC_ANALYZER */ + break; default: ; } diff --git a/firmware/development/logic_analyzer.cpp b/firmware/development/logic_analyzer.cpp index 0c1bc9bd49..4770c9befd 100644 --- a/firmware/development/logic_analyzer.cpp +++ b/firmware/development/logic_analyzer.cpp @@ -104,12 +104,20 @@ static void waIcuPeriodCallback(WaveReader *reader) { static void initWave(const char *name, int index) { brain_pin_e brainPin = CONFIG(logicAnalyzerPins)[index]; - if (brainPin == GPIO_UNASSIGNED) - return; - waveReaderCount++; efiAssertVoid(CUSTOM_ERR_6655, index < MAX_ICU_COUNT, "too many ICUs"); WaveReader *reader = &readers[index]; + + if (brainPin == GPIO_UNASSIGNED) { + /** + * in case we are running, and we select none for a channel that was running, + * this way we ensure that we do not get false report from that channel + **/ + reader->hw = nullptr; + return; + } + + reader->name = name; reader->hw = startDigitalCapture("wave input", brainPin); @@ -241,4 +249,42 @@ void stopLogicAnalyzerPins() { } } +void getChannelFreqAndDuty(int index, float *duty, int *freq) { + + float high,period; + + if ((duty == nullptr) || (freq == nullptr)) { + return; + } + + if (readers[index].hw == nullptr) { + *duty = 0.0; + *freq = 0; + } else { + high = getSignalOnTime(index); + period = getSignalPeriodMs(index); + + if ((period != 0) && (readers[index].hw->started)) { + + *duty = (high * 1000.0f) /(period * 10.0f); + *freq = (int)(1 / (period / 1000.0f)); + } else { + *duty = 0.0; + *freq = 0; + } + } + +} + +void reportLogicAnalyzerToTS() { +#if EFI_TUNER_STUDIO + int tmp; + getChannelFreqAndDuty(0,&tsOutputChannels.debugFloatField1, &tsOutputChannels.debugIntField1); + getChannelFreqAndDuty(1,&tsOutputChannels.debugFloatField2, &tsOutputChannels.debugIntField2); + getChannelFreqAndDuty(2,&tsOutputChannels.debugFloatField3, &tsOutputChannels.debugIntField3); + getChannelFreqAndDuty(3,&tsOutputChannels.debugFloatField4, &tmp); + tsOutputChannels.debugIntField4 = (int16_t)tmp; +#endif +} + #endif /* EFI_LOGIC_ANALYZER */ diff --git a/firmware/development/logic_analyzer.h b/firmware/development/logic_analyzer.h index 77fd912227..591788f782 100644 --- a/firmware/development/logic_analyzer.h +++ b/firmware/development/logic_analyzer.h @@ -55,6 +55,7 @@ void startLogicAnalyzerPins(); void stopLogicAnalyzerPins(); void printWave(Logging *logging); void showWaveInfo(void); +void reportLogicAnalyzerToTS(void); void waTriggerEventListener(trigger_event_e ckpSignalType, uint32_t index, efitick_t edgeTimestamp DECLARE_ENGINE_PARAMETER_SUFFIX);