From 9ae6f5c85fb464f0156b8a9673df239021144364 Mon Sep 17 00:00:00 2001 From: shadowm60 Date: Mon, 26 Oct 2020 04:26:20 +0200 Subject: [PATCH] Trigger logger (#1902) * Update tachometer.cpp Initial implementation of E30 M3 Tach output solution #907, unit_test plus debugging next * tacho unit tests First successfull unit test for tachometer * RAM adjustment so it would link * refactoring tacho, broken! * starting to make some progress...still fails after a few seconds * Rework with SW PWM * Update after code review * unit_test update * First working unit_test * Update .gitignore * Update engine_controller.cpp * Update engine_controller.cpp * Update tachometer.h * Update test_tacho.cpp * Switched UART DMA on * Revert "Switched UART DMA on" This reverts commit 4a23974c431e0e7fd760595d2161e74e6854897e. * tooth logger update Updated the way we send the buffer to TS Updated the way we log cam signals removed TDC, inj and ign direct log... this causes some flicker in TS, this way we log inj and ign comapred to a cranck or camshaft trigger. * Update tooth_logger.cpp Fix unit_tests * Update tooth_logger.h clean-up * Update tooth_logger.cpp remove dead code, actually i forgot to uncomment these lines. rename isTDC to trigger, since it is trigger (cam) for TS. Co-authored-by: rusefi --- firmware/console/binary/tooth_logger.cpp | 66 ++++++++++++++++++------ firmware/integration/rusefi_config.txt | 1 + firmware/tunerstudio/rusefi.input | 6 ++- 3 files changed, 56 insertions(+), 17 deletions(-) diff --git a/firmware/console/binary/tooth_logger.cpp b/firmware/console/binary/tooth_logger.cpp index 45efcbabad..5adbe6e779 100644 --- a/firmware/console/binary/tooth_logger.cpp +++ b/firmware/console/binary/tooth_logger.cpp @@ -29,7 +29,7 @@ typedef struct __attribute__ ((packed)) { // unfortunately all these fields are required by TS... bool priLevel : 1; bool secLevel : 1; - bool isTDC : 1; + bool trigger : 1; bool sync : 1; bool coil : 1; bool injector : 1; @@ -40,13 +40,16 @@ typedef struct __attribute__ ((packed)) { * If we can read buffer at 50Hz we want buffer to be about 400 elements. */ static composite_logger_s buffer[COMPOSITE_PACKET_COUNT] CCM_OPTIONAL; +static composite_logger_s *ptr_buffer_first = &buffer[0]; +static composite_logger_s *ptr_buffer_second = &buffer[(COMPOSITE_PACKET_COUNT/2)-1]; static size_t NextIdx = 0; static volatile bool ToothLoggerEnabled = false; - +static volatile bool firstBuffer = true; static uint32_t lastEdgeTimestamp = 0; static bool trigger1 = false; static bool trigger2 = false; +static bool trigger = false; // any coil, all coils thrown together static bool coil = false; // same about injectors @@ -65,7 +68,7 @@ int copyCompositeEvents(CompositeEvent *events) { event->timestamp = SWAP_UINT32(buffer[i].timestamp); event->primaryTrigger = buffer[i].priLevel; event->secondaryTrigger = buffer[i].secLevel; - event->isTDC = buffer[i].isTDC; + event->isTDC = buffer[i].trigger; event->sync = buffer[i].sync; event->coil = buffer[i].coil; event->injector = buffer[i].injector; @@ -76,13 +79,14 @@ int copyCompositeEvents(CompositeEvent *events) { #endif // EFI_UNIT_TEST static void SetNextCompositeEntry(efitick_t timestamp, bool trigger1, bool trigger2, - bool isTDC DECLARE_ENGINE_PARAMETER_SUFFIX) { + bool trigger DECLARE_ENGINE_PARAMETER_SUFFIX) { uint32_t nowUs = NT2US(timestamp); + // TS uses big endian, grumble buffer[NextIdx].timestamp = SWAP_UINT32(nowUs); buffer[NextIdx].priLevel = trigger1; buffer[NextIdx].secLevel = trigger2; - buffer[NextIdx].isTDC = isTDC; + buffer[NextIdx].trigger = trigger; buffer[NextIdx].sync = engine->triggerCentral.triggerState.shaft_is_synchronized; buffer[NextIdx].coil = coil; buffer[NextIdx].injector = injector; @@ -91,10 +95,24 @@ static void SetNextCompositeEntry(efitick_t timestamp, bool trigger1, bool trigg static_assert(sizeof(composite_logger_s) == COMPOSITE_PACKET_SIZE, "composite packet size"); - // If we hit the end, loop - if (NextIdx >= sizeof(buffer) / sizeof(buffer[0])) { - NextIdx = 0; + //If we hit the end, loop + if ((firstBuffer) && (NextIdx >= (COMPOSITE_PACKET_COUNT/2))) { + /* first half is full */ +#if EFI_TUNER_STUDIO + tsOutputChannels.toothLogReady = true; +#endif + firstBuffer = false; } + if ((!firstBuffer) && (NextIdx >= sizeof(buffer) / sizeof(buffer[0]))) { +#if EFI_TUNER_STUDIO + tsOutputChannels.toothLogReady = true; +#endif + NextIdx = 0; + firstBuffer = true; + } + + /////tsOutputChannels.toothLogReady = true; + } void LogTriggerTooth(trigger_event_e tooth, efitick_t timestamp DECLARE_ENGINE_PARAMETER_SUFFIX) { @@ -129,21 +147,25 @@ void LogTriggerTooth(trigger_event_e tooth, efitick_t timestamp DECLARE_ENGINE_P switch (tooth) { case SHAFT_PRIMARY_FALLING: trigger1 = false; + trigger = false; break; case SHAFT_PRIMARY_RISING: trigger1 = true; + trigger = false; break; case SHAFT_SECONDARY_FALLING: trigger2 = false; + trigger = true; break; case SHAFT_SECONDARY_RISING: trigger2 = true; + trigger = true; break; default: break; } - SetNextCompositeEntry(timestamp, trigger1, trigger2, false PASS_ENGINE_PARAMETER_SUFFIX); + SetNextCompositeEntry(timestamp, trigger1, trigger2, trigger PASS_ENGINE_PARAMETER_SUFFIX); } void LogTriggerTopDeadCenter(efitick_t timestamp DECLARE_ENGINE_PARAMETER_SUFFIX) { @@ -151,8 +173,9 @@ void LogTriggerTopDeadCenter(efitick_t timestamp DECLARE_ENGINE_PARAMETER_SUFFIX if (!ToothLoggerEnabled) { return; } - SetNextCompositeEntry(timestamp, trigger1, trigger2, true PASS_ENGINE_PARAMETER_SUFFIX); - SetNextCompositeEntry(timestamp + 10, trigger1, trigger2, false PASS_ENGINE_PARAMETER_SUFFIX); + UNUSED(timestamp); + //SetNextCompositeEntry(timestamp, trigger1, trigger2, true PASS_ENGINE_PARAMETER_SUFFIX); + //SetNextCompositeEntry(timestamp + 10, trigger1, trigger2, false PASS_ENGINE_PARAMETER_SUFFIX); } void LogTriggerCoilState(efitick_t timestamp, bool state DECLARE_ENGINE_PARAMETER_SUFFIX) { @@ -160,7 +183,8 @@ void LogTriggerCoilState(efitick_t timestamp, bool state DECLARE_ENGINE_PARAMETE return; } coil = state; - SetNextCompositeEntry(timestamp, trigger1, trigger2, false PASS_ENGINE_PARAMETER_SUFFIX); + UNUSED(timestamp); + //SetNextCompositeEntry(timestamp, trigger1, trigger2, trigger PASS_ENGINE_PARAMETER_SUFFIX); } void LogTriggerInjectorState(efitick_t timestamp, bool state DECLARE_ENGINE_PARAMETER_SUFFIX) { @@ -168,7 +192,8 @@ void LogTriggerInjectorState(efitick_t timestamp, bool state DECLARE_ENGINE_PARA return; } injector = state; - SetNextCompositeEntry(timestamp, trigger1, trigger2, false PASS_ENGINE_PARAMETER_SUFFIX); + UNUSED(timestamp); + //SetNextCompositeEntry(timestamp, trigger1, trigger2, trigger PASS_ENGINE_PARAMETER_SUFFIX); } void EnableToothLogger() { @@ -189,7 +214,7 @@ void EnableToothLogger() { // nb: this is a lie, as we may not have written anything // yet. However, we can let it continuously read out the buffer // as we update it, which looks pretty nice. - tsOutputChannels.toothLogReady = true; + tsOutputChannels.toothLogReady = false; #endif // EFI_TUNER_STUDIO } @@ -207,7 +232,18 @@ void DisableToothLogger() { } ToothLoggerBuffer GetToothLoggerBuffer() { - return { reinterpret_cast(buffer), sizeof(buffer) }; + if (firstBuffer) { +#if EFI_TUNER_STUDIO + tsOutputChannels.toothLogReady = false; +#endif + return { reinterpret_cast(ptr_buffer_second), (sizeof(buffer)/2) }; + } else { +#if EFI_TUNER_STUDIO + tsOutputChannels.toothLogReady = false; +#endif + return { reinterpret_cast(ptr_buffer_first), (sizeof(buffer)/2) }; + } } + #endif /* EFI_TOOTH_LOGGER */ diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 260dab3d61..637529a0e5 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -97,6 +97,7 @@ struct_no_prefix engine_configuration_s #define COMPOSITE_PACKET_COUNT 500 #define COMPOSITE_PACKET_SIZE 5 #define COMPOSITE_DATA_LENGTH @@COMPOSITE_PACKET_SIZE@@*@@COMPOSITE_PACKET_COUNT@@ +#define COMPOSITE_DATA_LENGTH_HALF @@COMPOSITE_DATA_LENGTH@@/2 #define MAP_ANGLE_SIZE 8 #define MAP_WINDOW_SIZE 8 diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 5edd5d084f..1bc4c02b2d 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -106,7 +106,7 @@ enable2ndByteCanID = false dataReadyCondition = { toothLogReady } continuousRead = true ; each packet is @@COMPOSITE_PACKET_SIZE@@ and we have @@COMPOSITE_PACKET_COUNT@@ of those - dataLength = @@COMPOSITE_DATA_LENGTH@@ + dataLength = @@COMPOSITE_DATA_LENGTH_HALF@@ ;tooth ; recordDef = headerLen, footerLen, recordLen @@ -124,7 +124,9 @@ enable2ndByteCanID = false recordField = secLevel, "SecLevel", 1, 1, 1.0, "Flag" recordField = trigger, "Trigger", 2, 1, 1.0, "Flag" recordField = sync, "Sync", 3, 1, 1.0, "Flag" - recordField = time, "Time", 8, 32, 0.01, "ms" + recordField = coil, "Coil", 4, 1, 1.0, "Flag" + recordField = inj, "Injector", 5, 1, 1.0, "Flag" + recordField = time, "Time", 8, 32, 0.001, "ms" ; it seems that TS also needs to know the diff.size of a tooth calcField = toothTime, "ToothTime", "ms", { time - pastValue(time, 1) }