rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
logic_analyzer.cpp File Reference

Detailed Description

Initialization of Input Capture pins used for rusEfi console sniffer.

This file is responsible for sniffing of external digital signals and registering these digital events in WaveChart used by the Engine Sniffer tab of rusEfi Console.

this is rusEfi build-in logic analyzer

Date
Jan 7, 2013
Author
Andrey Belomutskiy, (c) 2012-2020

Definition in file logic_analyzer.cpp.

Functions

static void riseCallback (WaveReader *reader)
 
void logicAnalyzerCallback (void *arg, efitick_t)
 
static void initWave (size_t index)
 
void waTriggerEventListener (trigger_event_e ckpSignalType, uint32_t index, efitick_t edgeTimestamp)
 
static float getSignalOnTime (int index)
 
static efitimeus_t getWaveOffset (int index)
 
static float getSignalPeriodMs (int index)
 
static void reportWave (Logging *logging, int index)
 
void printWave (Logging *logging)
 
void showWaveInfo (void)
 
void initWaveAnalyzer ()
 
void startLogicAnalyzerPins ()
 
void stopLogicAnalyzerPins ()
 
template<typename TFreq >
static void getChannelFreqAndDuty (int index, float &duty, TFreq &freq)
 
void reportLogicAnalyzerToTS ()
 

Variables

static volatile uint32_t engineCycleDurationUs
 
static volatile efitimeus_t previousEngineCycleTimeUs = 0
 
static WaveReader readers [LOGIC_ANALYZER_CHANNEL_COUNT]
 

Function Documentation

◆ getChannelFreqAndDuty()

template<typename TFreq >
static void getChannelFreqAndDuty ( int  index,
float duty,
TFreq &  freq 
)
static

Definition at line 261 of file logic_analyzer.cpp.

261 {
262 if (readers[index].line == 0) {
263 duty = 0.0;
264 freq = 0;
265 } else {
266 float high = getSignalOnTime(index);
267 float period = getSignalPeriodMs(index);
268
269 if (period != 0) {
270
271 duty = (high * 1000.0f) /(period * 10.0f);
272 freq = (int)(1 / (period / 1000.0f));
273 } else {
274 duty = 0.0;
275 freq = 0;
276 }
277 }
278}
beuint32_t period
static WaveReader readers[LOGIC_ANALYZER_CHANNEL_COUNT]
static float getSignalOnTime(int index)
static float getSignalPeriodMs(int index)
static float duty

Referenced by reportLogicAnalyzerToTS().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSignalOnTime()

static float getSignalOnTime ( int  index)
static

Definition at line 164 of file logic_analyzer.cpp.

164 {
165 WaveReader& reader = readers[index];
166
167 if (getTimeNowUs() - reader.lastActivityTimeUs > 4 * US_PER_SECOND) {
168 return 0.0f; // dwell time has expired
169 }
170 return reader.last_wave_high_widthUs / 1000.0f;
171}
efitimeus_t getTimeNowUs()
Definition efitime.cpp:26

Referenced by getChannelFreqAndDuty(), and reportWave().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSignalPeriodMs()

static float getSignalPeriodMs ( int  index)
static

Definition at line 177 of file logic_analyzer.cpp.

177 {
178 return readers[index].signalPeriodUs / 1000.0f;
179}

Referenced by getChannelFreqAndDuty(), and reportWave().

Here is the caller graph for this function:

◆ getWaveOffset()

static efitimeus_t getWaveOffset ( int  index)
static

Definition at line 173 of file logic_analyzer.cpp.

173 {
174 return readers[index].waveOffsetUs;
175}

Referenced by reportWave().

Here is the caller graph for this function:

◆ initWave()

static void initWave ( size_t  index)
static

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

Definition at line 129 of file logic_analyzer.cpp.

