2015-07-10 06:01:56 -07:00
|
|
|
/**
|
2020-03-26 05:03:55 -07:00
|
|
|
* @file bench_test.cpp
|
|
|
|
* @brief Utility methods related to bench testing.
|
2015-07-10 06:01:56 -07:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @date Sep 8, 2013
|
2020-01-13 18:57:43 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-07-10 06:01:56 -07:00
|
|
|
*
|
|
|
|
* This file is part of rusEfi - see http://rusefi.com
|
|
|
|
*
|
|
|
|
* rusEfi is free software; you can redistribute it and/or modify it under the terms of
|
|
|
|
* the GNU General Public License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* rusEfi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
|
|
|
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with this program.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2023-06-15 19:54:00 -07:00
|
|
|
static bool isRunningBench = false;
|
2023-09-06 05:16:45 -07:00
|
|
|
static OutputPin *outputOnTheBenchTest = nullptr;
|
2023-06-15 19:54:00 -07:00
|
|
|
|
|
|
|
bool isRunningBenchTest() {
|
|
|
|
return isRunningBench;
|
|
|
|
}
|
|
|
|
|
2023-09-06 05:16:45 -07:00
|
|
|
const OutputPin *getOutputOnTheBenchTest() {
|
|
|
|
return outputOnTheBenchTest;
|
|
|
|
}
|
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_ENGINE_CONTROL
|
2019-04-09 20:00:17 -07:00
|
|
|
#if !EFI_UNIT_TEST
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-11-10 09:39:47 -08:00
|
|
|
#include "flash_main.h"
|
2020-03-26 05:03:55 -07:00
|
|
|
#include "bench_test.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "main_trigger_callback.h"
|
2019-07-08 00:35:41 -07:00
|
|
|
#include "periodic_thread_controller.h"
|
2020-04-28 16:31:41 -07:00
|
|
|
#include "electronic_throttle.h"
|
2023-03-15 21:14:59 -07:00
|
|
|
#include "electronic_throttle_impl.h"
|
2020-03-24 16:50:04 -07:00
|
|
|
#include "malfunction_central.h"
|
2021-03-11 05:38:52 -08:00
|
|
|
#include "trigger_emulator_algo.h"
|
2023-09-06 05:16:45 -07:00
|
|
|
#include "vvt.h"
|
2021-03-11 19:42:59 -08:00
|
|
|
#include "microsecond_timer.h"
|
2019-09-05 07:30:27 -07:00
|
|
|
|
2020-12-16 05:28:53 -08:00
|
|
|
#if EFI_WIDEBAND_FIRMWARE_UPDATE
|
2021-07-13 04:32:41 -07:00
|
|
|
#include "rusefi_wideband.h"
|
2021-03-11 19:42:59 -08:00
|
|
|
#endif // EFI_WIDEBAND_FIRMWARE_UPDATE
|
2020-12-16 05:28:53 -08:00
|
|
|
|
2019-06-28 20:33:48 -07:00
|
|
|
#if EFI_PROD_CODE
|
|
|
|
#include "rusefi.h"
|
2019-08-03 16:58:38 -07:00
|
|
|
#include "mpu_util.h"
|
2019-06-28 20:33:48 -07:00
|
|
|
#endif /* EFI_PROD_CODE */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-09-05 07:30:27 -07:00
|
|
|
#if (BOARD_TLE8888_COUNT > 0)
|
|
|
|
#include "gpio/tle8888.h"
|
2021-03-11 19:42:59 -08:00
|
|
|
#endif // BOARD_TLE8888_COUNT
|
2019-09-05 07:30:27 -07:00
|
|
|
|
2023-05-25 06:40:16 -07:00
|
|
|
static scheduling_s benchSchedStart;
|
|
|
|
static scheduling_s benchSchedEnd;
|
|
|
|
|
2023-06-15 08:46:28 -07:00
|
|
|
#define BENCH_MSG "bench"
|
|
|
|
|
2022-01-03 16:57:34 -08:00
|
|
|
static void benchOn(OutputPin* output) {
|
2023-10-16 06:37:59 -07:00
|
|
|
output->setValue(BENCH_MSG, true, /*isForce*/ true);
|
2021-03-10 14:30:13 -08:00
|
|
|
}
|
|
|
|
|
2022-01-03 16:57:34 -08:00
|
|
|
static void benchOff(OutputPin* output) {
|
|
|
|
#if EFI_PROD_CODE && (BOARD_EXT_GPIOCHIPS > 0)
|
2023-06-29 14:14:07 -07:00
|
|
|
static char pin_error[64];
|
|
|
|
|
2022-08-01 12:41:47 -07:00
|
|
|
brain_pin_diag_e diag = output->getDiag();
|
2022-01-03 13:46:15 -08:00
|
|
|
if (diag == PIN_INVALID) {
|
|
|
|
efiPrintf("No Diag on this pin");
|
2022-01-03 11:21:54 -08:00
|
|
|
} else {
|
|
|
|
pinDiag2string(pin_error, sizeof(pin_error), diag);
|
|
|
|
efiPrintf("Diag says %s", pin_error);
|
|
|
|
}
|
2022-01-03 13:46:15 -08:00
|
|
|
#endif // EFI_PROD_CODE
|
2023-10-16 06:37:59 -07:00
|
|
|
output->setValue(BENCH_MSG, false, /*isForce*/ true);
|
2021-03-10 14:30:13 -08:00
|
|
|
}
|
|
|
|
|
2023-08-05 11:32:24 -07:00
|
|
|
static void runBench(OutputPin *output, float onTimeMs, float offTimeMs, int count) {
|
2021-03-10 14:30:13 -08:00
|
|
|
int onTimeUs = MS2US(maxF(0.1, onTimeMs));
|
|
|
|
int offTimeUs = MS2US(maxF(0.1, offTimeMs));
|
2020-11-24 11:11:41 -08:00
|
|
|
|
2021-03-11 11:05:15 -08:00
|
|
|
if (onTimeUs > TOO_FAR_INTO_FUTURE_US) {
|
2023-04-11 17:01:34 -07:00
|
|
|
firmwareError(ObdCode::CUSTOM_ERR_BENCH_PARAM, "onTime above limit %dus", TOO_FAR_INTO_FUTURE_US);
|
2021-03-11 11:05:15 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Running bench: ON_TIME=%d us OFF_TIME=%d us Counter=%d", onTimeUs, offTimeUs, count);
|
2023-08-05 10:35:12 -07:00
|
|
|
efiPrintf("output on %s", hwPortname(output->brainPin));
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
isRunningBench = true;
|
2023-09-06 05:16:45 -07:00
|
|
|
outputOnTheBenchTest = output;
|
2021-03-10 14:30:13 -08:00
|
|
|
|
2023-08-03 17:18:20 -07:00
|
|
|
for (int i = 0; isRunningBench && i < count; i++) {
|
2022-03-08 17:25:58 -08:00
|
|
|
engine->outputChannels.testBenchIter = i;
|
2021-03-10 14:30:13 -08:00
|
|
|
efitick_t nowNt = getTimeNowNt();
|
|
|
|
// start in a short time so the scheduler can precisely schedule the start event
|
|
|
|
efitick_t startTime = nowNt + US2NT(50);
|
|
|
|
efitick_t endTime = startTime + US2NT(onTimeUs);
|
|
|
|
|
|
|
|
// Schedule both events
|
2023-05-25 06:40:16 -07:00
|
|
|
engine->executor.scheduleByTimestampNt("bstart", &benchSchedStart, startTime, {benchOn, output});
|
|
|
|
engine->executor.scheduleByTimestampNt("bend", &benchSchedEnd, endTime, {benchOff, output});
|
2021-03-10 14:30:13 -08:00
|
|
|
|
|
|
|
// Wait one full cycle time for the event + delay to happen
|
|
|
|
chThdSleepMicroseconds(onTimeUs + offTimeUs);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
2022-03-08 17:25:58 -08:00
|
|
|
/* last */
|
|
|
|
engine->outputChannels.testBenchIter++;
|
2022-01-03 11:21:54 -08:00
|
|
|
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Done!");
|
2023-09-06 05:16:45 -07:00
|
|
|
outputOnTheBenchTest = nullptr;
|
2015-07-10 06:01:56 -07:00
|
|
|
isRunningBench = false;
|
|
|
|
}
|
|
|
|
|
2023-10-12 09:55:25 -07:00
|
|
|
// todo: migrate to smarter getOutputOnTheBenchTest() approach?
|
2017-07-24 16:38:00 -07:00
|
|
|
static volatile bool isBenchTestPending = false;
|
2020-12-16 05:28:53 -08:00
|
|
|
static bool widebandUpdatePending = false;
|
2023-04-12 19:44:57 -07:00
|
|
|
static float onTimeMs;
|
|
|
|
static float offTimeMs;
|
2015-07-10 06:01:56 -07:00
|
|
|
static int count;
|
|
|
|
static OutputPin* pinX;
|
|
|
|
|
2023-06-29 14:14:07 -07:00
|
|
|
static chibios_rt::CounterSemaphore benchSemaphore(0);
|
|
|
|
|
2023-08-05 11:32:24 -07:00
|
|
|
static void pinbench(float p_ontimeMs, float p_offtimeMs, int iterations,
|
2023-08-05 10:35:12 -07:00
|
|
|
OutputPin* pinParam)
|
2022-02-27 10:14:42 -08:00
|
|
|
{
|
2023-04-12 19:44:57 -07:00
|
|
|
onTimeMs = p_ontimeMs;
|
|
|
|
offTimeMs = p_offtimeMs;
|
2023-10-17 09:54:52 -07:00
|
|
|
#if EFI_SIMULATOR
|
2023-10-17 08:16:06 -07:00
|
|
|
count = maxI(2, iterations);
|
2023-10-17 09:54:52 -07:00
|
|
|
#else
|
|
|
|
count = iterations;
|
|
|
|
#endif // EFI_SIMULATOR
|
2015-07-10 06:01:56 -07:00
|
|
|
pinX = pinParam;
|
2022-02-27 10:14:42 -08:00
|
|
|
// let's signal bench thread to wake up
|
|
|
|
isBenchTestPending = true;
|
2023-06-29 14:14:07 -07:00
|
|
|
benchSemaphore.signal();
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2023-08-03 17:18:20 -07:00
|
|
|
static void cancelBenchTest() {
|
|
|
|
isRunningBench = false;
|
|
|
|
}
|
|
|
|
|
2022-02-27 10:14:42 -08:00
|
|
|
/*==========================================================================*/
|
|
|
|
|
2023-08-05 11:32:24 -07:00
|
|
|
static void doRunFuelInjBench(size_t humanIndex, float onTimeMs, float offTimeMs, int count) {
|
2023-04-28 18:01:08 -07:00
|
|
|
if (humanIndex < 1 || humanIndex > engineConfiguration->cylindersCount) {
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Invalid index: %d", humanIndex);
|
2016-03-14 21:01:37 -07:00
|
|
|
return;
|
|
|
|
}
|
2023-08-05 11:32:24 -07:00
|
|
|
pinbench(onTimeMs, offTimeMs, count,
|
2023-08-05 10:35:12 -07:00
|
|
|
&enginePins.injectors[humanIndex - 1]);
|
2016-03-14 21:01:37 -07:00
|
|
|
}
|
|
|
|
|
2023-08-05 11:32:24 -07:00
|
|
|
static void doRunSparkBench(size_t humanIndex, float onTime, float offTime, int count) {
|
2023-04-28 18:01:08 -07:00
|
|
|
if (humanIndex < 1 || humanIndex > engineConfiguration->cylindersCount) {
|
2022-02-27 10:14:42 -08:00
|
|
|
efiPrintf("Invalid index: %d", humanIndex);
|
|
|
|
return;
|
|
|
|
}
|
2023-08-05 11:32:24 -07:00
|
|
|
pinbench(onTime, offTime, count, &enginePins.coils[humanIndex - 1]);
|
2022-02-27 10:14:42 -08:00
|
|
|
}
|
|
|
|
|
2023-08-05 11:32:24 -07:00
|
|
|
static void doRunSolenoidBench(size_t humanIndex, float onTime, float offTime, int count) {
|
2021-01-02 14:18:44 -08:00
|
|
|
if (humanIndex < 1 || humanIndex > TCU_SOLENOID_COUNT) {
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("Invalid index: %d", humanIndex);
|
2021-01-02 14:18:44 -08:00
|
|
|
return;
|
|
|
|
}
|
2023-08-05 11:32:24 -07:00
|
|
|
pinbench(onTime, offTime, count, &enginePins.tcuSolenoids[humanIndex - 1]);
|
2021-01-02 14:18:44 -08:00
|
|
|
}
|
|
|
|
|
2023-08-05 11:32:24 -07:00
|
|
|
static void doRunBenchTestLuaOutput(size_t humanIndex, float onTimeMs, float offTimeMs, int count) {
|
2022-04-23 14:15:34 -07:00
|
|
|
if (humanIndex < 1 || humanIndex > LUA_PWM_COUNT) {
|
|
|
|
efiPrintf("Invalid index: %d", humanIndex);
|
|
|
|
return;
|
|
|
|
}
|
2023-08-05 11:32:24 -07:00
|
|
|
pinbench(onTimeMs, offTimeMs, count,
|
2023-08-05 10:35:12 -07:00
|
|
|
&enginePins.luaOutputPins[humanIndex - 1]);
|
2020-09-07 14:12:00 -07:00
|
|
|
}
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
/**
|
2023-08-05 11:32:24 -07:00
|
|
|
* cylinder #2, 5ms ON, 1000ms OFF, repeat 3 times
|
|
|
|
* fuelInjBenchExt 2 5 1000 3
|
2022-02-27 10:14:42 -08:00
|
|
|
*/
|
2023-08-05 11:32:24 -07:00
|
|
|
static void fuelInjBenchExt(float humanIndex, float onTimeMs, float offTimeMs, float count) {
|
|
|
|
doRunFuelInjBench((int)humanIndex, onTimeMs, offTimeMs, (int)count);
|
2022-02-27 10:14:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* fuelbench 5 1000 2
|
|
|
|
*/
|
2023-04-12 19:44:57 -07:00
|
|
|
static void fuelInjBench(float onTimeMs, float offTimeMs, float count) {
|
2023-08-05 11:32:24 -07:00
|
|
|
fuelInjBenchExt(1, onTimeMs, offTimeMs, count);
|
2022-02-27 10:14:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-08-05 11:32:24 -07:00
|
|
|
* sparkbench2 1 5 1000 2
|
2022-02-27 10:14:42 -08:00
|
|
|
*/
|
2023-08-05 11:32:24 -07:00
|
|
|
static void sparkBenchExt(float humanIndex, float onTime, float offTimeMs, float count) {
|
|
|
|
doRunSparkBench((int)humanIndex, onTime, offTimeMs, (int)count);
|
2022-02-27 10:14:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sparkbench 5 400 2
|
|
|
|
* 5 ms ON, 400 ms OFF, two times
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
2023-04-12 19:44:57 -07:00
|
|
|
static void sparkBench(float onTime, float offTimeMs, float count) {
|
2023-08-05 11:32:24 -07:00
|
|
|
sparkBenchExt(1, onTime, offTimeMs, count);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2021-01-02 14:18:44 -08:00
|
|
|
/**
|
2023-08-05 11:32:24 -07:00
|
|
|
* solenoid #2, 1000ms ON, 1000ms OFF, repeat 3 times
|
|
|
|
* tcusolbench 2 1000 1000 3
|
2021-01-02 14:18:44 -08:00
|
|
|
*/
|
2023-08-05 11:32:24 -07:00
|
|
|
static void tcuSolenoidBench(float humanIndex, float onTime, float offTimeMs, float count) {
|
|
|
|
doRunSolenoidBench((int)humanIndex, onTime, offTimeMs, (int)count);
|
2021-01-02 14:18:44 -08:00
|
|
|
}
|
|
|
|
|
2020-09-07 14:59:59 -07:00
|
|
|
/**
|
2023-08-05 11:32:24 -07:00
|
|
|
* channel #1, 5ms ON, 1000ms OFF, repeat 3 times
|
|
|
|
* fsiobench2 1 5 1000 3
|
2020-09-07 14:59:59 -07:00
|
|
|
*/
|
2023-08-05 11:32:24 -07:00
|
|
|
static void luaOutBench2(float humanIndex, float onTime, float offTimeMs, float count) {
|
|
|
|
doRunBenchTestLuaOutput((int)humanIndex, onTime, offTimeMs, (int)count);
|
2020-09-07 14:38:51 -07:00
|
|
|
}
|
|
|
|
|
2023-04-12 19:44:57 -07:00
|
|
|
static void fanBenchExt(float onTimeMs) {
|
2023-10-17 09:54:28 -07:00
|
|
|
pinbench(onTimeMs, 100.0, 1, &enginePins.fanRelay);
|
2017-07-24 17:40:01 -07:00
|
|
|
}
|
|
|
|
|
2023-09-06 05:16:45 -07:00
|
|
|
void fanBench() {
|
2023-10-10 18:29:27 -07:00
|
|
|
fanBenchExt(BENCH_FAN_DURATION);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2023-09-06 05:16:45 -07:00
|
|
|
void fan2Bench() {
|
2023-10-17 09:54:28 -07:00
|
|
|
pinbench(3000.0, 100.0, 1, &enginePins.fanRelay2);
|
2021-06-23 14:16:11 -07:00
|
|
|
}
|
|
|
|
|
2019-01-13 16:41:39 -08:00
|
|
|
/**
|
|
|
|
* we are blinking for 16 seconds so that one can click the button and walk around to see the light blinking
|
|
|
|
*/
|
2023-09-06 05:16:45 -07:00
|
|
|
void milBench() {
|
2023-08-05 11:32:24 -07:00
|
|
|
pinbench(500.0, 500.0, 16, &enginePins.checkEnginePin);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2023-09-06 05:16:45 -07:00
|
|
|
void starterRelayBench() {
|
2023-10-17 09:54:28 -07:00
|
|
|
pinbench(6000.0, 100.0, 1, &enginePins.starterControl);
|
2020-03-29 14:21:17 -07:00
|
|
|
}
|
|
|
|
|
2022-02-27 10:14:42 -08:00
|
|
|
static void fuelPumpBenchExt(float durationMs) {
|
2023-10-17 09:54:28 -07:00
|
|
|
pinbench(durationMs, 100.0, 1,
|
2023-08-05 10:35:12 -07:00
|
|
|
&enginePins.fuelPumpRelay);
|
2016-01-07 18:02:35 -08:00
|
|
|
}
|
|
|
|
|
2023-09-06 05:16:45 -07:00
|
|
|
void acRelayBench() {
|
2023-10-17 09:54:28 -07:00
|
|
|
pinbench(1000.0, 100.0, 1, &enginePins.acRelay);
|
2019-09-14 14:56:17 -07:00
|
|
|
}
|
|
|
|
|
2023-09-06 05:16:45 -07:00
|
|
|
static void mainRelayBench() {
|
2021-01-10 20:46:50 -08:00
|
|
|
// main relay is usually "ON" via FSIO thus bench testing that one is pretty unusual
|
2023-06-15 19:28:15 -07:00
|
|
|
engine->mainRelayBenchStart.reset();
|
2020-09-08 14:41:32 -07:00
|
|
|
}
|
|
|
|
|
2023-09-06 05:16:45 -07:00
|
|
|
static void hpfpValveBench() {
|
2023-08-05 11:32:24 -07:00
|
|
|
pinbench(engineConfiguration->benchTestOnTime, engineConfiguration->benchTestOffTime, engineConfiguration->benchTestCount,
|
2023-08-05 10:35:12 -07:00
|
|
|
&enginePins.hpfpValve);
|
2020-11-21 21:09:36 -08:00
|
|
|
}
|
|
|
|
|
2023-09-06 05:16:45 -07:00
|
|
|
void fuelPumpBench() {
|
2023-10-10 18:29:27 -07:00
|
|
|
fuelPumpBenchExt(BENCH_FUEL_PUMP_DURATION);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2023-09-06 05:16:45 -07:00
|
|
|
static void vvtValveBench(int vvtIndex) {
|
|
|
|
#if EFI_VVT_PID
|
|
|
|
pinbench(engineConfiguration->benchTestOnTime, engineConfiguration->benchTestOffTime, engineConfiguration->benchTestCount,
|
|
|
|
getVvtOutputPin(vvtIndex));
|
|
|
|
#endif // EFI_VVT_PID
|
|
|
|
}
|
|
|
|
|
2023-06-29 14:14:07 -07:00
|
|
|
class BenchController : public ThreadController<UTILITY_THREAD_STACK_SIZE> {
|
2019-02-10 20:54:41 -08:00
|
|
|
public:
|
2023-06-29 14:14:07 -07:00
|
|
|
BenchController() : ThreadController("BenchTest", PRIO_BENCH_TEST) { }
|
2019-02-10 20:54:41 -08:00
|
|
|
private:
|
2023-06-29 14:14:07 -07:00
|
|
|
void ThreadTask() override {
|
|
|
|
while (true) {
|
|
|
|
benchSemaphore.wait();
|
|
|
|
|
2023-06-30 11:10:05 -07:00
|
|
|
assertStackVoid("Bench", ObdCode::STACK_USAGE_MISC, EXPECTED_REMAINING_STACK);
|
2023-06-29 14:14:07 -07:00
|
|
|
|
|
|
|
if (isBenchTestPending) {
|
|
|
|
isBenchTestPending = false;
|
2023-08-05 11:32:24 -07:00
|
|
|
runBench(pinX, onTimeMs, offTimeMs, count);
|
2023-06-29 14:14:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (widebandUpdatePending) {
|
|
|
|
#if EFI_WIDEBAND_FIRMWARE_UPDATE && EFI_CAN_SUPPORT
|
|
|
|
updateWidebandFirmware();
|
|
|
|
#endif
|
|
|
|
widebandUpdatePending = false;
|
|
|
|
}
|
2020-12-16 05:28:53 -08:00
|
|
|
}
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
2019-02-10 20:54:41 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
static BenchController instance;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2023-10-08 12:14:42 -07:00
|
|
|
void handleBenchCategory(uint16_t index) {
|
2020-09-08 14:41:32 -07:00
|
|
|
switch(index) {
|
2023-09-06 05:16:45 -07:00
|
|
|
case BENCH_VVT0_VALVE:
|
|
|
|
vvtValveBench(0);
|
|
|
|
return;
|
|
|
|
case BENCH_VVT1_VALVE:
|
|
|
|
vvtValveBench(1);
|
|
|
|
return;
|
|
|
|
case BENCH_VVT2_VALVE:
|
|
|
|
vvtValveBench(2);
|
|
|
|
return;
|
|
|
|
case BENCH_VVT3_VALVE:
|
|
|
|
vvtValveBench(3);
|
|
|
|
return;
|
2021-11-10 18:07:38 -08:00
|
|
|
case BENCH_MAIN_RELAY:
|
2020-09-08 14:41:32 -07:00
|
|
|
mainRelayBench();
|
|
|
|
return;
|
2021-11-10 18:07:38 -08:00
|
|
|
case BENCH_HPFP_VALVE:
|
2020-11-21 21:13:55 -08:00
|
|
|
hpfpValveBench();
|
|
|
|
return;
|
2021-11-10 18:07:38 -08:00
|
|
|
case BENCH_FUEL_PUMP:
|
2020-09-08 14:41:32 -07:00
|
|
|
// cmd_test_fuel_pump
|
|
|
|
fuelPumpBench();
|
|
|
|
return;
|
2021-11-10 18:07:38 -08:00
|
|
|
case BENCH_STARTER_ENABLE_RELAY:
|
2020-09-08 14:41:32 -07:00
|
|
|
starterRelayBench();
|
|
|
|
return;
|
2021-11-10 18:07:38 -08:00
|
|
|
case BENCH_CHECK_ENGINE_LIGHT:
|
2020-09-08 14:41:32 -07:00
|
|
|
// cmd_test_check_engine_light
|
|
|
|
milBench();
|
|
|
|
return;
|
2021-11-10 18:07:38 -08:00
|
|
|
case BENCH_AC_COMPRESSOR_RELAY:
|
2020-09-08 14:41:32 -07:00
|
|
|
acRelayBench();
|
|
|
|
return;
|
2021-11-10 18:07:38 -08:00
|
|
|
case BENCH_FAN_RELAY:
|
2021-01-07 05:23:31 -08:00
|
|
|
fanBench();
|
|
|
|
return;
|
2021-11-11 17:27:45 -08:00
|
|
|
case BENCH_IDLE_VALVE:
|
|
|
|
// cmd_test_idle_valve
|
|
|
|
#if EFI_IDLE_CONTROL
|
|
|
|
startIdleBench();
|
|
|
|
#endif /* EFI_IDLE_CONTROL */
|
|
|
|
return;
|
2021-11-10 18:07:38 -08:00
|
|
|
case BENCH_FAN_RELAY_2:
|
2021-06-23 14:16:11 -07:00
|
|
|
fan2Bench();
|
|
|
|
return;
|
2023-08-03 17:18:20 -07:00
|
|
|
case BENCH_CANCEL:
|
|
|
|
cancelBenchTest();
|
|
|
|
return;
|
2021-01-07 05:23:31 -08:00
|
|
|
default:
|
2023-08-20 19:23:44 -07:00
|
|
|
criticalError("Unexpected bench function %d", index);
|
2020-09-08 14:41:32 -07:00
|
|
|
}
|
2020-09-05 21:27:02 -07:00
|
|
|
}
|
|
|
|
|
2019-04-23 20:20:14 -07:00
|
|
|
static void handleCommandX14(uint16_t index) {
|
2023-03-02 20:33:47 -08:00
|
|
|
// todo: define ts_14_command magic constants and use those in rusefi.input file!
|
2019-04-23 20:20:14 -07:00
|
|
|
switch (index) {
|
2021-10-28 10:49:44 -07:00
|
|
|
case TS_GRAB_TPS_CLOSED:
|
2019-04-29 22:21:09 -07:00
|
|
|
grabTPSIsClosed();
|
|
|
|
return;
|
2021-10-28 10:49:44 -07:00
|
|
|
case TS_GRAB_TPS_WOT:
|
2019-04-29 22:21:09 -07:00
|
|
|
grabTPSIsWideOpen();
|
|
|
|
return;
|
2019-09-05 07:30:27 -07:00
|
|
|
// case 4: tps2_closed
|
|
|
|
// case 5: tps2_wot
|
2021-10-28 10:49:44 -07:00
|
|
|
case TS_GRAB_PEDAL_UP:
|
2019-04-30 15:46:39 -07:00
|
|
|
grabPedalIsUp();
|
|
|
|
return;
|
2021-10-28 10:49:44 -07:00
|
|
|
case TS_GRAB_PEDAL_WOT:
|
2019-04-30 15:46:39 -07:00
|
|
|
grabPedalIsWideOpen();
|
|
|
|
return;
|
2021-10-28 10:49:44 -07:00
|
|
|
case TS_RESET_TLE8888:
|
2019-09-05 07:30:27 -07:00
|
|
|
#if (BOARD_TLE8888_COUNT > 0)
|
2020-10-23 09:25:30 -07:00
|
|
|
tle8888_req_init();
|
2019-09-05 07:30:27 -07:00
|
|
|
#endif
|
|
|
|
return;
|
2023-03-02 20:33:47 -08:00
|
|
|
case TS_WRITE_FLASH:
|
2019-11-10 09:39:47 -08:00
|
|
|
// cmd_write_config
|
2020-09-07 12:14:31 -07:00
|
|
|
#if EFI_INTERNAL_FLASH
|
2019-11-10 09:39:47 -08:00
|
|
|
writeToFlashNow();
|
2020-09-07 12:14:31 -07:00
|
|
|
#endif /* EFI_INTERNAL_FLASH */
|
2019-11-10 09:39:47 -08:00
|
|
|
return;
|
2021-03-11 05:38:52 -08:00
|
|
|
#if EFI_EMULATE_POSITION_SENSORS
|
2020-04-23 19:38:14 -07:00
|
|
|
case 0xD:
|
2021-03-11 05:38:52 -08:00
|
|
|
enableTriggerStimulator();
|
2020-04-23 19:38:14 -07:00
|
|
|
return;
|
2021-03-11 05:38:52 -08:00
|
|
|
case 0xF:
|
|
|
|
disableTriggerStimulator();
|
|
|
|
return;
|
|
|
|
case 0x13:
|
|
|
|
enableExternalTriggerStimulator();
|
|
|
|
return;
|
|
|
|
#endif // EFI_EMULATE_POSITION_SENSORS
|
2020-04-28 16:31:41 -07:00
|
|
|
#if EFI_ELECTRONIC_THROTTLE_BODY
|
2023-03-15 21:02:33 -07:00
|
|
|
case TS_ETB_RESET:
|
2023-03-15 21:14:59 -07:00
|
|
|
#if EFI_PROD_CODE
|
2023-03-15 20:01:20 -07:00
|
|
|
etbPidReset();
|
2023-03-15 21:14:59 -07:00
|
|
|
#endif
|
2023-03-15 20:01:20 -07:00
|
|
|
return;
|
2020-04-28 16:31:41 -07:00
|
|
|
case 0xE:
|
|
|
|
etbAutocal(0);
|
|
|
|
return;
|
2020-08-23 20:41:35 -07:00
|
|
|
case 0x11:
|
|
|
|
etbAutocal(1);
|
|
|
|
return;
|
2020-05-06 05:39:02 -07:00
|
|
|
case 0xC:
|
|
|
|
engine->etbAutoTune = true;
|
|
|
|
return;
|
|
|
|
case 0x10:
|
|
|
|
engine->etbAutoTune = false;
|
2020-07-26 15:24:02 -07:00
|
|
|
#if EFI_TUNER_STUDIO
|
2021-12-07 17:18:47 -08:00
|
|
|
engine->outputChannels.calibrationMode = (uint8_t)TsCalMode::None;
|
2020-07-26 15:24:02 -07:00
|
|
|
#endif // EFI_TUNER_STUDIO
|
2020-05-06 05:39:02 -07:00
|
|
|
return;
|
2020-04-28 16:31:41 -07:00
|
|
|
#endif
|
2020-12-16 05:28:53 -08:00
|
|
|
case 0x12:
|
|
|
|
widebandUpdatePending = true;
|
2023-06-29 14:14:07 -07:00
|
|
|
benchSemaphore.signal();
|
2020-12-16 05:28:53 -08:00
|
|
|
return;
|
2021-08-10 04:11:41 -07:00
|
|
|
case 0x15:
|
2021-08-10 04:29:55 -07:00
|
|
|
#if EFI_PROD_CODE
|
2021-08-10 04:11:41 -07:00
|
|
|
extern bool burnWithoutFlash;
|
|
|
|
burnWithoutFlash = true;
|
2021-08-10 04:29:55 -07:00
|
|
|
#endif // EFI_PROD_CODE
|
2021-08-10 04:11:41 -07:00
|
|
|
return;
|
2021-01-07 05:23:31 -08:00
|
|
|
default:
|
2023-08-20 19:23:44 -07:00
|
|
|
criticalError("Unexpected bench x14 %d", index);
|
2019-04-23 20:20:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 16:03:46 -08:00
|
|
|
extern bool rebootForPresetPending;
|
|
|
|
|
|
|
|
static void fatalErrorForPresetApply() {
|
|
|
|
rebootForPresetPending = true;
|
2023-04-11 17:01:34 -07:00
|
|
|
firmwareError(ObdCode::OBD_PCM_Processor_Fault,
|
2020-11-03 16:03:46 -08:00
|
|
|
"\n\nTo complete preset apply:\n"
|
|
|
|
" 1. Close TunerStudio\n"
|
|
|
|
" 2. Power cycle ECU\n"
|
|
|
|
" 3. Open TunerStudio and reconnect\n\n");
|
|
|
|
}
|
|
|
|
|
2019-03-12 17:33:13 -07:00
|
|
|
void executeTSCommand(uint16_t subsystem, uint16_t index) {
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("IO test subsystem=%d index=%d", subsystem, index);
|
2016-03-14 20:01:43 -07:00
|
|
|
|
2021-11-17 00:54:21 -08:00
|
|
|
bool running = !engine->rpmCalculator.isStopped();
|
2020-08-18 10:51:20 -07:00
|
|
|
|
2021-01-06 10:55:57 -08:00
|
|
|
switch (subsystem) {
|
2021-10-28 10:49:44 -07:00
|
|
|
case TS_CLEAR_WARNINGS:
|
2021-01-06 10:55:57 -08:00
|
|
|
clearWarnings();
|
|
|
|
break;
|
|
|
|
|
2021-10-28 10:49:44 -07:00
|
|
|
case TS_DEBUG_MODE:
|
|
|
|
engineConfiguration->debugMode = (debug_mode_e)index;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TS_IGNITION_CATEGORY:
|
2021-01-06 10:55:57 -08:00
|
|
|
if (!running) {
|
2023-08-05 11:32:24 -07:00
|
|
|
doRunSparkBench(index, engineConfiguration->benchTestOnTime,
|
2022-02-27 10:14:42 -08:00
|
|
|
engineConfiguration->benchTestOffTime, engineConfiguration->benchTestCount);
|
2021-01-06 10:55:57 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-10-28 10:49:44 -07:00
|
|
|
case TS_INJECTOR_CATEGORY:
|
2021-01-06 11:04:37 -08:00
|
|
|
if (!running) {
|
2023-08-05 11:32:24 -07:00
|
|
|
doRunFuelInjBench(index, engineConfiguration->benchTestOnTime,
|
2022-02-27 10:14:42 -08:00
|
|
|
engineConfiguration->benchTestOffTime, engineConfiguration->benchTestCount);
|
2021-01-06 10:55:57 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-08-24 09:02:22 -07:00
|
|
|
case TS_SOLENOID_CATEGORY:
|
2021-01-06 11:04:37 -08:00
|
|
|
if (!running) {
|
2023-08-05 11:32:24 -07:00
|
|
|
doRunSolenoidBench(index, 1000.0,
|
2022-02-27 10:14:42 -08:00
|
|
|
1000.0, engineConfiguration->benchTestCount);
|
2021-01-06 10:55:57 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-08-24 09:02:22 -07:00
|
|
|
case TS_LUA_OUTPUT_CATEGORY:
|
2021-01-06 11:04:37 -08:00
|
|
|
if (!running) {
|
2023-08-05 11:32:24 -07:00
|
|
|
doRunBenchTestLuaOutput(index, 4.0,
|
2022-02-27 10:14:42 -08:00
|
|
|
engineConfiguration->benchTestOffTime, engineConfiguration->benchTestCount);
|
2021-01-06 10:55:57 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-10-28 10:49:44 -07:00
|
|
|
case TS_X14:
|
2019-04-23 20:20:14 -07:00
|
|
|
handleCommandX14(index);
|
2021-01-06 10:55:57 -08:00
|
|
|
break;
|
2022-04-16 14:10:53 -07:00
|
|
|
#if defined(EFI_WIDEBAND_FIRMWARE_UPDATE) && EFI_CAN_SUPPORT
|
2022-08-24 09:02:22 -07:00
|
|
|
case TS_WIDEBAND:
|
2021-04-18 17:02:32 -07:00
|
|
|
setWidebandOffset(index);
|
2021-03-14 14:20:50 -07:00
|
|
|
break;
|
2022-04-16 14:10:53 -07:00
|
|
|
#endif // EFI_WIDEBAND_FIRMWARE_UPDATE && EFI_CAN_SUPPORT
|
2022-08-24 09:02:22 -07:00
|
|
|
case TS_BENCH_CATEGORY:
|
2020-09-05 21:27:02 -07:00
|
|
|
handleBenchCategory(index);
|
2021-01-06 10:55:57 -08:00
|
|
|
break;
|
|
|
|
|
2022-09-04 06:52:14 -07:00
|
|
|
case TS_SET_ENGINE_TYPE:
|
2020-11-03 16:03:46 -08:00
|
|
|
fatalErrorForPresetApply();
|
2019-01-20 19:17:06 -08:00
|
|
|
setEngineType(index);
|
2021-01-06 10:55:57 -08:00
|
|
|
break;
|
|
|
|
|
2022-09-04 06:52:14 -07:00
|
|
|
case TS_SET_DEFAULT_ENGINE:
|
2020-11-03 16:03:46 -08:00
|
|
|
fatalErrorForPresetApply();
|
2023-06-18 08:05:44 -07:00
|
|
|
setEngineType((int)DEFAULT_ENGINE_TYPE);
|
2021-01-06 10:55:57 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x79:
|
2019-01-05 20:33:04 -08:00
|
|
|
scheduleStopEngine();
|
2021-01-06 10:55:57 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xba:
|
2023-05-24 06:58:22 -07:00
|
|
|
#if EFI_DFU_JUMP
|
2019-07-27 16:51:54 -07:00
|
|
|
jump_to_bootloader();
|
2023-05-24 06:58:22 -07:00
|
|
|
#endif /* EFI_DFU_JUMP */
|
2021-01-06 10:55:57 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xbb:
|
2019-06-23 06:46:14 -07:00
|
|
|
#if EFI_PROD_CODE
|
2019-06-28 20:33:48 -07:00
|
|
|
rebootNow();
|
|
|
|
#endif /* EFI_PROD_CODE */
|
2021-01-06 11:16:45 -08:00
|
|
|
break;
|
2022-07-21 22:21:11 -07:00
|
|
|
|
|
|
|
#if EFI_USE_OPENBLT
|
|
|
|
case 0xbc:
|
|
|
|
/* Jump to OpenBLT if present */
|
|
|
|
jump_to_openblt();
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2021-01-07 05:23:31 -08:00
|
|
|
default:
|
2023-08-20 19:23:44 -07:00
|
|
|
criticalError("Unexpected bench subsystem %d %d", subsystem, index);
|
2016-03-14 21:01:37 -07:00
|
|
|
}
|
2016-03-14 20:01:43 -07:00
|
|
|
}
|
|
|
|
|
2022-01-03 00:35:26 -08:00
|
|
|
void onConfigurationChangeBenchTest() {
|
2023-05-29 13:31:39 -07:00
|
|
|
// default values if configuration was not specified
|
|
|
|
if (engineConfiguration->benchTestOnTime == 0) {
|
|
|
|
engineConfiguration->benchTestOnTime = 4;
|
|
|
|
}
|
|
|
|
|
2023-05-29 13:58:51 -07:00
|
|
|
if (engineConfiguration->benchTestOffTime < 5) {
|
2023-05-29 13:31:39 -07:00
|
|
|
engineConfiguration->benchTestOffTime = 500;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (engineConfiguration->benchTestCount < 1) {
|
|
|
|
engineConfiguration->benchTestCount = 3;
|
|
|
|
}
|
2022-01-03 00:35:26 -08:00
|
|
|
}
|
|
|
|
|
2021-04-21 11:28:48 -07:00
|
|
|
void initBenchTest() {
|
2015-07-10 06:01:56 -07:00
|
|
|
addConsoleAction("fuelpumpbench", fuelPumpBench);
|
2022-02-27 10:14:42 -08:00
|
|
|
addConsoleActionF("fuelpumpbench2", fuelPumpBenchExt);
|
|
|
|
|
|
|
|
addConsoleActionFFF(CMD_FUEL_BENCH, fuelInjBench);
|
2023-08-05 11:32:24 -07:00
|
|
|
addConsoleActionFFFF("fuelbench2", fuelInjBenchExt);
|
2022-02-27 10:14:42 -08:00
|
|
|
|
|
|
|
addConsoleActionFFF(CMD_SPARK_BENCH, sparkBench);
|
2023-08-05 11:32:24 -07:00
|
|
|
addConsoleActionFFFF("sparkbench2", sparkBenchExt);
|
2022-02-27 10:14:42 -08:00
|
|
|
|
2023-08-05 11:32:24 -07:00
|
|
|
addConsoleActionFFFF("tcusolbench", tcuSolenoidBench);
|
2022-02-27 10:14:42 -08:00
|
|
|
|
2021-06-23 14:16:11 -07:00
|
|
|
addConsoleAction(CMD_AC_RELAY_BENCH, acRelayBench);
|
2022-02-27 10:14:42 -08:00
|
|
|
|
2021-06-23 14:16:11 -07:00
|
|
|
addConsoleAction(CMD_FAN_BENCH, fanBench);
|
|
|
|
addConsoleAction(CMD_FAN2_BENCH, fan2Bench);
|
2022-02-27 10:14:42 -08:00
|
|
|
addConsoleActionF("fanbench2", fanBenchExt);
|
|
|
|
|
2021-01-10 17:30:08 -08:00
|
|
|
addConsoleAction("mainrelaybench", mainRelayBench);
|
2021-03-14 14:20:50 -07:00
|
|
|
|
2022-04-16 14:10:53 -07:00
|
|
|
#if EFI_WIDEBAND_FIRMWARE_UPDATE && EFI_CAN_SUPPORT
|
2020-12-16 05:28:53 -08:00
|
|
|
addConsoleAction("update_wideband", []() { widebandUpdatePending = true; });
|
2021-04-18 17:02:32 -07:00
|
|
|
addConsoleActionI("set_wideband_index", [](int index) { setWidebandOffset(index); });
|
2022-04-16 14:10:53 -07:00
|
|
|
#endif // EFI_WIDEBAND_FIRMWARE_UPDATE && EFI_CAN_SUPPORT
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2020-08-19 18:05:08 -07:00
|
|
|
addConsoleAction(CMD_STARTER_BENCH, starterRelayBench);
|
|
|
|
addConsoleAction(CMD_MIL_BENCH, milBench);
|
2020-11-21 21:47:43 -08:00
|
|
|
addConsoleAction(CMD_HPFP_BENCH, hpfpValveBench);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2023-08-05 11:32:24 -07:00
|
|
|
addConsoleActionFFFF("luabench2", luaOutBench2);
|
2022-07-21 12:17:32 -07:00
|
|
|
instance.start();
|
2022-01-03 00:35:26 -08:00
|
|
|
onConfigurationChangeBenchTest();
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2019-04-09 20:00:17 -07:00
|
|
|
#endif /* EFI_UNIT_TEST */
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif
|