26#define CHART_RESET_DELAY 1
41 volatile int fallEventCounter = 0;
42 volatile int riseEventCounter = 0;
44 int currentRevolutionCounter = 0;
49 efitimeus_t prevTotalOnTimeUs = 0;
51 efitimeus_t totalOnTimeAccumulatorUs = 0;
53 volatile efitimeus_t lastActivityTimeUs = 0;
57 volatile efitimeus_t periodEventTimeUs = 0;
58 volatile efitimeus_t widthEventTimeUs = 0;
60 volatile efitimeus_t signalPeriodUs = 0;
65 volatile efitimeus_t waveOffsetUs = 0;
66 volatile efitimeus_t last_wave_low_widthUs = 0;
67 volatile efitimeus_t last_wave_high_widthUs = 0;
70static WaveReader
readers[LOGIC_ANALYZER_CHANNEL_COUNT];
74 reader->riseEventCounter++;
75 reader->lastActivityTimeUs = nowUs;
79 uint32_t width = nowUs - reader->periodEventTimeUs;
80 reader->last_wave_low_widthUs = width;
82 reader->signalPeriodUs = nowUs - reader->widthEventTimeUs;
83 reader->widthEventTimeUs = nowUs;
86void WaveReader::onFallEvent() {
89 lastActivityTimeUs = nowUs;
93 efitimeus_t width = nowUs - widthEventTimeUs;
94 last_wave_high_widthUs = width;
96#if EFI_SHAFT_POSITION_INPUT
97 int revolutionCounter = getRevolutionCounter();
99 int revolutionCounter = 0;
102 totalOnTimeAccumulatorUs += width;
103 if (currentRevolutionCounter != revolutionCounter) {
107 currentRevolutionCounter = revolutionCounter;
108 prevTotalOnTimeUs = totalOnTimeAccumulatorUs;
109 totalOnTimeAccumulatorUs = 0;
114 periodEventTimeUs = nowUs;
118 WaveReader*
instance =
reinterpret_cast<WaveReader*
>(arg);
120 bool rise = palReadLine(
instance->line) == PAL_HIGH;
133 WaveReader *reader = &
readers[index];
144 reader->laIndex = index;
146 reader->line = PAL_LINE(
getHwPort(
"logic", brainPin),
getHwPin(
"logic", brainPin));
150 efiPrintf(
"wave%d input on %s", index,
hwPortname(brainPin));
159 efitimeus_t nowUs = NT2US(edgeTimestamp);
165 WaveReader& reader =
readers[index];
167 if (
getTimeNowUs() - reader.lastActivityTimeUs > 4 * US_PER_SECOND) {
170 return reader.last_wave_high_widthUs / 1000.0f;
174 return readers[index].waveOffsetUs;
178 return readers[index].signalPeriodUs / 1000.0f;
182 if (
readers[index].line == 0) {
192 logging->
appendPrintf(
"duty%d%s", index, LOG_DELIMITER);
193 logging->
appendFloat(100.0f * dwellMs / periodMs, 2);
199 logging->
appendPrintf(
"dwell%d%s", index, LOG_DELIMITER);
206 logging->
appendPrintf(
"total_dwell%d%s", index, LOG_DELIMITER);
210 logging->
appendPrintf(
"period%d%s", index, LOG_DELIMITER);
217 float oneDegreeUs = getOneDegreeTimeUs(rpm);
219 logging->
appendPrintf(
"advance%d%s", index, LOG_DELIMITER);
220 float angle = (offsetUs / oneDegreeUs) - tdcPosition();
233 efiPrintf(
"logic input #1: %d/%d",
readers[0].fallEventCounter,
readers[0].riseEventCounter);
237 if (hasFirmwareError()) {
245 for (
size_t index = 0; index < LOGIC_ANALYZER_CHANNEL_COUNT; index++) {
251 for (
int index = 0; index < LOGIC_ANALYZER_CHANNEL_COUNT; index++) {
260template <
typename TFreq>
262 if (
readers[index].line == 0) {
272 freq = (int)(1 / (
period / 1000.0f));
static BenchController instance
TunerStudioOutputChannels outputChannels
void void appendFloat(float value, int precision)
void appendPrintf(const char *fmt,...) __attribute__((format(printf
static float getOrZero(SensorType type)
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin)
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin)
Console package entry point header.
efitimeus_t getTimeNowUs()
static EngineAccessor engine
engine_configuration_s & activeConfiguration
static constexpr engine_configuration_s * engineConfiguration
void addEngineSnifferLogicAnalyzerEvent(int laIndex, FrontDirection frontDirection)
rusEfi console wave sniffer
uint32_t ioline_t
Type of an I/O line.
static volatile efitimeus_t previousEngineCycleTimeUs
static WaveReader readers[LOGIC_ANALYZER_CHANNEL_COUNT]
static void riseCallback(WaveReader *reader)
static void reportWave(Logging *logging, int index)
void waTriggerEventListener(trigger_event_e ckpSignalType, uint32_t index, efitick_t edgeTimestamp)
void stopLogicAnalyzerPins()
void logicAnalyzerCallback(void *arg, efitick_t)
void startLogicAnalyzerPins()
static volatile uint32_t engineCycleDurationUs
void printWave(Logging *logging)
static void initWave(size_t index)
void reportLogicAnalyzerToTS()
static void getChannelFreqAndDuty(int index, float &duty, TFreq &freq)
static efitimeus_t getWaveOffset(int index)
static float getSignalOnTime(int index)
static float getSignalPeriodMs(int index)
const char * hwPortname(brain_pin_e brainPin)
bool isBrainPinValid(brain_pin_e brainPin)
Shaft position sensor(s) decoder header.
brain_input_pin_e logicAnalyzerPins[LOGIC_ANALYZER_CHANNEL_COUNT]
void wrapAngle(angle_t &angle, const char *msg, ObdCode code)