From eb98e4c7e62c5f794dd2ba94260c7114e73d726b Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 25 Apr 2024 15:57:10 -0400 Subject: [PATCH] distinguish between "timestamp" and "duration" --- firmware/controllers/algo/engine_parts.h | 4 ++-- firmware/controllers/algo/rusefi_types.h | 2 ++ firmware/controllers/engine_cycle/map_averaging.h | 2 +- firmware/controllers/sensors/can_sensor.h | 4 ++-- firmware/controllers/sensors/core/functional_sensor.h | 2 +- firmware/controllers/sensors/core/stored_value_sensor.h | 4 ++-- firmware/controllers/sensors/frequency_sensor.h | 2 +- firmware/controllers/system/timer/event_queue.cpp | 2 +- firmware/controllers/system/timer/event_queue.h | 4 ++-- firmware/controllers/system/timer/single_timer_executor.cpp | 2 +- firmware/controllers/trigger/trigger_decoder.cpp | 4 ++-- firmware/hw_layer/debounce.h | 2 +- firmware/hw_layer/digital_input/trigger/trigger_input_adc.h | 4 ++-- firmware/util/peak_detect.h | 2 +- 14 files changed, 21 insertions(+), 19 deletions(-) diff --git a/firmware/controllers/algo/engine_parts.h b/firmware/controllers/algo/engine_parts.h index e338fa76b3..f8d1be246c 100644 --- a/firmware/controllers/algo/engine_parts.h +++ b/firmware/controllers/algo/engine_parts.h @@ -70,7 +70,7 @@ public: struct multispark_state { - efitick_t delay = 0; - efitick_t dwell = 0; + efidur_t delay = 0; + efidur_t dwell = 0; uint8_t count = 0; }; diff --git a/firmware/controllers/algo/rusefi_types.h b/firmware/controllers/algo/rusefi_types.h index ec36b67bfb..ec51cdc03a 100644 --- a/firmware/controllers/algo/rusefi_types.h +++ b/firmware/controllers/algo/rusefi_types.h @@ -42,6 +42,8 @@ */ using efitimems_t = uint32_t; +using efidur_t = efitick_t; + // date-time struct a la ctime struct tm typedef struct { uint32_t year = 0; diff --git a/firmware/controllers/engine_cycle/map_averaging.h b/firmware/controllers/engine_cycle/map_averaging.h index 1e83d8e41a..21e83f728d 100644 --- a/firmware/controllers/engine_cycle/map_averaging.h +++ b/firmware/controllers/engine_cycle/map_averaging.h @@ -32,7 +32,7 @@ void postMapState(TunerStudioOutputChannels *tsOutputChannels); class MapAverager : public StoredValueSensor { public: - MapAverager(SensorType type, efitick_t timeout) + MapAverager(SensorType type, efidur_t timeout) : StoredValueSensor(type, timeout) { } diff --git a/firmware/controllers/sensors/can_sensor.h b/firmware/controllers/sensors/can_sensor.h index 3288813e10..3a6ab620d7 100644 --- a/firmware/controllers/sensors/can_sensor.h +++ b/firmware/controllers/sensors/can_sensor.h @@ -19,7 +19,7 @@ */ class CanSensorBase : public StoredValueSensor, public CanListener { public: - CanSensorBase(uint32_t eid, SensorType type, efitick_t timeout) + CanSensorBase(uint32_t eid, SensorType type, efidur_t timeout) : StoredValueSensor(type, timeout) , CanListener(eid) { @@ -31,7 +31,7 @@ public: template class CanSensor : public CanSensorBase { public: - CanSensor(uint32_t eid, uint8_t offset, SensorType type, efitick_t timeout) + CanSensor(uint32_t eid, uint8_t offset, SensorType type, efidur_t timeout) : CanSensorBase(eid, type, timeout) , m_offset(offset) { diff --git a/firmware/controllers/sensors/core/functional_sensor.h b/firmware/controllers/sensors/core/functional_sensor.h index aaef8b1c32..932ca5b274 100644 --- a/firmware/controllers/sensors/core/functional_sensor.h +++ b/firmware/controllers/sensors/core/functional_sensor.h @@ -25,7 +25,7 @@ */ class FunctionalSensor : public StoredValueSensor { public: - FunctionalSensor(SensorType type, efitick_t timeoutPeriod) + FunctionalSensor(SensorType type, efidur_t timeoutPeriod) : StoredValueSensor(type, timeoutPeriod) { } void postRawValue(float inputValue, efitick_t timestamp); diff --git a/firmware/controllers/sensors/core/stored_value_sensor.h b/firmware/controllers/sensors/core/stored_value_sensor.h index 43649f7a69..5ba51f1c21 100644 --- a/firmware/controllers/sensors/core/stored_value_sensor.h +++ b/firmware/controllers/sensors/core/stored_value_sensor.h @@ -51,7 +51,7 @@ public: return result; } - StoredValueSensor(SensorType type, efitick_t timeoutNt) + StoredValueSensor(SensorType type, efidur_t timeoutNt) : Sensor(type) , m_result(unexpected) , m_timeoutPeriod(timeoutNt) @@ -84,6 +84,6 @@ public: private: SensorResult m_result; - efitick_t m_timeoutPeriod; + efidur_t m_timeoutPeriod; efitick_t m_lastUpdate = 0; }; diff --git a/firmware/controllers/sensors/frequency_sensor.h b/firmware/controllers/sensors/frequency_sensor.h index f314411378..c18af20cb2 100644 --- a/firmware/controllers/sensors/frequency_sensor.h +++ b/firmware/controllers/sensors/frequency_sensor.h @@ -7,7 +7,7 @@ class FrequencySensor : public FunctionalSensor { public: - FrequencySensor(SensorType type, efitick_t timeoutPeriod) + FrequencySensor(SensorType type, efidur_t timeoutPeriod) : FunctionalSensor(type, timeoutPeriod) { } diff --git a/firmware/controllers/system/timer/event_queue.cpp b/firmware/controllers/system/timer/event_queue.cpp index 5515ec957c..13596cde0a 100644 --- a/firmware/controllers/system/timer/event_queue.cpp +++ b/firmware/controllers/system/timer/event_queue.cpp @@ -21,7 +21,7 @@ extern int timeNowUs; extern bool verboseMode; #endif /* EFI_UNIT_TEST */ -EventQueue::EventQueue(efitick_t lateDelay) +EventQueue::EventQueue(efidur_t lateDelay) : m_lateDelay(lateDelay) { for (size_t i = 0; i < efi::size(m_pool); i++) { diff --git a/firmware/controllers/system/timer/event_queue.h b/firmware/controllers/system/timer/event_queue.h index 0a34da6024..89867d370a 100644 --- a/firmware/controllers/system/timer/event_queue.h +++ b/firmware/controllers/system/timer/event_queue.h @@ -44,7 +44,7 @@ public: // See comment in EventQueue::executeAll for info about lateDelay - it sets the // time gap between events for which we will wait instead of rescheduling the next // event in a group of events near one another. - explicit EventQueue(efitick_t lateDelay = 0); + explicit EventQueue(efidur_t lateDelay = 0); /** * O(size) - linear search in sorted linked list @@ -69,7 +69,7 @@ private: * this list is sorted */ scheduling_s *m_head = nullptr; - const efitick_t m_lateDelay; + const efidur_t m_lateDelay; scheduling_s* m_freelist = nullptr; scheduling_s m_pool[64]; diff --git a/firmware/controllers/system/timer/single_timer_executor.cpp b/firmware/controllers/system/timer/single_timer_executor.cpp index 34a7d74355..1f50184580 100644 --- a/firmware/controllers/system/timer/single_timer_executor.cpp +++ b/firmware/controllers/system/timer/single_timer_executor.cpp @@ -67,7 +67,7 @@ void SingleTimerExecutor::scheduleByTimestampNt(const char *msg, scheduling_s* s ScopePerf perf(PE::SingleTimerExecutorScheduleByTimestamp); #if EFI_ENABLE_ASSERTS - efitick_t deltaTimeNt = nt - getTimeNowNt(); + efidur_t deltaTimeNt = nt - getTimeNowNt(); if (deltaTimeNt >= TOO_FAR_INTO_FUTURE_NT) { // we are trying to set callback for too far into the future. This does not look right at all diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index e8b418c75a..8ee5d43659 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -71,7 +71,7 @@ void TriggerDecoderBase::resetState() { m_timeSinceDecodeError.init(); prevSignal = SHAFT_PRIMARY_FALLING; - startOfCycleNt = 0; + startOfCycleNt = {}; resetCurrentCycleState(); @@ -406,7 +406,7 @@ expected TriggerDecoderBase::decodeTriggerEvent( firmwareError(ObdCode::CUSTOM_OBD_93, "[%s] toothed_previous_time after nowNt prev=%d now=%d", msg, toothed_previous_time, nowNt); } - efitick_t currentDurationLong = isFirstEvent ? 0 : nowNt - toothed_previous_time; + efidur_t currentDurationLong = isFirstEvent ? 0 : (nowNt - toothed_previous_time); /** * For performance reasons, we want to work with 32 bit values. If there has been more then diff --git a/firmware/hw_layer/debounce.h b/firmware/hw_layer/debounce.h index a058170662..0e09830f18 100644 --- a/firmware/hw_layer/debounce.h +++ b/firmware/hw_layer/debounce.h @@ -27,7 +27,7 @@ public: bool getPhysicalState(); private: const char* const m_name; - efitick_t m_threshold; + efidur_t m_threshold; Timer timeLast; brain_pin_e *m_pin; brain_pin_e active_pin = Gpio::Unassigned; diff --git a/firmware/hw_layer/digital_input/trigger/trigger_input_adc.h b/firmware/hw_layer/digital_input/trigger/trigger_input_adc.h index 7500e13ee0..27605f885c 100644 --- a/firmware/hw_layer/digital_input/trigger/trigger_input_adc.h +++ b/firmware/hw_layer/digital_input/trigger/trigger_input_adc.h @@ -43,8 +43,8 @@ public: // these thresholds allow to switch from ADC mode (low-rpm) to EXTI mode (fast-rpm), indicating the clamping of the signal triggerAdcSample_t switchingThresholdLow = 0, switchingThresholdHigh = 0; - efitick_t minDeltaTimeForStableAdcDetectionNt = 0; - efitick_t stampCorrectionForAdc = 0; + efidur_t minDeltaTimeForStableAdcDetectionNt = 0; + efidur_t stampCorrectionForAdc = 0; int switchingCnt = 0, switchingTeethCnt = 0; int prevValue = 0; // not set efitick_t prevStamp = 0; diff --git a/firmware/util/peak_detect.h b/firmware/util/peak_detect.h index f5496dd774..d50d57f8a1 100644 --- a/firmware/util/peak_detect.h +++ b/firmware/util/peak_detect.h @@ -5,7 +5,7 @@ /** * Stores the recent peak value, preventing loss of intermittent peaks in a signal. */ -template +template class PeakDetect { public: TValue detect(TValue currentValue, efitick_t nowNt) {