logic analyzer uses exti (#4269)

* rename functions

* s

* logic analyzer implemented using EXTI

* s

* don't turn it off on hellen either

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2022-06-22 17:13:17 -07:00 committed by GitHub
parent 0bc445b461
commit 27cdab28f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 67 additions and 85 deletions

View File

@ -19,7 +19,7 @@ endif
DDEFS += -DHW_FRANKENSO=1 DDEFS += -DHW_FRANKENSO=1
DDEFS += $(DEFAULT_ENGINE_TYPE) DDEFS += $(DEFAULT_ENGINE_TYPE)
DDEFS += -DEFI_ICU_INPUTS=TRUE -DHAL_TRIGGER_USE_PAL=FALSE -DEFI_LOGIC_ANALYZER=TRUE DDEFS += -DEFI_ICU_INPUTS=TRUE -DHAL_TRIGGER_USE_PAL=FALSE
DDEFS += -DSTM32_I2C_USE_I2C3=TRUE DDEFS += -DSTM32_I2C_USE_I2C3=TRUE

View File

@ -13,9 +13,6 @@ DDEFS += -DLED_COMMUNICATION_BRAIN_PIN_MODE=INVERTED_OUTPUT
DDEFS += -DHW_HELLEN=1 DDEFS += -DHW_HELLEN=1
DDEFS += -DEFI_USE_OSC=TRUE DDEFS += -DEFI_USE_OSC=TRUE
# todo: is it broken?
DDEFS += -DEFI_LOGIC_ANALYZER=FALSE
DDEFS += -DEFI_ICU_INPUTS=FALSE DDEFS += -DEFI_ICU_INPUTS=FALSE
DDEFS += -DTS_NO_SECONDARY=TRUE DDEFS += -DTS_NO_SECONDARY=TRUE

View File

@ -66,7 +66,7 @@
* Build-in logic analyzer support. Logic analyzer viewer is one of the java console panes. * Build-in logic analyzer support. Logic analyzer viewer is one of the java console panes.
*/ */
#ifndef EFI_LOGIC_ANALYZER #ifndef EFI_LOGIC_ANALYZER
#define EFI_LOGIC_ANALYZER FALSE #define EFI_LOGIC_ANALYZER TRUE
#endif #endif
#ifndef EFI_ICU_INPUTS #ifndef EFI_ICU_INPUTS

View File

@ -19,11 +19,11 @@
#include "os_util.h" #include "os_util.h"
#include "rpm_calculator.h" #include "rpm_calculator.h"
#include "engine_sniffer.h" #include "engine_sniffer.h"
#include "digital_input_exti.h"
#if EFI_LOGIC_ANALYZER #if EFI_LOGIC_ANALYZER
#define CHART_RESET_DELAY 1 #define CHART_RESET_DELAY 1
#define MAX_ICU_COUNT 5
#if EFI_ENGINE_SNIFFER #if EFI_ENGINE_SNIFFER
extern WaveChart waveChart; extern WaveChart waveChart;
@ -35,15 +35,9 @@ extern WaveChart waveChart;
static volatile uint32_t engineCycleDurationUs; static volatile uint32_t engineCycleDurationUs;
static volatile efitimeus_t previousEngineCycleTimeUs = 0; static volatile efitimeus_t previousEngineCycleTimeUs = 0;
static int waveReaderCount = 0; static WaveReader readers[4];
static WaveReader readers[MAX_ICU_COUNT];
static void ensureInitialized(WaveReader *reader) { static void riseCallback(WaveReader *reader) {
/*may be*/UNUSED(reader);
efiAssertVoid(CUSTOM_ERR_6654, reader->hw != NULL && reader->hw->started, "wave analyzer NOT INITIALIZED");
}
static void waAnaWidthCallback(WaveReader *reader) {
efitick_t nowUs = getTimeNowUs(); efitick_t nowUs = getTimeNowUs();
reader->riseEventCounter++; reader->riseEventCounter++;
reader->lastActivityTimeUs = nowUs; reader->lastActivityTimeUs = nowUs;
@ -88,15 +82,22 @@ void WaveReader::onFallEvent() {
periodEventTimeUs = nowUs; periodEventTimeUs = nowUs;
} }
static void waIcuPeriodCallback(WaveReader *reader) { void logicAnalyzerCallback(void* arg, efitick_t stamp) {
reader->onFallEvent(); WaveReader* instance = reinterpret_cast<WaveReader*>(arg);
bool rise = palReadLine(instance->line) == PAL_HIGH;
if(rise) {
riseCallback(instance);
} else {
instance->onFallEvent();
}
} }
static void initWave(const char *name, int index) { static void initWave(const char *name, int index) {
brain_pin_e brainPin = engineConfiguration->logicAnalyzerPins[index]; brain_pin_e brainPin = engineConfiguration->logicAnalyzerPins[index];
waveReaderCount++; efiAssertVoid(CUSTOM_ERR_6655, index < efi::size(readers), "too many ICUs");
efiAssertVoid(CUSTOM_ERR_6655, index < MAX_ICU_COUNT, "too many ICUs");
WaveReader *reader = &readers[index]; WaveReader *reader = &readers[index];
if (!isBrainPinValid(brainPin)) { if (!isBrainPinValid(brainPin)) {
@ -104,28 +105,19 @@ static void initWave(const char *name, int index) {
* in case we are running, and we select none for a channel that was running, * 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 * this way we ensure that we do not get false report from that channel
**/ **/
reader->hw = nullptr; reader->line = 0;
return; return;
} }
reader->name = name; reader->name = name;
reader->hw = startDigitalCapture("wave input", brainPin); reader->line = PAL_LINE(getHwPort("logic", brainPin), getHwPin("logic", brainPin));
if (reader->hw != NULL) { efiExtiEnablePin("logic", brainPin, PAL_EVENT_MODE_BOTH_EDGES, logicAnalyzerCallback, (void*)reader);
reader->hw->setWidthCallback((VoidInt)(void*) waAnaWidthCallback, (void*) reader);
reader->hw->setPeriodCallback((VoidInt)(void*) waIcuPeriodCallback, (void*) reader);
}
efiPrintf("wave%d input on %s", index, hwPortname(brainPin)); efiPrintf("wave%d input on %s", index, hwPortname(brainPin));
} }
WaveReader::WaveReader() {
hw = nullptr;
}
void waTriggerEventListener(trigger_event_e ckpSignalType, uint32_t index, efitick_t edgeTimestamp) { void waTriggerEventListener(trigger_event_e ckpSignalType, uint32_t index, efitick_t edgeTimestamp) {
(void)ckpSignalType; (void)ckpSignalType;
if (index != 0) { if (index != 0) {
@ -138,70 +130,65 @@ void waTriggerEventListener(trigger_event_e ckpSignalType, uint32_t index, efiti
} }
static float getSignalOnTime(int index) { static float getSignalOnTime(int index) {
WaveReader *reader = &readers[index]; WaveReader& reader = readers[index];
ensureInitialized(reader);
if (getTimeNowUs() - reader->lastActivityTimeUs > 4 * US_PER_SECOND) { if (getTimeNowUs() - reader.lastActivityTimeUs > 4 * US_PER_SECOND) {
return 0.0f; // dwell time has expired return 0.0f; // dwell time has expired
} }
return reader->last_wave_high_widthUs / 1000.0f; return reader.last_wave_high_widthUs / 1000.0f;
} }
static efitime_t getWaveOffset(int index) { static efitime_t getWaveOffset(int index) {
WaveReader *reader = &readers[index]; return readers[index].waveOffsetUs;
ensureInitialized(reader);
return reader->waveOffsetUs;
} }
static float getSignalPeriodMs(int index) { static float getSignalPeriodMs(int index) {
WaveReader *reader = &readers[index]; return readers[index].signalPeriodUs / 1000.0f;
ensureInitialized(reader);
return reader->signalPeriodUs / 1000.0f;
} }
static void reportWave(Logging *logging, int index) { static void reportWave(Logging *logging, int index) {
if (readers[index].hw == nullptr) { if (readers[index].line == 0) {
return; return;
} }
if (readers[index].hw->started) {
// int counter = getEventCounter(index); // int counter = getEventCounter(index);
// debugInt2(logging, "ev", index, counter); // debugInt2(logging, "ev", index, counter);
float dwellMs = getSignalOnTime(index); float dwellMs = getSignalOnTime(index);
float periodMs = getSignalPeriodMs(index); float periodMs = getSignalPeriodMs(index);
logging->appendPrintf("duty%d%s", index, LOG_DELIMITER); logging->appendPrintf("duty%d%s", index, LOG_DELIMITER);
logging->appendFloat(100.0f * dwellMs / periodMs, 2); logging->appendFloat(100.0f * dwellMs / periodMs, 2);
logging->appendPrintf("%s", LOG_DELIMITER);
/**
* that's the ON time of the LAST signal
*/
logging->appendPrintf("dwell%d%s", index, LOG_DELIMITER);
logging->appendFloat(dwellMs, 2);
logging->appendPrintf("%s", LOG_DELIMITER);
/**
* that's the total ON time during the previous engine cycle
*/
logging->appendPrintf("total_dwell%d%s", index, LOG_DELIMITER);
logging->appendFloat(readers[index].prevTotalOnTimeUs / 1000.0f, 2);
logging->appendPrintf("%s", LOG_DELIMITER);
logging->appendPrintf("period%d%s", index, LOG_DELIMITER);
logging->appendFloat(periodMs, 2);
logging->appendPrintf("%s", LOG_DELIMITER);
uint32_t offsetUs = getWaveOffset(index);
int rpm = Sensor::getOrZero(SensorType::Rpm);
if (rpm != 0) {
float oneDegreeUs = getOneDegreeTimeUs(rpm);
logging->appendPrintf("advance%d%s", index, LOG_DELIMITER);
float angle = (offsetUs / oneDegreeUs) - tdcPosition();
fixAngle(angle, "waveAn", CUSTOM_ERR_6564);
logging->appendFloat(angle, 3);
logging->appendPrintf("%s", LOG_DELIMITER); logging->appendPrintf("%s", LOG_DELIMITER);
/**
* that's the ON time of the LAST signal
*/
logging->appendPrintf("dwell%d%s", index, LOG_DELIMITER);
logging->appendFloat(dwellMs, 2);
logging->appendPrintf("%s", LOG_DELIMITER);
/**
* that's the total ON time during the previous engine cycle
*/
logging->appendPrintf("total_dwell%d%s", index, LOG_DELIMITER);
logging->appendFloat(readers[index].prevTotalOnTimeUs / 1000.0f, 2);
logging->appendPrintf("%s", LOG_DELIMITER);
logging->appendPrintf("period%d%s", index, LOG_DELIMITER);
logging->appendFloat(periodMs, 2);
logging->appendPrintf("%s", LOG_DELIMITER);
uint32_t offsetUs = getWaveOffset(index);
int rpm = Sensor::getOrZero(SensorType::Rpm);
if (rpm != 0) {
float oneDegreeUs = getOneDegreeTimeUs(rpm);
logging->appendPrintf("advance%d%s", index, LOG_DELIMITER);
float angle = (offsetUs / oneDegreeUs) - tdcPosition();
fixAngle(angle, "waveAn", CUSTOM_ERR_6564);
logging->appendFloat(angle, 3);
logging->appendPrintf("%s", LOG_DELIMITER);
}
} }
} }
@ -234,27 +221,26 @@ void stopLogicAnalyzerPins() {
brain_pin_e brainPin = activeConfiguration.logicAnalyzerPins[index]; brain_pin_e brainPin = activeConfiguration.logicAnalyzerPins[index];
if (isBrainPinValid(brainPin)) { if (isBrainPinValid(brainPin)) {
stopDigitalCapture("wave input", brainPin); efiExtiDisablePin(brainPin);
} }
} }
} }
static void getChannelFreqAndDuty(int index, scaled_channel<float> *duty, scaled_channel<uint32_t> *freq) { static void getChannelFreqAndDuty(int index, scaled_channel<float> *duty, scaled_channel<uint32_t> *freq) {
float high, period;
float high,period;
if ((duty == nullptr) || (freq == nullptr)) { if ((duty == nullptr) || (freq == nullptr)) {
return; return;
} }
if (readers[index].hw == nullptr) { if (readers[index].line == 0) {
*duty = 0.0; *duty = 0.0;
*freq = 0; *freq = 0;
} else { } else {
high = getSignalOnTime(index); high = getSignalOnTime(index);
period = getSignalPeriodMs(index); period = getSignalPeriodMs(index);
if ((period != 0) && (readers[index].hw->started)) { if (period != 0) {
*duty = (high * 1000.0f) /(period * 10.0f); *duty = (high * 1000.0f) /(period * 10.0f);
*freq = (int)(1 / (period / 1000.0f)); *freq = (int)(1 / (period / 1000.0f));

View File

@ -11,15 +11,14 @@
#if EFI_LOGIC_ANALYZER #if EFI_LOGIC_ANALYZER
#include "digital_input_icu.h"
#include "engine_sniffer.h" #include "engine_sniffer.h"
class WaveReader { class WaveReader {
public: public:
WaveReader();
void onFallEvent(); void onFallEvent();
digital_input_s *hw; ioline_t line = 0;
const char *name = nullptr; const char *name = nullptr;
volatile int fallEventCounter = 0; volatile int fallEventCounter = 0;
volatile int riseEventCounter = 0; volatile int riseEventCounter = 0;