diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 2f3e4a8c02..977107a14c 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -451,7 +451,7 @@ void Engine::efiWatchdog() { return; } - if (engine->configBurnTimer.hasElapsedSec(5) && engineConfiguration->tempBooleanForVerySpecialLogic) { + if (engineConfiguration->tempBooleanForVerySpecialLogic && engine->configBurnTimer.hasElapsedSec(5)) { static efitimems_t mostRecentMs = 0; efitimems_t msNow = getTimeNowMs(); @@ -575,15 +575,6 @@ bool Engine::isMainRelayEnabled() const { #endif /* EFI_MAIN_RELAY_CONTROL */ } - -float Engine::getTimeIgnitionSeconds(void) const { - // return negative if the ignition is turned off - if (ignitionOnTimeNt == 0) - return -1; - float numSeconds = (float)NT2US(getTimeNowNt() - ignitionOnTimeNt) / US_PER_SECOND_F; - return numSeconds; -} - injection_mode_e getCurrentInjectionMode() { return getEngineRotationState()->isCranking() ? engineConfiguration->crankingInjectionMode : engineConfiguration->injectionMode; } diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 9fac0e2365..7b1d220298 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -280,7 +280,7 @@ public: int startStopStateToggleCounter = 0; /** - * this is needed by getTimeIgnitionSeconds() and checkShutdown() + * this is needed by and checkShutdown() * todo: refactor to Timer? */ efitick_t ignitionOnTimeNt = 0; @@ -378,13 +378,6 @@ public: */ bool isMainRelayEnabled() const; - /** - * Needed by EFI_MAIN_RELAY_CONTROL to handle fuel pump and shutdown timings correctly. - * This method returns the number of seconds since the ignition voltage is present. - * The return value is float for more FSIO flexibility. - */ - float getTimeIgnitionSeconds(void) const; - void onSparkFireKnockSense(uint8_t cylinderIndex, efitick_t nowNt); #if EFI_UNIT_TEST diff --git a/firmware/controllers/algo/rusefi_types.h b/firmware/controllers/algo/rusefi_types.h index a46dd70187..7f47046e41 100644 --- a/firmware/controllers/algo/rusefi_types.h +++ b/firmware/controllers/algo/rusefi_types.h @@ -41,14 +41,6 @@ using time_t = uint32_t; // time in seconds using efitimesec_t = time_t; -/** - * integer time in milliseconds (1/1_000 of a second) - * 32 bit 4B / 1000 = 4M seconds = 1111.11 hours = 23(or46?) days. - * Please restart your ECU every 23(or46?) days? :) See issue https://github.com/rusefi/rusefi/issues/4554 tag#4554 - * See getTimeNowUs() - */ -using efitimems_t = uint32_t; - /** * We use a signed type here so that subtraction result is a proper negative value. * A typical use-case negative result is when we do 'timeNow() - timeOfEvent' where timeOfEvent @@ -58,24 +50,30 @@ using efitimems_t = uint32_t; * See US2NT * See MS2US */ -using efitime_t = int64_t; + +/** + * platform-dependent tick since boot + * in case of stm32f4 that's 32-bit timer ticks (SCHEDULER_TIMER_DEVICE == TIM5) extended to 64 bits + */ +using efitick_t = int64_t; /** * 64 bit time in microseconds (1/1_000_000 of a second), since boot */ -using efitimeus_t = efitime_t; +using efitimeus_t = int64_t; /** * 64 bit time in milliseconds (1/1_000 of a second), since boot */ -using efitimems64_t = efitime_t; - +using efitimems64_t = int64_t; /** - * platform-dependent tick since boot - * in case of stm32f4 that's a CPU tick + * integer time in milliseconds (1/1_000 of a second) + * 32 bit 4B / 1000 = 4M seconds = 1111.11 hours = 23(or46?) days. + * Please restart your ECU every 23(or46?) days? :) See issue https://github.com/rusefi/rusefi/issues/4554 tag#4554 + * See getTimeNowUs() */ -using efitick_t = efitime_t; +using efitimems_t = uint32_t; using angle_t = float; diff --git a/firmware/controllers/can/can.h b/firmware/controllers/can/can.h index 380ff31c57..bdac32c78d 100644 --- a/firmware/controllers/can/can.h +++ b/firmware/controllers/can/can.h @@ -54,7 +54,7 @@ void registerCanSensor(CanSensorBase& sensor); class CanWrite final : public PeriodicController<512> { public: CanWrite(); - void PeriodicTask(efitime_t nowNt) override; + void PeriodicTask(efitick_t nowNt) override; }; // allow using shorthand CI diff --git a/firmware/controllers/can/can_tx.cpp b/firmware/controllers/can/can_tx.cpp index 463ad5b4b1..061e5897b9 100644 --- a/firmware/controllers/can/can_tx.cpp +++ b/firmware/controllers/can/can_tx.cpp @@ -25,7 +25,7 @@ CanWrite::CanWrite() { } -void CanWrite::PeriodicTask(efitime_t nowNt) { +void CanWrite::PeriodicTask(efitick_t nowNt) { UNUSED(nowNt); static uint16_t cycleCount = 0; CanCycle cycle(cycleCount); diff --git a/firmware/controllers/engine_cycle/rpm_calculator.cpp b/firmware/controllers/engine_cycle/rpm_calculator.cpp index cfb3dc3613..bce118e58e 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.cpp +++ b/firmware/controllers/engine_cycle/rpm_calculator.cpp @@ -376,7 +376,7 @@ efitick_t scheduleByAngle(scheduling_s *timer, efitick_t edgeTimestamp, angle_t // 'delayNt' is below 10 seconds here so we use 32 bit type for performance reasons int32_t delayNt = USF2NT(delayUs); - efitime_t delayedTime = edgeTimestamp + delayNt; + efitick_t delayedTime = edgeTimestamp + delayNt; engine->executor.scheduleByTimestampNt("angle", timer, delayedTime, action); diff --git a/firmware/controllers/system/timer/event_queue.cpp b/firmware/controllers/system/timer/event_queue.cpp index d1f717ba02..ce0e647cf2 100644 --- a/firmware/controllers/system/timer/event_queue.cpp +++ b/firmware/controllers/system/timer/event_queue.cpp @@ -25,7 +25,7 @@ extern bool verboseMode; /** * @return true if inserted into the head of the list */ -bool EventQueue::insertTask(scheduling_s *scheduling, efitime_t timeX, action_s action) { +bool EventQueue::insertTask(scheduling_s *scheduling, efitick_t timeX, action_s action) { ScopePerf perf(PE::EventQueueInsertTask); #if EFI_UNIT_TEST @@ -128,7 +128,7 @@ void EventQueue::remove(scheduling_s* scheduling) { * This method is always invoked under a lock * @return Get the timestamp of the soonest pending action, skipping all the actions in the past */ -expected EventQueue::getNextEventTime(efitime_t nowX) const { +expected EventQueue::getNextEventTime(efitick_t nowX) const { if (head != NULL) { if (head->momentX <= nowX) { /** @@ -157,7 +157,7 @@ uint32_t maxEventCallbackDuration = 0; * Invoke all pending actions prior to specified timestamp * @return number of executed actions */ -int EventQueue::executeAll(efitime_t now) { +int EventQueue::executeAll(efitick_t now) { ScopePerf perf(PE::EventQueueExecuteAll); int executionCounter = 0; @@ -175,7 +175,7 @@ int EventQueue::executeAll(efitime_t now) { return executionCounter; } -bool EventQueue::executeOne(efitime_t now) { +bool EventQueue::executeOne(efitick_t now) { // Read the head every time - a previously executed event could // have inserted something new at the head scheduling_s* current = head; diff --git a/firmware/controllers/system/timer/event_queue.h b/firmware/controllers/system/timer/event_queue.h index ca7bb0dcd2..b7d2564883 100644 --- a/firmware/controllers/system/timer/event_queue.h +++ b/firmware/controllers/system/timer/event_queue.h @@ -44,18 +44,18 @@ 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. - EventQueue(efitime_t lateDelay = 0) : lateDelay(lateDelay) {} + EventQueue(efitick_t lateDelay = 0) : lateDelay(lateDelay) {} /** * O(size) - linear search in sorted linked list */ - bool insertTask(scheduling_s *scheduling, efitime_t timeX, action_s action); + bool insertTask(scheduling_s *scheduling, efitick_t timeX, action_s action); void remove(scheduling_s* scheduling); - int executeAll(efitime_t now); - bool executeOne(efitime_t now); + int executeAll(efitick_t now); + bool executeOne(efitick_t now); - expected getNextEventTime(efitime_t nowUs) const; + expected getNextEventTime(efitick_t nowUs) const; void clear(void); int size(void) const; scheduling_s *getElementAtIndexForUnitText(int index); @@ -66,6 +66,6 @@ private: * this list is sorted */ scheduling_s *head = nullptr; - const efitime_t lateDelay; + const efitick_t lateDelay; }; diff --git a/firmware/controllers/system/timer/scheduler.h b/firmware/controllers/system/timer/scheduler.h index 4c59fd13be..47b35abe04 100644 --- a/firmware/controllers/system/timer/scheduler.h +++ b/firmware/controllers/system/timer/scheduler.h @@ -47,7 +47,7 @@ struct scheduling_s { /** * timestamp represented as 64-bit value of ticks since MCU start */ - volatile efitime_t momentX = 0; + volatile efitick_t momentX = 0; /** * Scheduler implementation uses a sorted linked list of these scheduling records. @@ -63,7 +63,7 @@ struct ExecutorInterface { * see also scheduleByAngle */ virtual void scheduleByTimestamp(const char *msg, scheduling_s *scheduling, efitimeus_t timeUs, action_s action) = 0; - virtual void scheduleByTimestampNt(const char *msg, scheduling_s *scheduling, efitime_t timeUs, action_s action) = 0; + virtual void scheduleByTimestampNt(const char *msg, scheduling_s *scheduling, efitick_t timeNt, action_s action) = 0; virtual void scheduleForLater(const char *msg, scheduling_s *scheduling, int delayUs, action_s action) = 0; virtual void cancel(scheduling_s* scheduling) = 0; }; diff --git a/firmware/controllers/system/timer/single_timer_executor.cpp b/firmware/controllers/system/timer/single_timer_executor.cpp index 92e02cc436..981f17e611 100644 --- a/firmware/controllers/system/timer/single_timer_executor.cpp +++ b/firmware/controllers/system/timer/single_timer_executor.cpp @@ -63,7 +63,7 @@ void SingleTimerExecutor::scheduleByTimestamp(const char *msg, scheduling_s *sch scheduleByTimestampNt(msg, scheduling, US2NT(timeUs), action); } -void SingleTimerExecutor::scheduleByTimestampNt(const char *msg, scheduling_s* scheduling, efitime_t nt, action_s action) { +void SingleTimerExecutor::scheduleByTimestampNt(const char *msg, scheduling_s* scheduling, efitick_t nt, action_s action) { ScopePerf perf(PE::SingleTimerExecutorScheduleByTimestamp); #if EFI_ENABLE_ASSERTS diff --git a/firmware/controllers/system/timer/single_timer_executor.h b/firmware/controllers/system/timer/single_timer_executor.h index e8c055cd0e..a82e18bb2b 100644 --- a/firmware/controllers/system/timer/single_timer_executor.h +++ b/firmware/controllers/system/timer/single_timer_executor.h @@ -14,7 +14,7 @@ class SingleTimerExecutor final : public ExecutorInterface { public: SingleTimerExecutor(); void scheduleByTimestamp(const char *msg, scheduling_s *scheduling, efitimeus_t timeUs, action_s action) override; - void scheduleByTimestampNt(const char *msg, scheduling_s *scheduling, efitime_t timeNt, action_s action) override; + void scheduleByTimestampNt(const char *msg, scheduling_s *scheduling, efitick_t timeNt, action_s action) override; void scheduleForLater(const char *msg, scheduling_s *scheduling, int delayUs, action_s action) override; void cancel(scheduling_s* scheduling) override; diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index 201a3868bc..6ad12ddb23 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -75,7 +75,7 @@ public: */ void incrementShaftSynchronizationCounter(); - efitime_t getTotalEventCounter() const; + int64_t getTotalEventCounter() const; expected decodeTriggerEvent( const char *msg, @@ -83,7 +83,7 @@ public: TriggerStateListener* triggerStateListener, const TriggerConfiguration& triggerConfiguration, const trigger_event_e signal, - const efitime_t nowUs); + const efitick_t nowNt); void onShaftSynchronization( bool wasSynchronized, diff --git a/firmware/development/logic_analyzer.cpp b/firmware/development/logic_analyzer.cpp index 05124ab362..7bbe4da840 100644 --- a/firmware/development/logic_analyzer.cpp +++ b/firmware/development/logic_analyzer.cpp @@ -170,7 +170,7 @@ static float getSignalOnTime(int index) { return reader.last_wave_high_widthUs / 1000.0f; } -static efitime_t getWaveOffset(int index) { +static efitimeus_t getWaveOffset(int index) { return readers[index].waveOffsetUs; } @@ -211,7 +211,7 @@ static void reportWave(Logging *logging, int index) { logging->appendFloat(periodMs, 2); logging->appendPrintf("%s", LOG_DELIMITER); - uint32_t offsetUs = getWaveOffset(index); + efitimeus_t offsetUs = getWaveOffset(index); int rpm = Sensor::getOrZero(SensorType::Rpm); if (rpm != 0) { float oneDegreeUs = getOneDegreeTimeUs(rpm); diff --git a/firmware/hw_layer/digital_input/trigger/trigger_input_adc.cpp b/firmware/hw_layer/digital_input/trigger/trigger_input_adc.cpp index cbd23ce6d8..8a3d3d1170 100644 --- a/firmware/hw_layer/digital_input/trigger/trigger_input_adc.cpp +++ b/firmware/hw_layer/digital_input/trigger/trigger_input_adc.cpp @@ -369,7 +369,7 @@ void TriggerAdcDetector::analogCallback(efitick_t stamp, triggerAdcSample_t valu integralSum = 0; #if 0 // update triggerAdcITerm - efitime_t deltaTimeUs = NT2US(stamp - prevStamp); + efitimeus_t deltaTimeUs = NT2US(stamp - prevStamp); if (deltaTimeUs > 200) { // 200 us = ~2500 RPM (we don't need this correction for large RPM) triggerAdcITerm = 1.0f / (triggerAdcITermCoef * deltaTimeUs); triggerAdcITerm = maxF(triggerAdcITerm, triggerAdcITermMin); diff --git a/firmware/util/efitime.h b/firmware/util/efitime.h index 0a3e07f46e..d55ec6e692 100644 --- a/firmware/util/efitime.h +++ b/firmware/util/efitime.h @@ -27,9 +27,9 @@ #define US2MS(US_TIME) ((US_TIME) / 1000) // microseconds to ticks -// since only about 20 seconds of ticks fit in 32 bits this macro is casting parameter into 64 bits 'efitime_t' type +// since only about 20 seconds of ticks fit in 32 bits this macro is casting parameter into 64 bits 'efitick_t' type // please note that int64 <-> float is a heavy operation thus we have 'USF2NT' below -#define US2NT(us) (((efitime_t)(us)) * US_TO_NT_MULTIPLIER) +#define US2NT(us) (((efitick_t)(us)) * US_TO_NT_MULTIPLIER) // microseconds to ticks, but floating point // If converting a floating point time period, use this macro to avoid diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index c47bd3473a..d975ba79e2 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -288,22 +288,22 @@ void EngineTestHelper::fireTriggerEvents(int count) { fireTriggerEvents2(count, 5); // 5ms } -void EngineTestHelper::assertInjectorUpEvent(const char *msg, int eventIndex, efitime_t momentX, long injectorIndex) { +void EngineTestHelper::assertInjectorUpEvent(const char *msg, int eventIndex, efitimeus_t momentX, long injectorIndex) { InjectionEvent *event = &engine.injectionEvents.elements[injectorIndex]; assertEvent(msg, eventIndex, (void*)turnInjectionPinHigh, momentX, event); } -void EngineTestHelper::assertInjectorDownEvent(const char *msg, int eventIndex, efitime_t momentX, long injectorIndex) { +void EngineTestHelper::assertInjectorDownEvent(const char *msg, int eventIndex, efitimeus_t momentX, long injectorIndex) { InjectionEvent *event = &engine.injectionEvents.elements[injectorIndex]; assertEvent(msg, eventIndex, (void*)turnInjectionPinLow, momentX, event); } -scheduling_s * EngineTestHelper::assertEvent5(const char *msg, int index, void *callback, efitime_t expectedTimestamp) { +scheduling_s * EngineTestHelper::assertEvent5(const char *msg, int index, void *callback, efitimeus_t expectedTimestamp) { TestExecutor *executor = &engine.executor; EXPECT_TRUE(executor->size() > index) << msg << " valid index"; scheduling_s *event = executor->getForUnitTest(index); assertEqualsM4(msg, " callback up/down", (void*)event->action.getCallback() == (void*) callback, 1); - efitime_t start = getTimeNowUs(); + efitimeus_t start = getTimeNowUs(); assertEqualsM4(msg, " timestamp", expectedTimestamp, event->momentX - start); return event; } @@ -322,12 +322,12 @@ AngleBasedEvent * EngineTestHelper::assertTriggerEvent(const char *msg, return event; } -scheduling_s * EngineTestHelper::assertScheduling(const char *msg, int index, scheduling_s *expected, void *callback, efitime_t expectedTimestamp) { +scheduling_s * EngineTestHelper::assertScheduling(const char *msg, int index, scheduling_s *expected, void *callback, efitimeus_t expectedTimestamp) { scheduling_s * actual = assertEvent5(msg, index, callback, expectedTimestamp); return actual; } -void EngineTestHelper::assertEvent(const char *msg, int index, void *callback, efitime_t momentX, InjectionEvent *expectedEvent) { +void EngineTestHelper::assertEvent(const char *msg, int index, void *callback, efitimeus_t momentX, InjectionEvent *expectedEvent) { scheduling_s *event = assertEvent5(msg, index, callback, momentX); InjectionEvent *actualEvent = (InjectionEvent *)event->action.getArgument(); diff --git a/unit_tests/engine_test_helper.h b/unit_tests/engine_test_helper.h index 8511e9cabb..ced719dd37 100644 --- a/unit_tests/engine_test_helper.h +++ b/unit_tests/engine_test_helper.h @@ -81,14 +81,14 @@ public: */ void clearQueue(); - scheduling_s * assertEvent5(const char *msg, int index, void *callback, efitime_t expectedTimestamp); - scheduling_s * assertScheduling(const char *msg, int index, scheduling_s *expected, void *callback, efitime_t expectedTimestamp); + scheduling_s * assertEvent5(const char *msg, int index, void *callback, efitimeus_t expectedTimestamp); + scheduling_s * assertScheduling(const char *msg, int index, scheduling_s *expected, void *callback, efitimeus_t expectedTimestamp); AngleBasedEvent * assertTriggerEvent(const char *msg, int index, AngleBasedEvent *expected, void *callback, int triggerEventIndex, angle_t angleOffsetFromTriggerEvent); - void assertEvent(const char *msg, int index, void *callback, efitime_t momentX, InjectionEvent *event); - void assertInjectorUpEvent(const char *msg, int eventIndex, efitime_t momentX, long injectorIndex); - void assertInjectorDownEvent(const char *msg, int eventIndex, efitime_t momentX, long injectorIndex); + void assertEvent(const char *msg, int index, void *callback, efitimeus_t momentX, InjectionEvent *event); + void assertInjectorUpEvent(const char *msg, int eventIndex, efitimeus_t momentX, long injectorIndex); + void assertInjectorDownEvent(const char *msg, int eventIndex, efitimeus_t momentX, long injectorIndex); // todo: open question if this is worth a helper method or should be inlined? void assertRpm(int expectedRpm, const char *msg); diff --git a/unit_tests/global_execution_queue.cpp b/unit_tests/global_execution_queue.cpp index 303ab01d51..cb281cdb94 100644 --- a/unit_tests/global_execution_queue.cpp +++ b/unit_tests/global_execution_queue.cpp @@ -28,7 +28,7 @@ void TestExecutor::scheduleForLater(const char *msg, scheduling_s *scheduling, i scheduleByTimestamp("test", scheduling, getTimeNowUs() + delayUs, action); } -int TestExecutor::executeAll(efitime_t now) { +int TestExecutor::executeAll(efitick_t now) { return schedulingQueue.executeAll(now); } diff --git a/unit_tests/global_execution_queue.h b/unit_tests/global_execution_queue.h index 79fd4834fc..7962fcea9b 100644 --- a/unit_tests/global_execution_queue.h +++ b/unit_tests/global_execution_queue.h @@ -20,7 +20,7 @@ public: void cancel(scheduling_s* scheduling) override; void clear(); - int executeAll(efitime_t now); + int executeAll(efitick_t now); int size(); scheduling_s * getHead(); scheduling_s * getForUnitTest(int index); diff --git a/unit_tests/mocks.h b/unit_tests/mocks.h index 3f6382cfca..cd1fec8ee3 100644 --- a/unit_tests/mocks.h +++ b/unit_tests/mocks.h @@ -79,7 +79,7 @@ public: virtual ~MockExecutor(); MOCK_METHOD(void, scheduleByTimestamp, (const char *msg, scheduling_s *scheduling, efitimeus_t timeUs, action_s action), (override)); - MOCK_METHOD(void, scheduleByTimestampNt, (const char *msg, scheduling_s *scheduling, efitime_t timeUs, action_s action), (override)); + MOCK_METHOD(void, scheduleByTimestampNt, (const char *msg, scheduling_s *scheduling, efitick_t timeNt, action_s action), (override)); MOCK_METHOD(void, scheduleForLater, (const char *msg, scheduling_s *scheduling, int delayUs, action_s action), (override)); MOCK_METHOD(void, cancel, (scheduling_s*), (override)); };