2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file injector_central.cpp
|
|
|
|
* @brief Utility methods related to fuel injection.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @date Sep 8, 2013
|
2018-01-20 17:55:31 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2018
|
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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// todo: rename this file
|
2018-09-16 19:26:57 -07:00
|
|
|
#include "global.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__)
|
2019-04-09 20:00:17 -07:00
|
|
|
#if !EFI_UNIT_TEST
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
#include "injector_central.h"
|
|
|
|
#include "io_pins.h"
|
|
|
|
#include "signal_executor.h"
|
|
|
|
#include "main_trigger_callback.h"
|
|
|
|
#include "engine_configuration.h"
|
|
|
|
#include "pin_repository.h"
|
2019-03-29 06:11:13 -07:00
|
|
|
#include "efi_gpio.h"
|
2017-07-25 19:00:39 -07:00
|
|
|
#include "settings.h"
|
2019-01-13 16:41:39 -08:00
|
|
|
#include "idle_thread.h"
|
2019-03-29 06:11:13 -07:00
|
|
|
#include "periodic_controller.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
EXTERN_ENGINE
|
|
|
|
;
|
|
|
|
|
2016-03-14 20:01:43 -07:00
|
|
|
static Logging * logger;
|
2016-01-11 14:01:33 -08:00
|
|
|
static bool isRunningBench = false;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-06-04 13:24:17 -07:00
|
|
|
// todo: move into Engine object?
|
|
|
|
// todo: looks like these flags are not currently used? dead functionality? unfinished functionality?
|
2016-09-15 11:02:45 -07:00
|
|
|
static int is_injector_enabled[INJECTION_PIN_COUNT];
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2016-01-11 14:01:33 -08:00
|
|
|
bool isRunningBenchTest(void) {
|
2015-07-10 06:01:56 -07:00
|
|
|
return isRunningBench;
|
|
|
|
}
|
|
|
|
|
2017-06-04 12:50:33 -07:00
|
|
|
static void assertCylinderId(int cylinderId, const char *msg) {
|
2015-07-10 06:01:56 -07:00
|
|
|
int isValid = cylinderId >= 1 && cylinderId <= engineConfiguration->specs.cylindersCount;
|
|
|
|
if (!isValid) {
|
|
|
|
// we are here only in case of a fatal issue - at this point it is fine to make some blocking i-o
|
|
|
|
//scheduleSimpleMsg(&logger, "cid=", cylinderId);
|
|
|
|
print("ERROR [%s] cid=%d\r\n", msg, cylinderId);
|
2018-07-25 20:03:04 -07:00
|
|
|
efiAssertVoid(CUSTOM_ERR_6647, false, "Cylinder ID");
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param cylinderId - from 1 to NUMBER_OF_CYLINDERS
|
|
|
|
*/
|
2017-06-04 12:50:33 -07:00
|
|
|
static int isInjectorEnabled(int cylinderId) {
|
2015-07-10 06:01:56 -07:00
|
|
|
assertCylinderId(cylinderId, "isInjectorEnabled");
|
|
|
|
return is_injector_enabled[cylinderId - 1];
|
|
|
|
}
|
|
|
|
|
2017-06-04 12:50:33 -07:00
|
|
|
static void printInjectorsStatus(void) {
|
2015-07-10 06:01:56 -07:00
|
|
|
for (int id = 1; id <= engineConfiguration->specs.cylindersCount; id++) {
|
2018-01-24 18:54:03 -08:00
|
|
|
scheduleMsg(logger, "injector_%d: %d", id, isInjectorEnabled(id));
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setInjectorEnabled(int id, int value) {
|
2018-07-25 20:03:04 -07:00
|
|
|
efiAssertVoid(CUSTOM_ERR_6648, id >= 0 && id < engineConfiguration->specs.cylindersCount, "injector id");
|
2015-07-10 06:01:56 -07:00
|
|
|
is_injector_enabled[id] = value;
|
2017-06-04 12:50:33 -07:00
|
|
|
printInjectorsStatus();
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void runBench(brain_pin_e brainPin, OutputPin *output, float delayMs, float onTimeMs, float offTimeMs,
|
|
|
|
int count) {
|
2019-01-28 17:00:17 -08:00
|
|
|
int delaySt = delayMs < 1 ? 1 : TIME_MS2I(delayMs);
|
|
|
|
int onTimeSt = onTimeMs < 1 ? 1 : TIME_MS2I(onTimeMs);
|
|
|
|
int offTimeSt = offTimeMs < 1 ? 1 : TIME_MS2I(offTimeMs);
|
2015-07-10 06:01:56 -07:00
|
|
|
if (delaySt < 0) {
|
2018-01-23 09:05:14 -08:00
|
|
|
scheduleMsg(logger, "Invalid delay %.2f", delayMs);
|
2015-07-10 06:01:56 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (onTimeSt <= 0) {
|
2018-01-23 09:05:14 -08:00
|
|
|
scheduleMsg(logger, "Invalid onTime %.2f", onTimeMs);
|
2015-07-10 06:01:56 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (offTimeSt <= 0) {
|
2018-01-23 09:05:14 -08:00
|
|
|
scheduleMsg(logger, "Invalid offTime %.2f", offTimeMs);
|
2015-07-10 06:01:56 -07:00
|
|
|
return;
|
|
|
|
}
|
2018-01-23 09:05:14 -08:00
|
|
|
scheduleMsg(logger, "Running bench: ON_TIME=%.2f ms OFF_TIME=%.2fms Counter=%d", onTimeMs, offTimeMs, count);
|
2016-03-14 20:01:43 -07:00
|
|
|
scheduleMsg(logger, "output on %s", hwPortname(brainPin));
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
if (delaySt != 0) {
|
|
|
|
chThdSleep(delaySt);
|
|
|
|
}
|
|
|
|
|
|
|
|
isRunningBench = true;
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
output->setValue(true);
|
|
|
|
chThdSleep(onTimeSt);
|
|
|
|
output->setValue(false);
|
|
|
|
chThdSleep(offTimeSt);
|
|
|
|
}
|
2016-03-14 20:01:43 -07:00
|
|
|
scheduleMsg(logger, "Done!");
|
2015-07-10 06:01:56 -07:00
|
|
|
isRunningBench = false;
|
|
|
|
}
|
|
|
|
|
2017-07-24 16:38:00 -07:00
|
|
|
static volatile bool isBenchTestPending = false;
|
2015-07-10 06:01:56 -07:00
|
|
|
static float onTime;
|
|
|
|
static float offTime;
|
|
|
|
static float delayMs;
|
|
|
|
static int count;
|
|
|
|
static brain_pin_e brainPin;
|
|
|
|
static OutputPin* pinX;
|
|
|
|
|
|
|
|
static void pinbench(const char *delayStr, const char *onTimeStr, const char *offTimeStr, const char *countStr,
|
|
|
|
OutputPin* pinParam, brain_pin_e brainPinParam) {
|
|
|
|
delayMs = atoff(delayStr);
|
|
|
|
onTime = atoff(onTimeStr);
|
|
|
|
offTime = atoff(offTimeStr);
|
|
|
|
count = atoi(countStr);
|
|
|
|
|
|
|
|
brainPin = brainPinParam;
|
|
|
|
pinX = pinParam;
|
2017-07-24 17:40:01 -07:00
|
|
|
isBenchTestPending = true; // let's signal bench thread to wake up
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2016-03-14 21:01:37 -07:00
|
|
|
static void doRunFuel(int humanIndex, const char *delayStr, const char * onTimeStr, const char *offTimeStr,
|
|
|
|
const char *countStr) {
|
|
|
|
if (humanIndex < 1 || humanIndex > engineConfiguration->specs.cylindersCount) {
|
|
|
|
scheduleMsg(logger, "Invalid index: %d", humanIndex);
|
|
|
|
return;
|
|
|
|
}
|
2019-01-09 19:57:33 -08:00
|
|
|
brain_pin_e b = CONFIGB(injectionPins)[humanIndex - 1];
|
2016-03-14 21:01:37 -07:00
|
|
|
pinbench(delayStr, onTimeStr, offTimeStr, countStr, &enginePins.injectors[humanIndex - 1], b);
|
|
|
|
}
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* delay 100, cylinder #2, 5ms ON, 1000ms OFF, repeat 2 times
|
|
|
|
* fuelbench2 100 2 5 1000 2
|
|
|
|
*/
|
|
|
|
static void fuelbench2(const char *delayStr, const char *indexStr, const char * onTimeStr, const char *offTimeStr,
|
|
|
|
const char *countStr) {
|
|
|
|
int index = atoi(indexStr);
|
2016-03-14 21:01:37 -07:00
|
|
|
doRunFuel(index, delayStr, onTimeStr, offTimeStr, countStr);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2017-07-24 17:40:01 -07:00
|
|
|
static void fanBenchExt(const char *durationMs) {
|
2019-01-09 19:57:33 -08:00
|
|
|
pinbench("0", durationMs, "100", "1", &enginePins.fanRelay, CONFIGB(fanPin));
|
2017-07-24 17:40:01 -07:00
|
|
|
}
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
void fanBench(void) {
|
2017-07-24 17:40:01 -07:00
|
|
|
fanBenchExt("3000");
|
2015-07-10 06:01:56 -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
|
|
|
|
*/
|
2015-07-10 06:01:56 -07:00
|
|
|
void milBench(void) {
|
2019-01-09 19:57:33 -08:00
|
|
|
pinbench("0", "500", "500", "16", &enginePins.checkEnginePin, CONFIGB(malfunctionIndicatorPin));
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2016-01-07 18:02:35 -08:00
|
|
|
void fuelPumpBenchExt(const char *durationMs) {
|
2019-01-09 19:57:33 -08:00
|
|
|
pinbench("0", durationMs, "100", "1", &enginePins.fuelPumpRelay, CONFIGB(fuelPumpPin));
|
2016-01-07 18:02:35 -08:00
|
|
|
}
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
void fuelPumpBench(void) {
|
2016-01-07 18:02:35 -08:00
|
|
|
fuelPumpBenchExt("3000");
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// fuelbench 5 1000 2
|
|
|
|
static void fuelbench(const char * onTimeStr, const char *offTimeStr, const char *countStr) {
|
|
|
|
fuelbench2("0", "1", onTimeStr, offTimeStr, countStr);
|
|
|
|
}
|
|
|
|
|
2016-03-14 21:01:37 -07:00
|
|
|
static void doRunSpark(int humanIndex, const char *delayStr, const char * onTimeStr, const char *offTimeStr,
|
|
|
|
const char *countStr) {
|
|
|
|
if (humanIndex < 1 || humanIndex > engineConfiguration->specs.cylindersCount) {
|
|
|
|
scheduleMsg(logger, "Invalid index: %d", humanIndex);
|
|
|
|
return;
|
|
|
|
}
|
2019-01-09 19:57:33 -08:00
|
|
|
brain_pin_e b = CONFIGB(ignitionPins)[humanIndex - 1];
|
2016-03-14 21:01:37 -07:00
|
|
|
pinbench(delayStr, onTimeStr, offTimeStr, countStr, &enginePins.coils[humanIndex - 1], b);
|
|
|
|
}
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* sparkbench2 0 1 5 1000 2
|
|
|
|
*/
|
|
|
|
static void sparkbench2(const char *delayStr, const char *indexStr, const char * onTimeStr, const char *offTimeStr,
|
|
|
|
const char *countStr) {
|
|
|
|
int index = atoi(indexStr);
|
2016-03-14 21:01:37 -07:00
|
|
|
doRunSpark(index, delayStr, onTimeStr, offTimeStr, countStr);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sparkbench 5 400 2
|
|
|
|
* 5 ms ON, 400 ms OFF, two times
|
|
|
|
*/
|
|
|
|
static void sparkbench(const char * onTimeStr, const char *offTimeStr, const char *countStr) {
|
|
|
|
sparkbench2("0", "1", onTimeStr, offTimeStr, countStr);
|
|
|
|
}
|
|
|
|
|
2017-04-24 19:35:16 -07:00
|
|
|
|
|
|
|
void dizzyBench(void) {
|
|
|
|
pinbench("300", "5", "400", "3", &enginePins.dizzyOutput, engineConfiguration->dizzySparkOutputPin);
|
|
|
|
}
|
|
|
|
|
2019-02-10 20:54:41 -08:00
|
|
|
class BenchController : public PeriodicController<UTILITY_THREAD_STACK_SIZE> {
|
|
|
|
public:
|
2019-02-11 12:09:24 -08:00
|
|
|
BenchController() : PeriodicController("BenchThread") { }
|
2019-02-10 20:54:41 -08:00
|
|
|
private:
|
|
|
|
void PeriodicTask(efitime_t nowNt) override {
|
2019-02-21 02:44:45 -08:00
|
|
|
UNUSED(nowNt);
|
2019-02-10 20:54:41 -08:00
|
|
|
setPeriod(NOT_TOO_OFTEN(10 /* ms */, engineConfiguration->auxPid[0].periodMs));
|
2017-04-24 19:35:16 -07:00
|
|
|
|
2017-07-24 16:38:00 -07:00
|
|
|
// naive inter-thread communication - waiting for a flag
|
2019-02-10 20:54:41 -08:00
|
|
|
if (isBenchTestPending) {
|
|
|
|
isBenchTestPending = false;
|
|
|
|
runBench(brainPin, pinX, delayMs, onTime, offTime, count);
|
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
|
|
|
|
2017-06-04 13:18:29 -07:00
|
|
|
void OutputPin::unregisterOutput(brain_pin_e oldPin, brain_pin_e newPin) {
|
|
|
|
if (oldPin != GPIO_UNASSIGNED && oldPin != newPin) {
|
|
|
|
scheduleMsg(logger, "unregistering %s", hwPortname(oldPin));
|
2017-07-10 18:34:31 -07:00
|
|
|
#if EFI_GPIO_HARDWARE || defined(__DOXYGEN__)
|
2019-04-09 16:31:10 -07:00
|
|
|
brain_pin_markUnused(oldPin);
|
2017-07-10 18:34:31 -07:00
|
|
|
port = NULL;
|
2018-10-30 05:42:36 -07:00
|
|
|
#endif /* EFI_GPIO_HARDWARE */
|
2016-09-14 16:03:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-12 17:33:13 -07:00
|
|
|
void executeTSCommand(uint16_t subsystem, uint16_t index) {
|
2016-03-14 20:01:43 -07:00
|
|
|
scheduleMsg(logger, "IO test subsystem=%d index=%d", subsystem, index);
|
|
|
|
|
2016-03-14 21:01:37 -07:00
|
|
|
if (subsystem == 0x12) {
|
|
|
|
doRunSpark(index, "300", "4", "400", "3");
|
|
|
|
} else if (subsystem == 0x13) {
|
2016-03-15 10:01:47 -07:00
|
|
|
doRunFuel(index, "300", "4", "400", "3");
|
|
|
|
} else if (subsystem == 0x14) {
|
2019-01-13 16:41:39 -08:00
|
|
|
// cmd_test_fuel_pump
|
2016-03-15 10:01:47 -07:00
|
|
|
fuelPumpBench();
|
|
|
|
} else if (subsystem == 0x15) {
|
|
|
|
fanBench();
|
|
|
|
} else if (subsystem == 0x16) {
|
2019-01-13 16:41:39 -08:00
|
|
|
// cmd_test_check_engine_light
|
2016-03-15 10:01:47 -07:00
|
|
|
milBench();
|
|
|
|
} else if (subsystem == 0x17) {
|
2019-01-13 16:41:39 -08:00
|
|
|
// cmd_test_idle_valve
|
2019-01-31 14:55:23 -08:00
|
|
|
#if EFI_IDLE_CONTROL || defined(__DOXYGEN__)
|
2019-01-13 16:41:39 -08:00
|
|
|
startIdleBench();
|
2019-01-31 14:55:23 -08:00
|
|
|
#endif
|
2017-05-01 19:33:20 -07:00
|
|
|
} else if (subsystem == 0x20 && index == 0x3456) {
|
2017-07-25 19:00:39 -07:00
|
|
|
// call to pit
|
|
|
|
setCallFromPitStop(30000);
|
2019-01-20 19:17:06 -08:00
|
|
|
} else if (subsystem == 0x30) {
|
|
|
|
setEngineType(index);
|
2019-03-12 17:33:13 -07:00
|
|
|
} else if (subsystem == 0x31) {
|
|
|
|
setEngineType(DEFAULT_ENGINE_TYPE);
|
2019-03-12 11:35:49 -07:00
|
|
|
} else if (subsystem == 0x79) {
|
2019-01-05 20:33:04 -08:00
|
|
|
scheduleStopEngine();
|
2016-03-14 21:01:37 -07:00
|
|
|
}
|
2016-03-14 20:01:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void initInjectorCentral(Logging *sharedLogger) {
|
|
|
|
logger = sharedLogger;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-06-04 12:50:33 -07:00
|
|
|
for (int i = 0; i < INJECTION_PIN_COUNT; i++) {
|
2015-07-10 06:01:56 -07:00
|
|
|
is_injector_enabled[i] = true;
|
|
|
|
}
|
|
|
|
|
2017-06-04 15:43:08 -07:00
|
|
|
enginePins.startInjectionPins();
|
|
|
|
enginePins.startIgnitionPins();
|
2017-11-26 19:30:37 -08:00
|
|
|
enginePins.startAuxValves();
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-06-04 12:50:33 -07:00
|
|
|
printInjectorsStatus();
|
2015-07-10 06:01:56 -07:00
|
|
|
addConsoleActionII("injector", setInjectorEnabled);
|
|
|
|
|
|
|
|
addConsoleAction("fuelpumpbench", fuelPumpBench);
|
2016-01-07 18:02:35 -08:00
|
|
|
addConsoleActionS("fuelpumpbench2", fuelPumpBenchExt);
|
2015-07-10 06:01:56 -07:00
|
|
|
addConsoleAction("fanbench", fanBench);
|
2017-07-24 17:40:01 -07:00
|
|
|
addConsoleActionS("fanbench2", fanBenchExt);
|
2017-04-24 19:43:29 -07:00
|
|
|
addConsoleAction("dizzybench", dizzyBench); // this is useful for tach output testing
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
addConsoleAction("milbench", milBench);
|
|
|
|
addConsoleActionSSS("fuelbench", fuelbench);
|
|
|
|
addConsoleActionSSS("sparkbench", sparkbench);
|
|
|
|
|
|
|
|
addConsoleActionSSSSS("fuelbench2", fuelbench2);
|
|
|
|
addConsoleActionSSSSS("sparkbench2", sparkbench2);
|
2019-02-10 20:54:41 -08:00
|
|
|
instance.setPeriod(200 /*ms*/);
|
|
|
|
instance.Start();
|
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
|