From 0079636f4c921f2b87ab16875050862a9576e308 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Tue, 11 Nov 2014 10:04:06 -0600 Subject: [PATCH] auto-sync --- firmware/controllers/algo/wave_chart.cpp | 11 +++++++---- firmware/controllers/algo/wave_chart.h | 3 ++- firmware/controllers/trigger/trigger_decoder.cpp | 10 +++++----- firmware/controllers/trigger/trigger_decoder.h | 1 - 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/firmware/controllers/algo/wave_chart.cpp b/firmware/controllers/algo/wave_chart.cpp index 179b3d37a6..74c28d569e 100644 --- a/firmware/controllers/algo/wave_chart.cpp +++ b/firmware/controllers/algo/wave_chart.cpp @@ -79,7 +79,7 @@ void WaveChart::resetWaveChart() { static char WAVE_LOGGING_BUFFER[WAVE_LOGGING_SIZE] CCM_OPTIONAL ; -int WaveChart::isWaveChartFull() { +bool_t WaveChart::isStartedTooLongAgo() { /** * Say at 300rpm we should get at least four events per revolution. * That's 300/60*4=20 events per second @@ -87,8 +87,11 @@ int WaveChart::isWaveChartFull() { * */ uint64_t chartDurationNt = getTimeNowNt() - startTimeNt; - bool startedTooLongAgo = startTimeNt!= 0 && NT2US(chartDurationNt) > engineConfiguration->digitalChartSize * 1000000 / 20; - return startedTooLongAgo || counter >= engineConfiguration->digitalChartSize; + return startTimeNt!= 0 && NT2US(chartDurationNt) > engineConfiguration->digitalChartSize * 1000000 / 20; +} + +bool_t WaveChart::isWaveChartFull() { + return counter >= engineConfiguration->digitalChartSize; } static void printStatus(void) { @@ -110,7 +113,7 @@ void setChartSize(int newSize) { } void WaveChart::publishChartIfFull() { - if (isWaveChartFull()) { + if (isWaveChartFull() || isStartedTooLongAgo()) { publishChart(); resetWaveChart(); } diff --git a/firmware/controllers/algo/wave_chart.h b/firmware/controllers/algo/wave_chart.h index 2a01e56320..48033f991b 100644 --- a/firmware/controllers/algo/wave_chart.h +++ b/firmware/controllers/algo/wave_chart.h @@ -23,7 +23,8 @@ public: void init(); void publishChart(); void resetWaveChart(); - int isWaveChartFull(); + bool_t isWaveChartFull(); + bool_t isStartedTooLongAgo(); void publishChartIfFull(); void addWaveChartEvent3(const char *name, const char *msg, const char *msg2); private: diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 6a56d3830a..b50aefc5cc 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -95,11 +95,9 @@ float TriggerState::getTriggerDutyCycle(int index) { static trigger_wheel_e eventIndex[6] = { T_PRIMARY, T_PRIMARY, T_SECONDARY, T_SECONDARY, T_CHANNEL_3, T_CHANNEL_3 }; static trigger_value_e eventType[6] = { TV_LOW, TV_HIGH, TV_LOW, TV_HIGH, TV_LOW, TV_HIGH }; -uint64_t TriggerState::getCurrentGapDuration(uint64_t nowUs) { - int64_t currentDuration = isFirstEvent ? 0 : nowUs - toothed_previous_time; - isFirstEvent = false; - return currentDuration; -} +#define getCurrentGapDuration(nowUs) \ + (isFirstEvent ? 0 : (nowUs) - toothed_previous_time) + /** * @brief Trigger decoding happens here @@ -124,12 +122,14 @@ void TriggerState::decodeTriggerEvent(trigger_shape_s const*triggerShape, trigge nextTriggerEvent(triggerWheel, nowUs); if (triggerShape->gapBothDirections) { toothed_previous_duration = getCurrentGapDuration(nowUs); + isFirstEvent = false; toothed_previous_time = nowUs; } return; } int64_t currentDuration = getCurrentGapDuration(nowUs); + isFirstEvent = false; efiAssertVoid(currentDuration >= 0, "decode: negative duration?"); // todo: skip a number of signal from the beginning diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index 4b54cf61bb..d9cfe1ebf8 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -50,7 +50,6 @@ public: private: void clear(); - uint64_t getCurrentGapDuration(uint64_t nowUs); /** * index within trigger revolution, from 0 to trigger event count */