2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file engine_controller.cpp
|
|
|
|
* @brief Controllers package entry point code
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @date Feb 7, 2013
|
2020-01-07 21:02:40 -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"
|
|
|
|
|
2019-07-03 18:48:04 -07:00
|
|
|
#include "os_access.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "trigger_central.h"
|
|
|
|
#include "fsio_core.h"
|
|
|
|
#include "fsio_impl.h"
|
|
|
|
#include "idle_thread.h"
|
2019-12-23 21:03:53 -08:00
|
|
|
#include "advance_map.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "main_trigger_callback.h"
|
|
|
|
#include "flash_main.h"
|
2020-03-26 05:03:55 -07:00
|
|
|
#include "bench_test.h"
|
2019-07-06 17:15:49 -07:00
|
|
|
#include "os_util.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "electronic_throttle.h"
|
|
|
|
#include "map_averaging.h"
|
2020-11-05 13:42:56 -08:00
|
|
|
#include "high_pressure_fuel_pump.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "malfunction_central.h"
|
|
|
|
#include "malfunction_indicator.h"
|
2019-12-23 21:03:53 -08:00
|
|
|
#include "speed_density.h"
|
2019-03-31 13:56:13 -07:00
|
|
|
#include "local_version_holder.h"
|
|
|
|
#include "alternator_controller.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "fuel_math.h"
|
2019-12-23 21:26:23 -08:00
|
|
|
#include "spark_logic.h"
|
|
|
|
#include "aux_valves.h"
|
2017-08-28 17:11:32 -07:00
|
|
|
#include "accelerometer.h"
|
2021-03-14 16:31:46 -07:00
|
|
|
#include "vvt.h"
|
2020-02-02 00:56:21 -08:00
|
|
|
#include "boost_control.h"
|
2020-03-23 17:44:34 -07:00
|
|
|
#include "launch_control.h"
|
2020-04-01 16:00:56 -07:00
|
|
|
#include "tachometer.h"
|
2020-04-26 11:06:28 -07:00
|
|
|
#include "gppwm.h"
|
2020-06-17 09:59:57 -07:00
|
|
|
#include "date_stamp.h"
|
2020-09-02 17:17:58 -07:00
|
|
|
#include "buttonshift.h"
|
2020-09-09 00:22:15 -07:00
|
|
|
#include "start_stop.h"
|
2020-12-04 17:28:48 -08:00
|
|
|
#include "dynoview.h"
|
2021-07-28 04:44:44 -07:00
|
|
|
#include "vr_pwm.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-12-23 20:25:08 -08:00
|
|
|
#if EFI_SENSOR_CHART
|
|
|
|
#include "sensor_chart.h"
|
2020-03-22 21:01:59 -07:00
|
|
|
#endif /* EFI_SENSOR_CHART */
|
2019-12-23 20:25:08 -08:00
|
|
|
|
|
|
|
#if EFI_TUNER_STUDIO
|
|
|
|
#include "tunerstudio.h"
|
2020-03-22 21:01:59 -07:00
|
|
|
#endif /* EFI_TUNER_STUDIO */
|
2019-12-23 20:25:08 -08:00
|
|
|
|
|
|
|
#if EFI_LOGIC_ANALYZER
|
|
|
|
#include "logic_analyzer.h"
|
2020-03-22 21:01:59 -07:00
|
|
|
#endif /* EFI_LOGIC_ANALYZER */
|
2019-12-23 20:25:08 -08:00
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if HAL_USE_ADC
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "AdcConfiguration.h"
|
2016-08-20 20:02:09 -07:00
|
|
|
#endif /* HAL_USE_ADC */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-07-09 05:33:40 -07:00
|
|
|
#if defined(EFI_BOOTLOADER_INCLUDE_CODE)
|
|
|
|
#include "bootloader/bootloader.h"
|
|
|
|
#endif /* EFI_BOOTLOADER_INCLUDE_CODE */
|
|
|
|
|
|
|
|
#include "periodic_task.h"
|
2020-04-26 14:07:39 -07:00
|
|
|
|
2019-07-09 05:33:40 -07:00
|
|
|
|
2019-09-21 12:43:18 -07:00
|
|
|
#if ! EFI_UNIT_TEST
|
2019-09-21 12:33:13 -07:00
|
|
|
#include "init.h"
|
2019-09-22 14:19:08 -07:00
|
|
|
#endif /* EFI_UNIT_TEST */
|
2019-09-21 12:43:18 -07:00
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_PROD_CODE
|
2019-03-29 06:11:13 -07:00
|
|
|
#include "pwm_tester.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "lcd_controller.h"
|
2016-08-20 20:02:09 -07:00
|
|
|
#endif /* EFI_PROD_CODE */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_CJ125
|
2019-04-09 16:12:35 -07:00
|
|
|
#include "cj125.h"
|
2019-07-09 05:33:40 -07:00
|
|
|
#endif /* EFI_CJ125 */
|
2018-11-03 06:44:34 -07:00
|
|
|
|
2020-03-22 21:01:59 -07:00
|
|
|
#if !EFI_UNIT_TEST
|
|
|
|
|
|
|
|
/**
|
2020-08-26 17:49:21 -07:00
|
|
|
* Would love to pass reference to configuration object into constructor but C++ does allow attributes after parenthesized initializer
|
2020-03-22 21:01:59 -07:00
|
|
|
*/
|
|
|
|
Engine ___engine CCM_OPTIONAL;
|
|
|
|
Engine * engine = &___engine;
|
|
|
|
|
2021-11-15 21:23:14 -08:00
|
|
|
#else // EFI_UNIT_TEST
|
|
|
|
|
|
|
|
Engine * engine;
|
|
|
|
|
2020-03-22 21:01:59 -07:00
|
|
|
#endif /* EFI_UNIT_TEST */
|
|
|
|
|
|
|
|
|
2019-12-23 21:03:53 -08:00
|
|
|
void initDataStructures(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
2020-02-26 15:16:35 -08:00
|
|
|
#if EFI_ENGINE_CONTROL
|
2019-12-23 21:03:53 -08:00
|
|
|
initFuelMap(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
initTimingMap(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
initSpeedDensity(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-02-26 15:16:35 -08:00
|
|
|
#endif // EFI_ENGINE_CONTROL
|
2019-12-23 21:03:53 -08:00
|
|
|
}
|
|
|
|
|
2020-03-22 21:01:59 -07:00
|
|
|
#if !EFI_UNIT_TEST
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-07-09 05:33:40 -07:00
|
|
|
static void doPeriodicSlowCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-07-09 05:33:40 -07:00
|
|
|
class PeriodicFastController : public PeriodicTimerController {
|
|
|
|
void PeriodicTask() override {
|
|
|
|
engine->periodicFastCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
int getPeriodMs() override {
|
|
|
|
return FAST_CALLBACK_PERIOD_MS;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class PeriodicSlowController : public PeriodicTimerController {
|
|
|
|
void PeriodicTask() override {
|
|
|
|
doPeriodicSlowCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
int getPeriodMs() override {
|
2020-06-13 19:46:10 -07:00
|
|
|
// no reason to have this configurable, looks like everyone is happy with 20Hz
|
2020-11-11 18:47:19 -08:00
|
|
|
return SLOW_CALLBACK_PERIOD_MS;
|
2019-07-09 05:33:40 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static PeriodicFastController fastController;
|
|
|
|
static PeriodicSlowController slowController;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-07-13 08:06:03 -07:00
|
|
|
class EngineStateBlinkingTask : public PeriodicTimerController {
|
|
|
|
int getPeriodMs() override {
|
|
|
|
return 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeriodicTask() override {
|
|
|
|
counter++;
|
2020-02-26 15:16:35 -08:00
|
|
|
#if EFI_SHAFT_POSITION_INPUT
|
2020-09-05 15:49:42 -07:00
|
|
|
bool is_running = ENGINE(rpmCalculator).isRunning();
|
2020-02-26 15:16:35 -08:00
|
|
|
#else
|
|
|
|
bool is_running = false;
|
2020-03-22 21:01:59 -07:00
|
|
|
#endif /* EFI_SHAFT_POSITION_INPUT */
|
2019-07-13 08:06:03 -07:00
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
if (is_running) {
|
2019-07-13 08:06:03 -07:00
|
|
|
// blink in running mode
|
|
|
|
enginePins.runningLedPin.setValue(counter % 2);
|
2015-07-10 06:01:56 -07:00
|
|
|
} else {
|
2020-09-05 15:49:42 -07:00
|
|
|
int is_cranking = ENGINE(rpmCalculator).isCranking();
|
2018-07-26 12:51:06 -07:00
|
|
|
enginePins.runningLedPin.setValue(is_cranking);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
}
|
2019-07-13 08:06:03 -07:00
|
|
|
private:
|
|
|
|
int counter = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
static EngineStateBlinkingTask engineStateBlinkingTask;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-11-11 18:31:24 -08:00
|
|
|
/**
|
|
|
|
* 32 bit return type overflows in 23 days. I think we do not expect rusEFI to run for 23 days straight days any time soon?
|
|
|
|
*/
|
2015-07-10 06:01:56 -07:00
|
|
|
efitimems_t currentTimeMillis(void) {
|
2021-11-11 13:43:41 -08:00
|
|
|
return US2MS(getTimeNowUs());
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2021-11-11 14:54:31 -08:00
|
|
|
/**
|
|
|
|
* Integer number of seconds since ECU boot.
|
|
|
|
* 31,710 years - would not overflow during our life span.
|
|
|
|
*/
|
2016-07-14 20:02:55 -07:00
|
|
|
efitimesec_t getTimeNowSeconds(void) {
|
2021-11-11 14:54:31 -08:00
|
|
|
return getTimeNowUs() / US_PER_SECOND;
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2021-11-15 04:02:34 -08:00
|
|
|
static void resetAccel() {
|
2019-07-12 20:15:52 -07:00
|
|
|
engine->tpsAccelEnrichment.resetAE();
|
2019-10-16 21:06:54 -07:00
|
|
|
|
2021-03-20 05:40:36 -07:00
|
|
|
for (size_t i = 0; i < efi::size(engine->injectionEvents.elements); i++)
|
2019-10-16 21:06:54 -07:00
|
|
|
{
|
2020-07-20 00:55:45 -07:00
|
|
|
engine->injectionEvents.elements[i].wallFuel.resetWF();
|
2019-10-16 21:06:54 -07:00
|
|
|
}
|
2016-01-08 12:01:38 -08:00
|
|
|
}
|
|
|
|
|
2019-07-07 16:59:48 -07:00
|
|
|
static void doPeriodicSlowCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
2020-03-22 21:01:59 -07:00
|
|
|
#if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
|
2019-02-23 09:33:49 -08:00
|
|
|
efiAssertVoid(CUSTOM_ERR_6661, getCurrentRemainingStack() > 64, "lowStckOnEv");
|
2020-11-18 17:53:03 -08:00
|
|
|
|
2020-03-23 07:32:41 -07:00
|
|
|
slowStartStopButtonCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-11-18 17:53:03 -08:00
|
|
|
|
2020-04-01 18:22:54 -07:00
|
|
|
|
2020-04-26 17:50:49 -07:00
|
|
|
efitick_t nowNt = getTimeNowNt();
|
2021-01-26 18:43:23 -08:00
|
|
|
for (int bankIndex = 0; bankIndex < BANKS_COUNT; bankIndex++) {
|
2021-02-08 17:38:38 -08:00
|
|
|
for (int camIndex = 0; camIndex < CAMS_PER_BANK; camIndex++) {
|
|
|
|
if (nowNt - engine->triggerCentral.vvtSyncTimeNt[bankIndex][camIndex] >= NT_PER_SECOND) {
|
|
|
|
// loss of VVT sync
|
|
|
|
engine->triggerCentral.vvtSyncTimeNt[bankIndex][camIndex] = 0;
|
|
|
|
|
|
|
|
}
|
2021-01-26 18:43:23 -08:00
|
|
|
}
|
2020-04-26 17:50:49 -07:00
|
|
|
}
|
|
|
|
|
2017-07-06 16:33:25 -07:00
|
|
|
/**
|
|
|
|
* Update engine RPM state if needed (check timeouts).
|
|
|
|
*/
|
2020-04-26 17:50:49 -07:00
|
|
|
bool isSpinning = engine->rpmCalculator.checkIfSpinning(nowNt PASS_ENGINE_PARAMETER_SUFFIX);
|
2019-01-24 18:12:55 -08:00
|
|
|
if (!isSpinning) {
|
|
|
|
engine->rpmCalculator.setStopSpinning(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
}
|
2017-07-06 16:33:25 -07:00
|
|
|
|
2020-09-05 15:49:42 -07:00
|
|
|
if (ENGINE(directSelfStimulation) || engine->rpmCalculator.isStopped()) {
|
2020-04-08 15:03:46 -07:00
|
|
|
/**
|
|
|
|
* rusEfi usually runs on hardware which halts execution while writing to internal flash, so we
|
|
|
|
* postpone writes to until engine is stopped. Writes in case of self-stimulation are fine.
|
|
|
|
*
|
|
|
|
* todo: allow writing if 2nd bank of flash is used
|
|
|
|
*/
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_INTERNAL_FLASH
|
2015-07-10 06:01:56 -07:00
|
|
|
writeToFlashIfPending();
|
2018-12-23 21:31:26 -08:00
|
|
|
#endif /* EFI_INTERNAL_FLASH */
|
2020-04-08 15:03:46 -07:00
|
|
|
}
|
|
|
|
|
2021-01-09 13:51:24 -08:00
|
|
|
if (engine->rpmCalculator.isStopped()) {
|
|
|
|
resetAccel();
|
|
|
|
} else {
|
2017-12-23 11:15:35 -08:00
|
|
|
updatePrimeInjectionPulseState(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2015-09-03 06:01:31 -07:00
|
|
|
}
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-04-15 18:09:43 -07:00
|
|
|
if (engine->versionForConfigurationListeners.isOld(engine->getGlobalConfigurationVersion())) {
|
2016-01-31 13:01:26 -08:00
|
|
|
updateAccelParameters();
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2019-01-14 07:58:38 -08:00
|
|
|
engine->periodicSlowCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-03-22 21:01:59 -07:00
|
|
|
#endif /* if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT */
|
2020-09-02 12:39:50 -07:00
|
|
|
|
|
|
|
if (CONFIG(tcuEnabled)) {
|
|
|
|
engine->gearController->update();
|
|
|
|
}
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2017-05-15 20:28:49 -07:00
|
|
|
void initPeriodicEvents(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
2019-07-09 13:08:49 -07:00
|
|
|
slowController.Start();
|
|
|
|
fastController.Start();
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2016-12-27 11:04:04 -08:00
|
|
|
char * getPinNameByAdcChannel(const char *msg, adc_channel_e hwChannel, char *buffer) {
|
2019-04-12 19:07:03 -07:00
|
|
|
#if HAL_USE_ADC
|
2021-01-05 13:02:20 -08:00
|
|
|
if (!isAdcChannelValid(hwChannel)) {
|
2016-12-27 11:04:04 -08:00
|
|
|
strcpy(buffer, "NONE");
|
|
|
|
} else {
|
2020-05-20 22:08:07 -07:00
|
|
|
strcpy(buffer, portname(getAdcChannelPort(msg, hwChannel)));
|
2016-12-27 11:04:04 -08:00
|
|
|
itoa10(&buffer[2], getAdcChannelPin(hwChannel));
|
|
|
|
}
|
2015-07-10 06:01:56 -07:00
|
|
|
#else
|
|
|
|
strcpy(buffer, "NONE");
|
2020-03-22 21:01:59 -07:00
|
|
|
#endif /* HAL_USE_ADC */
|
2020-05-20 22:08:07 -07:00
|
|
|
return buffer;
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static char pinNameBuffer[16];
|
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if HAL_USE_ADC
|
2015-07-10 06:01:56 -07:00
|
|
|
extern AdcDevice fastAdc;
|
2020-03-22 21:01:59 -07:00
|
|
|
#endif /* HAL_USE_ADC */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
static void printAnalogChannelInfoExt(const char *name, adc_channel_e hwChannel, float adcVoltage,
|
|
|
|
float dividerCoeff) {
|
2019-04-12 19:07:03 -07:00
|
|
|
#if HAL_USE_ADC
|
2021-01-05 13:02:20 -08:00
|
|
|
if (!isAdcChannelValid(hwChannel)) {
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("ADC is not assigned for %s", name);
|
2015-07-10 06:01:56 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
float voltage = adcVoltage * dividerCoeff;
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("%s ADC%d %s %s adc=%.2f/input=%.2fv/divider=%.2f", name, hwChannel, getAdc_channel_mode_e(getAdcMode(hwChannel)),
|
2016-12-27 11:04:04 -08:00
|
|
|
getPinNameByAdcChannel(name, hwChannel, pinNameBuffer), adcVoltage, voltage, dividerCoeff);
|
2020-03-22 21:01:59 -07:00
|
|
|
#endif /* HAL_USE_ADC */
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printAnalogChannelInfo(const char *name, adc_channel_e hwChannel) {
|
2019-04-12 19:07:03 -07:00
|
|
|
#if HAL_USE_ADC
|
2020-08-23 14:21:08 -07:00
|
|
|
printAnalogChannelInfoExt(name, hwChannel, getVoltage(name, hwChannel PASS_ENGINE_PARAMETER_SUFFIX), engineConfiguration->analogInputDividerCoefficient);
|
2020-03-22 21:01:59 -07:00
|
|
|
#endif /* HAL_USE_ADC */
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2021-11-15 04:02:34 -08:00
|
|
|
static void printAnalogInfo() {
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("analogInputDividerCoefficient: %.2f", engineConfiguration->analogInputDividerCoefficient);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
printAnalogChannelInfo("hip9011", engineConfiguration->hipOutputChannel);
|
|
|
|
printAnalogChannelInfo("fuel gauge", engineConfiguration->fuelLevelSensor);
|
2020-08-22 05:06:04 -07:00
|
|
|
printAnalogChannelInfo("TPS1 Primary", engineConfiguration->tps1_1AdcChannel);
|
|
|
|
printAnalogChannelInfo("TPS1 Secondary", engineConfiguration->tps1_2AdcChannel);
|
|
|
|
printAnalogChannelInfo("TPS2 Primary", engineConfiguration->tps2_1AdcChannel);
|
|
|
|
printAnalogChannelInfo("TPS2 Secondary", engineConfiguration->tps2_2AdcChannel);
|
2020-10-23 04:31:47 -07:00
|
|
|
printAnalogChannelInfo("LPF", engineConfiguration->lowPressureFuel.hwChannel);
|
|
|
|
printAnalogChannelInfo("HPF", engineConfiguration->highPressureFuel.hwChannel);
|
2020-08-18 21:46:57 -07:00
|
|
|
printAnalogChannelInfo("pPS1", engineConfiguration->throttlePedalPositionAdcChannel);
|
|
|
|
printAnalogChannelInfo("pPS2", engineConfiguration->throttlePedalPositionSecondAdcChannel);
|
2020-03-30 11:12:57 -07:00
|
|
|
printAnalogChannelInfo("CLT", engineConfiguration->clt.adcChannel);
|
|
|
|
printAnalogChannelInfo("IAT", engineConfiguration->iat.adcChannel);
|
2020-07-27 17:23:57 -07:00
|
|
|
printAnalogChannelInfo("AuxT1", engineConfiguration->auxTempSensor1.adcChannel);
|
|
|
|
printAnalogChannelInfo("AuxT2", engineConfiguration->auxTempSensor2.adcChannel);
|
2020-03-30 11:12:57 -07:00
|
|
|
printAnalogChannelInfo("MAF", engineConfiguration->mafAdcChannel);
|
2021-09-01 04:47:25 -07:00
|
|
|
for (int i = 0; i < AUX_ANALOG_INPUT_COUNT ; i++) {
|
2021-10-19 17:04:03 -07:00
|
|
|
adc_channel_e ch = engineConfiguration->auxAnalogInputs[i];
|
|
|
|
printAnalogChannelInfo("Aux analog", ch);
|
2016-05-15 21:02:01 -07:00
|
|
|
}
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
printAnalogChannelInfo("AFR", engineConfiguration->afr.hwChannel);
|
2020-03-30 11:12:57 -07:00
|
|
|
printAnalogChannelInfo("MAP", engineConfiguration->map.sensor.hwChannel);
|
|
|
|
printAnalogChannelInfo("BARO", engineConfiguration->baroSensor.hwChannel);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-11-15 11:30:13 -08:00
|
|
|
printAnalogChannelInfo("OilP", engineConfiguration->oilPressure.hwChannel);
|
|
|
|
|
2020-03-23 20:16:57 -07:00
|
|
|
printAnalogChannelInfo("CJ UR", engineConfiguration->cj125ur);
|
|
|
|
printAnalogChannelInfo("CJ UA", engineConfiguration->cj125ua);
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
printAnalogChannelInfo("HIP9011", engineConfiguration->hipOutputChannel);
|
2020-03-23 20:16:57 -07:00
|
|
|
|
2019-09-22 07:02:07 -07:00
|
|
|
printAnalogChannelInfoExt("Vbatt", engineConfiguration->vbattAdcChannel, getVoltage("vbatt", engineConfiguration->vbattAdcChannel PASS_ENGINE_PARAMETER_SUFFIX),
|
2015-07-10 06:01:56 -07:00
|
|
|
engineConfiguration->vbattDividerCoeff);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define isOutOfBounds(offset) ((offset<0) || (offset) >= (int) sizeof(engine_configuration_s))
|
|
|
|
|
|
|
|
static void getShort(int offset) {
|
|
|
|
if (isOutOfBounds(offset))
|
|
|
|
return;
|
|
|
|
uint16_t *ptr = (uint16_t *) (&((char *) engineConfiguration)[offset]);
|
|
|
|
uint16_t value = *ptr;
|
|
|
|
/**
|
2019-05-02 14:52:48 -07:00
|
|
|
* this response is part of rusEfi console API
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("short%s%d is %d", CONSOLE_DATA_PROTOCOL_TAG, offset, value);
|
2019-04-08 08:19:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void getByte(int offset) {
|
|
|
|
if (isOutOfBounds(offset))
|
|
|
|
return;
|
|
|
|
uint8_t *ptr = (uint8_t *) (&((char *) engineConfiguration)[offset]);
|
|
|
|
uint8_t value = *ptr;
|
|
|
|
/**
|
2019-05-02 14:52:48 -07:00
|
|
|
* this response is part of rusEfi console API
|
2019-04-08 08:19:07 -07:00
|
|
|
*/
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("byte%s%d is %d", CONSOLE_DATA_PROTOCOL_TAG, offset, value);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2019-04-08 08:57:16 -07:00
|
|
|
static void onConfigurationChanged() {
|
|
|
|
#if EFI_TUNER_STUDIO
|
|
|
|
// on start-up rusEfi would read from working copy of TS while
|
|
|
|
// we have a lot of console commands which write into real copy of configuration directly
|
|
|
|
// we have a bit of a mess here
|
|
|
|
syncTunerStudioCopy();
|
|
|
|
#endif /* EFI_TUNER_STUDIO */
|
|
|
|
incrementGlobalConfigurationVersion(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
}
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
static void setBit(const char *offsetStr, const char *bitStr, const char *valueStr) {
|
|
|
|
int offset = atoi(offsetStr);
|
|
|
|
if (absI(offset) == absI(ERROR_CODE)) {
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("invalid offset [%s]", offsetStr);
|
2015-07-10 06:01:56 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isOutOfBounds(offset)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int bit = atoi(bitStr);
|
|
|
|
if (absI(bit) == absI(ERROR_CODE)) {
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("invalid bit [%s]", bitStr);
|
2015-07-10 06:01:56 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
int value = atoi(valueStr);
|
|
|
|
if (absI(value) == absI(ERROR_CODE)) {
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("invalid value [%s]", valueStr);
|
2015-07-10 06:01:56 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
int *ptr = (int *) (&((char *) engineConfiguration)[offset]);
|
|
|
|
*ptr ^= (-value ^ *ptr) & (1 << bit);
|
|
|
|
/**
|
2019-05-02 14:52:48 -07:00
|
|
|
* this response is part of rusEfi console API
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("bit%s%d/%d is %d", CONSOLE_DATA_PROTOCOL_TAG, offset, bit, value);
|
2019-04-08 08:57:16 -07:00
|
|
|
onConfigurationChanged();
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void setShort(const int offset, const int value) {
|
|
|
|
if (isOutOfBounds(offset))
|
|
|
|
return;
|
|
|
|
uint16_t *ptr = (uint16_t *) (&((char *) engineConfiguration)[offset]);
|
|
|
|
*ptr = (uint16_t) value;
|
|
|
|
getShort(offset);
|
2019-04-08 08:57:16 -07:00
|
|
|
onConfigurationChanged();
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2019-04-08 08:19:07 -07:00
|
|
|
static void setByte(const int offset, const int value) {
|
|
|
|
if (isOutOfBounds(offset))
|
|
|
|
return;
|
|
|
|
uint8_t *ptr = (uint8_t *) (&((char *) engineConfiguration)[offset]);
|
|
|
|
*ptr = (uint8_t) value;
|
|
|
|
getByte(offset);
|
2019-04-08 08:57:16 -07:00
|
|
|
onConfigurationChanged();
|
2019-04-08 08:19:07 -07:00
|
|
|
}
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
static void getBit(int offset, int bit) {
|
|
|
|
if (isOutOfBounds(offset))
|
|
|
|
return;
|
|
|
|
int *ptr = (int *) (&((char *) engineConfiguration)[offset]);
|
|
|
|
int value = (*ptr >> bit) & 1;
|
|
|
|
/**
|
2019-05-02 14:52:48 -07:00
|
|
|
* this response is part of rusEfi console API
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("bit%s%d/%d is %d", CONSOLE_DATA_PROTOCOL_TAG, offset, bit, value);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void getInt(int offset) {
|
|
|
|
if (isOutOfBounds(offset))
|
|
|
|
return;
|
|
|
|
int *ptr = (int *) (&((char *) engineConfiguration)[offset]);
|
|
|
|
int value = *ptr;
|
|
|
|
/**
|
2019-05-02 14:52:48 -07:00
|
|
|
* this response is part of rusEfi console API
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("int%s%d is %d", CONSOLE_DATA_PROTOCOL_TAG, offset, value);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void setInt(const int offset, const int value) {
|
|
|
|
if (isOutOfBounds(offset))
|
|
|
|
return;
|
|
|
|
int *ptr = (int *) (&((char *) engineConfiguration)[offset]);
|
|
|
|
*ptr = value;
|
|
|
|
getInt(offset);
|
2019-04-08 08:57:16 -07:00
|
|
|
onConfigurationChanged();
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void getFloat(int offset) {
|
|
|
|
if (isOutOfBounds(offset))
|
|
|
|
return;
|
|
|
|
float *ptr = (float *) (&((char *) engineConfiguration)[offset]);
|
|
|
|
float value = *ptr;
|
|
|
|
/**
|
2019-05-02 14:52:48 -07:00
|
|
|
* this response is part of rusEfi console API
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("float%s%d is %.5f", CONSOLE_DATA_PROTOCOL_TAG, offset, value);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void setFloat(const char *offsetStr, const char *valueStr) {
|
|
|
|
int offset = atoi(offsetStr);
|
|
|
|
if (absI(offset) == absI(ERROR_CODE)) {
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("invalid offset [%s]", offsetStr);
|
2015-07-10 06:01:56 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isOutOfBounds(offset))
|
|
|
|
return;
|
|
|
|
float value = atoff(valueStr);
|
|
|
|
if (cisnan(value)) {
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("invalid value [%s]", valueStr);
|
2015-07-10 06:01:56 -07:00
|
|
|
return;
|
|
|
|
}
|
2019-01-04 21:57:09 -08:00
|
|
|
float *ptr = (float *) (&((char *) engineConfiguration)[offset]);
|
2015-07-10 06:01:56 -07:00
|
|
|
*ptr = value;
|
|
|
|
getFloat(offset);
|
2019-04-08 08:57:16 -07:00
|
|
|
onConfigurationChanged();
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
2019-09-22 14:19:08 -07:00
|
|
|
|
2021-11-15 04:02:34 -08:00
|
|
|
static void initConfigActions() {
|
2015-07-10 06:01:56 -07:00
|
|
|
addConsoleActionSS("set_float", (VoidCharPtrCharPtr) setFloat);
|
|
|
|
addConsoleActionII("set_int", (VoidIntInt) setInt);
|
|
|
|
addConsoleActionII("set_short", (VoidIntInt) setShort);
|
2019-04-08 08:19:07 -07:00
|
|
|
addConsoleActionII("set_byte", (VoidIntInt) setByte);
|
2015-07-10 06:01:56 -07:00
|
|
|
addConsoleActionSSS("set_bit", setBit);
|
2019-04-08 08:19:07 -07:00
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
addConsoleActionI("get_float", getFloat);
|
|
|
|
addConsoleActionI("get_int", getInt);
|
|
|
|
addConsoleActionI("get_short", getShort);
|
2019-04-08 08:19:07 -07:00
|
|
|
addConsoleActionI("get_byte", getByte);
|
2015-07-10 06:01:56 -07:00
|
|
|
addConsoleActionII("get_bit", getBit);
|
|
|
|
}
|
2019-12-23 19:30:58 -08:00
|
|
|
#endif /* EFI_UNIT_TEST */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-12-23 19:30:58 -08:00
|
|
|
// this method is used by real firmware and simulator and unit test
|
2021-04-21 11:28:48 -07:00
|
|
|
void commonInitEngineController(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
2021-04-21 09:53:13 -07:00
|
|
|
initInterpolation();
|
2019-12-23 19:40:23 -08:00
|
|
|
|
2018-01-30 11:53:13 -08:00
|
|
|
#if EFI_SIMULATOR
|
|
|
|
printf("commonInitEngineController\n");
|
|
|
|
#endif
|
2019-12-23 19:30:58 -08:00
|
|
|
|
|
|
|
#if !EFI_UNIT_TEST
|
2015-07-10 06:01:56 -07:00
|
|
|
initConfigActions();
|
2019-12-23 19:30:58 -08:00
|
|
|
#endif /* EFI_UNIT_TEST */
|
|
|
|
|
2019-12-23 20:32:43 -08:00
|
|
|
#if EFI_ENGINE_CONTROL
|
|
|
|
/**
|
2020-03-26 05:03:55 -07:00
|
|
|
* This has to go after 'enginePins.startPins()' in order to
|
2019-12-23 20:32:43 -08:00
|
|
|
* properly detect un-assigned output pins
|
|
|
|
*/
|
|
|
|
prepareShapes(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
#endif /* EFI_PROD_CODE && EFI_ENGINE_CONTROL */
|
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_SENSOR_CHART
|
2016-05-28 16:02:28 -07:00
|
|
|
initSensorChart();
|
|
|
|
#endif /* EFI_SENSOR_CHART */
|
|
|
|
|
2019-12-23 19:30:58 -08:00
|
|
|
#if EFI_PROD_CODE || EFI_SIMULATOR
|
|
|
|
initSettings();
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
if (hasFirmwareError()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-12-23 19:30:58 -08:00
|
|
|
#endif
|
|
|
|
|
2020-04-26 14:50:03 -07:00
|
|
|
#if !EFI_UNIT_TEST
|
|
|
|
// This is tested independently - don't configure sensors for tests.
|
|
|
|
// This lets us selectively mock them for each test.
|
2021-04-18 17:02:32 -07:00
|
|
|
initNewSensors();
|
2020-04-26 14:50:03 -07:00
|
|
|
#endif /* EFI_UNIT_TEST */
|
|
|
|
|
2021-04-20 11:09:41 -07:00
|
|
|
initSensors(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-04-26 14:50:03 -07:00
|
|
|
|
2021-04-21 11:28:48 -07:00
|
|
|
initAccelEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-04-26 14:50:03 -07:00
|
|
|
|
|
|
|
#if EFI_FSIO
|
2021-04-21 11:28:48 -07:00
|
|
|
initFsioImpl(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-04-26 14:50:03 -07:00
|
|
|
#endif /* EFI_FSIO */
|
|
|
|
|
|
|
|
initGpPwm(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
|
|
|
|
#if EFI_IDLE_CONTROL
|
2021-04-20 11:09:41 -07:00
|
|
|
startIdleThread(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-04-26 14:50:03 -07:00
|
|
|
#endif /* EFI_IDLE_CONTROL */
|
|
|
|
|
2020-09-02 17:17:58 -07:00
|
|
|
initButtonShift(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
|
2021-04-21 09:53:13 -07:00
|
|
|
initButtonDebounce();
|
2020-09-09 00:22:15 -07:00
|
|
|
initStartStopButton(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
|
2020-04-26 14:50:03 -07:00
|
|
|
#if EFI_ELECTRONIC_THROTTLE_BODY
|
|
|
|
initElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
#endif /* EFI_ELECTRONIC_THROTTLE_BODY */
|
|
|
|
|
|
|
|
#if EFI_MAP_AVERAGING
|
|
|
|
if (engineConfiguration->isMapAveragingEnabled) {
|
2021-04-21 11:28:48 -07:00
|
|
|
initMapAveraging(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-04-26 14:50:03 -07:00
|
|
|
}
|
|
|
|
#endif /* EFI_MAP_AVERAGING */
|
|
|
|
|
|
|
|
#if EFI_BOOST_CONTROL
|
2021-04-21 11:28:48 -07:00
|
|
|
initBoostCtrl(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-04-26 14:50:03 -07:00
|
|
|
#endif /* EFI_BOOST_CONTROL */
|
|
|
|
|
|
|
|
#if EFI_LAUNCH_CONTROL
|
2021-04-20 11:09:41 -07:00
|
|
|
initLaunchControl(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-12-04 17:28:48 -08:00
|
|
|
#endif
|
|
|
|
|
2019-12-23 19:50:04 -08:00
|
|
|
#if EFI_SHAFT_POSITION_INPUT
|
|
|
|
/**
|
|
|
|
* there is an implicit dependency on the fact that 'tachometer' listener is the 1st listener - this case
|
|
|
|
* other listeners can access current RPM value
|
|
|
|
*/
|
2021-04-21 11:28:48 -07:00
|
|
|
initRpmCalculator(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2019-12-23 19:50:04 -08:00
|
|
|
#endif /* EFI_SHAFT_POSITION_INPUT */
|
2019-12-23 20:25:08 -08:00
|
|
|
|
|
|
|
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || EFI_SIMULATOR || EFI_UNIT_TEST
|
|
|
|
if (CONFIG(isEngineControlEnabled)) {
|
2021-04-21 11:28:48 -07:00
|
|
|
initAuxValves(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2019-12-23 20:25:08 -08:00
|
|
|
/**
|
2019-12-23 21:26:23 -08:00
|
|
|
* This method adds trigger listener which actually schedules ignition
|
2019-12-23 20:25:08 -08:00
|
|
|
*/
|
2021-04-21 11:28:48 -07:00
|
|
|
initMainEventListener(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-11-09 19:53:46 -08:00
|
|
|
#if EFI_HPFP
|
2020-11-05 13:42:56 -08:00
|
|
|
initHPFP(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-11-09 19:53:23 -08:00
|
|
|
#endif // EFI_HPFP
|
2019-12-23 20:25:08 -08:00
|
|
|
}
|
|
|
|
#endif /* EFI_ENGINE_CONTROL */
|
|
|
|
|
2020-04-01 16:00:56 -07:00
|
|
|
initTachometer(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2016-01-12 19:01:53 -08:00
|
|
|
}
|
|
|
|
|
2021-08-16 03:59:43 -07:00
|
|
|
// Returns false if there's an obvious problem with the loaded configuration
|
|
|
|
bool validateConfig(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
|
|
|
if (CONFIG(specs.cylindersCount) > MAX_CYLINDER_COUNT) {
|
|
|
|
firmwareError(OBD_PCM_Processor_Fault, "Invalid cylinder count: %d", CONFIG(specs.cylindersCount));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fueling
|
|
|
|
{
|
|
|
|
ensureArrayIsAscending("VE load", config->veLoadBins);
|
|
|
|
ensureArrayIsAscending("VE RPM", config->veRpmBins);
|
|
|
|
|
|
|
|
ensureArrayIsAscending("Lambda/AFR load", config->lambdaLoadBins);
|
|
|
|
ensureArrayIsAscending("Lambda/AFR RPM", config->lambdaRpmBins);
|
|
|
|
|
|
|
|
ensureArrayIsAscending("Fuel CLT mult", config->cltFuelCorrBins);
|
|
|
|
ensureArrayIsAscending("Fuel IAT mult", config->iatFuelCorrBins);
|
|
|
|
|
|
|
|
ensureArrayIsAscending("Injection phase load", config->injPhaseLoadBins);
|
|
|
|
ensureArrayIsAscending("Injection phase RPM", config->injPhaseRpmBins);
|
|
|
|
|
|
|
|
ensureArrayIsAscending("TPS/TPS AE from", config->tpsTpsAccelFromRpmBins);
|
|
|
|
ensureArrayIsAscending("TPS/TPS AE to", config->tpsTpsAccelToRpmBins);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignition
|
|
|
|
{
|
|
|
|
ensureArrayIsAscending("Dwell RPM", engineConfiguration->sparkDwellRpmBins);
|
|
|
|
|
|
|
|
ensureArrayIsAscending("Ignition load", config->ignitionLoadBins);
|
|
|
|
ensureArrayIsAscending("Ignition RPM", config->ignitionRpmBins);
|
|
|
|
|
|
|
|
ensureArrayIsAscending("Ignition CLT corr", engineConfiguration->cltTimingBins);
|
|
|
|
|
|
|
|
ensureArrayIsAscending("Ignition IAT corr IAT", config->ignitionIatCorrLoadBins);
|
|
|
|
ensureArrayIsAscending("Ignition IAT corr RPM", config->ignitionIatCorrRpmBins);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config->mapEstimateTpsBins[1] != 0) { // only validate map if not all zeroes default
|
|
|
|
ensureArrayIsAscending("Map estimate TPS", config->mapEstimateTpsBins);
|
|
|
|
}
|
|
|
|
|
2021-08-16 04:21:07 -07:00
|
|
|
if (config->mapEstimateRpmBins[1] != 0) { // only validate map if not all zeroes default
|
|
|
|
ensureArrayIsAscending("Map estimate RPM", config->mapEstimateRpmBins);
|
|
|
|
}
|
|
|
|
|
|
|
|
ensureArrayIsAscending("MAF decoding", config->mafDecodingBins);
|
2021-08-16 03:59:43 -07:00
|
|
|
|
|
|
|
// Cranking tables
|
|
|
|
ensureArrayIsAscending("Cranking fuel mult", config->crankingFuelBins);
|
|
|
|
ensureArrayIsAscending("Cranking duration", config->crankingCycleBins);
|
|
|
|
ensureArrayIsAscending("Cranking TPS", engineConfiguration->crankingTpsBins);
|
|
|
|
|
|
|
|
// Idle tables
|
|
|
|
ensureArrayIsAscending("Idle target RPM", engineConfiguration->cltIdleRpmBins);
|
|
|
|
ensureArrayIsAscending("Idle warmup mult", config->cltIdleCorrBins);
|
2021-08-16 04:21:07 -07:00
|
|
|
if (engineConfiguration->iacCoastingBins[1] != 0) { // only validate map if not all zeroes default
|
|
|
|
ensureArrayIsAscending("Idle coasting position", engineConfiguration->iacCoastingBins);
|
|
|
|
}
|
|
|
|
if (config->idleVeBins[1] != 0) { // only validate map if not all zeroes default
|
|
|
|
ensureArrayIsAscending("Idle VE", config->idleVeBins);
|
|
|
|
}
|
|
|
|
if (config->idleAdvanceBins[1] != 0) { // only validate map if not all zeroes default
|
|
|
|
ensureArrayIsAscending("Idle timing", config->idleAdvanceBins);
|
|
|
|
}
|
|
|
|
|
2021-09-18 19:12:22 -07:00
|
|
|
for (size_t index = 0; index < efi::size(CONFIG(vrThreshold)); index++) {
|
|
|
|
auto& cfg = CONFIG(vrThreshold)[index];
|
|
|
|
|
|
|
|
if (cfg.pin == GPIO_UNASSIGNED) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ensureArrayIsAscending("VR Bins", cfg.rpmBins);
|
|
|
|
ensureArrayIsAscending("VR values", cfg.values);
|
|
|
|
}
|
2021-08-16 03:59:43 -07:00
|
|
|
|
|
|
|
// Boost
|
|
|
|
ensureArrayIsAscending("Boost control TPS", config->boostTpsBins);
|
|
|
|
ensureArrayIsAscending("Boost control RPM", config->boostRpmBins);
|
|
|
|
|
|
|
|
// ETB
|
|
|
|
ensureArrayIsAscending("Pedal map pedal", config->pedalToTpsPedalBins);
|
|
|
|
ensureArrayIsAscending("Pedal map RPM", config->pedalToTpsRpmBins);
|
|
|
|
|
|
|
|
// VVT
|
2021-09-09 11:11:48 -07:00
|
|
|
if (CONFIG(camInputs[0]) != GPIO_UNASSIGNED) {
|
|
|
|
ensureArrayIsAscending("VVT intake load", config->vvtTable1LoadBins);
|
|
|
|
ensureArrayIsAscending("VVT intake RPM", config->vvtTable1RpmBins);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if CAM_INPUTS_COUNT != 1
|
|
|
|
if (CONFIG(camInputs[1]) != GPIO_UNASSIGNED) {
|
|
|
|
ensureArrayIsAscending("VVT exhaust load", config->vvtTable2LoadBins);
|
|
|
|
ensureArrayIsAscending("VVT exhaust RPM", config->vvtTable2RpmBins);
|
|
|
|
}
|
|
|
|
#endif
|
2021-08-16 03:59:43 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-12-23 19:30:58 -08:00
|
|
|
#if !EFI_UNIT_TEST
|
|
|
|
|
2021-04-21 11:28:48 -07:00
|
|
|
void initEngineContoller(DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
2016-01-12 19:01:53 -08:00
|
|
|
addConsoleAction("analoginfo", printAnalogInfo);
|
2019-12-23 20:32:43 -08:00
|
|
|
|
|
|
|
#if EFI_PROD_CODE && EFI_ENGINE_CONTROL
|
2021-04-21 11:28:48 -07:00
|
|
|
initBenchTest();
|
2019-12-23 20:32:43 -08:00
|
|
|
#endif /* EFI_PROD_CODE && EFI_ENGINE_CONTROL */
|
|
|
|
|
2021-04-21 11:28:48 -07:00
|
|
|
commonInitEngineController();
|
2016-01-12 19:01:53 -08:00
|
|
|
|
2019-12-03 22:11:10 -08:00
|
|
|
#if EFI_LOGIC_ANALYZER
|
2015-07-10 06:01:56 -07:00
|
|
|
if (engineConfiguration->isWaveAnalyzerEnabled) {
|
2021-04-21 11:28:48 -07:00
|
|
|
initWaveAnalyzer();
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
2019-12-03 22:11:10 -08:00
|
|
|
#endif /* EFI_LOGIC_ANALYZER */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_CJ125
|
2018-01-22 09:24:03 -08:00
|
|
|
/**
|
|
|
|
* this uses SimplePwm which depends on scheduler, has to be initialized after scheduler
|
|
|
|
*/
|
2021-04-21 11:28:48 -07:00
|
|
|
initCJ125(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2018-11-03 06:44:34 -07:00
|
|
|
#endif /* EFI_CJ125 */
|
2018-01-22 09:24:03 -08:00
|
|
|
|
2016-06-01 17:01:36 -07:00
|
|
|
if (hasFirmwareError()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-13 08:06:03 -07:00
|
|
|
engineStateBlinkingTask.Start();
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-07-28 04:44:44 -07:00
|
|
|
initVrPwm(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_PWM_TESTER
|
2015-07-10 06:01:56 -07:00
|
|
|
initPwmTester();
|
2017-03-19 14:42:15 -07:00
|
|
|
#endif /* EFI_PWM_TESTER */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_ALTERNATOR_CONTROL
|
2021-04-21 11:28:48 -07:00
|
|
|
initAlternatorCtrl(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2020-03-23 17:44:34 -07:00
|
|
|
#endif /* EFI_ALTERNATOR_CONTROL */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_AUX_PID
|
2021-04-20 11:09:41 -07:00
|
|
|
initAuxPid();
|
2020-03-23 17:44:34 -07:00
|
|
|
#endif /* EFI_AUX_PID */
|
2016-06-27 19:02:41 -07:00
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_MALFUNCTION_INDICATOR
|
2016-12-27 21:02:03 -08:00
|
|
|
initMalfunctionIndicator();
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif /* EFI_MALFUNCTION_INDICATOR */
|
|
|
|
|
2018-01-23 05:24:13 -08:00
|
|
|
initEgoAveraging(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_PROD_CODE
|
2015-07-10 06:01:56 -07:00
|
|
|
addConsoleAction("reset_accel", resetAccel);
|
2017-03-19 14:42:15 -07:00
|
|
|
#endif /* EFI_PROD_CODE */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_HD44780_LCD
|
2015-07-10 06:01:56 -07:00
|
|
|
initLcdController();
|
2017-03-19 14:42:15 -07:00
|
|
|
#endif /* EFI_HD44780_LCD */
|
2015-08-19 13:01:36 -07:00
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
2018-03-24 18:13:08 -07:00
|
|
|
|
2020-05-03 09:40:43 -07:00
|
|
|
/**
|
|
|
|
* these two variables are here only to let us know how much RAM is available, also these
|
|
|
|
* help to notice when RAM usage goes up - if a code change adds to RAM usage these variables would fail
|
|
|
|
* linking process which is the way to raise the alarm
|
|
|
|
*
|
|
|
|
* You get "cannot move location counter backwards" linker error when you run out of RAM. When you run out of RAM you shall reduce these
|
2020-08-02 14:21:07 -07:00
|
|
|
* UNUSED_SIZE constants.
|
2020-05-03 09:40:43 -07:00
|
|
|
*/
|
2019-02-06 20:30:53 -08:00
|
|
|
#ifndef RAM_UNUSED_SIZE
|
2021-11-12 19:10:05 -08:00
|
|
|
#define RAM_UNUSED_SIZE 4000
|
2019-02-06 20:30:53 -08:00
|
|
|
#endif
|
|
|
|
#ifndef CCM_UNUSED_SIZE
|
2021-11-11 08:11:40 -08:00
|
|
|
#define CCM_UNUSED_SIZE 2400
|
2019-02-06 20:30:53 -08:00
|
|
|
#endif
|
|
|
|
static char UNUSED_RAM_SIZE[RAM_UNUSED_SIZE];
|
|
|
|
static char UNUSED_CCM_SIZE[CCM_UNUSED_SIZE] CCM_OPTIONAL;
|
2018-03-24 18:13:08 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* See also VCS_VERSION
|
|
|
|
*/
|
|
|
|
int getRusEfiVersion(void) {
|
|
|
|
if (UNUSED_RAM_SIZE[0] != 0)
|
|
|
|
return 123; // this is here to make the compiler happy about the unused array
|
|
|
|
if (UNUSED_CCM_SIZE[0] * 0 != 0)
|
|
|
|
return 3211; // this is here to make the compiler happy about the unused array
|
2019-04-12 19:07:03 -07:00
|
|
|
#if defined(EFI_BOOTLOADER_INCLUDE_CODE)
|
2018-03-24 18:13:08 -07:00
|
|
|
// make bootloader code happy too
|
|
|
|
if (initBootloader() != 0)
|
|
|
|
return 123;
|
|
|
|
#endif /* EFI_BOOTLOADER_INCLUDE_CODE */
|
2020-06-17 09:59:57 -07:00
|
|
|
return VCS_DATE;
|
2018-03-24 18:13:08 -07:00
|
|
|
}
|
2019-04-09 20:00:17 -07:00
|
|
|
#endif /* EFI_UNIT_TEST */
|