129 {
131
132 efiAssertVoid(ObdCode::CUSTOM_ERR_6655, index < efi::size(readers), "too many ICUs");
133 WaveReader *reader = &readers[index];
134
135 if (!isBrainPinValid(brainPin)) {
136 /**
137 * in case we are running, and we select none for a channel that was running,
138 * this way we ensure that we do not get false report from that channel
139 **/
140 reader->line = 0;
141 return;
142 }
143
144 reader->laIndex = index;
145
146 reader->line = PAL_LINE(getHwPort("logic", brainPin), getHwPin("logic", brainPin));
147
148 efiExtiEnablePin("logic", brainPin, PAL_EVENT_MODE_BOTH_EDGES, logicAnalyzerCallback, (void*)reader);
149
150 efiPrintf("wave%d input on %s", index, hwPortname(brainPin));
151}
int efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, ExtiCallback cb, void *cb_data)
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin)
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin)
static constexpr engine_configuration_s * engineConfiguration
void logicAnalyzerCallback(void *arg, efitick_t)
@ CUSTOM_ERR_6655
const char * hwPortname(brain_pin_e brainPin)
bool isBrainPinValid(brain_pin_e brainPin)
brain_input_pin_e logicAnalyzerPins[LOGIC_ANALYZER_CHANNEL_COUNT]

Referenced by startLogicAnalyzerPins().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initWaveAnalyzer()

void initWaveAnalyzer ( )

Definition at line 236 of file logic_analyzer.cpp.

236 {
237 if (hasFirmwareError()) {
238 return;
239 }
240
241 addConsoleAction("waveinfo", showWaveInfo);
242}
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
void showWaveInfo(void)

Referenced by initRealHardwareEngineController().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ logicAnalyzerCallback()

void logicAnalyzerCallback ( void *  arg,
efitick_t   
)

Definition at line 117 of file logic_analyzer.cpp.

117 {
118 WaveReader* instance = reinterpret_cast<WaveReader*>(arg);
119
120 bool rise = palReadLine(instance->line) == PAL_HIGH;
121
122 if (rise) {
124 } else {
125 instance->onFallEvent();
126 }
127}
static BenchController instance
static void riseCallback(WaveReader *reader)

Referenced by initWave().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ printWave()

void printWave ( Logging logging)

Definition at line 227 of file logic_analyzer.cpp.

227 {
228 reportWave(logging, 0);
229 reportWave(logging, 1);
230}
static void reportWave(Logging *logging, int index)

Referenced by updateDevConsoleState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reportLogicAnalyzerToTS()

void reportLogicAnalyzerToTS ( void  )

Definition at line 280 of file logic_analyzer.cpp.

280 {
281#if EFI_TUNER_STUDIO
286#endif
287}
TunerStudioOutputChannels outputChannels
Definition engine.h:109
static EngineAccessor engine
Definition engine.h:413
static void getChannelFreqAndDuty(int index, float &duty, TFreq &freq)

Referenced by updateTunerStudioState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reportWave()

static void reportWave ( Logging logging,
int  index 
)
static

that's the ON time of the LAST signal

that's the total ON time during the previous engine cycle

Definition at line 181 of file logic_analyzer.cpp.

