2019-07-07 12:22:46 -07:00
|
|
|
/*
|
|
|
|
* @file tooth_logger.h
|
|
|
|
*
|
|
|
|
* @date Jul 7, 2019
|
|
|
|
* @author Matthew Kennedy
|
|
|
|
*/
|
|
|
|
|
2019-07-06 17:48:58 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "rusefi_enums.h"
|
2022-09-07 16:35:52 -07:00
|
|
|
#include "expected.h"
|
2022-09-10 22:59:44 -07:00
|
|
|
#include "trigger_structure.h"
|
2019-07-06 17:48:58 -07:00
|
|
|
|
2020-07-19 21:36:10 -07:00
|
|
|
#if EFI_UNIT_TEST
|
|
|
|
#include "logicdata.h"
|
2022-07-04 13:57:17 -07:00
|
|
|
const std::vector<CompositeEvent>& getCompositeEvents();
|
2020-07-19 21:36:10 -07:00
|
|
|
#endif // EFI_UNIT_TEST
|
|
|
|
|
2020-05-26 19:30:53 -07:00
|
|
|
void EnableToothLoggerIfNotEnabled();
|
|
|
|
|
2019-07-06 17:48:58 -07:00
|
|
|
// Enable the tooth logger - this clears the buffer starts logging
|
|
|
|
void EnableToothLogger();
|
|
|
|
|
|
|
|
// Stop logging - leave buffer intact
|
|
|
|
void DisableToothLogger();
|
|
|
|
|
|
|
|
// A new tooth has arrived! Log to the buffer if enabled.
|
2021-11-16 01:15:29 -08:00
|
|
|
void LogTriggerTooth(trigger_event_e tooth, efitick_t timestamp);
|
2019-07-06 17:48:58 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void LogTriggerTopDeadCenter(efitick_t timestamp);
|
2020-04-19 17:46:29 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void LogTriggerCoilState(efitick_t timestamp, bool state);
|
2020-05-25 21:07:18 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void LogTriggerInjectorState(efitick_t timestamp, bool state);
|
2020-05-25 21:07:18 -07:00
|
|
|
|
2022-12-15 04:34:10 -08:00
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
|
|
// the whole order of all packet bytes is reversed, not just the 'endian-swap' integers
|
|
|
|
uint32_t timestamp;
|
|
|
|
// unfortunately all these fields are required by TS...
|
|
|
|
bool priLevel : 1;
|
|
|
|
bool secLevel : 1;
|
|
|
|
bool trigger : 1;
|
|
|
|
bool sync : 1;
|
|
|
|
bool coil : 1;
|
|
|
|
bool injector : 1;
|
|
|
|
} composite_logger_s;
|
|
|
|
|
|
|
|
static constexpr size_t toothLoggerEntriesPerBuffer = 250;
|
|
|
|
|
|
|
|
struct CompositeBuffer {
|
|
|
|
composite_logger_s buffer[toothLoggerEntriesPerBuffer];
|
|
|
|
size_t nextIdx;
|
|
|
|
Timer startTime;
|
2019-07-06 17:48:58 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// Get a reference to the buffer
|
2022-12-15 04:34:10 -08:00
|
|
|
// Returns nullptr if no buffer is available
|
2022-12-17 17:01:15 -08:00
|
|
|
CompositeBuffer* GetToothLoggerBufferNonblocking();
|
|
|
|
// Blocks until a buffer is available
|
|
|
|
CompositeBuffer* GetToothLoggerBufferBlocking();
|
|
|
|
|
2022-12-15 04:34:10 -08:00
|
|
|
// Return a buffer to the pool once its contents have been read
|
|
|
|
void ReturnToothLoggerBuffer(CompositeBuffer*);
|
|
|
|
|
|
|
|
#include "big_buffer.h"
|