bench test uses a semaphore instead of flags+sleep

This commit is contained in:
Matthew Kennedy 2023-06-29 17:14:07 -04:00 committed by rusefillc
parent a5c7ff9a73
commit d1f59c057f
2 changed files with 23 additions and 19 deletions

View File

@ -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<UTILITY_THREAD_STACK_SIZE> {
class BenchController : public ThreadController<UTILITY_THREAD_STACK_SIZE> {
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();
}

View File

@ -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