181 {
182 if (readers[index].line == 0) {
183 return;
184 }
185
186// int counter = getEventCounter(index);
187// debugInt2(logging, "ev", index, counter);
188
189 float dwellMs = getSignalOnTime(index);
190 float periodMs = getSignalPeriodMs(index);
191
192 logging->appendPrintf("duty%d%s", index, LOG_DELIMITER);
193 logging->appendFloat(100.0f * dwellMs / periodMs, 2);
194 logging->appendPrintf("%s", LOG_DELIMITER);
195
196 /**
197 * that's the ON time of the LAST signal
198 */
199 logging->appendPrintf("dwell%d%s", index, LOG_DELIMITER);
200 logging->appendFloat(dwellMs, 2);
201 logging->appendPrintf("%s", LOG_DELIMITER);
202
203 /**
204 * that's the total ON time during the previous engine cycle
205 */
206 logging->appendPrintf("total_dwell%d%s", index, LOG_DELIMITER);
207 logging->appendFloat(readers[index].prevTotalOnTimeUs / 1000.0f, 2);
208 logging->appendPrintf("%s", LOG_DELIMITER);
209
210 logging->appendPrintf("period%d%s", index, LOG_DELIMITER);
211 logging->appendFloat(periodMs, 2);
212 logging->appendPrintf("%s", LOG_DELIMITER);
213
214 efitimeus_t offsetUs = getWaveOffset(index);
216 if (rpm != 0) {
217 float oneDegreeUs = getOneDegreeTimeUs(rpm);
218
219 logging->appendPrintf("advance%d%s", index, LOG_DELIMITER);
220 float angle = (offsetUs / oneDegreeUs) - tdcPosition();
221 wrapAngle(angle, "waveAn", ObdCode::CUSTOM_ERR_6564);
222 logging->appendFloat(angle, 3);
223 logging->appendPrintf("%s", LOG_DELIMITER);
224 }
225}
void void appendFloat(float value, int precision)
void appendPrintf(const char *fmt,...) __attribute__((format(printf
static float getOrZero(SensorType type)
Definition sensor.h:83
static efitimeus_t getWaveOffset(int index)
@ CUSTOM_ERR_6564
void wrapAngle(angle_t &angle, const char *msg, ObdCode code)

Referenced by printWave().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ riseCallback()

static void riseCallback ( WaveReader *  reader)
static

Definition at line 72 of file logic_analyzer.cpp.

72 {
73 efitimeus_t nowUs = getTimeNowUs();
74 reader->riseEventCounter++;
75 reader->lastActivityTimeUs = nowUs;
76 assertIsrContext(ObdCode::CUSTOM_ERR_6670);
78
79 uint32_t width = nowUs - reader->periodEventTimeUs;
80 reader->last_wave_low_widthUs = width;
81
82 reader->signalPeriodUs = nowUs - reader->widthEventTimeUs;
83 reader->widthEventTimeUs = nowUs;
84}
void addEngineSnifferLogicAnalyzerEvent(int laIndex, FrontDirection frontDirection)
@ CUSTOM_ERR_6670

Referenced by logicAnalyzerCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ showWaveInfo()

void showWaveInfo ( void  )

Definition at line 232 of file logic_analyzer.cpp.

232 {
233 efiPrintf("logic input #1: %d/%d", readers[0].fallEventCounter, readers[0].riseEventCounter);
234}

Referenced by initWaveAnalyzer().

Here is the caller graph for this function:

◆ startLogicAnalyzerPins()

void startLogicAnalyzerPins ( )

Definition at line 244 of file logic_analyzer.cpp.

244 {
245 for (size_t index = 0; index < LOGIC_ANALYZER_CHANNEL_COUNT; index++) {
246 initWave(index);
247 }
248}
static void initWave(size_t index)

Referenced by applyNewHardwareSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stopLogicAnalyzerPins()

void stopLogicAnalyzerPins ( )

Definition at line 250 of file logic_analyzer.cpp.

250 {
251 for (int index = 0; index < LOGIC_ANALYZER_CHANNEL_COUNT; index++) {
253
254 if (isBrainPinValid(brainPin)) {
255 efiExtiDisablePin(brainPin);
256 }
257 }
258}
void efiExtiDisablePin(brain_pin_e brainPin)
engine_configuration_s & activeConfiguration

Referenced by stopHardware().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ waTriggerEventListener()

void waTriggerEventListener ( trigger_event_e  ckpSignalType,
uint32_t  index,
efitick_t  edgeTimestamp 
)

Definition at line 153 of file logic_analyzer.cpp.

153 {
154 (void)ckpSignalType;
155 if (index != 0) {
156 return;
157 }
158
159 efitimeus_t nowUs = NT2US(edgeTimestamp);
162}
static volatile efitimeus_t previousEngineCycleTimeUs
static volatile uint32_t engineCycleDurationUs

Referenced by TriggerCentral::handleShaftSignal().

Here is the caller graph for this function:

Variable Documentation

◆ engineCycleDurationUs

volatile uint32_t engineCycleDurationUs
static

Difference between current 1st trigger event and previous 1st trigger event.

Definition at line 31 of file logic_analyzer.cpp.

Referenced by waTriggerEventListener().

◆ previousEngineCycleTimeUs

volatile efitimeus_t previousEngineCycleTimeUs = 0
static

Definition at line 32 of file logic_analyzer.cpp.

Referenced by waTriggerEventListener().

◆ readers

WaveReader readers[LOGIC_ANALYZER_CHANNEL_COUNT]
static

Go to the source code of this file.