From 830e733053add9bc23a99ae49cfb536295a861d6 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Wed, 27 Feb 2019 17:12:52 -0500 Subject: [PATCH] fix #698 --- README.md | 1 + firmware/controllers/algo/signal_executor.cpp | 1 - .../system/SingleTimerExecutor.cpp | 2 +- .../controllers/system/SingleTimerExecutor.h | 2 +- .../system/signal_executor_sleep.cpp | 4 ---- firmware/hw_layer/hardware.cpp | 3 +++ firmware/hw_layer/microsecond_timer.cpp | 20 +++---------------- firmware/svnversion.h | 6 +++--- unit_tests/global_execution_queue.cpp | 4 ---- 9 files changed, 12 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 8cf6de6d12..51e6a5fd39 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ See https://rusefi.com/forum/viewtopic.php?f=5&t=9 | Release date | Revision | Details | | ------------ | --------- | ------- | +| 02/27/2019 | r16886 | bugfix #698: concurrency defect with single timer executor initialization | | 02/23/2019 | r16857 | improvement #688: better support for 144 and 176 pin packages | | 02/05/2019 | r16713 | improvement #631: ChibiOS 18 | | 01/11/2019 | r16346 | bugfix #663: SPI fixes for CJ125 for stm32 errata STM32f405/7/15/17 | diff --git a/firmware/controllers/algo/signal_executor.cpp b/firmware/controllers/algo/signal_executor.cpp index 1bf3011bd1..157f15a0d8 100644 --- a/firmware/controllers/algo/signal_executor.cpp +++ b/firmware/controllers/algo/signal_executor.cpp @@ -48,7 +48,6 @@ InjectionSignalPair::InjectionSignalPair() { } void initSignalExecutor(void) { - initSignalExecutorImpl(); } #if FUEL_MATH_EXTREME_LOGGING diff --git a/firmware/controllers/system/SingleTimerExecutor.cpp b/firmware/controllers/system/SingleTimerExecutor.cpp index c93586c9e1..633a748b00 100644 --- a/firmware/controllers/system/SingleTimerExecutor.cpp +++ b/firmware/controllers/system/SingleTimerExecutor.cpp @@ -156,7 +156,7 @@ void SingleTimerExecutor::scheduleTimerCallback() { hwSetTimerDuration = GET_TIMESTAMP() - beforeHwSetTimer; } -void initSignalExecutorImpl(void) { +void initSingleTimerExecutorHardware(void) { globalTimerCallback = executorCallback; initMicrosecondTimer(); } diff --git a/firmware/controllers/system/SingleTimerExecutor.h b/firmware/controllers/system/SingleTimerExecutor.h index 5867aefd0b..cc56c7b479 100644 --- a/firmware/controllers/system/SingleTimerExecutor.h +++ b/firmware/controllers/system/SingleTimerExecutor.h @@ -27,7 +27,7 @@ private: void scheduleTimerCallback(); }; -void initSignalExecutorImpl(void); +void initSingleTimerExecutorHardware(void); void executorStatistics(); #endif /* SINGLETIMEREXECUTOR_H_ */ diff --git a/firmware/controllers/system/signal_executor_sleep.cpp b/firmware/controllers/system/signal_executor_sleep.cpp index f5f26c1be4..6ccf332037 100644 --- a/firmware/controllers/system/signal_executor_sleep.cpp +++ b/firmware/controllers/system/signal_executor_sleep.cpp @@ -91,8 +91,4 @@ void SleepExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs, schf doScheduleForLater(scheduling, delayUs, callback, param); } -void initSignalExecutorImpl(void) { - -} - #endif /* EFI_SIGNAL_EXECUTOR_SLEEP */ diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 03bdcb31bf..8f404642c6 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -375,6 +375,9 @@ void initHardware(Logging *l) { resetConfigurationExt(sharedLogger, engineConfiguration->engineType PASS_ENGINE_PARAMETER_SUFFIX); #endif /* EFI_INTERNAL_FLASH */ + // it's important to initialize this pretty early in the game before any scheduling usages + initSingleTimerExecutorHardware(); + #if EFI_HD44780_LCD // initI2Cmodule(); lcd_HD44780_init(sharedLogger); diff --git a/firmware/hw_layer/microsecond_timer.cpp b/firmware/hw_layer/microsecond_timer.cpp index 643067977b..a8688196cb 100644 --- a/firmware/hw_layer/microsecond_timer.cpp +++ b/firmware/hw_layer/microsecond_timer.cpp @@ -48,6 +48,7 @@ static char buff[32]; static int timerFreezeCounter = 0; static volatile int setHwTimerCounter = 0; +static volatile bool hwStarted = false; extern bool hasFirmwareErrorFlag; @@ -56,6 +57,7 @@ extern bool hasFirmwareErrorFlag; * This function should be invoked under kernel lock which would disable interrupts. */ void setHardwareUsTimer(int32_t timeUs) { + efiAssertVoid(OBD_PCM_Processor_Fault, hwStarted, "HW.started"); setHwTimerCounter++; /** * #259 BUG error: not positive timeUs @@ -99,15 +101,6 @@ static void hwTimerCallback(GPTDriver *gptp) { } isTimerPending = false; -// // test code -// setOutputPinValue(LED_CRANKING, timerCallbackCounter % 2); -// int mod = timerCallbackCounter % 400; -// chSysLockFromISR() -// ; -// setHardwareUsTimer(400 - mod); -// chSysUnlockFromISR() -// ; - uint32_t before = GET_TIMESTAMP(); globalTimerCallback(NULL); uint32_t precisionCallbackDuration = GET_TIMESTAMP() - before; @@ -116,7 +109,6 @@ static void hwTimerCallback(GPTDriver *gptp) { } } - class MicrosecondTimerWatchdogController : public PeriodicController { public: @@ -151,18 +143,12 @@ void initMicrosecondTimer(void) { gptStart(&GPTDEVICE, &gpt5cfg); efiAssertVoid(CUSTOM_ERR_TIMER_STATE, GPTDEVICE.state == GPT_READY, "hw state"); + hwStarted = true; lastSetTimerTimeNt = getTimeNowNt(); #if EFI_EMULATE_POSITION_SENSORS watchdogControllerInstance.Start(); #endif /* EFI_ENGINE_EMULATOR */ - -// // test code -// chSysLock() -// ; -// setHardwareUsTimer(300); -// chSysUnlock() -// ; } #endif /* EFI_PROD_CODE */ diff --git a/firmware/svnversion.h b/firmware/svnversion.h index 31def2ec1f..2de12c088b 100644 --- a/firmware/svnversion.h +++ b/firmware/svnversion.h @@ -1,12 +1,12 @@ // This file was generated by Version2Header -// Sat Feb 23 08:50:46 EST 2019 +// Wed Feb 27 16:59:18 EST 2019 #ifndef GIT_HASH -#define GIT_HASH "f3b64f5227a4160df076bc68d2c29094b185bfa5" +#define GIT_HASH "fb3d06aebfa19ceedc3619f50158fed13e7feadd" #endif #ifndef VCS_VERSION -#define VCS_VERSION "16857" +#define VCS_VERSION "16886" #endif diff --git a/unit_tests/global_execution_queue.cpp b/unit_tests/global_execution_queue.cpp index e90fc56aa4..cb57002168 100644 --- a/unit_tests/global_execution_queue.cpp +++ b/unit_tests/global_execution_queue.cpp @@ -43,7 +43,3 @@ void TestExecutor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t tim } schedulingQueue.insertTask(scheduling, timeUs, callback, param); } - -void initSignalExecutorImpl(void) { -} -