diff --git a/firmware/controllers/bench_test.cpp b/firmware/controllers/bench_test.cpp index ec8868fdd1..e37c07e3ef 100644 --- a/firmware/controllers/bench_test.cpp +++ b/firmware/controllers/bench_test.cpp @@ -64,10 +64,10 @@ static void benchOn(OutputPin* output) { output->setValue(BENCH_MSG, true); } -static char pin_error[64]; - static void benchOff(OutputPin* output) { #if EFI_PROD_CODE && (BOARD_EXT_GPIOCHIPS > 0) + static char pin_error[64]; + brain_pin_diag_e diag = output->getDiag(); if (diag == PIN_INVALID) { efiPrintf("No Diag on this pin"); @@ -127,6 +127,8 @@ static int count; static brain_pin_e brainPin; static OutputPin* pinX; +static chibios_rt::CounterSemaphore benchSemaphore(0); + static void pinbench(float startdelay, float p_ontimeMs, float p_offtimeMs, int iterations, OutputPin* pinParam, brain_pin_e brainPinParam) { @@ -138,6 +140,7 @@ static void pinbench(float startdelay, float p_ontimeMs, float p_offtimeMs, int brainPin = brainPinParam; // let's signal bench thread to wake up isBenchTestPending = true; + benchSemaphore.signal(); } /*==========================================================================*/ @@ -275,27 +278,27 @@ void fuelPumpBench(void) { fuelPumpBenchExt(3000.0); } -class BenchController : public PeriodicController { +class BenchController : public ThreadController { public: - BenchController() : PeriodicController("BenchThread") { } + BenchController() : ThreadController("BenchTest", PRIO_BENCH_TEST) { } private: - void PeriodicTask(efitick_t nowNt) override { - UNUSED(nowNt); - setPeriod(50 /* ms */); + void ThreadTask() override { + while (true) { + benchSemaphore.wait(); - assertStackVoid("Bench", ObdCode::STACK_USAGE_BENCH, EXPECTED_REMAINING_STACK); + assertStackVoid("Bench", ObdCode::STACK_USAGE_BENCH, EXPECTED_REMAINING_STACK); - // naive inter-thread communication - waiting for a flag - if (isBenchTestPending) { - isBenchTestPending = false; - runBench(brainPin, pinX, startDelayMs, onTimeMs, offTimeMs, count); - } + if (isBenchTestPending) { + isBenchTestPending = false; + runBench(brainPin, pinX, startDelayMs, onTime, offTime, count); + } - if (widebandUpdatePending) { -#if EFI_WIDEBAND_FIRMWARE_UPDATE && EFI_CAN_SUPPORT - updateWidebandFirmware(); -#endif - widebandUpdatePending = false; + if (widebandUpdatePending) { + #if EFI_WIDEBAND_FIRMWARE_UPDATE && EFI_CAN_SUPPORT + updateWidebandFirmware(); + #endif + widebandUpdatePending = false; + } } } }; @@ -404,6 +407,7 @@ static void handleCommandX14(uint16_t index) { #endif case 0x12: widebandUpdatePending = true; + benchSemaphore.signal(); return; case 0x14: #ifdef STM32F7 @@ -577,7 +581,6 @@ void initBenchTest() { addConsoleAction(CMD_HPFP_BENCH, hpfpValveBench); addConsoleActionFFFFF("luabench2", luaOutBench2); - instance.setPeriod(200 /*ms*/); instance.start(); onConfigurationChangeBenchTest(); } diff --git a/firmware/controllers/thread_priority.h b/firmware/controllers/thread_priority.h index fe0b7472b2..88f93232c6 100644 --- a/firmware/controllers/thread_priority.h +++ b/firmware/controllers/thread_priority.h @@ -39,6 +39,7 @@ #define PRIO_AUX_SERIAL NORMALPRIO #define PRIO_KNOCK_PROCESS (NORMALPRIO - 10) #define PRIO_HIP9011 (NORMALPRIO - 10) +#define PRIO_BENCH_TEST (NORMALPRIO - 10) // These are intentionally low priority so they can't get in the way of anything else #define PRIO_FLASH_WRITE LOWPRIO + 20