diff --git a/firmware/controllers/system/SingleTimerExecutor.cpp b/firmware/controllers/system/SingleTimerExecutor.cpp index 5522b5d525..01c5d81e48 100644 --- a/firmware/controllers/system/SingleTimerExecutor.cpp +++ b/firmware/controllers/system/SingleTimerExecutor.cpp @@ -34,7 +34,6 @@ extern schfunc_t globalTimerCallback; * these fields are global in order to facilitate debugging */ static uint64_t nextEventTimeNt = 0; -static uint64_t hwAlarmTime = 0; uint32_t beforeHwSetTimer; uint32_t hwSetTimerTime; @@ -74,9 +73,12 @@ void Executor::scheduleByTime(scheduling_s *scheduling, efitimeus_t timeUs, schf // this would guard the queue and disable interrupts lockAnyContext(); } - queue.insertTask(scheduling, US2NT(timeUs), callback, param); + bool_t needToResetTimer = queue.insertTask(scheduling, US2NT(timeUs), callback, param); if (!reentrantFlag) { doExecute(); + if (needToResetTimer) { + scheduleTimerCallback(); + } unlockAnyContext(); } } @@ -89,6 +91,7 @@ void Executor::schedule(scheduling_s *scheduling, uint64_t nowUs, int delayUs, s void Executor::onTimerCallback() { lockAnyContext(); doExecute(); + scheduleTimerCallback(); unlockAnyContext(); } @@ -122,19 +125,19 @@ void Executor::doExecute() { firmwareError("Someone has stolen my lock"); return; } - uint64_t nowNt = getTimeNowNt(); reentrantFlag = false; +} + +void Executor::scheduleTimerCallback() { /** - * 'executeAll' is potentially invoking heavy callbacks, let's grab fresh time value? - */ - /** - * Let's set up the timer for the next execution + * Let's grab fresh time value */ + uint64_t nowNt = getTimeNowNt(); nextEventTimeNt = queue.getNextEventTime(nowNt); efiAssertVoid(nextEventTimeNt > nowNt, "setTimer constraint"); if (nextEventTimeNt == EMPTY_QUEUE) return; // no pending events in the queue - hwAlarmTime = NT2US(nextEventTimeNt - nowNt); + int32_t hwAlarmTime = NT2US((int32_t)nextEventTimeNt - (int32_t)nowNt); beforeHwSetTimer = GET_TIMESTAMP(); setHardwareUsTimer(hwAlarmTime == 0 ? 1 : hwAlarmTime); hwSetTimerTime = GET_TIMESTAMP() - beforeHwSetTimer; diff --git a/firmware/controllers/system/SingleTimerExecutor.h b/firmware/controllers/system/SingleTimerExecutor.h index 2b586c862b..9b5b40c79d 100644 --- a/firmware/controllers/system/SingleTimerExecutor.h +++ b/firmware/controllers/system/SingleTimerExecutor.h @@ -21,6 +21,7 @@ private: EventQueue queue; bool reentrantFlag; void doExecute(); + void scheduleTimerCallback(); }; void initSignalExecutorImpl(void); diff --git a/firmware/controllers/system/scheduler.h b/firmware/controllers/system/scheduler.h index 85cc749a61..b21de938e9 100644 --- a/firmware/controllers/system/scheduler.h +++ b/firmware/controllers/system/scheduler.h @@ -11,8 +11,10 @@ typedef void (*schfunc_t)(void *); -typedef struct scheduling_struct scheduling_s; -struct scheduling_struct { +class scheduling_s { +public: + scheduling_s(); + #if EFI_SIGNAL_EXECUTOR_SLEEP VirtualTimer timer; #endif /* EFI_SIGNAL_EXECUTOR_SLEEP */ @@ -22,6 +24,7 @@ struct scheduling_struct { void *param; scheduling_s *next; const char *name; +// bool_t isScheduled; }; void scheduleTask(const char *prefix, scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param); diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index 9782aa5c8d..727a2b3eca 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -200,12 +200,14 @@ static void onTdcCallback(void) { static void tdcMarkCallback(trigger_event_e ckpSignalType, uint32_t index0 DECLARE_ENGINE_PARAMETER_S) { (void) ckpSignalType; bool isTriggerSynchronizationPoint = index0 == 0; - if (isTriggerSynchronizationPoint) { + if (isTriggerSynchronizationPoint && engineConfiguration->isDigitalChartEnabled) { int revIndex2 = engine->rpmCalculator.getRevolutionCounter() % 2; int rpm = getRpm(); // todo: use event-based scheduling, not just time-based scheduling - scheduleByAngle(rpm, &tdcScheduler[revIndex2], tdcPosition(), - (schfunc_t) onTdcCallback, NULL, &engine->rpmCalculator); + if (isValidRpm(rpm)) { + scheduleByAngle(rpm, &tdcScheduler[revIndex2], tdcPosition(), + (schfunc_t) onTdcCallback, NULL, &engine->rpmCalculator); + } } } #endif @@ -249,18 +251,9 @@ void initRpmCalculator(Engine *engine) { * it takes the crankshaft to rotate to the specified angle. */ void scheduleByAngle(int rpm, scheduling_s *timer, angle_t angle, schfunc_t callback, void *param, RpmCalculator *calc) { - if (!isValidRpm(rpm)) { - /** - * this might happen in case of a single trigger event after a pause - this is normal, so no - * warning here - */ - return; - } - float delayUs = getOneDegreeTimeUs(rpm) * angle; - if (cisnan(delayUs)) { - firmwareError("NaN delay?"); - return; - } + efiAssertVoid(isValidRpm(rpm), "RPM check expected"); + float delayUs = calc->oneDegreeUs * angle; + efiAssertVoid(!cisnan(delayUs), "NaN delay?"); scheduleTask("by angle", timer, (int) delayUs, callback, param); } #endif diff --git a/firmware/hw_layer/hw_layer.mk b/firmware/hw_layer/hw_layer.mk index 72364e4e5d..b9c3a5f7b0 100644 --- a/firmware/hw_layer/hw_layer.mk +++ b/firmware/hw_layer/hw_layer.mk @@ -6,12 +6,12 @@ HW_LAYER_EGT_CPP = $(PROJECT_DIR)/hw_layer/can_hw.cpp \ HW_LAYER_EMS = $(HW_LAYER_EGT) \ $(PROJECT_DIR)/hw_layer/mcp3208.c \ - $(PROJECT_DIR)/hw_layer/microsecond_timer.c \ $(PROJECT_DIR)/hw_layer/flash.c \ $(PROJECT_DIR)/hw_layer/rtc_helper.c HW_LAYER_EMS_CPP = $(HW_LAYER_EGT_CPP) \ $(PROJECT_DIR)/hw_layer/pin_repository.cpp \ + $(PROJECT_DIR)/hw_layer/microsecond_timer.cpp \ $(PROJECT_DIR)/hw_layer/wave_analyzer_hw.cpp \ $(PROJECT_DIR)/hw_layer/hardware.cpp \ $(PROJECT_DIR)/hw_layer/neo6m.cpp \ diff --git a/firmware/hw_layer/microsecond_timer.c b/firmware/hw_layer/microsecond_timer.cpp similarity index 99% rename from firmware/hw_layer/microsecond_timer.c rename to firmware/hw_layer/microsecond_timer.cpp index 23e562e4bb..0481895b30 100644 --- a/firmware/hw_layer/microsecond_timer.c +++ b/firmware/hw_layer/microsecond_timer.cpp @@ -1,5 +1,5 @@ /** - * @file microsecond_timer.c + * @file microsecond_timer.cpp * * Here we have a 1MHz timer dedicated to event scheduling. We are using one of the 32-bit timers here, * so this timer can schedule events up to 4B/100M ~ 4000 seconds ~ 1 hour from current time. diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index ba01e21810..46b8b30d4d 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -42,7 +42,7 @@ struct_no_prefix engine_configuration_s ! please note that 1024 here is 4 * FUEL_RPM_COUNT * FUEL_LOAD_COUNT custom fuel_table_t 1024 array, F32, @OFFSET@, [16x16],"ms", 1, 0, 0.0, 300.0, 2 -custom ve_table_t 1024 array, F32, @OFFSET@, [16x16],"%", 1, 0, 0, 200.0, 2 +custom ve_table_t 1024 array, F32, @OFFSET@, [16x16],"%", 1, 0, 0, 999.0, 2 custom afr_table_t 1024 array, F32, @OFFSET@, [16x16],"deg", 1, 0, 0, 25.0, 2 ! please note that 1024 here is 4 * IGN_LOAD_COUNT * IGN_RPM_COUNT diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 81d1c0bafe..26e04c5fc8 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -290,5 +290,5 @@ int getRusEfiVersion(void) { return 123; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE[0] * 0 != 0) return 3211; // this is here to make the compiler happy about the unused array - return 20150416; + return 20150417; } diff --git a/firmware/tunerstudio/rusefi.ini b/firmware/tunerstudio/rusefi.ini index 7be77c12ae..bdfc508e72 100644 --- a/firmware/tunerstudio/rusefi.ini +++ b/firmware/tunerstudio/rusefi.ini @@ -504,7 +504,7 @@ page = 1 ignitionTable = array, F32, 11832, [16x16],"deg", 1, 0, -360, 360, 2 ignitionLoadBins = array, F32, 12856, [16], "Load", 1, 0.0, 0, 300.0, 2 ignitionRpmBins = array, F32, 12920, [16], "RPM", 1, 0.0, 0, 18000.0, 2 - veTable = array, F32, 12984, [16x16],"%", 1, 0, 0, 200.0, 2 + veTable = array, F32, 12984, [16x16],"%", 1, 0, 0, 999.0, 2 veLoadBins = array, F32, 14008, [16], "%", 1, 0.0, 0, 300.0, 2 veRpmBins = array, F32, 14072, [16], "RPM", 1, 0.0, 0, 18000.0, 2 afrTable = array, F32, 14136, [16x16],"deg", 1, 0, 0, 25.0, 2