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

Functions

 fail ("EFI_SHAFT_POSITION_INPUT required to have EFI_EMULATE_POSITION_SENSORS") static_assert(sizeof(composite_logger_s)
 
void jsonTraceEntry (const char *name, int pid, bool isEnter, efitick_t timestamp)
 
const std::vector< CompositeEvent > & getCompositeEvents ()
 
void SetNextCompositeEntry (efitick_t timestamp)
 
void EnableToothLogger ()
 
void DisableToothLogger ()
 
static void setToothLogReady (bool value)
 
static CompositeBufferGetToothLoggerBufferImpl (sysinterval_t timeout)
 
CompositeBufferGetToothLoggerBufferNonblocking ()
 
CompositeBufferGetToothLoggerBufferBlocking ()
 
void ReturnToothLoggerBuffer (CompositeBuffer *buffer)
 
static CompositeBufferfindBuffer (efitick_t timestamp)
 
void LogTriggerSync (bool isSync, efitick_t timestamp)
 
void LogTriggerCamTooth (bool isRising, efitick_t timestamp, int index)
 
void LogTriggerTooth (trigger_event_e tooth, efitick_t timestamp)
 
void LogTriggerTopDeadCenter (efitick_t timestamp)
 
void LogTriggerCoilState (efitick_t timestamp, size_t index, bool state)
 
void LogTriggerInjectorState (efitick_t timestamp, size_t index, bool state)
 
void EnableToothLoggerIfNotEnabled ()
 
bool IsToothLoggerEnabled ()
 

Variables

composite packet size
 
static volatile bool ToothLoggerEnabled = false
 
static bool currentTrigger1 = false
 
static bool currentTrigger2 = false
 
static bool currentTdc = false
 
static bool currentCoilState = false
 
static bool currentInjectorState = false
 
static std::vector< CompositeEvent > events
 
static constexpr size_t BUFFER_COUNT = BIG_BUFFER_SIZE / sizeof(CompositeBuffer)
 
static CompositeBufferbuffers = nullptr
 
static chibios_rt::Mailbox< CompositeBuffer *, BUFFER_COUNT > freeBuffers CCM_OPTIONAL
 
static CompositeBuffercurrentBuffer = nullptr
 
static BigBufferHandle bufferHandle
 

Function Documentation

◆ DisableToothLogger()

void DisableToothLogger ( )

Definition at line 77 of file tooth_logger.cpp.

77 {
78 ToothLoggerEnabled = false;
79}
static volatile bool ToothLoggerEnabled

Referenced by TunerStudio::handleCrcCommand(), perfTraceEnable(), and sdLoggerStop().

Here is the caller graph for this function:

◆ EnableToothLogger()

void EnableToothLogger ( )

Definition at line 72 of file tooth_logger.cpp.

72 {
73 ToothLoggerEnabled = true;
74 events.clear();
75}
static std::vector< CompositeEvent > events

Referenced by EnableToothLoggerIfNotEnabled(), TunerStudio::handleCrcCommand(), and sdLoggerStart().

Here is the caller graph for this function:

◆ EnableToothLoggerIfNotEnabled()

void EnableToothLoggerIfNotEnabled ( )

Definition at line 370 of file tooth_logger.cpp.

370 {
371 if (!ToothLoggerEnabled) {
373 }
374}
void EnableToothLogger()

Referenced by TunerStudio::handleCrcCommand().

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

◆ fail()

fail ( "EFI_SHAFT_POSITION_INPUT required to have EFI_EMULATE_POSITION_SENSORS"  )

Engine idles around 20Hz and revs up to 140Hz, at 60/2 and 8 cylinders we have about 20Khz events If we can read buffer at 50Hz we want buffer to be about 400 elements.

◆ findBuffer()

static CompositeBuffer * findBuffer ( efitick_t  timestamp)
static

Definition at line 187 of file tooth_logger.cpp.

187 {
189
190 if (!currentBuffer) {
191 // try and find a buffer, if none available, we can't log
192 if (MSG_OK != freeBuffers.fetchI(&buffer)) {
193 return nullptr;
194 }
195
196 // Record the time of the last buffer swap so we can force a swap after a minimum period of time
197 // This ensures the user sees *something* even if they don't have enough trigger events
198 // to fill the buffer.
199 buffer->startTime.reset(timestamp);
200 buffer->nextIdx = 0;
201
203 }
204
205 return currentBuffer;
206}
static chibios_rt::Mailbox< CanFrameData *, LUA_canFrameCount > freeBuffers
static CompositeBuffer * currentBuffer
static BigBufferHandle buffer

◆ getCompositeEvents()

const std::vector< CompositeEvent > & getCompositeEvents ( )

Definition at line 54 of file tooth_logger.cpp.

54 {
55 return events;
56}

◆ GetToothLoggerBufferBlocking()

CompositeBuffer * GetToothLoggerBufferBlocking ( )

Definition at line 176 of file tooth_logger.cpp.

176 {
177 return GetToothLoggerBufferImpl(TIME_INFINITE);
178}
static CompositeBuffer * GetToothLoggerBufferImpl(sysinterval_t timeout)

Referenced by sdTriggerLogger().

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

◆ GetToothLoggerBufferImpl()

static CompositeBuffer * GetToothLoggerBufferImpl ( sysinterval_t  timeout)
static

Definition at line 148 of file tooth_logger.cpp.

148 {
150 msg_t msg = filledBuffers.fetch(&buffer, timeout);
151
152 if (msg == MSG_TIMEOUT) {
153 setToothLogReady(false);
154 return nullptr;
155 }
156
157 if (msg != MSG_OK) {
158 // What even happened if we didn't get timeout, but also didn't get OK?
159 return nullptr;
160 }
161
162 chibios_rt::CriticalSectionLocker csl;
163
164 // If the used list is empty, clear the ready flag
165 if (filledBuffers.getUsedCountI() == 0) {
166 setToothLogReady(false);
167 }
168
169 return buffer;
170}
static chibios_rt::Mailbox< CanFrameData *, LUA_canFrameCount > filledBuffers
static void setToothLogReady(bool value)

Referenced by GetToothLoggerBufferBlocking(), and GetToothLoggerBufferNonblocking().

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

◆ GetToothLoggerBufferNonblocking()

CompositeBuffer * GetToothLoggerBufferNonblocking ( )

Definition at line 172 of file tooth_logger.cpp.

172 {
173 return GetToothLoggerBufferImpl(TIME_IMMEDIATE);
174}

Referenced by TunerStudio::handleCrcCommand().

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

◆ IsToothLoggerEnabled()

bool IsToothLoggerEnabled ( )

Definition at line 376 of file tooth_logger.cpp.

376 {
377 return ToothLoggerEnabled;
378}

Referenced by perfTraceEnable().

Here is the caller graph for this function:

◆ jsonTraceEntry()

void jsonTraceEntry ( const char name,
int  pid,
bool  isEnter,
efitick_t  timestamp 
)

Definition at line 38 of file tooth_logger.cpp.

38 {
39extern FILE *jsonTrace;
40 if (jsonTrace != nullptr) {
41 fprintf(jsonTrace, ",\n");
42 fprintf(jsonTrace, "{\"name\":\"%s\",\"ph\":\"%s\",\"tid\":0,\"pid\":%d,\"ts\":%f}",
43 name,
44 isEnter ? "B" : "E",
45 pid,
46 timestamp / 1000.0);
47 }
48}

Referenced by LogTriggerCamTooth(), LogTriggerCoilState(), LogTriggerInjectorState(), LogTriggerSync(), and LogTriggerTooth().

Here is the caller graph for this function:

◆ LogTriggerCamTooth()

void LogTriggerCamTooth ( bool  isRising,
efitick_t  timestamp,
int  index 
)

Definition at line 269 of file tooth_logger.cpp.

269 {
270#if EFI_UNIT_TEST
271 jsonTraceEntry("cam", JSON_CAM_PID + index, /*isEnter*/isRising, timestamp);
272#else
273 UNUSED(isRising); UNUSED(timestamp); UNUSED(index);
274#endif
275}
UNUSED(samplingTimeSeconds)
void jsonTraceEntry(const char *name, int pid, bool isEnter, efitick_t timestamp)

Referenced by logVvtFront().

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

◆ LogTriggerCoilState()

void LogTriggerCoilState ( efitick_t  timestamp,
size_t  index,
bool  state 
)

Definition at line 346 of file tooth_logger.cpp.

346 {
347#if EFI_UNIT_TEST
348 jsonTraceEntry("coil", 20 + index, state, timestamp);
349#endif // EFI_UNIT_TEST
350 if (!ToothLoggerEnabled) {
351 return;
352 }
354 UNUSED(timestamp); UNUSED(index);
355 //SetNextCompositeEntry(timestamp, trigger1, trigger2, trigger);
356}
state("state", SensorCategory.SENSOR_INPUTS, FieldType.INT8, 1871, 1.0, -1.0, -1.0, "")
static bool currentCoilState

Referenced by fireSparkAndPrepareNextSchedule(), and turnSparkPinHighStartCharging().

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

◆ LogTriggerInjectorState()

void LogTriggerInjectorState ( efitick_t  timestamp,
size_t  index,
bool  state 
)

Definition at line 358 of file tooth_logger.cpp.

358 {
359#if EFI_UNIT_TEST
360 jsonTraceEntry("inj", 30 + index, state, timestamp);
361#endif // EFI_UNIT_TEST
362 if (!ToothLoggerEnabled) {
363 return;
364 }
366 UNUSED(timestamp); UNUSED(index);
367 //SetNextCompositeEntry(timestamp, trigger1, trigger2, trigger);
368}
static bool currentInjectorState

Referenced by InjectorOutputPin::close(), and InjectorOutputPin::open().

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

◆ LogTriggerSync()

void LogTriggerSync ( bool  isSync,
efitick_t  timestamp 
)

Definition at line 261 of file tooth_logger.cpp.

261 {
262#if EFI_UNIT_TEST
263 jsonTraceEntry("sync", 3, /*isEnter*/isSync, timestamp);
264#else
265 UNUSED(isSync); UNUSED(timestamp);
266#endif
267}

Referenced by TriggerDecoderBase::setShaftSynchronized().

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

◆ LogTriggerTooth()

void LogTriggerTooth ( trigger_event_e  tooth,
efitick_t  timestamp 
)

Definition at line 277 of file tooth_logger.cpp.

277 {
278#if EFI_UNIT_TEST
279 if (tooth == SHAFT_PRIMARY_RISING) {
280 jsonTraceEntry("trg0", JSON_TRG_PID, /*isEnter*/true, timestamp);
281 } else if (tooth == SHAFT_PRIMARY_FALLING) {
282 jsonTraceEntry("trg0", JSON_TRG_PID, /*isEnter*/false, timestamp);
283 }
284#endif // EFI_UNIT_TEST
285
286 efiAssertVoid(ObdCode::CUSTOM_ERR_6650, hasLotsOfRemainingStack(), "l-t-t");
287 // bail if we aren't enabled
288 if (!ToothLoggerEnabled) {
289 return;
290 }
291
292 // Don't log at significant engine speed
293 if (!getTriggerCentral()->isEngineSnifferEnabled) {
294 return;
295 }
296
298
299/*
300 // We currently only support the primary trigger falling edge
301 // (this is the edge that VR sensors are accurate on)
302 // Since VR sensors are the most useful case here, this is okay for now.
303 if (tooth != SHAFT_PRIMARY_FALLING) {
304 return;
305 }
306
307 uint32_t nowUs = NT2US(timestamp);
308 // 10us per LSB - this gives plenty of accuracy, yet fits 655.35 ms in to a uint16
309 uint16_t delta = static_cast<uint16_t>((nowUs - lastEdgeTimestamp) / 10);
310 lastEdgeTimestamp = nowUs;
311
312 SetNextEntry(delta);
313*/
314
315 switch (tooth) {
317 currentTrigger1 = false;
318 break;
320 currentTrigger1 = true;
321 break;
323 currentTrigger2 = false;
324 break;
326 currentTrigger2 = true;
327 break;
328 default:
329 break;
330 }
331
332 SetNextCompositeEntry(timestamp);
333}
TriggerCentral * getTriggerCentral()
Definition engine.cpp:590
@ CUSTOM_ERR_6650
@ LogTriggerTooth
@ SHAFT_SECONDARY_RISING
@ SHAFT_SECONDARY_FALLING
@ SHAFT_PRIMARY_FALLING
@ SHAFT_PRIMARY_RISING
static bool currentTrigger1
static bool currentTrigger2
void SetNextCompositeEntry(efitick_t timestamp)
Here is the call graph for this function:

◆ LogTriggerTopDeadCenter()

void LogTriggerTopDeadCenter ( efitick_t  timestamp)

Definition at line 335 of file tooth_logger.cpp.

335 {
336 // bail if we aren't enabled
337 if (!ToothLoggerEnabled) {
338 return;
339 }
340 currentTdc = true;
341 SetNextCompositeEntry(timestamp);
342 currentTdc = false;
343 SetNextCompositeEntry(timestamp + 10);
344}
static bool currentTdc

Referenced by onTdcCallback().

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

◆ ReturnToothLoggerBuffer()

void ReturnToothLoggerBuffer ( CompositeBuffer buffer)

Definition at line 180 of file tooth_logger.cpp.

180 {
181 chibios_rt::CriticalSectionLocker csl;
182
183 msg_t msg = freeBuffers.postI(buffer);
184 criticalAssertVoid(msg == MSG_OK, "Composite logger post to free buffer fail");
185}

Referenced by TunerStudio::handleCrcCommand(), and sdTriggerLogger().

Here is the caller graph for this function:

◆ SetNextCompositeEntry()

static void SetNextCompositeEntry ( efitick_t  timestamp)

Definition at line 58 of file tooth_logger.cpp.

58 {
59 CompositeEvent event;
60
61 event.timestamp = timestamp;
62 event.primaryTrigger = currentTrigger1;
63 event.secondaryTrigger = currentTrigger2;
64 event.isTDC = currentTdc;
66 event.coil = currentCoilState;
67 event.injector = currentInjectorState;
68
69 events.push_back(event);
70}
TriggerCentral triggerCentral
Definition engine.h:318
PrimaryTriggerDecoder triggerState
bool getShaftSynchronized() const
static EngineAccessor engine
Definition engine.h:413

Referenced by LogTriggerTooth(), and LogTriggerTopDeadCenter().

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

◆ setToothLogReady()

static void setToothLogReady ( bool  value)
static

Definition at line 92 of file tooth_logger.cpp.

92 {
93#if EFI_TUNER_STUDIO && (EFI_PROD_CODE || EFI_SIMULATOR)
95#endif // EFI_TUNER_STUDIO
96}
TunerStudioOutputChannels outputChannels
Definition engine.h:109

Referenced by GetToothLoggerBufferImpl().

Here is the caller graph for this function:

Variable Documentation

◆ BUFFER_COUNT

constexpr size_t BUFFER_COUNT = BIG_BUFFER_SIZE / sizeof(CompositeBuffer)
staticconstexpr

Definition at line 83 of file tooth_logger.cpp.

◆ bufferHandle

BigBufferHandle bufferHandle
static

Definition at line 98 of file tooth_logger.cpp.

◆ buffers

CompositeBuffer* buffers = nullptr
static

Definition at line 86 of file tooth_logger.cpp.

◆ CCM_OPTIONAL

static chibios_rt::Mailbox< CompositeBuffer *, BUFFER_COUNT > filledBuffers CCM_OPTIONAL
static

Definition at line 87 of file tooth_logger.cpp.

◆ currentBuffer

CompositeBuffer* currentBuffer = nullptr
static

Definition at line 90 of file tooth_logger.cpp.

Referenced by findBuffer().

◆ currentCoilState

bool currentCoilState = false
static

Definition at line 32 of file tooth_logger.cpp.

Referenced by LogTriggerCoilState(), and SetNextCompositeEntry().

◆ currentInjectorState

bool currentInjectorState = false
static

Definition at line 34 of file tooth_logger.cpp.

Referenced by LogTriggerInjectorState(), and SetNextCompositeEntry().

◆ currentTdc

bool currentTdc = false
static

Definition at line 30 of file tooth_logger.cpp.

Referenced by LogTriggerTopDeadCenter(), and SetNextCompositeEntry().

◆ currentTrigger1

bool currentTrigger1 = false
static

Definition at line 28 of file tooth_logger.cpp.

Referenced by LogTriggerTooth(), and SetNextCompositeEntry().

◆ currentTrigger2

bool currentTrigger2 = false
static

Definition at line 29 of file tooth_logger.cpp.

Referenced by LogTriggerTooth(), and SetNextCompositeEntry().

◆ events

std::vector<CompositeEvent> events
static

◆ size

composite packet size

◆ ToothLoggerEnabled

volatile bool ToothLoggerEnabled = false
static

Go to the source code of this file.